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
2 changes: 1 addition & 1 deletion generators/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/meshery/meshkit/utils/component"
"github.com/meshery/meshkit/utils/manifests"
"github.com/meshery/schemas/models/v1beta1/category"
"github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
_component "github.com/meshery/schemas/models/v1beta3/component"
"gopkg.in/yaml.v2"
)
Expand Down
2 changes: 1 addition & 1 deletion generators/github/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/meshery/meshkit/utils/kubernetes"
"github.com/meshery/meshkit/utils/manifests"
"github.com/meshery/schemas/models/v1beta1/category"
"github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
_component "github.com/meshery/schemas/models/v1beta3/component"
"gopkg.in/yaml.v3"
)
Expand Down
12 changes: 7 additions & 5 deletions models/meshmodel/registry/v1beta1/component_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"github.com/meshery/meshkit/models/meshmodel/entity"
"github.com/meshery/meshkit/models/meshmodel/registry"
"github.com/meshery/schemas/models/v1beta1/category"
"github.com/meshery/schemas/models/v1beta1/connection"
"github.com/meshery/schemas/models/v1beta1/model"
connectionv1beta3 "github.com/meshery/schemas/models/v1beta3/connection"
"github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta3/component"
"gorm.io/gorm/clause"
)
Expand All @@ -33,7 +33,7 @@
ComponentDefinitionDB component.ComponentDefinition `gorm:"embedded"`
ModelDB model.ModelDefinition `gorm:"embedded"`
CategoryDB category.CategoryDefinition `gorm:"embedded"`
ConnectionDB connection.Connection `gorm:"embedded"`
ConnectionDB connectionv1beta3.Connection `gorm:"embedded"`
}

func (cf *ComponentFilter) GetById(db *database.Handler) (entity.Entity, error) {
Expand Down Expand Up @@ -148,12 +148,14 @@
cm.ComponentDefinitionDB.Component.Schema = ""
}

reg := cm.ConnectionDB
cd := cm.ComponentDefinitionDB
cd.Model = &cm.ModelDB

Check failure on line 152 in models/meshmodel/registry/v1beta1/component_filter.go

View workflow job for this annotation

GitHub Actions / test

cannot use &cm.ModelDB (value of type *"github.com/meshery/schemas/models/v1beta2/model".ModelDefinition) as *"github.com/meshery/schemas/models/v1beta1/model".ModelDefinition value in assignment
Comment on lines 151 to 152

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Taking the address of a field of the loop variable cm (&cm.ModelDB) is a classic Go loop variable capture bug (pre-Go 1.22). Since cm is reused across iterations, all component definitions in defs will end up pointing to the same ModelDB address (the last element's model).

To fix this, copy cm.ModelDB to a local variable inside the loop before taking its address, similar to how it is handled in model_filter.go.

		cd := cm.ComponentDefinitionDB
		modelDB := cm.ModelDB
		cd.Model = &modelDB

if cd.Model != nil {
cd.Model.Category = cm.CategoryDB
cd.Model.Registrant = reg
// ConnectionDB is now typed as v1beta3.Connection — assign directly.
// GORM reads all columns (description, url, sub_type, etc.) correctly
// since db: tags are identical to the connections table columns.
cd.Model.Registrant = cm.ConnectionDB

Check failure on line 158 in models/meshmodel/registry/v1beta1/component_filter.go

View workflow job for this annotation

GitHub Actions / test

cannot use cm.ConnectionDB (variable of struct type "github.com/meshery/schemas/models/v1beta3/connection".Connection) as "github.com/meshery/schemas/models/v1beta1/connection".Connection value in assignment
}
defs = append(defs, &cd)
}
Expand Down
2 changes: 1 addition & 1 deletion models/meshmodel/registry/v1beta1/model_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/meshery/meshkit/models/meshmodel/entity"
"github.com/meshery/meshkit/models/meshmodel/registry"
"github.com/meshery/schemas/models/v1alpha3/relationship"
"github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta3/component"

"gorm.io/gorm/clause"
Expand Down
2 changes: 1 addition & 1 deletion models/registration/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/meshery/meshkit/utils"

"github.com/meshery/schemas/models/v1alpha3/relationship"
"github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta3/component"
)

Expand Down
41 changes: 35 additions & 6 deletions models/registration/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"github.com/meshery/meshkit/models/meshmodel/entity"
meshmodel "github.com/meshery/meshkit/models/meshmodel/registry"
"github.com/meshery/schemas/models/v1alpha3/relationship"
"github.com/meshery/schemas/models/v1beta1/connection"
"github.com/meshery/schemas/models/v1beta1/model"
connectionv1beta1 "github.com/meshery/schemas/models/v1beta1/connection"
"github.com/meshery/schemas/models/v1beta3/connection"
modelv1beta1 "github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta3/component"
)

