@@ -288,32 +288,38 @@ func (r *Context) getIntentUpdate(ctx context.Context, key storebackend.Key, con
288288 return update , nil
289289}
290290
291- func (r * Context ) getDeviationUpdate (ctx context.Context , targetKey storebackend.Key , deviation * config.Deviation ) ([]* sdcpb.Update , error ) {
291+ func (r * Context ) getDeviationUpdate (ctx context.Context , targetKey storebackend.Key , deviation * config.Deviation ) ([]* sdcpb.Update , [] * sdcpb. Path , error ) {
292292 log := log .FromContext (ctx )
293- update := make ([]* sdcpb.Update , 0 , len (deviation .Spec .Deviations ))
293+ updates := make ([]* sdcpb.Update , 0 )
294+ deletes := make ([]* sdcpb.Path , 0 )
294295
295296 for _ , deviation := range deviation .Spec .Deviations {
296- if deviation .Reason == "NOT_APPLIED" && deviation .CurrentValue != "<nil>" {
297+ if deviation .Reason == "NOT_APPLIED" && deviation .CurrentValue != "<nil>" {
297298 path , err := utils .ParsePath (deviation .Path )
298299 if err != nil {
299- return nil , fmt .Errorf ("deviation path parsing failed forr target %s, path %s invalid" , targetKey .String (), deviation .Path )
300+ return nil , nil , fmt .Errorf ("deviation path parsing failed forr target %s, path %s invalid" , targetKey .String (), deviation .Path )
300301 }
301302
302303 val := & sdcpb.TypedValue {}
303304 if err := prototext .Unmarshal ([]byte (deviation .CurrentValue ), val ); err != nil {
304305 log .Error ("deviation proto unmarshal failed" , "key" , targetKey .String (), "path" , deviation .Path , "currentValue" , deviation .CurrentValue )
305306 continue
306- }
307+ }
307308
308- update = append (update , & sdcpb.Update {
309+ updates = append (updates , & sdcpb.Update {
309310 Path : path ,
310311 Value : val ,
311312 })
312313 } else {
313314 // delete case to be updated with the new protos
315+ path , err := utils .ParsePath (deviation .Path )
316+ if err != nil {
317+ return nil , nil , fmt .Errorf ("deviation path parsing failed forr target %s, path %s invalid" , targetKey .String (), deviation .Path )
318+ }
319+ deletes = append (deletes , path )
314320 }
315321 }
316- return update , nil
322+ return updates , deletes , nil
317323}
318324
319325/*
@@ -392,7 +398,7 @@ func (r *Context) TransactionSet(ctx context.Context, req *sdcpb.TransactionSetR
392398 if req .DryRun {
393399 return msg , nil
394400 }
395-
401+
396402 if err := r .TransactionConfirm (ctx , req .DatastoreName , req .TransactionId ); err != nil {
397403 return msg , err
398404 }
@@ -426,7 +432,7 @@ func (r *Context) SetIntent(ctx context.Context, key storebackend.Key, config *c
426432 })
427433
428434 if ! config .IsRevertive () {
429- update , err := r .getDeviationUpdate (ctx , key , & deviation )
435+ updates , deletes , err := r .getDeviationUpdate (ctx , key , & deviation )
430436 if err != nil {
431437 return "" , err
432438 }
@@ -454,7 +460,8 @@ func (r *Context) SetIntent(ctx context.Context, key storebackend.Key, config *c
454460 Deviation : true ,
455461 Intent : fmt .Sprintf ("deviation:%s" , GetGVKNSN (config )),
456462 Priority : int32 (newPriority ),
457- Update : update ,
463+ Update : updates ,
464+ Deletes : deletes ,
458465 })
459466 }
460467 }
@@ -488,11 +495,11 @@ func (r *Context) DeleteIntent(ctx context.Context, key storebackend.Key, config
488495 Timeout : ptr .To (int32 (60 )),
489496 Intents : []* sdcpb.TransactionIntent {
490497 {
491- Intent : GetGVKNSN (config ),
492- Priority : int32 (config .Spec .Priority ),
493- Delete : true ,
498+ Intent : GetGVKNSN (config ),
499+ Priority : int32 (config .Spec .Priority ),
500+ Delete : true ,
494501 DeleteIgnoreNoExist : true ,
495- Orphan : config .Orphan (),
502+ Orphan : config .Orphan (),
496503 },
497504 },
498505 })
@@ -511,7 +518,7 @@ func (r *Context) RecoverIntents(ctx context.Context, key storebackend.Key, conf
511518 intents := make ([]* sdcpb.TransactionIntent , 0 , len (configs )+ len (deviations ))
512519 // we only include deviations that have
513520 for _ , deviation := range deviations {
514- update , err := r .getDeviationUpdate (ctx , key , deviation )
521+ updates , deletes , err := r .getDeviationUpdate (ctx , key , deviation )
515522 if err != nil {
516523 return "" , err
517524 }
@@ -524,12 +531,13 @@ func (r *Context) RecoverIntents(ctx context.Context, key storebackend.Key, conf
524531 newPriority --
525532 }
526533 // only include items for which deviations exist
527- if len (update ) != 0 {
534+ if len (updates ) != 0 || len ( deletes ) != 0 {
528535 intents = append (intents , & sdcpb.TransactionIntent {
529536 Deviation : true ,
530537 Intent : fmt .Sprintf ("deviation:%s" , GetGVKNSN (deviation )),
531538 Priority : int32 (newPriority ),
532- Update : update ,
539+ Update : updates ,
540+ Deletes : deletes ,
533541 })
534542 }
535543 }
@@ -579,7 +587,7 @@ func (r *Context) SetIntents(
579587 for key , deviation := range deviationsToUpdate {
580588 deviationsToUpdateSet .Insert (key )
581589
582- update , err := r .getDeviationUpdate (ctx , targetKey , deviation )
590+ updates , deletes , err := r .getDeviationUpdate (ctx , targetKey , deviation )
583591 if err != nil {
584592 log .Error ("Transaction getDeviationUpdate deviation" , "error" , err .Error ())
585593 return nil , err
@@ -594,12 +602,13 @@ func (r *Context) SetIntents(
594602 newPriority --
595603 }
596604 // only include items for which deviations exist
597- if len (update ) != 0 {
605+ if len (updates ) != 0 || len ( deletes ) != 0 {
598606 intents = append (intents , & sdcpb.TransactionIntent {
599607 Deviation : true ,
600608 Intent : fmt .Sprintf ("deviation:%s" , GetGVKNSN (deviation )),
601609 Priority : int32 (newPriority ),
602- Update : update ,
610+ Update : updates ,
611+ Deletes : deletes ,
603612 })
604613 }
605614 }
@@ -608,9 +617,9 @@ func (r *Context) SetIntents(
608617 deviationsToDeleteSet .Insert (key )
609618 // only include items for which deviations exist
610619 intents = append (intents , & sdcpb.TransactionIntent {
611- Intent : fmt .Sprintf ("deviation:%s" , GetGVKNSN (deviation )),
620+ Intent : fmt .Sprintf ("deviation:%s" , GetGVKNSN (deviation )),
612621 //Priority: int32(config.Spec.Priority),
613- Delete : true ,
622+ Delete : true ,
614623 DeleteIgnoreNoExist : true ,
615624 })
616625 }
@@ -630,9 +639,9 @@ func (r *Context) SetIntents(
630639 for key , config := range configsToDelete {
631640 configsToDeleteSet .Insert (key )
632641 intents = append (intents , & sdcpb.TransactionIntent {
633- Intent : GetGVKNSN (config ),
642+ Intent : GetGVKNSN (config ),
634643 //Priority: int32(config.Spec.Priority),
635- Delete : true ,
644+ Delete : true ,
636645 DeleteIgnoreNoExist : true ,
637646 })
638647 }
0 commit comments