From 10897841f6529b377f7e2852c87c931127785d66 Mon Sep 17 00:00:00 2001 From: Arjun Mehta <231106746+arjunmehta-git@users.noreply.github.com> Date: Tue, 18 Aug 2026 15:25:47 -0500 Subject: [PATCH] Accept v1beta3 relationship schemaVersion at registration getEntity dispatched relationships only on the v1beta2 and v1alpha3 schema version strings, so a definition authored against the canonical v1beta3 construct published by meshery/schemas fell through to the default case and failed to register - in server seeding and in mesheryctl model import alike. Components and models in the same switch already accept both their legacy and current version strings. Accept relationships.meshery.io/v1beta3 in the relationship case, decoding into the same shape-compatible registration struct, and add a RelationshipSchemaVersionV1Beta3 constant beside the existing v1beta2 one. Cover acceptance of the new version and rejection of unknown versions in tests. Fixes #1095 Signed-off-by: Arjun Mehta <231106746+arjunmehta-git@users.noreply.github.com> --- models/registration/utils.go | 7 +++++- models/registration/utils_test.go | 37 +++++++++++++++++++++++++++++++ schema/validator.go | 6 +++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/models/registration/utils.go b/models/registration/utils.go index 876c23b6a..3a64affe5 100644 --- a/models/registration/utils.go +++ b/models/registration/utils.go @@ -45,7 +45,12 @@ func getEntity(byt []byte) (et entity.Entity, _ error) { return nil, ErrGetEntity(fmt.Errorf("Invalid model definition: %s", err.Error())) } et = &model - case schema.RelationshipSchemaVersionV1Beta2, v1alpha3.RelationshipSchemaVersion: + // Accept v1alpha3, v1beta2, and v1beta3 relationship schema version + // strings, mirroring the component/model compatibility above. The wire + // shapes are compatible with the v1alpha3 Go struct (meshery/meshery's + // relationship_version_bridge.go round-trips them with shallow typed + // copies), so all three decode into the same registration type. + case schema.RelationshipSchemaVersionV1Beta2, schema.RelationshipSchemaVersionV1Beta3, v1alpha3.RelationshipSchemaVersion: var rel relationship.RelationshipDefinition err := encoding.Unmarshal(byt, &rel) if err != nil { diff --git a/models/registration/utils_test.go b/models/registration/utils_test.go index dddd947b2..46b5943a4 100644 --- a/models/registration/utils_test.go +++ b/models/registration/utils_test.go @@ -29,3 +29,40 @@ func TestGetEntityAcceptsV1Beta2RelationshipSchemaVersion(t *testing.T) { require.NoError(t, err) assert.Equal(t, entity.RelationshipDefinition, actual.Type()) } + +func TestGetEntityAcceptsV1Beta3RelationshipSchemaVersion(t *testing.T) { + t.Parallel() + + relationshipDocument := []byte(`{ + "schemaVersion": "relationships.meshery.io/v1beta3", + "kind": "edge", + "type": "non-binding", + "subType": "reference", + "model": { + "name": "kubernetes", + "model": { + "version": "v1.0.0" + } + }, + "version": "v1.0.0" + }`) + + actual, err := getEntity(relationshipDocument) + require.NoError(t, err) + assert.Equal(t, entity.RelationshipDefinition, actual.Type()) +} + +func TestGetEntityRejectsUnknownRelationshipSchemaVersion(t *testing.T) { + t.Parallel() + + relationshipDocument := []byte(`{ + "schemaVersion": "relationships.meshery.io/v1beta9", + "kind": "edge", + "type": "non-binding", + "subType": "reference", + "version": "v1.0.0" + }`) + + _, err := getEntity(relationshipDocument) + require.Error(t, err) +} diff --git a/schema/validator.go b/schema/validator.go index f8af4a6b9..822f8f29c 100644 --- a/schema/validator.go +++ b/schema/validator.go @@ -33,6 +33,12 @@ const ( // the string to keep all packages in sync. const RelationshipSchemaVersionV1Beta2 = "relationships.meshery.io/v1beta2" +// RelationshipSchemaVersionV1Beta3 is the schema version string for v1beta3 +// relationship definitions, the current authoring target published by +// meshery/schemas. Use this constant instead of hard-coding the string to +// keep all packages in sync. +const RelationshipSchemaVersionV1Beta3 = "relationships.meshery.io/v1beta3" + // Ref identifies which schema should be used to validate a document. type Ref struct { SchemaVersion string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`