Skip to content

Commit c96d42e

Browse files
author
HeerakKashyap
committed
feat: implement EntityType() method to resolve Connection.Type field conflict
Signed-off-by: HeerakKashyap <[email protected]>
1 parent 8c383bc commit c96d42e

File tree

8 files changed

+28
-30
lines changed

8 files changed

+28
-30
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
gopkg.in/yaml.v3 v3.0.1
4545
gorm.io/driver/postgres v1.5.11
4646
gorm.io/driver/sqlite v1.5.7
47-
gorm.io/gorm v1.30.0
47+
gorm.io/gorm v1.30.1
4848
helm.sh/helm/v3 v3.18.4
4949
k8s.io/api v0.33.2
5050
k8s.io/apimachinery v0.33.2
@@ -199,7 +199,7 @@ require (
199199
github.com/nats-io/nkeys v0.4.9 // indirect
200200
github.com/nats-io/nuid v1.0.1 // indirect
201201
github.com/novln/docker-parser v1.0.0 // indirect
202-
github.com/oapi-codegen/runtime v1.1.1 // indirect
202+
github.com/oapi-codegen/runtime v1.1.2 // indirect
203203
github.com/opencontainers/go-digest v1.0.0 // indirect
204204
github.com/openshift/api v3.9.0+incompatible // indirect
205205
github.com/pelletier/go-toml/v2 v2.2.4 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
425425
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
426426
github.com/novln/docker-parser v1.0.0 h1:PjEBd9QnKixcWczNGyEdfUrP6GR0YUilAqG7Wksg3uc=
427427
github.com/novln/docker-parser v1.0.0/go.mod h1:oCeM32fsoUwkwByB5wVjsrsVQySzPWkl3JdlTn1txpE=
428-
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
429-
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
428+
github.com/oapi-codegen/runtime v1.1.2 h1:P2+CubHq8fO4Q6fV1tqDBZHCwpVpvPg7oKiYzQgXIyI=
429+
github.com/oapi-codegen/runtime v1.1.2/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
430430
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
431431
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
432432
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
@@ -698,8 +698,8 @@ gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
698698
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
699699
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
700700
gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
701-
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
702-
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
701+
gorm.io/gorm v1.30.1 h1:lSHg33jJTBxs2mgJRfRZeLDG+WZaHYCk3Wtfl6Ngzo4=
702+
gorm.io/gorm v1.30.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
703703
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
704704
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
705705
helm.sh/helm/v3 v3.18.4 h1:pNhnHM3nAmDrxz6/UC+hfjDY4yeDATQCka2/87hkZXQ=

models/meshmodel/core/v1beta1/connection.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@ import (
99
"github.com/meshery/meshkit/database"
1010
"github.com/meshery/meshkit/models/meshmodel/entity"
1111
"github.com/meshery/meshkit/utils"
12+
schemav1beta1 "github.com/meshery/schemas/models/v1beta1"
1213
"github.com/meshery/schemas/models/v1beta1/connection"
1314
v1beta1 "github.com/meshery/schemas/models/v1beta1/model"
1415
"gorm.io/gorm/clause"
1516
)
1617

17-
// ConnectionSchemaVersion is the schema version for connection definitions
18-
// This should match the schema version defined in the JSON schema
19-
const ConnectionSchemaVersion = "connections.meshery.io/v1beta1"
18+
// ConnectionSchemaVersion is imported from the schemas repo
19+
// This ensures consistency with the schema definition
20+
const ConnectionSchemaVersion = schemav1beta1.ConnectionSchemaVersion
2021

21-
// swagger:response ConnectionDefinition
22+
// ConnectionDefinition wraps the Connection from schemas to implement the Entity interface
23+
// This allows us to use Connection entities directly in PackagingUnit as requested by maintainer
2224
type ConnectionDefinition struct {
23-
ID uuid.UUID `json:"-" gorm:"primaryKey"`
24-
Kind string `json:"kind,omitempty" yaml:"kind"`
25-
Version string `json:"version,omitempty" yaml:"version"`
26-
ModelID uuid.UUID `json:"-" gorm:"column:modelID"`
27-
Model v1beta1.ModelDefinition `json:"model"`
28-
SubType string `json:"subType" yaml:"subType"`
29-
Connection connection.Connection `json:"connection" yaml:"connection"`
30-
CreatedAt time.Time `json:"-"`
31-
UpdatedAt time.Time `json:"-"`
25+
connection.Connection
26+
ModelID uuid.UUID `json:"-" gorm:"column:modelID"`
27+
Model v1beta1.ModelDefinition `json:"model"`
28+
CreatedAt time.Time `json:"-"`
29+
UpdatedAt time.Time `json:"-"`
3230
}
3331

3432
func (c ConnectionDefinition) GetID() uuid.UUID {
@@ -43,12 +41,12 @@ func (c *ConnectionDefinition) GenerateID() (uuid.UUID, error) {
4341
return id, nil
4442
}
4543

46-
func (c ConnectionDefinition) Type() entity.EntityType {
44+
func (c ConnectionDefinition) EntityType() entity.EntityType {
4745
return entity.ConnectionDefinition
4846
}
4947

5048
func (c *ConnectionDefinition) GetEntityDetail() string {
51-
return fmt.Sprintf("type: %s, definition version: %s, name: %s, model: %s, version: %s", c.Type(), c.Version, c.Kind, c.Model.Name, c.Model.Version)
49+
return fmt.Sprintf("type: %s, name: %s, kind: %s, model: %s, version: %s", c.EntityType(), c.Name, c.Kind, c.Model.Name, c.Model.Version)
5250
}
5351

5452
func (c *ConnectionDefinition) Create(db *database.Handler, hostID uuid.UUID) (uuid.UUID, error) {

models/meshmodel/core/v1beta1/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ func (p *PolicyDefinition) GenerateID() (uuid.UUID, error) {
3535
return uuid.NewV4()
3636
}
3737

38-
func (p PolicyDefinition) Type() entity.EntityType {
38+
func (p PolicyDefinition) EntityType() entity.EntityType {
3939
return entity.PolicyDefinition
4040
}
4141

4242
func (p *PolicyDefinition) GetEntityDetail() string {
43-
return fmt.Sprintf("type: %s, definition version: %s, name: %s, model: %s, version: %s", p.Type(), p.Version, p.Kind, p.Model.Name, p.Model.Version)
43+
return fmt.Sprintf("type: %s, definition version: %s, name: %s, model: %s, version: %s", p.EntityType(), p.Version, p.Kind, p.Model.Name, p.Model.Version)
4444
}
4545

4646
func (p *PolicyDefinition) Create(db *database.Handler, hostID uuid.UUID) (uuid.UUID, error) {

models/meshmodel/entity/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Filter interface {
2626
type Entity interface {
2727
// Entity is referred as any type of schema managed by the registry
2828
// ComponentDefinitions and PolicyDefinitions are examples of entities
29-
Type() EntityType
29+
EntityType() EntityType
3030
GetEntityDetail() string
3131
GenerateID() (uuid.UUID, error)
3232
GetID() uuid.UUID

models/meshmodel/registry/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (rm *RegistryManager) RegisterEntity(h connection.Connection, en entity.Ent
132132
ID: id,
133133
RegistrantID: registrantID,
134134
Entity: entityID,
135-
Type: en.Type(),
135+
Type: en.EntityType(),
136136
CreatedAt: time.Now(),
137137
UpdatedAt: time.Now(),
138138
}

models/registration/dir.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func processDir(dirPath string, pkg *PackagingUnit, regErrStore RegistrationErro
170170
}
171171

172172
// Add the entity to the packaging unit
173-
switch e.Type() {
173+
switch e.EntityType() {
174174
case entity.Model:
175175
model, err := utils.Cast[*model.ModelDefinition](e)
176176
if err != nil {

models/registration/register.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) {
9494

9595
// If model cannot be registered, don't register anything else
9696
if err != nil {
97-
err = ErrRegisterEntity(err, string(model.Type()), model.DisplayName)
97+
err = ErrRegisterEntity(err, string(model.EntityType()), model.DisplayName)
9898
rh.regErrStore.InsertEntityRegError(model.Registrant.Kind, "", entity.Model, model.Name, err)
9999
return
100100
}
@@ -129,7 +129,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) {
129129

130130
_, _, err := rh.regManager.RegisterEntity(model.Registrant, &comp)
131131
if err != nil {
132-
err = ErrRegisterEntity(err, string(comp.Type()), comp.DisplayName)
132+
err = ErrRegisterEntity(err, string(comp.EntityType()), comp.DisplayName)
133133
rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.ComponentDefinition, comp.DisplayName, err)
134134
} else {
135135
// Successful registration, add to successfulComponents
@@ -142,7 +142,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) {
142142
rel.Model = model
143143
_, _, err := rh.regManager.RegisterEntity(model.Registrant, &rel)
144144
if err != nil {
145-
err = ErrRegisterEntity(err, string(rel.Type()), string(rel.Kind))
145+
err = ErrRegisterEntity(err, string(rel.EntityType()), string(rel.Kind))
146146
rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.RelationshipDefinition, rel.Id.String(), err)
147147
} else {
148148
// Successful registration, add to successfulRelationships
@@ -156,7 +156,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) {
156156
c.Model = model
157157
_, _, err := rh.regManager.RegisterEntity(model.Registrant, &c)
158158
if err != nil {
159-
err = ErrRegisterEntity(err, string(c.Type()), c.Kind)
159+
err = ErrRegisterEntity(err, string(c.EntityType()), c.Kind)
160160
rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.ConnectionDefinition, c.Kind, err)
161161
} else {
162162
// Successful registration, add to successfulConnections

0 commit comments

Comments
 (0)