From cf2c4a98eb414d0269161c6fc7fb6c4d349d053d Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Mon, 24 Jun 2024 15:31:42 +0200 Subject: [PATCH] feat!: remove deprecated `spec.scaleTarget.deployment` field (#1060) Signed-off-by: Zbynek Roubalik --- CHANGELOG.md | 2 +- .../bases/http.keda.sh_httpscaledobjects.yaml | 6 +--- interceptor/proxy_handlers_test.go | 18 +++++------ .../http/v1alpha1/httpscaledobject_types.go | 5 +-- .../http/httpscaledobject_controller.go | 32 ------------------- operator/controllers/http/suite_test.go | 6 ++-- .../ingress_in_app_namespace_test.go | 2 +- .../ingress_in_keda_namespace_test.go | 2 +- .../interceptor_otel_metrics_test.go | 2 +- .../interceptor_prometheus_metrics_test.go | 2 +- .../interceptor_tls/interceptor_tls_test.go | 2 +- .../internal_service/internal_service_test.go | 2 +- .../multiple_hosts/multiple_hosts_test.go | 2 +- tests/checks/path_prefix/path_prefix_test.go | 4 +-- 14 files changed, 24 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d96f68..891e04e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ This changelog keeps track of work items that have been completed and are ready ### Breaking Changes -- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO)) +- **General**: Drop support for deprecated field `spec.scaleTargetRef.deployment` ([#1061](https://github.com/kedacore/http-add-on/issues/1061)) ### New diff --git a/config/crd/bases/http.keda.sh_httpscaledobjects.yaml b/config/crd/bases/http.keda.sh_httpscaledobjects.yaml index de61304b..2c48f3ef 100644 --- a/config/crd/bases/http.keda.sh_httpscaledobjects.yaml +++ b/config/crd/bases/http.keda.sh_httpscaledobjects.yaml @@ -98,10 +98,6 @@ spec: properties: apiVersion: type: string - deployment: - description: 'Deprecated: The name of the deployment to scale - according to HTTP traffic' - type: string kind: type: string name: @@ -152,7 +148,7 @@ spec: type: object type: object targetPendingRequests: - description: (optional) DEPRECATED (use SscalingMetric instead) Target + description: (optional) DEPRECATED (use ScalingMetric instead) Target metric value format: int32 type: integer diff --git a/interceptor/proxy_handlers_test.go b/interceptor/proxy_handlers_test.go index a09517ca..d4a5e41e 100644 --- a/interceptor/proxy_handlers_test.go +++ b/interceptor/proxy_handlers_test.go @@ -236,9 +236,9 @@ func TestWaitFailedConnectionTLS(t *testing.T) { }, Spec: httpv1alpha1.HTTPScaledObjectSpec{ ScaleTargetRef: httpv1alpha1.ScaleTargetRef{ - Deployment: "nosuchdepl", - Service: "nosuchdepl", - Port: 8081, + Name: "nosuchdepl", + Service: "nosuchdepl", + Port: 8081, }, TargetPendingRequests: ptr.To[int32](1234), }, @@ -359,9 +359,9 @@ func TestTimesOutOnWaitFuncTLS(t *testing.T) { }, Spec: httpv1alpha1.HTTPScaledObjectSpec{ ScaleTargetRef: httpv1alpha1.ScaleTargetRef{ - Deployment: "nosuchdepl", - Service: "nosuchsvc", - Port: 9091, + Name: "nosuchdepl", + Service: "nosuchsvc", + Port: 9091, }, TargetPendingRequests: ptr.To[int32](1234), }, @@ -634,9 +634,9 @@ func TestWaitHeaderTimeoutTLS(t *testing.T) { }, Spec: httpv1alpha1.HTTPScaledObjectSpec{ ScaleTargetRef: httpv1alpha1.ScaleTargetRef{ - Deployment: "nosuchdepl", - Service: "testsvc", - Port: 9094, + Name: "nosuchdepl", + Service: "testsvc", + Port: 9094, }, TargetPendingRequests: ptr.To[int32](1234), }, diff --git a/operator/apis/http/v1alpha1/httpscaledobject_types.go b/operator/apis/http/v1alpha1/httpscaledobject_types.go index 3187054b..0b2b039b 100644 --- a/operator/apis/http/v1alpha1/httpscaledobject_types.go +++ b/operator/apis/http/v1alpha1/httpscaledobject_types.go @@ -22,9 +22,6 @@ import ( // ScaleTargetRef contains all the details about an HTTP application to scale and route to type ScaleTargetRef struct { - // Deprecated: The name of the deployment to scale according to HTTP traffic - // +optional - Deployment string `json:"deployment"` // +optional Name string `json:"name"` // +optional @@ -95,7 +92,7 @@ type HTTPScaledObjectSpec struct { // (optional) Replica information // +optional Replicas *ReplicaStruct `json:"replicas,omitempty"` - // (optional) DEPRECATED (use SscalingMetric instead) Target metric value + // (optional) DEPRECATED (use ScalingMetric instead) Target metric value // +optional TargetPendingRequests *int32 `json:"targetPendingRequests,omitempty" description:"The target metric value for the HPA (Default 100)"` // (optional) Cooldown period value diff --git a/operator/controllers/http/httpscaledobject_controller.go b/operator/controllers/http/httpscaledobject_controller.go index 6951d8be..317d69f6 100644 --- a/operator/controllers/http/httpscaledobject_controller.go +++ b/operator/controllers/http/httpscaledobject_controller.go @@ -18,12 +18,10 @@ package http import ( "context" - "errors" "fmt" "time" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" - appsv1 "k8s.io/api/apps/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -36,7 +34,6 @@ import ( httpv1alpha1 "github.com/kedacore/http-add-on/operator/apis/http/v1alpha1" "github.com/kedacore/http-add-on/operator/controllers/http/config" "github.com/kedacore/http-add-on/operator/controllers/util" - "github.com/kedacore/http-add-on/pkg/k8s" ) // HTTPScaledObjectReconciler reconciles a HTTPScaledObject object @@ -89,14 +86,6 @@ func (r *HTTPScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, err } - // TODO(jorturfer): delete this for v0.9.0 - if httpso.Spec.ScaleTargetRef.Name == "" || - httpso.Spec.ScaleTargetRef.Kind == "" || - httpso.Spec.ScaleTargetRef.APIVersion == "" { - logger.Info(".spec.scaleTargetRef.Deployment is deprecated, performing automated migration") - return ctrl.Result{}, r.migrateTargetRef(ctx, httpso) - } - // update status httpso.Status.TargetWorkload = fmt.Sprintf("%s/%s/%s", httpso.Spec.ScaleTargetRef.APIVersion, httpso.Spec.ScaleTargetRef.Kind, httpso.Spec.ScaleTargetRef.Name) httpso.Status.TargetService = fmt.Sprintf("%s:%d", httpso.Spec.ScaleTargetRef.Service, httpso.Spec.ScaleTargetRef.Port) @@ -173,24 +162,3 @@ func (r *HTTPScaledObjectReconciler) SetupWithManager(mgr ctrl.Manager) error { ))). Complete(r) } - -// TODO(jorturfer): delete this for v0.9.0 -func (r *HTTPScaledObjectReconciler) migrateTargetRef(ctx context.Context, httpso *httpv1alpha1.HTTPScaledObject) error { - if (httpso.Spec.ScaleTargetRef.Deployment != "") == (httpso.Spec.ScaleTargetRef.Name != "") { - return errors.New("exactly one of .spec.scaleTargetRef.deployment and .spec.scaleTargetRef.name must be set") - } - - if httpso.Spec.ScaleTargetRef.Name == "" { - httpso.Spec.ScaleTargetRef.Name = httpso.Spec.ScaleTargetRef.Deployment - } - if httpso.Spec.ScaleTargetRef.Kind == "" { - httpso.Spec.ScaleTargetRef.Kind = k8s.ObjectKind(&appsv1.Deployment{}) - } - if httpso.Spec.ScaleTargetRef.APIVersion == "" { - httpso.Spec.ScaleTargetRef.APIVersion = appsv1.SchemeGroupVersion.Identifier() - } - - httpso.Spec.ScaleTargetRef.Deployment = "" - - return r.Client.Update(ctx, httpso) -} diff --git a/operator/controllers/http/suite_test.go b/operator/controllers/http/suite_test.go index e7e1e09b..53e1d781 100644 --- a/operator/controllers/http/suite_test.go +++ b/operator/controllers/http/suite_test.go @@ -152,9 +152,9 @@ func newCommonTestInfraWithSkipScaledObjectCreation(namespace, appName string) * }, Spec: httpv1alpha1.HTTPScaledObjectSpec{ ScaleTargetRef: httpv1alpha1.ScaleTargetRef{ - Deployment: appName, - Service: appName, - Port: 8081, + Name: appName, + Service: appName, + Port: 8081, }, Hosts: []string{"myhost1.com", "myhost2.com"}, }, diff --git a/tests/checks/ingress_in_app_namespace/ingress_in_app_namespace_test.go b/tests/checks/ingress_in_app_namespace/ingress_in_app_namespace_test.go index 7f886b87..56d7b25f 100644 --- a/tests/checks/ingress_in_app_namespace/ingress_in_app_namespace_test.go +++ b/tests/checks/ingress_in_app_namespace/ingress_in_app_namespace_test.go @@ -160,7 +160,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: diff --git a/tests/checks/ingress_in_keda_namespace/ingress_in_keda_namespace_test.go b/tests/checks/ingress_in_keda_namespace/ingress_in_keda_namespace_test.go index 11b7db65..e03e0de7 100644 --- a/tests/checks/ingress_in_keda_namespace/ingress_in_keda_namespace_test.go +++ b/tests/checks/ingress_in_keda_namespace/ingress_in_keda_namespace_test.go @@ -148,7 +148,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: diff --git a/tests/checks/interceptor_otel_metrics/interceptor_otel_metrics_test.go b/tests/checks/interceptor_otel_metrics/interceptor_otel_metrics_test.go index c0caae9c..46882756 100644 --- a/tests/checks/interceptor_otel_metrics/interceptor_otel_metrics_test.go +++ b/tests/checks/interceptor_otel_metrics/interceptor_otel_metrics_test.go @@ -127,7 +127,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: diff --git a/tests/checks/interceptor_prometheus_metrics/interceptor_prometheus_metrics_test.go b/tests/checks/interceptor_prometheus_metrics/interceptor_prometheus_metrics_test.go index 52981265..a8c936ed 100644 --- a/tests/checks/interceptor_prometheus_metrics/interceptor_prometheus_metrics_test.go +++ b/tests/checks/interceptor_prometheus_metrics/interceptor_prometheus_metrics_test.go @@ -126,7 +126,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: diff --git a/tests/checks/interceptor_tls/interceptor_tls_test.go b/tests/checks/interceptor_tls/interceptor_tls_test.go index 8ae88b8f..48bba494 100644 --- a/tests/checks/interceptor_tls/interceptor_tls_test.go +++ b/tests/checks/interceptor_tls/interceptor_tls_test.go @@ -125,7 +125,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8443 replicas: diff --git a/tests/checks/internal_service/internal_service_test.go b/tests/checks/internal_service/internal_service_test.go index 41e224ba..9886f6b2 100644 --- a/tests/checks/internal_service/internal_service_test.go +++ b/tests/checks/internal_service/internal_service_test.go @@ -120,7 +120,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: diff --git a/tests/checks/multiple_hosts/multiple_hosts_test.go b/tests/checks/multiple_hosts/multiple_hosts_test.go index e4f4315f..46b514c7 100644 --- a/tests/checks/multiple_hosts/multiple_hosts_test.go +++ b/tests/checks/multiple_hosts/multiple_hosts_test.go @@ -126,7 +126,7 @@ spec: concurrency: targetValue: 20 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: diff --git a/tests/checks/path_prefix/path_prefix_test.go b/tests/checks/path_prefix/path_prefix_test.go index 4c11bd18..d11f7316 100644 --- a/tests/checks/path_prefix/path_prefix_test.go +++ b/tests/checks/path_prefix/path_prefix_test.go @@ -115,7 +115,7 @@ spec: targetPendingRequests: 100 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}} + name: {{.DeploymentName}} service: {{.ServiceName}} port: 8080 replicas: @@ -190,7 +190,7 @@ spec: targetValue: 20 scaledownPeriod: 10 scaleTargetRef: - deployment: {{.DeploymentName}}-2 + name: {{.DeploymentName}}-2 service: {{.ServiceName}}-2 port: 8080 replicas: