Skip to content

Commit 82aeae3

Browse files
committed
added sdc protos
1 parent 40e95ce commit 82aeae3

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/prometheus/client_model v0.6.2
2727
github.com/prometheus/prometheus v0.300.1
2828
github.com/sdcio/data-server v0.0.62
29-
github.com/sdcio/sdc-protos v0.0.44
29+
github.com/sdcio/sdc-protos v0.0.45-0.20250818091419-82cddb2deab0
3030
github.com/spf13/cobra v1.9.1
3131
github.com/stretchr/testify v1.10.0
3232
go.opentelemetry.io/otel v1.37.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ github.com/sdcio/data-server v0.0.62 h1:1nHjm8e+zC1O+7sK7g+tDF00p6ZQGXddyQqjj3YA
250250
github.com/sdcio/data-server v0.0.62/go.mod h1:pDM51uL89Bo7mQXBcJc72vn4XxdKu5xInD+7o7E4L4Q=
251251
github.com/sdcio/schema-server v0.0.31 h1:gWSSDvyzwWy2xYu2TCQdXYvqCA0gg3RhYKb9PplYeD4=
252252
github.com/sdcio/schema-server v0.0.31/go.mod h1:qa2bbfKyR4bHeZ85hicRpD4d+VtiPp9xs9/ey3shqZg=
253-
github.com/sdcio/sdc-protos v0.0.44 h1:YIvP4b4QPGtFJ90QlImGAturBun6vDgeGrynFLGxbgM=
254-
github.com/sdcio/sdc-protos v0.0.44/go.mod h1:i7eqaPKkw3bVaK3kLOgrnHvuphUQtRCXrDH0grX5n8w=
253+
github.com/sdcio/sdc-protos v0.0.45-0.20250818091419-82cddb2deab0 h1:Pnv3La9edwua3dpaaq29/4XR2U0A2KnAaGqDrP8v1Oo=
254+
github.com/sdcio/sdc-protos v0.0.45-0.20250818091419-82cddb2deab0/go.mod h1:i7eqaPKkw3bVaK3kLOgrnHvuphUQtRCXrDH0grX5n8w=
255255
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
256256
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
257257
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=

pkg/target/context.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)