From 98afaa5528c3f1fe0f28de7fa684b21dcce027a4 Mon Sep 17 00:00:00 2001 From: Knative Prow Robot Date: Fri, 20 Sep 2024 08:13:56 +0100 Subject: [PATCH] [release-1.15] For satefulset kafka dispatchers we ignore the replica (#1891) * For satefulset kafka dispatchers we ignore the replica, since kafka controller handles it. also they are not HPAs Signed-off-by: Matthias Wessendorf * Update pkg/reconciler/common/hpa.go Co-authored-by: Pierangelo Di Pilato * Update function doc Signed-off-by: Matthias Wessendorf --------- Signed-off-by: Matthias Wessendorf Co-authored-by: Matthias Wessendorf Co-authored-by: Pierangelo Di Pilato --- pkg/reconciler/common/ha.go | 2 +- pkg/reconciler/common/hpa.go | 7 +++++-- pkg/reconciler/common/hpa_test.go | 6 ++++++ pkg/reconciler/common/workload_override.go | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/reconciler/common/ha.go b/pkg/reconciler/common/ha.go index 9686086586..0cedaab765 100644 --- a/pkg/reconciler/common/ha.go +++ b/pkg/reconciler/common/ha.go @@ -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 } diff --git a/pkg/reconciler/common/hpa.go b/pkg/reconciler/common/hpa.go index fba4a35cdb..09518fb992 100644 --- a/pkg/reconciler/common/hpa.go +++ b/pkg/reconciler/common/hpa.go @@ -21,9 +21,9 @@ 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", @@ -31,6 +31,9 @@ func hasHorizontalPodAutoscaler(name string) bool { "eventing-webhook", "mt-broker-ingress", "mt-broker-filter", + "kafka-broker-dispatcher", + "kafka-source-dispatcher", + "kafka-channel-dispatcher", ).Has(name) } diff --git a/pkg/reconciler/common/hpa_test.go b/pkg/reconciler/common/hpa_test.go index 41a4154ddf..84d1bbc2e7 100644 --- a/pkg/reconciler/common/hpa_test.go +++ b/pkg/reconciler/common/hpa_test.go @@ -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), diff --git a/pkg/reconciler/common/workload_override.go b/pkg/reconciler/common/workload_override.go index 18ab7a2b84..59e9e418d0 100644 --- a/pkg/reconciler/common/workload_override.go +++ b/pkg/reconciler/common/workload_override.go @@ -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 } } @@ -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 } }