Skip to content

Commit

Permalink
For satefulset kafka dispatchers we ignore the replica, since kafka c…
Browse files Browse the repository at this point in the history
…ontroller handles it. also they are not HPAs

Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew committed Sep 19, 2024
1 parent a674567 commit b22253a
Show file tree
Hide file tree
Showing 4 changed files with 13 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
6 changes: 4 additions & 2 deletions pkg/reconciler/common/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ 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 o, the replicas should be controlled by HPAs minReplicas 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",
).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 b22253a

Please sign in to comment.