@@ -55,8 +55,14 @@ func TestBindFlags(t *testing.T) {
5555 "secret-auto-annotation" ,
5656 "configmap-annotation" ,
5757 "secret-annotation" ,
58+ "configmap-exclude-annotation" ,
59+ "secret-exclude-annotation" ,
60+ "secretproviderclass-auto-annotation" ,
61+ "secretproviderclass-annotation" ,
62+ "secretproviderclass-exclude-annotation" ,
5863 "auto-search-annotation" ,
5964 "search-match-annotation" ,
65+ "ignore-annotation" ,
6066 "pause-deployment-annotation" ,
6167 "pause-deployment-time-annotation" ,
6268 "watch-namespace" ,
@@ -153,6 +159,131 @@ func TestBindFlags_CustomValues(t *testing.T) {
153159 }
154160}
155161
162+ func TestApplyFlags_SecretProviderClassAnnotations (t * testing.T ) {
163+ // Defaults are preserved when the flags are not provided.
164+ resetViper ()
165+ cfg := NewDefault ()
166+ fs := pflag .NewFlagSet ("test" , pflag .ContinueOnError )
167+ BindFlags (fs , cfg )
168+ if err := fs .Parse (nil ); err != nil {
169+ t .Fatalf ("Parse() error = %v" , err )
170+ }
171+ if err := ApplyFlags (cfg ); err != nil {
172+ t .Fatalf ("ApplyFlags() error = %v" , err )
173+ }
174+ defaults := DefaultAnnotations ()
175+ if cfg .Annotations .SecretProviderClassAuto != defaults .SecretProviderClassAuto {
176+ t .Errorf ("SecretProviderClassAuto = %q, want default %q" , cfg .Annotations .SecretProviderClassAuto , defaults .SecretProviderClassAuto )
177+ }
178+ if cfg .Annotations .SecretProviderClassReload != defaults .SecretProviderClassReload {
179+ t .Errorf ("SecretProviderClassReload = %q, want default %q" , cfg .Annotations .SecretProviderClassReload , defaults .SecretProviderClassReload )
180+ }
181+ if cfg .Annotations .SecretProviderClassExclude != defaults .SecretProviderClassExclude {
182+ t .Errorf ("SecretProviderClassExclude = %q, want default %q" , cfg .Annotations .SecretProviderClassExclude , defaults .SecretProviderClassExclude )
183+ }
184+
185+ // Custom values are applied from the flags.
186+ resetViper ()
187+ cfg = NewDefault ()
188+ fs = pflag .NewFlagSet ("test" , pflag .ContinueOnError )
189+ BindFlags (fs , cfg )
190+ args := []string {
191+ "--secretproviderclass-auto-annotation=spc.example.com/auto" ,
192+ "--secretproviderclass-annotation=spc.example.com/reload" ,
193+ "--secretproviderclass-exclude-annotation=spc.example.com/exclude" ,
194+ }
195+ if err := fs .Parse (args ); err != nil {
196+ t .Fatalf ("Parse() error = %v" , err )
197+ }
198+ if err := ApplyFlags (cfg ); err != nil {
199+ t .Fatalf ("ApplyFlags() error = %v" , err )
200+ }
201+ if cfg .Annotations .SecretProviderClassAuto != "spc.example.com/auto" {
202+ t .Errorf ("SecretProviderClassAuto = %q, want %q" , cfg .Annotations .SecretProviderClassAuto , "spc.example.com/auto" )
203+ }
204+ if cfg .Annotations .SecretProviderClassReload != "spc.example.com/reload" {
205+ t .Errorf ("SecretProviderClassReload = %q, want %q" , cfg .Annotations .SecretProviderClassReload , "spc.example.com/reload" )
206+ }
207+ if cfg .Annotations .SecretProviderClassExclude != "spc.example.com/exclude" {
208+ t .Errorf ("SecretProviderClassExclude = %q, want %q" , cfg .Annotations .SecretProviderClassExclude , "spc.example.com/exclude" )
209+ }
210+ }
211+
212+ func TestApplyFlags_ExcludeAnnotations (t * testing.T ) {
213+ // Defaults are preserved when the flags are not provided.
214+ resetViper ()
215+ cfg := NewDefault ()
216+ fs := pflag .NewFlagSet ("test" , pflag .ContinueOnError )
217+ BindFlags (fs , cfg )
218+ if err := fs .Parse (nil ); err != nil {
219+ t .Fatalf ("Parse() error = %v" , err )
220+ }
221+ if err := ApplyFlags (cfg ); err != nil {
222+ t .Fatalf ("ApplyFlags() error = %v" , err )
223+ }
224+ defaults := DefaultAnnotations ()
225+ if cfg .Annotations .ConfigmapExclude != defaults .ConfigmapExclude {
226+ t .Errorf ("ConfigmapExclude = %q, want default %q" , cfg .Annotations .ConfigmapExclude , defaults .ConfigmapExclude )
227+ }
228+ if cfg .Annotations .SecretExclude != defaults .SecretExclude {
229+ t .Errorf ("SecretExclude = %q, want default %q" , cfg .Annotations .SecretExclude , defaults .SecretExclude )
230+ }
231+
232+ // Custom values are applied from the flags.
233+ resetViper ()
234+ cfg = NewDefault ()
235+ fs = pflag .NewFlagSet ("test" , pflag .ContinueOnError )
236+ BindFlags (fs , cfg )
237+ args := []string {
238+ "--configmap-exclude-annotation=cm.example.com/exclude" ,
239+ "--secret-exclude-annotation=sec.example.com/exclude" ,
240+ }
241+ if err := fs .Parse (args ); err != nil {
242+ t .Fatalf ("Parse() error = %v" , err )
243+ }
244+ if err := ApplyFlags (cfg ); err != nil {
245+ t .Fatalf ("ApplyFlags() error = %v" , err )
246+ }
247+ if cfg .Annotations .ConfigmapExclude != "cm.example.com/exclude" {
248+ t .Errorf ("ConfigmapExclude = %q, want %q" , cfg .Annotations .ConfigmapExclude , "cm.example.com/exclude" )
249+ }
250+ if cfg .Annotations .SecretExclude != "sec.example.com/exclude" {
251+ t .Errorf ("SecretExclude = %q, want %q" , cfg .Annotations .SecretExclude , "sec.example.com/exclude" )
252+ }
253+ }
254+
255+ func TestApplyFlags_IgnoreAnnotation (t * testing.T ) {
256+ // Default is preserved when the flag is not provided.
257+ resetViper ()
258+ cfg := NewDefault ()
259+ fs := pflag .NewFlagSet ("test" , pflag .ContinueOnError )
260+ BindFlags (fs , cfg )
261+ if err := fs .Parse (nil ); err != nil {
262+ t .Fatalf ("Parse() error = %v" , err )
263+ }
264+ if err := ApplyFlags (cfg ); err != nil {
265+ t .Fatalf ("ApplyFlags() error = %v" , err )
266+ }
267+ if cfg .Annotations .Ignore != DefaultAnnotations ().Ignore {
268+ t .Errorf ("Ignore = %q, want default %q" , cfg .Annotations .Ignore , DefaultAnnotations ().Ignore )
269+ }
270+
271+ // Custom value is applied from the flag.
272+ resetViper ()
273+ cfg = NewDefault ()
274+ fs = pflag .NewFlagSet ("test" , pflag .ContinueOnError )
275+ BindFlags (fs , cfg )
276+ if err := fs .Parse ([]string {"--ignore-annotation=my.company.com/reloader-ignore" }); err != nil {
277+ t .Fatalf ("Parse() error = %v" , err )
278+ }
279+ if err := ApplyFlags (cfg ); err != nil {
280+ t .Fatalf ("ApplyFlags() error = %v" , err )
281+ }
282+ if cfg .Annotations .Ignore != "my.company.com/reloader-ignore" {
283+ t .Errorf ("Ignore = %q, want %q" , cfg .Annotations .Ignore , "my.company.com/reloader-ignore" )
284+ }
285+ }
286+
156287func TestApplyFlags_BooleanStrings (t * testing.T ) {
157288 tests := []struct {
158289 name string
0 commit comments