Expand All @@ -18,6 +20,22 @@
_ []v1beta1.PolicyDefinition
}

// connV3ToV1 field-copies a v1beta3 Connection to v1beta1 Connection.
// Required at the RegisterEntity boundary: the RegistryManager signature
// expects v1beta1.Connection (stable internal API) while ModelDefinition.Registrant
// is now v1beta3.Connection (canonical wire format). DB column tags are
// identical in both versions so no data is lost or altered.
func connV3ToV1(c connection.Connection) connectionv1beta1.Connection {
return connectionv1beta1.Connection{
ID: c.ID,
Name: c.Name,
Kind: c.Kind,
Type: c.Type,
SubType: c.SubType,
Status: connectionv1beta1.ConnectionStatus(c.Status),
}
}

type RegistrationHelper struct {
regManager *meshmodel.RegistryManager
regErrStore RegistrationErrorStore
Expand Down Expand Up @@ -88,8 +106,8 @@
}
}

model.Registrant.Status = connection.ConnectionStatusRegistered

Check failure on line 109 in models/registration/register.go

View workflow job for this annotation

GitHub Actions / test

cannot use connection.ConnectionStatusRegistered (constant "registered" of string type "github.com/meshery/schemas/models/v1beta3/connection".ConnectionStatus) as "github.com/meshery/schemas/models/v1beta1/connection".ConnectionStatus value in assignment
_, _, err := rh.regManager.RegisterEntity(model.Registrant, &model)
_, _, err := rh.regManager.RegisterEntity(connV3ToV1(model.Registrant), &model)

Check failure on line 110 in models/registration/register.go

View workflow job for this annotation

GitHub Actions / test

cannot use model.Registrant (variable of struct type "github.com/meshery/schemas/models/v1beta1/connection".Connection) as "github.com/meshery/schemas/models/v1beta3/connection".Connection value in argument to connV3ToV1

// If model cannot be registered, don't register anything else
if err != nil {
Expand All @@ -110,7 +128,7 @@
continue
}

comp.Model = &model

Check failure on line 131 in models/registration/register.go

View workflow job for this annotation

GitHub Actions / test

cannot use &model (value of type *"github.com/meshery/schemas/models/v1beta2/model".ModelDefinition) as *"github.com/meshery/schemas/models/v1beta1/model".ModelDefinition value in assignment

if comp.Styles != nil {
// Write SVG for components
Expand All @@ -125,7 +143,7 @@
)
}

_, _, err := rh.regManager.RegisterEntity(model.Registrant, &comp)
_, _, err := rh.regManager.RegisterEntity(connV3ToV1(model.Registrant), &comp)

Check failure on line 146 in models/registration/register.go

View workflow job for this annotation

GitHub Actions / test

cannot use model.Registrant (variable of struct type "github.com/meshery/schemas/models/v1beta1/connection".Connection) as "github.com/meshery/schemas/models/v1beta3/connection".Connection value in argument to connV3ToV1
if err != nil {
err = ErrRegisterEntity(err, string(comp.Type()), comp.DisplayName)
rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.ComponentDefinition, comp.DisplayName, err)
Expand All @@ -137,9 +155,20 @@

