Skip to content

Commit

Permalink
Factored in Justin's feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheftako committed Nov 6, 2024
1 parent dd94ee5 commit c8c109e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions operator/pkg/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Check failure on line 547 in operator/pkg/controllers/utils.go

View workflow job for this annotation

GitHub Actions / lint

`isntances` is a misspelling of `instances` (misspell)
}
return nil
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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)

Check failure on line 631 in operator/pkg/controllers/utils.go

View workflow job for this annotation

GitHub Actions / lint

`isntances` is a misspelling of `instances` (misspell)
}
return nil
}
Expand Down

0 comments on commit c8c109e

Please sign in to comment.