From 1278582ff8c6f0701e30832a96ff449ad2a18295 Mon Sep 17 00:00:00 2001 From: shudeshp Date: Thu, 31 Oct 2024 16:53:54 -0400 Subject: [PATCH] bugfix: updated quayComponentLabel generation for HPA --- pkg/middleware/middleware.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index 86f02cded..2e0eae9bf 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -34,7 +34,27 @@ func Process(quay *v1.QuayRegistry, qctx *quaycontext.QuayRegistryContext, obj c return nil, err } - quayComponentLabel := labels.Set(objectMeta.GetLabels()).Get("quay-component") + quayComponentLabel := "" + + if hpa, ok := obj.(*autoscalingv2.HorizontalPodAutoscaler); ok { + // HPA may have its own specific labels that are not necessarily present in the standard object metadata. + // Therefore, we need to check both labels and annotations specifically for HPA to ensure we capture the correct quay-component label. + if labels := hpa.GetLabels(); labels != nil { + if labelValue, exists := labels["quay-component"]; exists { + quayComponentLabel = labelValue + } + } + + if quayComponentLabel == "" { + if annotations := hpa.GetAnnotations(); annotations != nil { + if annotationValue, exists := annotations["quay-component"]; exists { + quayComponentLabel = annotationValue + } + } + } + } else { + quayComponentLabel = labels.Set(objectMeta.GetLabels()).Get("quay-component") + } // Flatten config bundle `Secret` if strings.Contains(objectMeta.GetName(), configSecretPrefix+"-") {