// 3. Register relationships
for _, rel := range pkg.Relationships {
rel.Model = model.ToReference()
// Convert v1beta2.ModelReference to v1beta1.ModelReference at the
// v1alpha3/relationship boundary. Both structs have identical fields
// (same names and types); only their package paths differ.
v2ref := model.ToReference()
rel.Model = modelv1beta1.ModelReference{
DisplayName: v2ref.DisplayName,
ID: v2ref.ID,
Model: modelv1beta1.Model{Version: v2ref.Model.Version},
Name: v2ref.Name,
Registrant: modelv1beta1.RegistrantReference{Kind: v2ref.Registrant.Kind},
Version: v2ref.Version,
}
rel.ModelId = &model.ID
_, _, err := rh.regManager.RegisterEntity(model.Registrant, &rel)
_, _, err := rh.regManager.RegisterEntity(connV3ToV1(model.Registrant), &rel)

Check failure on line 171 in models/registration/register.go

View workflow job for this annotation

GitHub Actions / test

cannot use model.Registrant (variable of struct type "github.com/meshery/schemas/models/v1beta1/connection".Connection) as "github.com/meshery/schemas/models/v1beta3/connection".Connection value in argument to connV3ToV1
if err != nil {
err = ErrRegisterEntity(err, string(rel.Type()), string(rel.Kind))
rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.RelationshipDefinition, rel.ID.String(), err)
Expand Down
2 changes: 1 addition & 1 deletion models/registration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/meshery/schemas/models/v1alpha3"
"github.com/meshery/schemas/models/v1alpha3/relationship"
"github.com/meshery/schemas/models/v1beta1"
"github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta3"
"github.com/meshery/schemas/models/v1beta3/component"
)
Expand Down
10 changes: 5 additions & 5 deletions registry/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/meshery/meshkit/utils/store"
"github.com/meshery/schemas/models/v1beta1/capability"
"github.com/meshery/schemas/models/v1beta1/category"
"github.com/meshery/schemas/models/v1beta1/connection"
_model "github.com/meshery/schemas/models/v1beta1/model"
connectionv1beta3 "github.com/meshery/schemas/models/v1beta3/connection"
_model "github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta1/subcategory"
"github.com/meshery/schemas/models/v1beta3"
"github.com/meshery/schemas/models/v1beta3/component"
Expand Down Expand Up @@ -374,7 +374,7 @@ published: %s
markdown = strings.ReplaceAll(markdown, "\r", "\n")
return markdown
}
func createNewRegistrant(registrantName string) connection.Connection {
func createNewRegistrant(registrantName string) connectionv1beta3.Connection {
kind := utils.ReplaceSpacesAndConvertToLowercase(registrantName)
switch kind {
case "artifacthub":
Expand All @@ -386,9 +386,9 @@ func createNewRegistrant(registrantName string) connection.Connection {
case "kubernetes":
registrantName = "Kubernetes"
}
newRegistrant := connection.Connection{
newRegistrant := connectionv1beta3.Connection{
Name: registrantName,
Status: connection.ConnectionStatusDiscovered,
Status: connectionv1beta3.ConnectionStatusDiscovered,
Type: "registry",
Kind: kind,
}
Expand Down
2 changes: 1 addition & 1 deletion registry/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func ProcessRelationships(relationshipCSVHelper *RelationshipCSVHelper, spreadsh
}

var rel _rel.RelationshipDefinition
rel.SchemaVersion = schema.RelationshipSchemaVersionV1Beta2
rel.SchemaVersion = schema.RelationshipSchemaVersionV1Beta3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

When updating the relationship schema version to v1beta3, please make sure to also add schema.RelationshipSchemaVersionV1Beta3 to the switch sv.SchemaVersion statement in getEntity within models/registration/utils.go.

Currently, getEntity only handles schema.RelationshipSchemaVersionV1Beta2 and v1alpha3.RelationshipSchemaVersion. If a relationship with v1beta3 is processed, it will fall through to the default case and fail registration with an unrecognized schema version error.

rel.Kind = _rel.RelationshipDefinitionKind(utils.ReplaceSpacesWithHyphenAndConvertToLowercase(relationship.KIND))
rel.RelationshipType = utils.ReplaceSpacesWithHyphenAndConvertToLowercase(relationship.Type)
rel.SubType = utils.ReplaceSpacesWithHyphenAndConvertToLowercase(relationship.SubType)
Expand Down
5 changes: 5 additions & 0 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const (
// the string to keep all packages in sync.
const RelationshipSchemaVersionV1Beta2 = "relationships.meshery.io/v1beta2"

// RelationshipSchemaVersionV1Beta3 is the canonical schema version string for
// v1beta3 relationship definitions. model generate uses this version to align
// with the templates used by model init.
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
2 changes: 1 addition & 1 deletion utils/component/openapi_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"gopkg.in/yaml.v3"

"github.com/meshery/schemas/models/v1beta1/model"
"github.com/meshery/schemas/models/v1beta2/model"
"github.com/meshery/schemas/models/v1beta3"
"github.com/meshery/schemas/models/v1beta3/component"
)
Expand Down Expand Up @@ -135,7 +135,7 @@
Metadata: component.ComponentDefinition_Metadata{
IsNamespaced: isNamespaced,
},
Model: &model.ModelDefinition{

Check failure on line 138 in utils/component/openapi_generator.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &model.ModelDefinition{…} (value of type *"github.com/meshery/schemas/models/v1beta2/model".ModelDefinition) as *"github.com/meshery/schemas/models/v1beta1/model".ModelDefinition value in struct literal (typecheck)

Check failure on line 138 in utils/component/openapi_generator.go

View workflow job for this annotation

GitHub Actions / test

cannot use &model.ModelDefinition{…} (value of type *"github.com/meshery/schemas/models/v1beta2/model".ModelDefinition) as *"github.com/meshery/schemas/models/v1beta1/model".ModelDefinition value in struct literal
SchemaVersion: v1beta3.ModelSchemaVersion,
Model: model.Model{
Version: pkg.GetVersion(),
Expand Down
Loading