diff --git a/models/registration/svg_helper.go b/models/registration/svg_helper.go index 362ce93c..5189d39c 100644 --- a/models/registration/svg_helper.go +++ b/models/registration/svg_helper.go @@ -5,19 +5,10 @@ import ( "os" "path/filepath" "strings" - "sync" ) -var hashCheckSVG = make(map[string]string) -var mx sync.Mutex var UISVGPaths = make([]string, 1) -func writeHashCheckSVG(key string, val string) { - mx.Lock() - hashCheckSVG[key] = val - mx.Unlock() -} - func WriteAndReplaceSVGWithFileSystemPath(svgColor, svgWhite, svgComplete string, baseDir, dirname, filename string, isModel bool) (svgColorPath, svgWhitePath, svgCompletePath string) { filename = strings.ToLower(filename) successCreatingDirectory := false @@ -35,7 +26,6 @@ func WriteAndReplaceSVGWithFileSystemPath(svgColor, svgWhite, svgComplete string } successCreatingDirectory = true - f, err := os.Create(filepath.Join(path, filename+"-color.svg")) if err != nil { fmt.Println(err) @@ -58,7 +48,6 @@ func WriteAndReplaceSVGWithFileSystemPath(svgColor, svgWhite, svgComplete string } successCreatingDirectory = true - f, err := os.Create(filepath.Join(path, filename+"-white.svg")) if err != nil { fmt.Println(err) diff --git a/orchestration/design.go b/orchestration/design.go new file mode 100644 index 00000000..2e0a9adb --- /dev/null +++ b/orchestration/design.go @@ -0,0 +1,51 @@ +package orchestration + +import "github.com/meshery/schemas/models/v1beta1/component" + +const ( + ResourceSourceDesignIdLabelKey = "design.meshery.io/id" + ResourceSourceDesignVersionLabelKey = "design.meshery.io/version" + ResourceSourceComponentIdLabelKey = "component.meshery.io/id" +) + +// Enriches the component with additional labels and annotations related to the design and component +// This is useful for tracking the source of the component and design in the cluster +// for allowing orchestration through Meshery +func EnrichComponentWithMesheryMetadata(comp *component.ComponentDefinition, designId string, designVersion string) error { + + // Initialize Configuration if nil + if comp.Configuration == nil { + comp.Configuration = make(map[string]interface{}) + } + + // Check and initialize Metadata if absent + metadata, ok := comp.Configuration["metadata"].(map[string]interface{}) + if !ok || metadata == nil { + metadata = map[string]interface{}{ + "labels": make(map[string]interface{}), + "annotations": make(map[string]interface{}), + } + comp.Configuration["metadata"] = metadata + } + + // Check and initialize Labels if absent + labels, ok := metadata["labels"].(map[string]interface{}) + if !ok || labels == nil { + labels = make(map[string]interface{}) + metadata["labels"] = labels + } + + annotations, ok := metadata["annotations"].(map[string]interface{}) + + if !ok || annotations == nil { + annotations = make(map[string]interface{}) + metadata["annotations"] = annotations + } + + // Assign the new label + labels[ResourceSourceDesignIdLabelKey] = designId + annotations[ResourceSourceDesignVersionLabelKey] = designVersion + annotations[ResourceSourceComponentIdLabelKey] = comp.Id.String() + + return nil +}