@@ -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 , manager string ) error {
112+ func (s * State ) UpdateObject (tv * typed.TypedValue , version fieldpath.APIVersion , ignored * fieldpath. Set , manager string ) error {
113113 err := s .checkInit (version )
114114 if err != nil {
115115 return err
@@ -118,7 +118,7 @@ func (s *State) UpdateObject(tv *typed.TypedValue, version fieldpath.APIVersion,
118118 if err != nil {
119119 return err
120120 }
121- newObj , managers , err := s .Updater .Update (s .Live , tv , version , s .Managers , manager )
121+ newObj , managers , err := s .Updater .Update (s .Live , tv , version , s .Managers , ignored , manager )
122122 if err != nil {
123123 return err
124124 }
@@ -129,12 +129,12 @@ func (s *State) UpdateObject(tv *typed.TypedValue, version fieldpath.APIVersion,
129129}
130130
131131// Update the current state with the passed in object
132- func (s * State ) Update (obj typed.YAMLObject , version fieldpath.APIVersion , manager string ) error {
132+ func (s * State ) Update (obj typed.YAMLObject , version fieldpath.APIVersion , ignored * fieldpath. Set , manager string ) error {
133133 tv , err := s .parseConfig (version , obj )
134134 if err != nil {
135135 return err
136136 }
137- return s .UpdateObject (tv , version , manager )
137+ return s .UpdateObject (tv , version , ignored , manager )
138138}
139139
140140func (s * State ) ApplyObject (tv * typed.TypedValue , version fieldpath.APIVersion , manager string , force bool ) error {
@@ -348,15 +348,16 @@ func (f ForceApplyObject) preprocess(parser Parser) (Operation, error) {
348348// Update is a type of operation. It is a controller type of
349349// update. Errors are passed along.
350350type Update struct {
351- Manager string
352- APIVersion fieldpath.APIVersion
353- Object typed.YAMLObject
351+ Manager string
352+ APIVersion fieldpath.APIVersion
353+ Object typed.YAMLObject
354+ IgnoredFields * fieldpath.Set
354355}
355356
356357var _ Operation = & Update {}
357358
358359func (u Update ) run (state * State ) error {
359- return state .Update (u .Object , u .APIVersion , u .Manager )
360+ return state .Update (u .Object , u .APIVersion , u .IgnoredFields , u . Manager )
360361}
361362
362363func (u Update ) preprocess (parser Parser ) (Operation , error ) {
@@ -365,24 +366,26 @@ func (u Update) preprocess(parser Parser) (Operation, error) {
365366 return nil , err
366367 }
367368 return UpdateObject {
368- Manager : u .Manager ,
369- APIVersion : u .APIVersion ,
370- Object : tv ,
369+ Manager : u .Manager ,
370+ APIVersion : u .APIVersion ,
371+ Object : tv ,
372+ IgnoredFields : u .IgnoredFields ,
371373 }, nil
372374}
373375
374376// UpdateObject is a type of operation. It is a controller type of
375377// update. Errors are passed along.
376378type UpdateObject struct {
377- Manager string
378- APIVersion fieldpath.APIVersion
379- Object * typed.TypedValue
379+ Manager string
380+ APIVersion fieldpath.APIVersion
381+ Object * typed.TypedValue
382+ IgnoredFields * fieldpath.Set
380383}
381384
382385var _ Operation = & Update {}
383386
384387func (u UpdateObject ) run (state * State ) error {
385- return state .UpdateObject (u .Object , u .APIVersion , u .Manager )
388+ return state .UpdateObject (u .Object , u .APIVersion , u .IgnoredFields , u . Manager )
386389}
387390
388391func (f UpdateObject ) preprocess (parser Parser ) (Operation , error ) {
@@ -550,3 +553,30 @@ func (op ExpectState) run(state *State) error {
550553func (op ExpectState ) preprocess (parser Parser ) (Operation , error ) {
551554 return op , nil
552555}
556+
557+ // ExpectManagedFields is an Operation checking if the manager owns the defined fields in the current state
558+ // If the Fields are nil, it won't be an error if the manager is missing
559+ type ExpectManagedFields struct {
560+ Manager string
561+ Fields * fieldpath.Set
562+ }
563+
564+ var _ Operation = ExpectManagedFields {}
565+
566+ func (op ExpectManagedFields ) run (state * State ) error {
567+ manager , ok := state .Managers [op .Manager ]
568+ if ! ok {
569+ if op .Fields == nil {
570+ return nil
571+ }
572+ return fmt .Errorf ("manager not found: %s" , op .Manager )
573+ }
574+ if diff := manager .Set ().Difference (op .Fields ); ! diff .Empty () {
575+ return fmt .Errorf ("unexpected managedFields for %s: \n %v" , op .Manager , diff )
576+ }
577+ return nil
578+ }
579+
580+ func (op ExpectManagedFields ) preprocess (parser Parser ) (Operation , error ) {
581+ return op , nil
582+ }
0 commit comments