From c8c109e07e80dea316b1c7446ca506229a87ddb6 Mon Sep 17 00:00:00 2001 From: Walter Fender Date: Wed, 6 Nov 2024 22:15:02 +0000 Subject: [PATCH] Factored in Justin's feedback. --- ...nrm.cloud.google.com_controllerreconcilers.yaml | 4 ++-- ...google.com_namespacedcontrollerreconcilers.yaml | 4 ++-- .../v1alpha1/controllerreconciler_types.go | 8 ++++---- .../configconnector/configconnector_controller.go | 4 ++-- .../configconnectorcontext_controller.go | 4 ++-- operator/pkg/controllers/utils.go | 14 +++++++++++--- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_controllerreconcilers.yaml b/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_controllerreconcilers.yaml index d7eba76dcb..71e2f3dfbf 100644 --- a/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_controllerreconcilers.yaml +++ b/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_controllerreconcilers.yaml @@ -41,8 +41,8 @@ spec: spec: description: ControllerReconcilerSpec is the specification of ControllerReconciler. properties: - pprofConfig: - description: PprofConfigures the debug endpoint on the service. + pprof: + description: Configures the debug endpoint on the service. properties: pprofPort: description: The port that the pprof server binds to if enabled diff --git a/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_namespacedcontrollerreconcilers.yaml b/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_namespacedcontrollerreconcilers.yaml index 53904a0347..12375d8ba5 100644 --- a/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_namespacedcontrollerreconcilers.yaml +++ b/operator/config/crd/bases/customize.core.cnrm.cloud.google.com_namespacedcontrollerreconcilers.yaml @@ -41,8 +41,8 @@ spec: spec: description: NamespacedControllerReconciler is the specification of NamespacedControllerReconciler. properties: - pprofConfig: - description: PprofConfigures the debug endpoint on the service. + pprof: + description: Configures the debug endpoint on the service. properties: pprofPort: description: The port that the pprof server binds to if enabled diff --git a/operator/pkg/apis/core/customize/v1alpha1/controllerreconciler_types.go b/operator/pkg/apis/core/customize/v1alpha1/controllerreconciler_types.go index de540e5b64..0def1b0c14 100644 --- a/operator/pkg/apis/core/customize/v1alpha1/controllerreconciler_types.go +++ b/operator/pkg/apis/core/customize/v1alpha1/controllerreconciler_types.go @@ -41,9 +41,9 @@ type NamespacedControllerReconcilerSpec struct { // If not specified, the default will be Token Bucket with qps 20, burst 30. // +optional RateLimit *RateLimit `json:"rateLimit,omitempty"` - // PprofConfigures the debug endpoint on the service. + // Configures the debug endpoint on the service. // +optional - PprofConfig *PprofConfig `json:"pprofConfig,omitempty"` + Pprof *PprofConfig `json:"pprof,omitempty"` } type RateLimit struct { @@ -105,9 +105,9 @@ type ControllerReconcilerSpec struct { // If not specified, the default will be Token Bucket with qps 20, burst 30. // +optional RateLimit *RateLimit `json:"rateLimit,omitempty"` - // PprofConfigures the debug endpoint on the service. + // Configures the debug endpoint on the service. // +optional - PprofConfig *PprofConfig `json:"pprofConfig,omitempty"` + Pprof *PprofConfig `json:"pprof,omitempty"` } // ControllerReconcilerStatus defines the observed state of ControllerReconciler. diff --git a/operator/pkg/controllers/configconnector/configconnector_controller.go b/operator/pkg/controllers/configconnector/configconnector_controller.go index 7c909e7bc9..bd4b4cfe99 100644 --- a/operator/pkg/controllers/configconnector/configconnector_controller.go +++ b/operator/pkg/controllers/configconnector/configconnector_controller.go @@ -861,8 +861,8 @@ func (r *Reconciler) applyControllerReconcilerCR(ctx context.Context, cr *custom r.log.Error(err, errMsg) return r.handleApplyControllerReconcilerFailed(ctx, cr, errMsg) } - if err := controllers.ApplyContainerPprofConfig(m, cr.Name, cr.Spec.PprofConfig); err != nil { - msg := fmt.Sprintf("failed to apply pprof config customization %s: %v", cr.Name, err) + if err := controllers.ApplyContainerPprof(m, cr.Name, cr.Spec.Pprof); err != nil { + msg := fmt.Sprintf("failed to apply pprof customization %s: %v", cr.Name, err) return r.handleApplyControllerReconcilerFailed(ctx, cr, msg) } return r.handleApplyControllerReconcilerSucceeded(ctx, cr) diff --git a/operator/pkg/controllers/configconnectorcontext/configconnectorcontext_controller.go b/operator/pkg/controllers/configconnectorcontext/configconnectorcontext_controller.go index dc821b1089..e1a9053372 100644 --- a/operator/pkg/controllers/configconnectorcontext/configconnectorcontext_controller.go +++ b/operator/pkg/controllers/configconnectorcontext/configconnectorcontext_controller.go @@ -551,8 +551,8 @@ func (r *Reconciler) applyNamespacedControllerReconciler(ctx context.Context, cr msg := fmt.Sprintf("failed to apply rate limit customization %s: %v", cr.Name, err) return r.handleApplyNamespacedControllerReconcilerFailed(ctx, cr.Namespace, cr.Name, msg) } - if err := controllers.ApplyContainerPprofConfig(m, cr.Name, cr.Spec.PprofConfig); err != nil { - msg := fmt.Sprintf("failed to apply pprof config customization %s: %v", cr.Name, err) + if err := controllers.ApplyContainerPprof(m, cr.Name, cr.Spec.Pprof); err != nil { + msg := fmt.Sprintf("failed to apply pprof customization %s: %v", cr.Name, err) return r.handleApplyNamespacedControllerReconcilerFailed(ctx, cr.Namespace, cr.Name, msg) } return r.handleApplyNamespacedControllerReconcilerSucceeded(ctx, cr.Namespace, cr.Name) diff --git a/operator/pkg/controllers/utils.go b/operator/pkg/controllers/utils.go index 87167e3c79..a596df9e96 100644 --- a/operator/pkg/controllers/utils.go +++ b/operator/pkg/controllers/utils.go @@ -530,6 +530,7 @@ func ApplyContainerRateLimit(m *manifest.Objects, targetControllerName string, r targetControllerName, strings.Join(customizev1alpha1.ValidRateLimitControllers, ", ")) } + count := 0 for _, item := range m.Items { if item.GroupVersionKind() != targetControllerGVK { continue @@ -540,7 +541,10 @@ func ApplyContainerRateLimit(m *manifest.Objects, targetControllerName string, r if err := item.MutateContainers(customizeRateLimitFn(targetContainerName, ratelimit)); err != nil { return err } - break // we already found the matching controller, no need to keep looking. + count++ + } + if count != 1 { + return fmt.Errorf("rate limit customization for %s modified %d isntances.", targetControllerName, count) } return nil } @@ -587,7 +591,7 @@ func applyRateLimitToContainerArg(container map[string]interface{}, rateLimit *c return nil } -func ApplyContainerPprofConfig(m *manifest.Objects, targetControllerName string, pprofConfig *customizev1alpha1.PprofConfig) error { +func ApplyContainerPprof(m *manifest.Objects, targetControllerName string, pprofConfig *customizev1alpha1.PprofConfig) error { if pprofConfig == nil { return nil } @@ -610,6 +614,7 @@ func ApplyContainerPprofConfig(m *manifest.Objects, targetControllerName string, targetControllerName, strings.Join(customizev1alpha1.SupportedPprofControllers, ", ")) } + count := 0 for _, item := range m.Items { if item.GroupVersionKind() != targetControllerGVK { continue @@ -620,7 +625,10 @@ func ApplyContainerPprofConfig(m *manifest.Objects, targetControllerName string, if err := item.MutateContainers(customizePprofConfigFn(targetContainerName, pprofConfig)); err != nil { return err } - break // we already found the matching controller, no need to keep looking. + count++ + } + if count != 1 { + return fmt.Errorf("pprof config customization for %s modified %d isntances.", targetControllerName, count) } return nil }