From d30a4c76151159d0c6618b5df3553f6abb5c0524 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 19 Aug 2024 13:45:52 +0530 Subject: [PATCH 1/5] fix: fetch styles from db w/signoff Signed-off-by: Jougan-0 --- models/meshmodel/registry/registry.go | 4 -- .../registry/v1beta1/model_filter.go | 42 ++----------------- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/models/meshmodel/registry/registry.go b/models/meshmodel/registry/registry.go index cc9d1c1b..e934df61 100644 --- a/models/meshmodel/registry/registry.go +++ b/models/meshmodel/registry/registry.go @@ -197,10 +197,6 @@ func (rm *RegistryManager) GetEntities(f entity.Filter) ([]entity.Entity, int64, return f.Get(rm.db) } -func (rm *RegistryManager) GetEntityById(f entity.Filter) (entity.Entity, error) { - return f.GetById(rm.db) -} - func HostnameToPascalCase(input string) string { parts := strings.Split(input, ".") caser := cases.Title(language.English) diff --git a/models/meshmodel/registry/v1beta1/model_filter.go b/models/meshmodel/registry/v1beta1/model_filter.go index 1819f1d2..9a806dc3 100644 --- a/models/meshmodel/registry/v1beta1/model_filter.go +++ b/models/meshmodel/registry/v1beta1/model_filter.go @@ -3,7 +3,6 @@ package v1beta1 import ( "github.com/layer5io/meshkit/database" "github.com/layer5io/meshkit/models/meshmodel/entity" - "github.com/layer5io/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" "github.com/meshery/schemas/models/v1beta1/component" "github.com/meshery/schemas/models/v1beta1/model" @@ -50,42 +49,6 @@ func countUniqueModels(models []model.ModelDefinition) int { return len(set) } -func (mf *ModelFilter) GetById(db *database.Handler) (entity.Entity, error) { - m := &model.ModelDefinition{} - - // Retrieve the model by ID - err := db.First(m, "id = ?", mf.Id).Error - if err != nil { - return nil, registry.ErrGetById(err, mf.Id) - } - - // Include components if requested - if mf.Components { - var components []component.ComponentDefinition - componentFinder := db.Model(&component.ComponentDefinition{}). - Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version"). - Where("component_definition_dbs.model_id = ?", m.Id) - if err := componentFinder.Scan(&components).Error; err != nil { - return nil, err - } - m.Components = components - } - - // Include relationships if requested - if mf.Relationships { - var relationships []relationship.RelationshipDefinition - relationshipFinder := db.Model(&relationship.RelationshipDefinition{}). - Select("relationship_definition_dbs.*"). - Where("relationship_definition_dbs.model_id = ?", m.Id) - if err := relationshipFinder.Scan(&relationships).Error; err != nil { - return nil, err - } - m.Relationships = relationships - } - - return m, nil -} - func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, error) { var modelWithCategories []model.ModelDefinition @@ -102,6 +65,9 @@ func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, e var includeComponents, includeRelationships bool if mf.Greedy { + if mf.Id != "" { + finder = finder.First("model_dbs.id = ?", mf.Id) + } if mf.Name != "" && mf.DisplayName != "" { finder = finder.Where("model_dbs.name LIKE ? OR model_dbs.display_name LIKE ?", "%"+mf.Name+"%", "%"+mf.DisplayName+"%") } else if mf.Name != "" { @@ -180,7 +146,7 @@ func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, e if includeComponents { var components []component.ComponentDefinition finder := db.Model(&component.ComponentDefinition{}). - Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version"). + Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version,component_definition_dbs.styles"). Where("component_definition_dbs.model_id = ?", _modelDB.Id) if err := finder.Scan(&components).Error; err != nil { return nil, 0, 0, err From 1483c4b306ee7462d3c5528bafe4e4cf4492e1e4 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 19 Aug 2024 13:47:57 +0530 Subject: [PATCH 2/5] fix liniting w/signoff Signed-off-by: Jougan-0 --- go.mod | 2 -- go.sum | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b914a6d2..d778a3fe 100644 --- a/go.mod +++ b/go.mod @@ -260,5 +260,3 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) - -replace github.com/meshery/schemas => ../schemas diff --git a/go.sum b/go.sum index 58dff424..59233ba0 100644 --- a/go.sum +++ b/go.sum @@ -608,6 +608,8 @@ github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/meshery/kompose v1.0.1 h1:lg8B/pkLh6762jeFsQATD8UJZZwXZf/aviC3/dzw78A= github.com/meshery/kompose v1.0.1/go.mod h1:TWhWTEMbJBUzENf4JTEtBmZRFm/r8n0nS6v4/nSD2vA= +github.com/meshery/schemas v0.7.19 h1:HS+PCZ3ZXbs7cv0JSUNW3kYnbypt3WqZjQ7fMQPy8uo= +github.com/meshery/schemas v0.7.19/go.mod h1:UfiO+zm92yLkaJP0aroNwVnjuozoh793AWDXrKDYmT0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= From 5d1230f96d588d92dcb403b224bca523ea974124 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 19 Aug 2024 17:32:37 +0530 Subject: [PATCH 3/5] missing function w/signoff Signed-off-by: Jougan-0 --- .../registry/v1beta1/model_filter.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/models/meshmodel/registry/v1beta1/model_filter.go b/models/meshmodel/registry/v1beta1/model_filter.go index 9a806dc3..86971485 100644 --- a/models/meshmodel/registry/v1beta1/model_filter.go +++ b/models/meshmodel/registry/v1beta1/model_filter.go @@ -3,6 +3,7 @@ package v1beta1 import ( "github.com/layer5io/meshkit/database" "github.com/layer5io/meshkit/models/meshmodel/entity" + "github.com/layer5io/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" "github.com/meshery/schemas/models/v1beta1/component" "github.com/meshery/schemas/models/v1beta1/model" @@ -48,6 +49,41 @@ func countUniqueModels(models []model.ModelDefinition) int { } return len(set) } +func (mf *ModelFilter) GetById(db *database.Handler) (entity.Entity, error) { + m := &model.ModelDefinition{} + + // Retrieve the model by ID + err := db.First(m, "id = ?", mf.Id).Error + if err != nil { + return nil, registry.ErrGetById(err, mf.Id) + } + + // Include components if requested + if mf.Components { + var components []component.ComponentDefinition + componentFinder := db.Model(&component.ComponentDefinition{}). + Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version"). + Where("component_definition_dbs.model_id = ?", m.Id) + if err := componentFinder.Scan(&components).Error; err != nil { + return nil, err + } + m.Components = components + } + + // Include relationships if requested + if mf.Relationships { + var relationships []relationship.RelationshipDefinition + relationshipFinder := db.Model(&relationship.RelationshipDefinition{}). + Select("relationship_definition_dbs.*"). + Where("relationship_definition_dbs.model_id = ?", m.Id) + if err := relationshipFinder.Scan(&relationships).Error; err != nil { + return nil, err + } + m.Relationships = relationships + } + + return m, nil +} func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, error) { From 96522532c5f76dde1e97b7f957c3591588df9bd5 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Tue, 20 Aug 2024 17:42:40 +0530 Subject: [PATCH 4/5] use source_uri from model metadata Signed-off-by: MUzairS15 --- models/meshmodel/core/v1beta1/host.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/models/meshmodel/core/v1beta1/host.go b/models/meshmodel/core/v1beta1/host.go index 0d2cdee2..fe7d1c61 100644 --- a/models/meshmodel/core/v1beta1/host.go +++ b/models/meshmodel/core/v1beta1/host.go @@ -62,8 +62,8 @@ type ArtifactHub struct{} const MesheryAnnotationPrefix = "design.meshery.io" func (ah ArtifactHub) HandleDependents(comp component.ComponentDefinition, kc *kubernetes.Client, isDeploy, performUpgrade bool) (summary string, err error) { - sourceURI, err := utils.Cast[string](comp.Metadata.AdditionalProperties["source_uri"]) // should be part of registrant data(?) - if err != nil { + sourceURI, ok := comp.Model.Metadata.AdditionalProperties["source_uri"] // should be part of registrant data(?) + if !ok { return summary, err } @@ -72,9 +72,14 @@ func (ah ArtifactHub) HandleDependents(comp component.ComponentDefinition, kc *k act = kubernetes.INSTALL } + _sourceURI, err := utils.Cast[string](sourceURI) + if err != nil { + return summary, err + } + if sourceURI != "" { err = kc.ApplyHelmChart(kubernetes.ApplyHelmChartConfig{ - URL: sourceURI, + URL: _sourceURI, Namespace: comp.Configuration["namespace"].(string), CreateNamespace: true, Action: act, From 2dea93949a08c60b8041a90b8f113b2fe7c0d136 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Tue, 20 Aug 2024 18:05:03 +0530 Subject: [PATCH 5/5] remove debug logs Signed-off-by: MUzairS15 --- models/meshmodel/registry/registry.go | 1 - models/meshmodel/registry/v1beta1/component_filter.go | 3 --- utils/kubernetes/apply-manifest.go | 2 -- 3 files changed, 6 deletions(-) diff --git a/models/meshmodel/registry/registry.go b/models/meshmodel/registry/registry.go index cc9d1c1b..ad1b03cc 100644 --- a/models/meshmodel/registry/registry.go +++ b/models/meshmodel/registry/registry.go @@ -177,7 +177,6 @@ func (rm *RegistryManager) GetRegistrants(f *models.HostFilter) ([]models.MeshMo var response []models.MeshModelHostsWithEntitySummary - fmt.Println("result--------------------------", result) for _, r := range result { res := models.MeshModelHostsWithEntitySummary{ Connection: r.Connection, diff --git a/models/meshmodel/registry/v1beta1/component_filter.go b/models/meshmodel/registry/v1beta1/component_filter.go index 3265abfc..76a6fb57 100644 --- a/models/meshmodel/registry/v1beta1/component_filter.go +++ b/models/meshmodel/registry/v1beta1/component_filter.go @@ -1,8 +1,6 @@ package v1beta1 import ( - "fmt" - "github.com/layer5io/meshkit/database" "github.com/layer5io/meshkit/models/meshmodel/entity" "github.com/layer5io/meshkit/models/meshmodel/registry" @@ -139,7 +137,6 @@ func (componentFilter *ComponentFilter) Get(db *database.Handler) ([]entity.Enti err := finder. Scan(&componentDefinitionsWithModel).Error if err != nil { - fmt.Println("line 123 : =+++++++++++++++", err) return nil, 0, 0, err } diff --git a/utils/kubernetes/apply-manifest.go b/utils/kubernetes/apply-manifest.go index 91a4e8f9..f1d1beac 100644 --- a/utils/kubernetes/apply-manifest.go +++ b/utils/kubernetes/apply-manifest.go @@ -2,7 +2,6 @@ package kubernetes import ( "context" - "fmt" "strings" v1 "k8s.io/api/core/v1" @@ -95,7 +94,6 @@ func (client *Client) ApplyManifest(contents []byte, recvOptions ApplyOptions) e return err } } else { - fmt.Println("Creating object", object) _, err = createObject(helper, options.Namespace, object, options.Update) if err != nil && !kubeerror.IsAlreadyExists(err) { if recvOptions.IgnoreErrors {