Skip to content

Commit 047ef71

Browse files
fix: remove redundant status propagation from model to component
1 parent 0e83574 commit 047ef71

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

registry/component.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ type ComponentCSV struct {
5858

5959
// The Component Definition generated assumes or is only for components which have registrant as "meshery"
6060
func (c *ComponentCSV) CreateComponentDefinition(isModelPublished bool, defVersion string) (component.ComponentDefinition, error) {
61+
var statusPtr *component.ComponentDefinitionStatus
6162
if c.Status != "" {
62-
if utils.ReplaceSpacesAndConvertToLowercase(c.Status) == "ignored" {
63-
status = entity.Ignored
63+
normalized := utils.ReplaceSpacesAndConvertToLowercase(c.Status)
64+
65+
if normalized == "ignored" {
66+
s := component.ComponentDefinitionStatus(entity.Ignored)
67+
statusPtr = &s
6468
}
6569
}
6670
componentDefinition := &component.ComponentDefinition{
@@ -71,13 +75,15 @@ func (c *ComponentCSV) CreateComponentDefinition(isModelPublished bool, defVersi
7175
Metadata: component.ComponentDefinition_Metadata{
7276
Published: isModelPublished,
7377
},
74-
Status: (*component.ComponentDefinitionStatus)(&status),
7578
Component: component.Component{
7679
Kind: c.Component,
7780
Schema: c.Schema,
7881
Version: c.Version,
7982
},
8083
}
84+
if statusPtr != nil {
85+
componentDefinition.Status = statusPtr
86+
}
8187
if c.Description != "" {
8288
componentDefinition.Description = c.Description
8389
}
@@ -93,12 +99,7 @@ var compStyleValues = []string{
9399
}
94100

95101
func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefinition) error {
96-
if c.Status != "" {
97-
if utils.ReplaceSpacesAndConvertToLowercase(c.Status) == "ignored" {
98-
status = entity.Ignored
99-
}
100-
}
101-
compDef.Status = (*component.ComponentDefinitionStatus)(&status)
102+
102103
var existingAddditionalProperties map[string]interface{}
103104
if c.Description != "" {
104105
compDef.Description = c.Description

registry/model.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var defVersion = "v1.0.0"
6060

6161
// keep
6262
type ModelCSV struct {
63+
Status *_model.ModelDefinitionStatus `json:"status,omitempty"`
6364
Registrant string `json:"registrant" csv:"registrant"`
6465
ModelDisplayName string `json:"modelDisplayName" csv:"modelDisplayName"`
6566
Model string `json:"model" csv:"model"`
@@ -174,9 +175,10 @@ func (m *ModelCSV) UpdateModelDefinition(modelDef *_model.ModelDefinition) error
174175
return nil
175176
}
176177
func (mcv *ModelCSV) CreateModelDefinition(version, defVersion string) _model.ModelDefinition {
177-
status := entity.Ignored
178-
if strings.ToLower(mcv.PublishToRegistry) == "true" {
179-
status = entity.Enabled
178+
var status _model.ModelDefinitionStatus
179+
180+
if strings.ToLower(strings.TrimSpace(mcv.PublishToRegistry)) != "true" {
181+
status = _model.ModelDefinitionStatus(entity.Ignored)
180182
}
181183
var catname category.CategoryDefinition
182184
catname.Name = mcv.Category
@@ -189,7 +191,7 @@ func (mcv *ModelCSV) CreateModelDefinition(version, defVersion string) _model.Mo
189191

190192
SchemaVersion: v1beta1.ModelSchemaVersion,
191193
Name: mcv.Model,
192-
Status: _model.ModelDefinitionStatus(status),
194+
Status: status,
193195
Registrant: registrant,
194196
SubCategory: mcv.SubCategory,
195197
Model: _model.Model{
@@ -533,8 +535,10 @@ func (m ModelCSVHelper) Cleanup() error {
533535
}
534536
func AssignDefaultsForCompDefs(componentDef *component.ComponentDefinition, modelDef *_model.ModelDefinition) {
535537
// Assign the status from the model to the component
536-
compStatus := component.ComponentDefinitionStatus(modelDef.Status)
537-
componentDef.Status = &compStatus
538+
if modelDef.Status != "" && string(modelDef.Status) != string(entity.Enabled) {
539+
compStatus := component.ComponentDefinitionStatus(modelDef.Status)
540+
componentDef.Status = &compStatus
541+
}
538542

539543
// Initialize AdditionalProperties and Styles if nil
540544
if componentDef.Metadata.AdditionalProperties == nil {
@@ -1080,10 +1084,8 @@ func InvokeGenerationFromSheetWithOptions(wg *sync.WaitGroup, path string, model
10801084
func GenerateDefsForCoreRegistrant(model ModelCSV, ComponentCSVHelper *ComponentCSVHelper, path string, modelName string) error {
10811085
var version string
10821086
parts := strings.Split(model.SourceURL, "/")
1083-
// Assuming the URL is always of the format "protocol://github.com/owner/repo/tree/definitions/{model-name}/version/components"
1084-
// We know the version is the 7th element (0-indexed) in the split URL
10851087
if len(parts) >= 8 {
1086-
version = parts[8] // Fetch the version from the expected position
1088+
version = parts[8]
10871089
} else {
10881090
return fmt.Errorf("invalid SourceURL format: %s", model.SourceURL)
10891091
}
@@ -1135,9 +1137,7 @@ func GenerateDefsForCoreRegistrant(model ModelCSV, ComponentCSVHelper *Component
11351137
Log.Error(ErrUpdateComponent(err, modelName, comp.Component))
11361138
continue
11371139
}
1138-
if _status != nil {
1139-
componentDef.Status = _status
1140-
}
1140+
componentDef.Status = _status
11411141
componentDef.Model = modelDef
11421142
alreadyExists, err = componentDef.WriteComponentDefinition(compDirPath, "json")
11431143
if err != nil {

0 commit comments

Comments
 (0)