@@ -132,17 +132,17 @@ func UpdateConfiguratorWithOptions(ctx consolectx.Context, res *meshresource.Dyn
132132}
133133
134134func updateConfiguratorUnsafe (ctx consolectx.Context , res * meshresource.DynamicConfigResource , opts RuleMutationOptions ) error {
135- if err := checkExpectedVersion (ctx , RuleKindName {Kind : meshresource .DynamicConfigKind , Mesh : res .Mesh , Name : res .Name }, opts ); err != nil {
135+ kindName := RuleKindName {Kind : meshresource .DynamicConfigKind , Mesh : res .Mesh , Name : res .Name }
136+ if err := prepareRuleMutation (ctx , kindName , opts ); err != nil {
136137 return err
137138 }
138- if err := putAdminHint (ctx , res , versioning .OperationUpdate , opts ); err != nil {
139- return err
140- }
141- if err := ctx .ResourceManager ().Update (res ); err != nil {
142- logger .Warnf ("update %s configurator failed with error: %s" , res .Name , err .Error ())
143- return err
144- }
145- return nil
139+ return applyAdminMutation (ctx , res , versioning .OperationUpdate , opts , func () error {
140+ if err := ctx .ResourceManager ().Update (res ); err != nil {
141+ logger .Warnf ("update %s configurator failed with error: %s" , res .Name , err .Error ())
142+ return err
143+ }
144+ return nil
145+ })
146146}
147147
148148func CreateConfigurator (ctx consolectx.Context , res * meshresource.DynamicConfigResource ) error {
@@ -161,17 +161,17 @@ func CreateConfiguratorWithOptions(ctx consolectx.Context, res *meshresource.Dyn
161161}
162162
163163func createConfiguratorUnsafe (ctx consolectx.Context , res * meshresource.DynamicConfigResource , opts RuleMutationOptions ) error {
164- if err := checkExpectedVersion (ctx , RuleKindName {Kind : meshresource .DynamicConfigKind , Mesh : res .Mesh , Name : res .Name }, opts ); err != nil {
165- return err
166- }
167- if err := putAdminHint (ctx , res , versioning .OperationCreate , opts ); err != nil {
168- return err
169- }
170- if err := ctx .ResourceManager ().Add (res ); err != nil {
171- logger .Warnf ("create %s configurator failed with error: %s" , res .Name , err .Error ())
164+ kindName := RuleKindName {Kind : meshresource .DynamicConfigKind , Mesh : res .Mesh , Name : res .Name }
165+ if err := prepareRuleMutation (ctx , kindName , opts ); err != nil {
172166 return err
173167 }
174- return nil
168+ return applyAdminMutation (ctx , res , versioning .OperationCreate , opts , func () error {
169+ if err := ctx .ResourceManager ().Add (res ); err != nil {
170+ logger .Warnf ("create %s configurator failed with error: %s" , res .Name , err .Error ())
171+ return err
172+ }
173+ return nil
174+ })
175175}
176176
177177func DeleteConfigurator (ctx consolectx.Context , name string , mesh string ) error {
@@ -191,19 +191,21 @@ func DeleteConfiguratorWithOptions(ctx consolectx.Context, name string, mesh str
191191
192192func deleteConfiguratorUnsafe (ctx consolectx.Context , name string , mesh string , opts RuleMutationOptions ) error {
193193 kindName := RuleKindName {Kind : meshresource .DynamicConfigKind , Mesh : mesh , Name : name }
194+ if err := repairPendingIntent (ctx , kindName ); err != nil {
195+ return err
196+ }
194197 res , err := getExistingRule (ctx , kindName )
195198 if err != nil {
196199 return err
197200 }
198201 if err := checkExpectedVersion (ctx , kindName , opts ); err != nil {
199202 return err
200203 }
201- if err := putAdminHint (ctx , res , versioning .OperationDelete , opts ); err != nil {
202- return err
203- }
204- if err := ctx .ResourceManager ().DeleteByKey (meshresource .DynamicConfigKind , mesh , coremodel .BuildResourceKey (mesh , name )); err != nil {
205- logger .Warnf ("delete %s configurator failed with error: %s" , name , err .Error ())
206- return err
207- }
208- return nil
204+ return applyAdminMutation (ctx , res , versioning .OperationDelete , opts , func () error {
205+ if err := ctx .ResourceManager ().DeleteByKey (meshresource .DynamicConfigKind , mesh , coremodel .BuildResourceKey (mesh , name )); err != nil {
206+ logger .Warnf ("delete %s configurator failed with error: %s" , name , err .Error ())
207+ return err
208+ }
209+ return nil
210+ })
209211}
0 commit comments