Skip to content

Commit

Permalink
feat!: remove deprecated spec.scaleTarget.deployment field (#1060)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik authored Jun 24, 2024
1 parent 84a9560 commit cf2c4a9
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 63 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 1 addition & 5 deletions config/crd/bases/http.keda.sh_httpscaledobjects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions interceptor/proxy_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down
5 changes: 1 addition & 4 deletions operator/apis/http/v1alpha1/httpscaledobject_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions operator/controllers/http/httpscaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions operator/controllers/http/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down
2 changes: 1 addition & 1 deletion tests/checks/interceptor_tls/interceptor_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8443
replicas:
Expand Down
2 changes: 1 addition & 1 deletion tests/checks/internal_service/internal_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down
2 changes: 1 addition & 1 deletion tests/checks/multiple_hosts/multiple_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ spec:
concurrency:
targetValue: 20
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down
4 changes: 2 additions & 2 deletions tests/checks/path_prefix/path_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ spec:
targetPendingRequests: 100
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}
name: {{.DeploymentName}}
service: {{.ServiceName}}
port: 8080
replicas:
Expand Down Expand Up @@ -190,7 +190,7 @@ spec:
targetValue: 20
scaledownPeriod: 10
scaleTargetRef:
deployment: {{.DeploymentName}}-2
name: {{.DeploymentName}}-2
service: {{.ServiceName}}-2
port: 8080
replicas:
Expand Down

0 comments on commit cf2c4a9

Please sign in to comment.