Skip to content

Commit

Permalink
add logic for assign meshery specific labels and annotations
Browse files Browse the repository at this point in the history
Signed-off-by: aabidsofi19 <[email protected]>
  • Loading branch information
aabidsofi19 committed Dec 19, 2024
1 parent e717d52 commit f3e2d76
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions orchestration/design.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
package orchestration

import "github.com/meshery/schemas/models/v1beta1/component"

const (
ResourceSourceDesignIdLabelKey = "design.meshery.io/id"
ResourceSourceDesignNameLabelKey = "design.meshery.io/name"
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, designName 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[ResourceSourceDesignNameLabelKey] = designName
annotations[ResourceSourceComponentIdLabelKey] = comp.Id.String()

return nil
}

0 comments on commit f3e2d76

Please sign in to comment.