Skip to content

Commit 1a49271

Browse files
committed
include delete in deviations
1 parent 5db88e1 commit 1a49271

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

pkg/target/context.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (r *Context) getDeviationUpdate(ctx context.Context, targetKey storebackend
293293
update := make([]*sdcpb.Update, 0, len(deviation.Spec.Deviations))
294294

295295
for _, deviation := range deviation.Spec.Deviations {
296-
if deviation.Reason == "NOT_APPLIED" {
296+
if deviation.Reason == "NOT_APPLIED" && deviation.CurrentValue != "<nil>"{
297297
path, err := utils.ParsePath(deviation.Path)
298298
if err != nil {
299299
return nil, fmt.Errorf("deviation path parsing failed forr target %s, path %s invalid", targetKey.String(), deviation.Path)
@@ -303,18 +303,14 @@ func (r *Context) getDeviationUpdate(ctx context.Context, targetKey storebackend
303303
if err := prototext.Unmarshal([]byte(deviation.CurrentValue), val); err != nil {
304304
log.Error("deviation proto unmarshal failed", "key", targetKey.String(), "path", deviation.Path, "currentValue", deviation.CurrentValue)
305305
continue
306-
//return nil, fmt.Errorf("create data failed for target %s, val %s invalid", key.String(), deviation.CurrentValue)
307306
}
308307

309-
//val, err := parse_value((deviation.CurrentValue))
310-
//if err != nil {
311-
// return nil, fmt.Errorf("create data failed for target %s, val %s invalid", key.String(), deviation.CurrentValue)
312-
//}
313-
314308
update = append(update, &sdcpb.Update{
315309
Path: path,
316310
Value: val,
317311
})
312+
} else {
313+
// delete case to be updated with the new protos
318314
}
319315
}
320316
return update, nil
@@ -582,6 +578,7 @@ func (r *Context) SetIntents(
582578
intents := make([]*sdcpb.TransactionIntent, 0)
583579
for key, deviation := range deviationsToUpdate {
584580
deviationsToUpdateSet.Insert(key)
581+
585582
update, err := r.getDeviationUpdate(ctx, targetKey, deviation)
586583
if err != nil {
587584
log.Error("Transaction getDeviationUpdate deviation", "error", err.Error())

pkg/transactor/transactor.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,19 @@ func getConfigsAndDeviationsToTransact(
553553
} else {
554554
// check for change of deviation
555555
if cfg.HashDeviationGenerationChanged(*deviation) {
556-
//change
557-
// safe copy of labels
558-
labels := safeCopyLabels(deviation.GetLabels())
559-
labels["priority"] = strconv.Itoa(int(cfg.Spec.Priority))
560-
deviation.SetLabels(labels)
561-
deviationsToUpdate[key] = deviation
562-
deviationsToUpdateSet.Insert(key)
556+
if deviation.HasNotAppliedDeviation() {
557+
//change
558+
// safe copy of labels
559+
labels := safeCopyLabels(deviation.GetLabels())
560+
labels["priority"] = strconv.Itoa(int(cfg.Spec.Priority))
561+
deviation.SetLabels(labels)
562+
deviationsToUpdate[key] = deviation
563+
deviationsToUpdateSet.Insert(key)
564+
} else {
565+
deviationsToDelete[key] = deviation
566+
deviationsToDeleteSet.Insert(key)
567+
}
568+
563569
}
564570
if len(deviation.Spec.Deviations) == 0 {
565571
deviationsToDelete[key] = deviation
@@ -579,11 +585,18 @@ func getConfigsAndDeviationsToTransact(
579585

580586
if !cfg.IsRevertive() {
581587
if len(deviation.Spec.Deviations) != 0 {
582-
labels := safeCopyLabels(deviation.GetLabels())
583-
labels["priority"] = strconv.Itoa(int(cfg.Spec.Priority))
584-
deviation.SetLabels(labels)
585-
deviationsToUpdate[key] = deviation
586-
deviationsToUpdateSet.Insert(key)
588+
if deviation.HasNotAppliedDeviation() {
589+
//change
590+
// safe copy of labels
591+
labels := safeCopyLabels(deviation.GetLabels())
592+
labels["priority"] = strconv.Itoa(int(cfg.Spec.Priority))
593+
deviation.SetLabels(labels)
594+
deviationsToUpdate[key] = deviation
595+
deviationsToUpdateSet.Insert(key)
596+
} else {
597+
deviationsToDelete[key] = deviation
598+
deviationsToDeleteSet.Insert(key)
599+
}
587600
} else {
588601
deviationsToDelete[key] = deviation
589602
deviationsToDeleteSet.Insert(key)

0 commit comments

Comments
 (0)