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
7 changes: 6 additions & 1 deletion models/registration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions models/registration/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down