@@ -42,26 +42,30 @@ type PodCounts struct {
4242 Succeeded int
4343}
4444
45- // Add labels to metadata for subresources
45+ // Fix labels in maps
4646func 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
5254 }
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"
5361 }
5462 }
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
6264 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+ }
6569 }
6670 // visit submaps and arrays
6771 for _ , v := range m {
@@ -74,7 +78,7 @@ func fixMap(appWrapper *mcadv1beta1.AppWrapper, m map[string]interface{}) {
7478 }
7579}
7680
77- // Add labels to metadata for subresources
81+ // Fix labels in arrays
7882func fixArray (appWrapper * mcadv1beta1.AppWrapper , a []interface {}) {
7983 // visit submaps and arrays
8084 for _ , v := range a {
0 commit comments