Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit fb9795c

Browse files
authored
Inject labels in more places (#69)
1 parent 040f03e commit fb9795c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

internal/controller/resource_manager.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,22 @@ type PodCounts struct {
4343

4444
// Add labels to metadata for subresources
4545
func fixMap(appWrapper *mcadv1beta1.AppWrapper, m map[string]interface{}) {
46-
// assume an object with fields apiVersion, kind, and metadata is a subresource
47-
_, hasApiVersion := m["apiVersion"]
48-
_, hasKind := m["kind"]
49-
metadata, hasMetadata := m["metadata"].(map[string]interface{})
50-
if hasApiVersion && hasKind && hasMetadata {
51-
// inject labels in metadata
52-
labels, hasLabels := metadata["labels"].(map[string]interface{})
53-
if !hasLabels {
54-
labels = map[string]interface{}{}
55-
metadata["labels"] = labels
46+
// inject metadata in templates
47+
if template, ok := m["template"].(map[string]interface{}); ok {
48+
if _, ok := template["spec"]; ok {
49+
if _, ok := template["metadata"]; !ok {
50+
template["metadata"] = map[string]interface{}{}
51+
}
52+
}
53+
}
54+
// inject labels in metadata
55+
if metadata, ok := m["metadata"].(map[string]interface{}); ok {
56+
if _, ok := metadata["labels"]; !ok {
57+
metadata["labels"] = map[string]interface{}{}
5658
}
59+
}
60+
// inject appwrapper labels
61+
if labels, ok := m["labels"].(map[string]interface{}); ok {
5762
labels[namespaceLabel] = appWrapper.Namespace
5863
labels[nameLabel] = appWrapper.Name
5964
}

0 commit comments

Comments
 (0)