@@ -64,6 +64,7 @@ const (
64
64
flagReconcileDefaultMaxConcurrency = "reconcile-default-max-concurrent-syncs"
65
65
flagReconcileResourceMaxConcurrency = "reconcile-resource-max-concurrent-syncs"
66
66
flagFeatureGates = "feature-gates"
67
+ flagReconcileResources = "reconcile-resources"
67
68
envVarAWSRegion = "AWS_REGION"
68
69
)
69
70
@@ -104,6 +105,7 @@ type Config struct {
104
105
ReconcileResourceResyncSeconds []string
105
106
ReconcileDefaultMaxConcurrency int
106
107
ReconcileResourceMaxConcurrency []string
108
+ ReconcileResources string
107
109
// TODO(a-hilaly): migrate to k8s.io/component-base and implement a proper parser for feature gates.
108
110
FeatureGates featuregate.FeatureGates
109
111
featureGatesRaw string
@@ -250,6 +252,11 @@ func (cfg *Config) BindFlags() {
250
252
"Valid keys are feature names and valid values are 'true' or 'false'." +
251
253
"Available features: " + strings .Join (featuregate .GetDefaultFeatureGates ().GetFeatureNames (), ", " ),
252
254
)
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
+ )
253
260
}
254
261
255
262
// SetupLogger initializes the logger used in the service controller
@@ -389,6 +396,12 @@ func (cfg *Config) validateReconcileConfigResources(supportedGVKs []schema.Group
389
396
return fmt .Errorf ("invalid value for flag '%s': %v" , flagReconcileResourceMaxConcurrency , err )
390
397
}
391
398
}
399
+
400
+ // Also validate the resource filter settings
401
+ if err := cfg .validateReconcileResources (supportedGVKs ); err != nil {
402
+ return err
403
+ }
404
+
392
405
return nil
393
406
}
394
407
@@ -564,3 +577,61 @@ func parseFeatureGates(featureGatesRaw string) (map[string]bool, error) {
564
577
565
578
return featureGatesMap , nil
566
579
}
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