@@ -42,26 +42,30 @@ type PodCounts struct {
42
42
Succeeded int
43
43
}
44
44
45
- // Add labels to metadata for subresources
45
+ // Fix labels in maps
46
46
func fixMap (appWrapper * mcadv1beta1.AppWrapper , m map [string ]interface {}) {
47
- // inject metadata in templates
48
- if template , ok := m ["template" ].(map [string ]interface {}); ok {
49
- if _ , ok := template ["spec" ]; ok {
50
- if _ , ok := template ["metadata" ]; ! ok {
51
- template ["metadata" ] = map [string ]interface {}{}
47
+ // inject placeholder in pod specs
48
+ if spec , ok := m ["spec" ].(map [string ]interface {}); ok {
49
+ if _ , ok := spec ["containers" ]; ok {
50
+ metadata , ok := m ["metadata" ].(map [string ]interface {})
51
+ if ! ok {
52
+ metadata = map [string ]interface {}{}
53
+ m ["metadata" ] = metadata
52
54
}
55
+ labels , ok := metadata ["labels" ].(map [string ]interface {})
56
+ if ! ok {
57
+ labels = map [string ]interface {}{}
58
+ metadata ["labels" ] = labels
59
+ }
60
+ labels [nameLabel ] = "placeholder"
53
61
}
54
62
}
55
- // inject labels in metadata
56
- if metadata , ok := m ["metadata" ].(map [string ]interface {}); ok {
57
- if _ , ok := metadata ["labels" ]; ! ok {
58
- metadata ["labels" ] = map [string ]interface {}{}
59
- }
60
- }
61
- // inject appwrapper labels
63
+ // replace placeholder with actual labels
62
64
if labels , ok := m ["labels" ].(map [string ]interface {}); ok {
63
- labels [namespaceLabel ] = appWrapper .Namespace
64
- labels [nameLabel ] = appWrapper .Name
65
+ if _ , ok := labels [nameLabel ]; ok {
66
+ labels [namespaceLabel ] = appWrapper .Namespace
67
+ labels [nameLabel ] = appWrapper .Name
68
+ }
65
69
}
66
70
// visit submaps and arrays
67
71
for _ , v := range m {
@@ -74,7 +78,7 @@ func fixMap(appWrapper *mcadv1beta1.AppWrapper, m map[string]interface{}) {
74
78
}
75
79
}
76
80
77
- // Add labels to metadata for subresources
81
+ // Fix labels in arrays
78
82
func fixArray (appWrapper * mcadv1beta1.AppWrapper , a []interface {}) {
79
83
// visit submaps and arrays
80
84
for _ , v := range a {
0 commit comments