From b677d0fc1459d96d4b5d6ba5d4f3b158aba5b9b2 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 18 Nov 2024 13:33:11 +0000 Subject: [PATCH] pass through diffs and replaces --- pkg/pf/internal/plugin/provider_server.go | 56 +++++------------------ 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/pkg/pf/internal/plugin/provider_server.go b/pkg/pf/internal/plugin/provider_server.go index 45273eaa4..17d8df2ca 100644 --- a/pkg/pf/internal/plugin/provider_server.go +++ b/pkg/pf/internal/plugin/provider_server.go @@ -18,8 +18,6 @@ import ( "context" "encoding/json" "fmt" - "sort" - "strings" "github.com/blang/semver" pbempty "github.com/golang/protobuf/ptypes/empty" @@ -92,55 +90,23 @@ func (p *providerServer) marshalDiff(diff plugin.DiffResult) (*pulumirpc.DiffRes // Infer the result from the detailed diff. var diffs, replaces []string var detailedDiff map[string]*pulumirpc.PropertyDiff - if len(diff.DetailedDiff) == 0 { - diffs = make([]string, len(diff.ChangedKeys)) - for i, k := range diff.ChangedKeys { - diffs[i] = string(k) - } - replaces = make([]string, len(diff.ReplaceKeys)) - for i, k := range diff.ReplaceKeys { - replaces[i] = string(k) - } - } else { - changes = pulumirpc.DiffResponse_DIFF_SOME - - properties := map[string]struct{}{} + if len(diff.DetailedDiff) != 0 { detailedDiff = make(map[string]*pulumirpc.PropertyDiff) for path, diff := range diff.DetailedDiff { - for k := range detailedDiff { - // Turn the attribute name into a top-level property name by trimming everything after the first dot. - if firstSep := strings.IndexAny(k, ".["); firstSep != -1 { - k = k[:firstSep] - } - properties[k] = struct{}{} - } - - var kind pulumirpc.PropertyDiff_Kind - switch diff.Kind { - case pl.DiffAdd: - kind = pulumirpc.PropertyDiff_ADD - case pl.DiffAddReplace: - kind, replaces = pulumirpc.PropertyDiff_ADD_REPLACE, append(replaces, path) - case pl.DiffDelete: - kind = pulumirpc.PropertyDiff_DELETE - case pl.DiffDeleteReplace: - kind, replaces = pulumirpc.PropertyDiff_DELETE, append(replaces, path) - case pl.DiffUpdate: - kind = pulumirpc.PropertyDiff_UPDATE - case pl.DiffUpdateReplace: - kind, replaces = pulumirpc.PropertyDiff_UPDATE_REPLACE, append(replaces, path) - } - detailedDiff[path] = &pulumirpc.PropertyDiff{ - Kind: kind, + Kind: pulumirpc.PropertyDiff_Kind(diff.Kind), //nolint:gosec InputDiff: diff.InputDiff, } } - diffs = make([]string, 0, len(properties)) - for k := range properties { - diffs = append(diffs, k) - } - sort.Strings(diffs) + } + + diffs = make([]string, len(diff.ChangedKeys)) + for i, k := range diff.ChangedKeys { + diffs[i] = string(k) + } + replaces = make([]string, len(diff.ReplaceKeys)) + for i, k := range diff.ReplaceKeys { + replaces[i] = string(k) } return &pulumirpc.DiffResponse{