From a7ecf19674ac15c2aa67ce21b49def38e9fa7318 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Mon, 3 Aug 2026 23:56:11 +0530 Subject: [PATCH] fix: parse design-id label as a UUID string, not raw bytes ParseList read the design.meshery.io/id label with uuid.FromBytes, but the label value is the design ID as a canonical UUID string (36 bytes), not 16 raw bytes. FromBytes returned an error which was discarded, so PatternResource was set to a pointer to the nil UUID for every design-associated resource, and MeshSync never associated a discovered resource with the design that created it. Parse the value with uuid.Parse and only set PatternResource on success, so an invalid value leaves it nil instead of the nil UUID. Signed-off-by: Harsh Singh --- pkg/model/model_converter.go | 5 +-- pkg/model/model_converter_test.go | 51 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/pkg/model/model_converter.go b/pkg/model/model_converter.go index b8986f6a..16b09e2f 100644 --- a/pkg/model/model_converter.go +++ b/pkg/model/model_converter.go @@ -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 diff --git a/pkg/model/model_converter_test.go b/pkg/model/model_converter_test.go index 993d8d66..493300dd 100644 --- a/pkg/model/model_converter_test.go +++ b/pkg/model/model_converter_test.go @@ -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" ) @@ -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.