Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/model/model_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ func ParseList(
})

if string(key) == orchestration.ResourceSourceDesignIdLabelKey {
id, _ := uuid.FromBytes(value)
result.PatternResource = &id
if id, err := uuid.Parse(string(value)); err == nil {
result.PatternResource = &id
}
}

return nil
Expand Down
51 changes: 51 additions & 0 deletions pkg/model/model_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"encoding/json"
"testing"

"github.com/google/uuid"
"github.com/meshery/meshkit/broker"
"github.com/meshery/meshkit/orchestration"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand Down Expand Up @@ -46,6 +48,55 @@ func TestParseList_ManagedFieldsNotCaptured(t *testing.T) {
}
}

// TestParseList_DesignIDLabelParsed is the regression test for the design-id
// parsing fix: the design.meshery.io/id label carries the design UUID as a
// canonical string, so it must be parsed with uuid.Parse. uuid.FromBytes expects
// 16 raw bytes and errored on the 36-byte string, and the discarded error left
// PatternResource pointing at the nil UUID for every design-associated resource.
func TestParseList_DesignIDLabelParsed(t *testing.T) {
designID := uuid.New()

cases := []struct {
name string
labelValue string
want *uuid.UUID
}{
{"valid design id is parsed", designID.String(), &designID},
{"invalid design id leaves PatternResource nil", "not-a-uuid", nil},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
obj := newUnstructured(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "sample",
"namespace": "default",
"labels": map[string]interface{}{
orchestration.ResourceSourceDesignIdLabelKey: tc.labelValue,
},
},
})

got := ParseList(obj, broker.Add, "cluster-1").PatternResource

if tc.want == nil {
if got != nil {
t.Fatalf("PatternResource = %v, want nil for label value %q", *got, tc.labelValue)
}
return
}
if got == nil {
t.Fatalf("PatternResource = nil, want %v", *tc.want)
}
if *got != *tc.want {
t.Fatalf("PatternResource = %v, want %v", *got, *tc.want)
}
})
}
}

// TestParseList_SecretRedactionDisabledByDefault asserts the default (env var
// unset) behavior is byte-for-byte unchanged: Secret data/stringData passes
// through exactly as it appears in the source object.
Expand Down