Skip to content

Commit b8f3972

Browse files
authored
Remove deprecations and fix CRD columns (#888)
* Remove deprecations and fix CRD columns Signed-off-by: Jorge Turrado <[email protected]> * add missing files Signed-off-by: Jorge Turrado <[email protected]> * add missing files Signed-off-by: Jorge Turrado <[email protected]> * fix duplicated conditions Signed-off-by: Jorge Turrado <[email protected]> * fix style Signed-off-by: Jorge Turrado <[email protected]> * fix space Signed-off-by: Jorge Turrado <[email protected]> * Update changelog Signed-off-by: Jorge Turrado <[email protected]> --------- Signed-off-by: Jorge Turrado <[email protected]>
1 parent 855547a commit b8f3972

File tree

10 files changed

+50
-283
lines changed

10 files changed

+50
-283
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This changelog keeps track of work items that have been completed and are ready
1717

1818
### Breaking Changes
1919

20-
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
20+
- **General**: `host` field has been removed in favor of `hosts` in `HTTPScaledObject` ([#552](https://github.com/kedacore/http-add-on/issues/552)|[#888](https://github.com/kedacore/http-add-on/pull/888))
2121

2222
### New
2323

@@ -44,8 +44,6 @@ New deprecation(s):
4444

4545
Previously announced deprecation(s):
4646

47-
- **General**: `host` field deprecated in favor of `hosts` in `HTTPScaledObject` ([#552](https://github.com/kedacore/http-add-on/issues/552))
48-
4947
### Other
5048

5149
- **General**: Bump golang version ([#853](https://github.com/kedacore/http-add-on/pull/853))

config/crd/bases/http.keda.sh_httpscaledobjects.yaml

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ spec:
1717
scope: Namespaced
1818
versions:
1919
- additionalPrinterColumns:
20-
- jsonPath: .spec.scaleTargetRef.deploymentName
21-
name: ScaleTargetDeploymentName
20+
- jsonPath: .status.targetWorkload
21+
name: TargetWorkload
2222
type: string
23-
- jsonPath: .spec.scaleTargetRef
24-
name: ScaleTargetServiceName
23+
- jsonPath: .status.targetService
24+
name: TargetService
2525
type: string
26-
- jsonPath: .spec.scaleTargetRef
27-
name: ScaleTargetPort
28-
type: integer
2926
- jsonPath: .spec.replicas.min
3027
name: MinReplicas
3128
type: integer
@@ -58,19 +55,12 @@ spec:
5855
spec:
5956
description: HTTPScaledObjectSpec defines the desired state of HTTPScaledObject
6057
properties:
61-
host:
62-
description: (optional) (deprecated) The host to route. All requests
63-
which the "Host" header matches .spec.host and the Request Target
64-
matches any .spec.pathPrefixes will be routed to the Service and
65-
Port specified in the scaleTargetRef. The .spec.host field is mutually
66-
exclusive with the .spec.hosts field.
67-
type: string
6858
hosts:
69-
description: (optional) The hosts to route. All requests which the
70-
"Host" header matches any .spec.hosts and the Request Target matches
71-
any .spec.pathPrefixes will be routed to the Service and Port specified
72-
in the scaleTargetRef. The .spec.hosts field is mutually exclusive
73-
with the .spec.host field.
59+
description: The hosts to route. All requests which the "Host" header
60+
matches any .spec.hosts and the Request Target matches any .spec.pathPrefixes
61+
will be routed to the Service and Port specified in the scaleTargetRef.
62+
The .spec.hosts field is mutually exclusive with the .spec.host
63+
field.
7464
items:
7565
type: string
7666
type: array
@@ -178,6 +168,12 @@ spec:
178168
- type
179169
type: object
180170
type: array
171+
targetService:
172+
description: TargetService reflects details about the scaled service.
173+
type: string
174+
targetWorkload:
175+
description: TargetWorkload reflects details about the scaled workload.
176+
type: string
181177
type: object
182178
type: object
183179
served: true

operator/apis/http/v1alpha1/httpscaledobject_types.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,7 @@ type ReplicaStruct struct {
4747

4848
// HTTPScaledObjectSpec defines the desired state of HTTPScaledObject
4949
type HTTPScaledObjectSpec struct {
50-
// (optional) (deprecated) The host to route. All requests which the "Host"
51-
// header matches .spec.host and the Request Target matches any
52-
// .spec.pathPrefixes will be routed to the Service and Port specified in
53-
// the scaleTargetRef. The .spec.host field is mutually exclusive with the
54-
// .spec.hosts field.
55-
// +optional
56-
Host *string `json:"host,omitempty"`
57-
// (optional) The hosts to route. All requests which the "Host" header
50+
// The hosts to route. All requests which the "Host" header
5851
// matches any .spec.hosts and the Request Target matches any
5952
// .spec.pathPrefixes will be routed to the Service and Port specified in
6053
// the scaleTargetRef. The .spec.hosts field is mutually exclusive with the
@@ -141,16 +134,21 @@ type HTTPScaledObjectCondition struct {
141134

142135
// HTTPScaledObjectStatus defines the observed state of HTTPScaledObject
143136
type HTTPScaledObjectStatus struct {
137+
// TargetWorkload reflects details about the scaled workload.
138+
// +optional
139+
TargetWorkload string `json:"targetWorkload,omitempty" description:"It reflects details about the scaled workload"`
140+
// TargetService reflects details about the scaled service.
141+
// +optional
142+
TargetService string `json:"targetService,omitempty" description:"It reflects details about the scaled service"`
144143
// Conditions of the operator
145144
Conditions []HTTPScaledObjectCondition `json:"conditions,omitempty" description:"List of auditable conditions of the operator"`
146145
}
147146

148147
// +genclient
149148
// +k8s:openapi-gen=true
150149
// +kubebuilder:object:root=true
151-
// +kubebuilder:printcolumn:name="ScaleTargetDeploymentName",type="string",JSONPath=".spec.scaleTargetRef.deploymentName"
152-
// +kubebuilder:printcolumn:name="ScaleTargetServiceName",type="string",JSONPath=".spec.scaleTargetRef"
153-
// +kubebuilder:printcolumn:name="ScaleTargetPort",type="integer",JSONPath=".spec.scaleTargetRef"
150+
// +kubebuilder:printcolumn:name="TargetWorkload",type="string",JSONPath=".status.targetWorkload"
151+
// +kubebuilder:printcolumn:name="TargetService",type="string",JSONPath=".status.targetService"
154152
// +kubebuilder:printcolumn:name="MinReplicas",type="integer",JSONPath=".spec.replicas.min"
155153
// +kubebuilder:printcolumn:name="MaxReplicas",type="integer",JSONPath=".spec.replicas.max"
156154
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

operator/apis/http/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/controllers/http/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateApplicationResources(
3030
)
3131

3232
// set initial statuses
33-
AddCondition(
33+
AddOrUpdateCondition(
3434
httpso,
3535
*SetMessage(
3636
CreateCondition(

operator/controllers/http/condition_provider.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@ func SaveStatus(
2929
}
3030
}
3131

32-
// AddCondition adds a new condition to the HTTPScaledObject
33-
func AddCondition(httpso *httpv1alpha1.HTTPScaledObject, condition httpv1alpha1.HTTPScaledObjectCondition) *httpv1alpha1.HTTPScaledObject {
34-
httpso.Status.Conditions = append(httpso.Status.Conditions, condition)
32+
// AddOrUpdateCondition adds or update a condition to the HTTPScaledObject
33+
func AddOrUpdateCondition(httpso *httpv1alpha1.HTTPScaledObject, condition httpv1alpha1.HTTPScaledObjectCondition) *httpv1alpha1.HTTPScaledObject {
34+
found := false
35+
for i := range httpso.Status.Conditions {
36+
if httpso.Status.Conditions[i].Reason == condition.Reason {
37+
found = true
38+
httpso.Status.Conditions[i] = condition
39+
}
40+
}
41+
if !found {
42+
httpso.Status.Conditions = append(httpso.Status.Conditions, condition)
43+
}
3544
return httpso
3645
}
3746

operator/controllers/http/httpscaledobject_controller.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package http
1919
import (
2020
"context"
2121
"errors"
22+
"fmt"
2223
"time"
2324

2425
appsv1 "k8s.io/api/apps/v1"
@@ -86,11 +87,6 @@ func (r *HTTPScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Req
8687
return ctrl.Result{}, err
8788
}
8889

89-
// TODO(pedrotorres): delete this on v0.6.0
90-
if httpso.Spec.Host != nil {
91-
logger.Info(".spec.host is deprecated, performing automated migration to .spec.hosts")
92-
return ctrl.Result{}, r.migrateHost(ctx, httpso)
93-
}
9490
// TODO(jorturfer): delete this for v0.9.0
9591
if httpso.Spec.ScaleTargetRef.Name == "" ||
9692
httpso.Spec.ScaleTargetRef.Kind == "" ||
@@ -99,6 +95,10 @@ func (r *HTTPScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Req
9995
return ctrl.Result{}, r.migrateTargetRef(ctx, httpso)
10096
}
10197

98+
// update status
99+
httpso.Status.TargetWorkload = fmt.Sprintf("%s/%s/%s", httpso.Spec.ScaleTargetRef.APIVersion, httpso.Spec.ScaleTargetRef.Kind, httpso.Spec.ScaleTargetRef.Name)
100+
httpso.Status.TargetService = fmt.Sprintf("%s:%d", httpso.Spec.ScaleTargetRef.Service, httpso.Spec.ScaleTargetRef.Port)
101+
102102
// httpso is updated now
103103
logger.Info(
104104
"Reconciling HTTPScaledObject",
@@ -125,7 +125,7 @@ func (r *HTTPScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Req
125125
ctx,
126126
logger,
127127
r.Client,
128-
AddCondition(
128+
AddOrUpdateCondition(
129129
httpso,
130130
*SetMessage(
131131
CreateCondition(
@@ -150,18 +150,6 @@ func (r *HTTPScaledObjectReconciler) SetupWithManager(mgr ctrl.Manager) error {
150150
Complete(r)
151151
}
152152

153-
// TODO(pedrotorres): delete this on v0.6.0
154-
func (r *HTTPScaledObjectReconciler) migrateHost(ctx context.Context, httpso *httpv1alpha1.HTTPScaledObject) error {
155-
if (httpso.Spec.Hosts != nil) == (httpso.Spec.Host != nil) {
156-
return errors.New("exactly one of .spec.host and .spec.hosts must be set")
157-
}
158-
httpso.Spec.Hosts = []string{
159-
*httpso.Spec.Host,
160-
}
161-
httpso.Spec.Host = nil
162-
return r.Client.Update(ctx, httpso)
163-
}
164-
165153
// TODO(jorturfer): delete this for v0.9.0
166154
func (r *HTTPScaledObjectReconciler) migrateTargetRef(ctx context.Context, httpso *httpv1alpha1.HTTPScaledObject) error {
167155
if (httpso.Spec.ScaleTargetRef.Deployment != "") == (httpso.Spec.ScaleTargetRef.Name != "") {

operator/controllers/http/scaled_object.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package http
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/go-logr/logr"
87
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
@@ -75,7 +74,7 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateScaledObject(
7574
return err
7675
}
7776
} else {
78-
AddCondition(
77+
AddOrUpdateCondition(
7978
httpso,
8079
*SetMessage(
8180
CreateCondition(
@@ -92,7 +91,7 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateScaledObject(
9291
}
9392
}
9493

95-
AddCondition(
94+
AddOrUpdateCondition(
9695
httpso,
9796
*SetMessage(
9897
CreateCondition(
@@ -103,43 +102,5 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateScaledObject(
103102
"App ScaledObject created",
104103
),
105104
)
106-
107-
return r.purgeLegacySO(ctx, cl, logger, httpso)
108-
}
109-
110-
// TODO(pedrotorres): delete this on v0.6.0
111-
func (r *HTTPScaledObjectReconciler) purgeLegacySO(
112-
ctx context.Context,
113-
cl client.Client,
114-
logger logr.Logger,
115-
httpso *httpv1alpha1.HTTPScaledObject,
116-
) error {
117-
legacyName := fmt.Sprintf("%s-app", httpso.GetName())
118-
legacyKey := client.ObjectKey{
119-
Namespace: httpso.GetNamespace(),
120-
Name: legacyName,
121-
}
122-
123-
var legacySO kedav1alpha1.ScaledObject
124-
if err := cl.Get(ctx, legacyKey, &legacySO); err != nil {
125-
if errors.IsNotFound(err) {
126-
logger.Info("legacy ScaledObject not found")
127-
return nil
128-
}
129-
130-
logger.Error(err, "failed getting legacy ScaledObject")
131-
return err
132-
}
133-
134-
if err := cl.Delete(ctx, &legacySO); err != nil {
135-
if errors.IsNotFound(err) {
136-
logger.Info("legacy ScaledObject not found")
137-
return nil
138-
}
139-
140-
logger.Error(err, "failed deleting legacy ScaledObject")
141-
return err
142-
}
143-
144105
return nil
145106
}

tests/checks/path_prefix/path_prefix_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ metadata:
107107
name: {{.HTTPScaledObjectName}}
108108
namespace: {{.TestNamespace}}
109109
spec:
110-
host: {{.Host}}
110+
hosts:
111+
- {{.Host}}
111112
pathPrefixes:
112113
- {{.PathPrefix0}}
113114
- {{.PathPrefix1}}
@@ -180,7 +181,8 @@ metadata:
180181
name: {{.HTTPScaledObjectName}}-2
181182
namespace: {{.TestNamespace}}
182183
spec:
183-
host: {{.Host}}
184+
hosts:
185+
- {{.Host}}
184186
pathPrefixes:
185187
- {{.PathPrefix2}}
186188
targetPendingRequests: 100

0 commit comments

Comments
 (0)