Skip to content

Commit

Permalink
fix(controller): don't set replicas to nil if autoscale is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio committed Jul 4, 2023
1 parent 7684680 commit 2b9df7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ func newNginx(instanceMergedWithFlavors *v1alpha1.RpaasInstance, plan *v1alpha1.
instanceMergedWithFlavors.Spec.Service = mergeServiceWithDNS(instanceMergedWithFlavors)

replicas := instanceMergedWithFlavors.Spec.Replicas
if instanceMergedWithFlavors.Spec.Autoscale != nil {
if isAutoscaleEnabled(instanceMergedWithFlavors.Spec.Autoscale) {
// NOTE: we should avoid changing the number of replicas as it's managed by HPA.
replicas = nil
}
Expand Down
17 changes: 17 additions & 0 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ func Test_newNginx(t *testing.T) {
return n
},
},
"with KEDA configs set but autoscale disabled": {
instance: func(i *v1alpha1.RpaasInstance) *v1alpha1.RpaasInstance {
i.Spec.Replicas = func(n int32) *int32 { return &n }(15)
i.Spec.Autoscale = &v1alpha1.RpaasInstanceAutoscaleSpec{
KEDAOptions: &v1alpha1.AutoscaleKEDAOptions{
Enabled: true,
PrometheusServerAddress: "https://prometheus.example.com",
RPSQueryTemplate: "vector(100)",
},
}
return i
},
expected: func(n *nginxv1alpha1.Nginx) *nginxv1alpha1.Nginx {
n.Spec.Replicas = func(n int32) *int32 { return &n }(15)
return n
},
},
}

for name, tt := range tests {
Expand Down

0 comments on commit 2b9df7f

Please sign in to comment.