@@ -109,7 +109,7 @@ func (s *State) checkInit(version fieldpath.APIVersion) error {
109109 return nil
110110}
111111
112- func (s * State ) UpdateObject (tv * typed.TypedValue , version fieldpath.APIVersion , ignored map [fieldpath. APIVersion ] * fieldpath. Set , manager string ) error {
112+ func (s * State ) UpdateObject (tv * typed.TypedValue , version fieldpath.APIVersion , manager string ) error {
113113 err := s .checkInit (version )
114114 if err != nil {
115115 return err
@@ -118,7 +118,6 @@ func (s *State) UpdateObject(tv *typed.TypedValue, version fieldpath.APIVersion,
118118 if err != nil {
119119 return err
120120 }
121- defer setIgnoredFieldsAndCleanup (s .Updater , ignored )()
122121 newObj , managers , err := s .Updater .Update (s .Live , tv , version , s .Managers , manager )
123122 if err != nil {
124123 return err
@@ -130,15 +129,15 @@ func (s *State) UpdateObject(tv *typed.TypedValue, version fieldpath.APIVersion,
130129}
131130
132131// Update the current state with the passed in object
133- func (s * State ) Update (obj typed.YAMLObject , version fieldpath.APIVersion , ignored map [fieldpath. APIVersion ] * fieldpath. Set , manager string ) error {
132+ func (s * State ) Update (obj typed.YAMLObject , version fieldpath.APIVersion , manager string ) error {
134133 tv , err := s .Parser .Type (string (version )).FromYAML (FixTabsOrDie (obj ))
135134 if err != nil {
136135 return err
137136 }
138- return s .UpdateObject (tv , version , ignored , manager )
137+ return s .UpdateObject (tv , version , manager )
139138}
140139
141- func (s * State ) ApplyObject (tv * typed.TypedValue , version fieldpath.APIVersion , ignored map [fieldpath. APIVersion ] * fieldpath. Set , manager string , force bool ) error {
140+ func (s * State ) ApplyObject (tv * typed.TypedValue , version fieldpath.APIVersion , manager string , force bool ) error {
142141 err := s .checkInit (version )
143142 if err != nil {
144143 return err
@@ -147,7 +146,6 @@ func (s *State) ApplyObject(tv *typed.TypedValue, version fieldpath.APIVersion,
147146 if err != nil {
148147 return err
149148 }
150- defer setIgnoredFieldsAndCleanup (s .Updater , ignored )()
151149 new , managers , err := s .Updater .Apply (s .Live , tv , version , s .Managers , manager , force )
152150 if err != nil {
153151 return err
@@ -160,12 +158,12 @@ func (s *State) ApplyObject(tv *typed.TypedValue, version fieldpath.APIVersion,
160158}
161159
162160// Apply the passed in object to the current state
163- func (s * State ) Apply (obj typed.YAMLObject , version fieldpath.APIVersion , ignored map [fieldpath. APIVersion ] * fieldpath. Set , manager string , force bool ) error {
161+ func (s * State ) Apply (obj typed.YAMLObject , version fieldpath.APIVersion , manager string , force bool ) error {
164162 tv , err := s .Parser .Type (string (version )).FromYAML (FixTabsOrDie (obj ))
165163 if err != nil {
166164 return err
167165 }
168- return s .ApplyObject (tv , version , ignored , manager , force )
166+ return s .ApplyObject (tv , version , manager , force )
169167}
170168
171169// CompareLive takes a YAML string and returns the comparison with the
@@ -233,11 +231,10 @@ func addedConflicts(one, other merge.Conflicts) merge.Conflicts {
233231// conflict, the user can specify the expected conflicts. If conflicts
234232// don't match, an error will occur.
235233type Apply struct {
236- Manager string
237- APIVersion fieldpath.APIVersion
238- Object typed.YAMLObject
239- Conflicts merge.Conflicts
240- IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
234+ Manager string
235+ APIVersion fieldpath.APIVersion
236+ Object typed.YAMLObject
237+ Conflicts merge.Conflicts
241238}
242239
243240var _ Operation = & Apply {}
@@ -256,26 +253,24 @@ func (a Apply) preprocess(parser Parser) (Operation, error) {
256253 return nil , err
257254 }
258255 return ApplyObject {
259- Manager : a .Manager ,
260- APIVersion : a .APIVersion ,
261- Object : tv ,
262- Conflicts : a .Conflicts ,
263- IgnoredFields : a .IgnoredFields ,
256+ Manager : a .Manager ,
257+ APIVersion : a .APIVersion ,
258+ Object : tv ,
259+ Conflicts : a .Conflicts ,
264260 }, nil
265261}
266262
267263type ApplyObject struct {
268- Manager string
269- APIVersion fieldpath.APIVersion
270- Object * typed.TypedValue
271- Conflicts merge.Conflicts
272- IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
264+ Manager string
265+ APIVersion fieldpath.APIVersion
266+ Object * typed.TypedValue
267+ Conflicts merge.Conflicts
273268}
274269
275270var _ Operation = & ApplyObject {}
276271
277272func (a ApplyObject ) run (state * State ) error {
278- err := state .ApplyObject (a .Object , a .APIVersion , a .IgnoredFields , a . Manager , false )
273+ err := state .ApplyObject (a .Object , a .APIVersion , a .Manager , false )
279274 if err != nil {
280275 if _ , ok := err .(merge.Conflicts ); ! ok || a .Conflicts == nil {
281276 return err
@@ -305,16 +300,15 @@ func (a ApplyObject) preprocess(parser Parser) (Operation, error) {
305300// ForceApply is a type of operation. It is a forced-apply run by a
306301// manager with a given object. Any error will be returned.
307302type ForceApply struct {
308- Manager string
309- APIVersion fieldpath.APIVersion
310- Object typed.YAMLObject
311- IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
303+ Manager string
304+ APIVersion fieldpath.APIVersion
305+ Object typed.YAMLObject
312306}
313307
314308var _ Operation = & ForceApply {}
315309
316310func (f ForceApply ) run (state * State ) error {
317- return state .Apply (f .Object , f .APIVersion , f .IgnoredFields , f . Manager , true )
311+ return state .Apply (f .Object , f .APIVersion , f .Manager , true )
318312}
319313
320314func (f ForceApply ) preprocess (parser Parser ) (Operation , error ) {
@@ -323,26 +317,24 @@ func (f ForceApply) preprocess(parser Parser) (Operation, error) {
323317 return nil , err
324318 }
325319 return ForceApplyObject {
326- Manager : f .Manager ,
327- APIVersion : f .APIVersion ,
328- Object : tv ,
329- IgnoredFields : f .IgnoredFields ,
320+ Manager : f .Manager ,
321+ APIVersion : f .APIVersion ,
322+ Object : tv ,
330323 }, nil
331324}
332325
333326// ForceApplyObject is a type of operation. It is a forced-apply run by
334327// a manager with a given object. Any error will be returned.
335328type ForceApplyObject struct {
336- Manager string
337- APIVersion fieldpath.APIVersion
338- Object * typed.TypedValue
339- IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
329+ Manager string
330+ APIVersion fieldpath.APIVersion
331+ Object * typed.TypedValue
340332}
341333
342334var _ Operation = & ForceApplyObject {}
343335
344336func (f ForceApplyObject ) run (state * State ) error {
345- return state .ApplyObject (f .Object , f .APIVersion , f .IgnoredFields , f . Manager , true )
337+ return state .ApplyObject (f .Object , f .APIVersion , f .Manager , true )
346338}
347339
348340func (f ForceApplyObject ) preprocess (parser Parser ) (Operation , error ) {
@@ -352,16 +344,15 @@ func (f ForceApplyObject) preprocess(parser Parser) (Operation, error) {
352344// Update is a type of operation. It is a controller type of
353345// update. Errors are passed along.
354346type Update struct {
355- Manager string
356- APIVersion fieldpath.APIVersion
357- Object typed.YAMLObject
358- IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
347+ Manager string
348+ APIVersion fieldpath.APIVersion
349+ Object typed.YAMLObject
359350}
360351
361352var _ Operation = & Update {}
362353
363354func (u Update ) run (state * State ) error {
364- return state .Update (u .Object , u .APIVersion , u .IgnoredFields , u . Manager )
355+ return state .Update (u .Object , u .APIVersion , u .Manager )
365356}
366357
367358func (u Update ) preprocess (parser Parser ) (Operation , error ) {
@@ -370,26 +361,24 @@ func (u Update) preprocess(parser Parser) (Operation, error) {
370361 return nil , err
371362 }
372363 return UpdateObject {
373- Manager : u .Manager ,
374- APIVersion : u .APIVersion ,
375- Object : tv ,
376- IgnoredFields : u .IgnoredFields ,
364+ Manager : u .Manager ,
365+ APIVersion : u .APIVersion ,
366+ Object : tv ,
377367 }, nil
378368}
379369
380370// UpdateObject is a type of operation. It is a controller type of
381371// update. Errors are passed along.
382372type UpdateObject struct {
383- Manager string
384- APIVersion fieldpath.APIVersion
385- Object * typed.TypedValue
386- IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
373+ Manager string
374+ APIVersion fieldpath.APIVersion
375+ Object * typed.TypedValue
387376}
388377
389378var _ Operation = & Update {}
390379
391380func (u UpdateObject ) run (state * State ) error {
392- return state .UpdateObject (u .Object , u .APIVersion , u .IgnoredFields , u . Manager )
381+ return state .UpdateObject (u .Object , u .APIVersion , u .Manager )
393382}
394383
395384func (f UpdateObject ) preprocess (parser Parser ) (Operation , error ) {
@@ -416,6 +405,8 @@ type TestCase struct {
416405 Managed fieldpath.ManagedFields
417406 // Set to true if the test case needs the union behavior enabled.
418407 RequiresUnions bool
408+ // IgnoredFields containing the set to ignore for every version
409+ IgnoredFields map [fieldpath.APIVersion ]* fieldpath.Set
419410}
420411
421412// Test runs the test-case using the given parser and a dummy converter.
@@ -447,7 +438,7 @@ func (tc TestCase) PreprocessOperations(parser Parser) error {
447438// actually passes..
448439func (tc TestCase ) BenchWithConverter (parser Parser , converter merge.Converter ) error {
449440 state := State {
450- Updater : & merge.Updater {Converter : converter },
441+ Updater : & merge.Updater {Converter : converter , IgnoredFields : tc . IgnoredFields },
451442 Parser : parser ,
452443 }
453444 if tc .RequiresUnions {
@@ -467,7 +458,7 @@ func (tc TestCase) BenchWithConverter(parser Parser, converter merge.Converter)
467458// TestWithConverter runs the test-case using the given parser and converter.
468459func (tc TestCase ) TestWithConverter (parser Parser , converter merge.Converter ) error {
469460 state := State {
470- Updater : & merge.Updater {Converter : converter },
461+ Updater : & merge.Updater {Converter : converter , IgnoredFields : tc . IgnoredFields },
471462 Parser : parser ,
472463 }
473464 if tc .RequiresUnions {
@@ -516,13 +507,3 @@ func (tc TestCase) TestWithConverter(parser Parser, converter merge.Converter) e
516507
517508 return nil
518509}
519-
520- // setIgnoredFieldsAndCleanup sets the ignored fields for the provided updater and returns the cleanup function resetting them again
521- // this way it can be called in a single defer call
522- func setIgnoredFieldsAndCleanup (updater * merge.Updater , ignored map [fieldpath.APIVersion ]* fieldpath.Set ) func () {
523- if ignored == nil {
524- return func () {}
525- }
526- updater .IgnoredFields = ignored
527- return func () { updater .IgnoredFields = nil }
528- }
0 commit comments