Skip to content

Commit

Permalink
[release-1.14] For satefulset kafka dispatchers we ignore the replica (
Browse files Browse the repository at this point in the history
…#1890)

* For satefulset kafka dispatchers we ignore the replica, since kafka controller handles it. also they are not HPAs

Signed-off-by: Matthias Wessendorf <[email protected]>

* Update pkg/reconciler/common/hpa.go

Co-authored-by: Pierangelo Di Pilato <[email protected]>

* Update function doc

Signed-off-by: Matthias Wessendorf <[email protected]>

---------

Signed-off-by: Matthias Wessendorf <[email protected]>
Co-authored-by: Matthias Wessendorf <[email protected]>
Co-authored-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent b35b75c commit b9f02a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/common/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func HighAvailabilityTransform(obj base.KComponent) mf.Transformer {
replicas := int64(*ha.Replicas)

// Transform deployments that support HA.
if u.GetKind() == "Deployment" && !haUnSupported(u.GetName()) && !hasHorizontalPodAutoscaler(u.GetName()) {
if u.GetKind() == "Deployment" && !haUnSupported(u.GetName()) && !hasHorizontalPodOrCustomAutoscaler(u.GetName()) {
if err := unstructured.SetNestedField(u.Object, replicas, "spec", "replicas"); err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/reconciler/common/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)

// When a Podspecable has HPA, the replicas should be controlled by HPAs minReplicas instead of operator.
// When a Podspecable has HPA or a custom autoscaling, the replicas should be controlled by it instead of operator.
// Hence, skip changing the spec.replicas for these Podspecables.
func hasHorizontalPodAutoscaler(name string) bool {
func hasHorizontalPodOrCustomAutoscaler(name string) bool {
return sets.NewString(
"webhook",
"activator",
"3scale-kourier-gateway",
"eventing-webhook",
"mt-broker-ingress",
"mt-broker-filter",
"kafka-broker-dispatcher",
"kafka-source-dispatcher",
"kafka-channel-dispatcher",
).Has(name)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/common/hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func TestHpaTransform(t *testing.T) {
replicas: 5,
expected: makeUnstructuredDeployment(t, "not-a-hpa"),
err: nil,
}, {
name: "Kafka Dispatcher is custom autoscaler",
in: makeUnstructuredDeployment(t, "kafka-source-dispatcher"),
replicas: 5,
expected: makeUnstructuredDeploymentReplicas(t, "kafka-source-dispatcher", 1),
err: nil,
}, {
name: "minReplicas same as override",
in: makeUnstructuredHPA(t, "hpa", 1, 2),
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/common/workload_override.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func OverridesTransform(overrides []base.WorkloadOverride, log *zap.SugaredLogge
ps = &deployment.Spec.Template

// Do not set replicas, if this resource is controlled by a HPA
if override.Replicas != nil && !hasHorizontalPodAutoscaler(override.Name) {
if override.Replicas != nil && !hasHorizontalPodOrCustomAutoscaler(override.Name) {
deployment.Spec.Replicas = override.Replicas
}
}
Expand All @@ -62,7 +62,7 @@ func OverridesTransform(overrides []base.WorkloadOverride, log *zap.SugaredLogge
ps = &ss.Spec.Template

// Do not set replicas, if this resource is controlled by a HPA
if override.Replicas != nil && !hasHorizontalPodAutoscaler(override.Name) {
if override.Replicas != nil && !hasHorizontalPodOrCustomAutoscaler(override.Name) {
ss.Spec.Replicas = override.Replicas
}
}
Expand Down

0 comments on commit b9f02a6

Please sign in to comment.