Skip to content

Commit

Permalink
feat: Propagate HTTPScaledObject labels and annotations to ScaledObje…
Browse files Browse the repository at this point in the history
…ct (#899)
  • Loading branch information
JorTurFer authored Jan 27, 2024
1 parent d9277ab commit 6453b18
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ This changelog keeps track of work items that have been completed and are ready
## Unreleased

### Breaking Changes

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))

### New

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
- **General**: Propagate HTTPScaledObject labels and annotations to ScaledObject ([#840](https://github.com/kedacore/http-add-on/issues/840))

### Improvements

Expand All @@ -37,11 +38,10 @@ You can find all deprecations in [this overview](https://github.com/kedacore/htt

New deprecation(s):

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))

Previously announced deprecation(s):

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
- **General**: Deprecated `KEDA_HTTP_DEPLOYMENT_CACHE_POLLING_INTERVAL_MS` in favor of `KEDA_HTTP_ENDPOINTS_CACHE_POLLING_INTERVAL_MS` ([#438](https://github.com/kedacore/http-add-on/issues/438))

### Other

Expand Down
2 changes: 2 additions & 0 deletions operator/controllers/http/scaled_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateScaledObject(
appScaledObject := k8s.NewScaledObject(
httpso.GetNamespace(),
httpso.GetName(), // HTTPScaledObject name is the same as the ScaledObject name
httpso.Labels,
httpso.Annotations,
httpso.Spec.ScaleTargetRef,
externalScalerHostName,
httpso.Spec.Hosts,
Expand Down
24 changes: 24 additions & 0 deletions operator/controllers/http/scaled_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func TestCreateOrUpdateScaledObject(t *testing.T) {
metadata.Name,
)

r.EqualValues(
testInfra.httpso.ObjectMeta.Labels,
metadata.Labels,
)

r.EqualValues(
testInfra.httpso.ObjectMeta.Annotations,
metadata.Annotations,
)

var minReplicaCount *int32
var maxReplicaCount *int32
if replicas := testInfra.httpso.Spec.Replicas; replicas != nil {
Expand Down Expand Up @@ -98,6 +108,8 @@ func TestCreateOrUpdateScaledObject(t *testing.T) {
}
*testInfra.httpso.Spec.Replicas.Min++
*testInfra.httpso.Spec.Replicas.Max++
testInfra.httpso.ObjectMeta.Labels["test"] = "test-label"
testInfra.httpso.ObjectMeta.Annotations["test"] = "test-annotation"
r.NoError(reconciller.createOrUpdateScaledObject(
testInfra.ctx,
testInfra.cl,
Expand All @@ -114,6 +126,18 @@ func TestCreateOrUpdateScaledObject(t *testing.T) {
testInfra.httpso,
)
r.NoError(err)

metadata = retSO.ObjectMeta
r.EqualValues(
testInfra.httpso.ObjectMeta.Labels,
metadata.Labels,
)

r.EqualValues(
testInfra.httpso.ObjectMeta.Annotations,
metadata.Annotations,
)

spec = retSO.Spec
r.Equal(
*testInfra.httpso.Spec.Replicas.Min,
Expand Down
6 changes: 6 additions & 0 deletions operator/controllers/http/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func newCommonTestInfra(namespace, appName string) *commonTestInfra {
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: appName,
Labels: map[string]string{
"label": "a",
},
Annotations: map[string]string{
"annotation": "b",
},
},
Spec: httpv1alpha1.HTTPScaledObjectSpec{
ScaleTargetRef: httpv1alpha1.ScaleTargetRef{
Expand Down
8 changes: 6 additions & 2 deletions pkg/k8s/scaledobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
func NewScaledObject(
namespace string,
name string,
labels map[string]string,
annotations map[string]string,
workloadRef v1alpha1.ScaleTargetRef,
scalerAddress string,
hosts []string,
Expand All @@ -37,8 +39,10 @@ func NewScaledObject(
Kind: ObjectKind(&kedav1alpha1.ScaledObject{}),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
Namespace: namespace,
Name: name,
Labels: labels,
Annotations: annotations,
},
Spec: kedav1alpha1.ScaledObjectSpec{
ScaleTargetRef: &kedav1alpha1.ScaleTarget{
Expand Down

0 comments on commit 6453b18

Please sign in to comment.