Skip to content

Commit

Permalink
hpa: Do not set replicas to 2 when override set to null (PROJQUAY-6474)
Browse files Browse the repository at this point in the history
- When replicas override is set to null, the deployment should not be edited
  • Loading branch information
jonathankingfc committed Aug 26, 2024
1 parent 5a9b970 commit 9b57412
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 6 additions & 1 deletion apis/quay/v1/quayregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

quaycontext "github.com/quay/quay-operator/pkg/context"
Expand Down Expand Up @@ -754,14 +755,18 @@ func init() {
}

// GetReplicasOverrideForComponent returns the overrides set by the user for the provided
// component. Returns nil if not set.
// component. Returns nil if not set. Returns -1 if the override is set to nil.
func GetReplicasOverrideForComponent(quay *QuayRegistry, kind ComponentKind) *int32 {
for _, cmp := range quay.Spec.Components {
if cmp.Kind != kind {
continue
}

if cmp.Overrides == nil {
return ptr.To[int32](2)
}

if cmp.Overrides.Replicas == nil {
return nil
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"

Expand Down Expand Up @@ -122,12 +121,11 @@ func Process(quay *v1.QuayRegistry, qctx *quaycontext.QuayRegistryContext, obj c
// if no number of replicas has been set in kustomization files
// we set its value to two or to the value provided by the user
// as an override (if provided).
desired := ptr.To[int32](2)

if r := v1.GetReplicasOverrideForComponent(quay, kind); r != nil {
desired = r
dep.Spec.Replicas = r
}

dep.Spec.Replicas = desired
break
}
}
Expand Down

0 comments on commit 9b57412

Please sign in to comment.