@@ -64,6 +64,7 @@ const (
6464 flagReconcileDefaultMaxConcurrency = "reconcile-default-max-concurrent-syncs"
6565 flagReconcileResourceMaxConcurrency = "reconcile-resource-max-concurrent-syncs"
6666 flagFeatureGates = "feature-gates"
67+ flagReconcileResources = "reconcile-resources"
6768 envVarAWSRegion = "AWS_REGION"
6869)
6970
@@ -104,6 +105,7 @@ type Config struct {
104105 ReconcileResourceResyncSeconds []string
105106 ReconcileDefaultMaxConcurrency int
106107 ReconcileResourceMaxConcurrency []string
108+ ReconcileResources string
107109 // TODO(a-hilaly): migrate to k8s.io/component-base and implement a proper parser for feature gates.
108110 FeatureGates featuregate.FeatureGates
109111 featureGatesRaw string
@@ -250,6 +252,11 @@ func (cfg *Config) BindFlags() {
250252 "Valid keys are feature names and valid values are 'true' or 'false'." +
251253 "Available features: " + strings .Join (featuregate .GetDefaultFeatureGates ().GetFeatureNames (), ", " ),
252254 )
255+ flag .StringVar (
256+ & cfg .ReconcileResources , flagReconcileResources ,
257+ "" ,
258+ "A comma-separated list of resource kinds to reconcile. If unspecified, all resources will be reconciled." ,
259+ )
253260}
254261
255262// SetupLogger initializes the logger used in the service controller
@@ -297,7 +304,7 @@ func (cfg *Config) Validate(ctx context.Context, options ...Option) error {
297304 if len (merged .gvks ) > 0 {
298305 err := cfg .validateReconcileConfigResources (merged .gvks )
299306 if err != nil {
300- return fmt . Errorf ( "invalid value for flag '%s': %v" , flagReconcileResourceResyncSeconds , err )
307+ return err
301308 }
302309 }
303310
@@ -389,6 +396,12 @@ func (cfg *Config) validateReconcileConfigResources(supportedGVKs []schema.Group
389396 return fmt .Errorf ("invalid value for flag '%s': %v" , flagReconcileResourceMaxConcurrency , err )
390397 }
391398 }
399+
400+ // Also validate the resource filter settings
401+ if err := cfg .validateReconcileResources (supportedGVKs ); err != nil {
402+ return err
403+ }
404+
392405 return nil
393406}
394407
@@ -564,3 +577,61 @@ func parseFeatureGates(featureGatesRaw string) (map[string]bool, error) {
564577
565578 return featureGatesMap , nil
566579}
580+
581+ // GetReconcileResources returns a slice of resource kinds that should be reconciled.
582+ func (cfg * Config ) GetReconcileResources () ([]string , error ) {
583+ return parseReconcileResourcesString (cfg .ReconcileResources )
584+ }
585+
586+ // parseReconcileResourcesString parses the reconcileResources flag and returns a slice
587+ // of resource kinds to reconcile.
588+ func parseReconcileResourcesString (resources string ) ([]string , error ) {
589+ resources = strings .TrimSpace (resources )
590+ if resources == "" {
591+ return nil , nil
592+ }
593+
594+ visited := make (map [string ]bool )
595+ resourceKinds := []string {}
596+
597+ for _ , kind := range strings .Split (resources , "," ) {
598+ kind = strings .TrimSpace (kind )
599+ if kind == "" {
600+ return nil , fmt .Errorf ("invalid resource kind: empty kind" )
601+ }
602+ if _ , ok := visited [kind ]; ok {
603+ return nil , fmt .Errorf ("duplicate resource kind '%s'" , kind )
604+ }
605+ visited [kind ] = true
606+ resourceKinds = append (resourceKinds , kind )
607+ }
608+ return resourceKinds , nil
609+ }
610+
611+ // validateReconcileResources validates that the specified resource kinds are supported by the controller.
612+ func (cfg * Config ) validateReconcileResources (supportedGVKs []schema.GroupVersionKind ) error {
613+ resources , err := cfg .GetReconcileResources ()
614+ if err != nil {
615+ return fmt .Errorf ("invalid value for flag '%s': %v" , flagReconcileResources , err )
616+ }
617+ if len (resources ) == 0 {
618+ return nil
619+ }
620+
621+ validResourceKinds := make ([]string , 0 , len (supportedGVKs ))
622+ for _ , gvk := range supportedGVKs {
623+ validResourceKinds = append (validResourceKinds , gvk .Kind )
624+ }
625+
626+ for _ , resource := range resources {
627+ if ! ackutil .InStrings (resource , validResourceKinds ) {
628+ return fmt .Errorf (
629+ "invalid value for flag '%s': resource kind '%s' is not supported by this controller. Valid resource kinds are: %s" ,
630+ flagReconcileResources ,
631+ resource ,
632+ strings .Join (validResourceKinds , ", " ),
633+ )
634+ }
635+ }
636+ return nil
637+ }
0 commit comments