Introduce skip-name-validation flag and consolidate tests#7075
Conversation
This change introduces a 'skip-name-validation' flag across various controllers to bypass the duplicate controller name check during registration. This is particularly useful for integration tests where multiple managers might be created in the same process, avoiding conflicts in controller-runtime's global name registry. Additionally, consolidated 'kccmanager_skipnamevalidation_test.go' into 'kccmanager_test.go'.
- Use k8s.io/utils/ptr.To instead of taking address of struct fields for controller options. - Clarify SkipNameValidation comments and flag description. - Add note about global state in controller-runtime during tests.
cheftako
left a comment
There was a problem hiding this comment.
Approving for now. Lets get these cleaned up soon.
| flag.CommandLine.AddGoFlagSet(goflag.CommandLine) | ||
| flag.BoolVar(&enablePprof, "enable-pprof", false, "Enable the pprof server.") | ||
| flag.IntVar(&pprofPort, "pprof-port", 6060, "The port that the pprof server binds to if enabled.") | ||
| flag.BoolVar(&skipNameValidation, "skip-name-validation", false, "option to bypass the duplicate controller name check during registration; false by default") |
There was a problem hiding this comment.
Nit: Dislike booleans in APIs. Also not sure why we need this control in the deletion defender.
| // Register the registration controller, which will dynamically create controllers for | ||
| // all our resources. | ||
| if err := registration.AddDeletionDefender(mgr, &controller.Deps{}); err != nil { | ||
| if err := registration.AddDeletionDefender(mgr, &controller.Deps{SkipNameValidation: skipNameValidation}); err != nil { |
There was a problem hiding this comment.
Nit: Seems like we can just pass false here.
| flag.Float32Var(&rateLimitQps, "qps", 20.0, "The client-side token bucket rate limit qps.") | ||
| flag.IntVar(&rateLimitBurst, "burst", 30, "The client-side token bucket rate limit burst.") | ||
| flag.StringVar(&leaderElectionMode, "leader-election-type", "disabled", "Leader election mode. One of: default, multicluster.") | ||
| flag.BoolVar(&skipNameValidation, "skip-name-validation", false, "option to bypass the global controller name registry in controller-runtime; false by default") |
There was a problem hiding this comment.
Nit: Dislike booleans in APIs. Also not sure why we need this control in the manager? Seems like we are running the manager from cli tool. We should chat about this. In a 10K namespace cluster, I don't think its safe to spin up 10K pods. I would rather have this run in process and take longer.
| flag.BoolVar(&enablePprof, "enable-pprof", false, "Enable the pprof server.") | ||
| flag.IntVar(&pprofPort, "pprof-port", 6060, "The port that the pprof server binds to if enabled.") | ||
| flag.StringVar(&managerNamespaceIsolation, k8s.ManagerNamespaceIsolationFlag, k8s.ManagerNamespaceIsolationShared, fmt.Sprintf("'%s' if all controller managers run in shared 'cnrm-system' namespace, '%s' if controller managers run in dedicated namespace. Default is '%s'", k8s.ManagerNamespaceIsolationShared, k8s.ManagerNamespaceIsolationDedicated, k8s.ManagerNamespaceIsolationShared)) | ||
| flag.BoolVar(&skipNameValidation, "skip-name-validation", false, "option to bypass the duplicate controller name check during registration; false by default") |
There was a problem hiding this comment.
Nit: Dislike booleans in APIs. Also not sure why we need this control in the unmanaged detector? Lets get a bug going and clean this up before 1.48
|
|
||
| func Add(mgr manager.Manager, crd *apiextensions.CustomResourceDefinition) error { | ||
| func Add(mgr manager.Manager, crd *apiextensions.CustomResourceDefinition, opt controller.Options) error { | ||
| if opt.MaxConcurrentReconciles == 0 { |
There was a problem hiding this comment.
NIT: Should probably be <= 0. Assuming we not support negatives.
| // add adds a new Controller to mgr with r as the reconcile.Reconciler. | ||
| func add(mgr manager.Manager, r *Reconciler) error { | ||
| func add(mgr manager.Manager, r *Reconciler, opt controller.Options) error { | ||
| if opt.MaxConcurrentReconciles == 0 { |
| // add adds a new Controller to mgr with r as the reconcile.Reconciler. | ||
| func add(mgr manager.Manager, r *ReconcileIAMPolicy) error { | ||
| func add(mgr manager.Manager, r *ReconcileIAMPolicy, opt controller.Options) error { | ||
| if opt.MaxConcurrentReconciles == 0 { |
| // add adds a new Controller to mgr with r as the reconcile.Reconciler. | ||
| func add(mgr manager.Manager, r *Reconciler) error { | ||
| func add(mgr manager.Manager, r *Reconciler, opt controller.Options) error { | ||
| if opt.MaxConcurrentReconciles == 0 { |
| func Add(ctx context.Context, mgr manager.Manager, gvk schema.GroupVersionKind, opt controller.Options) error { | ||
| logger := crlog.FromContext(ctx) | ||
|
|
||
| if opt.MaxConcurrentReconciles == 0 { |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cheftako The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
3a7898e
This PR cherry-picks the changes from PR #7075 to the release-1.147 branch
BRIEF Change description
Introduce
skip-name-validationflag to bypass duplicate controller name checks during registration and consolidate related tests.WHY do we need this change?
In integration tests and certain multi-manager scenarios, creating multiple managers in the same process can lead to conflicts in
controller-runtime's global controller name registry. This flag allows for opting out of that check when such conflicts are expected or managed.Special notes for your reviewer:
Merged
pkg/controller/kccmanager/kccmanager_skipnamevalidation_test.gointopkg/controller/kccmanager/kccmanager_test.goto maintain a cleaner package structure.Ran
make fmtto ensure proper code formatting.Does this PR add something which needs to be 'release noted'?
Additional documentation e.g., references, usage docs, etc.:
Intended Milestone
Tests you have done
Ran all tests in
pkg/controller/kccmanagerpackage:go test -v ./pkg/controller/kccmanager -tags=integrationmake ready-prto ensure this PR is ready for review.