@@ -39,6 +39,7 @@ type addMetadataOptions struct {
39
39
mapValidator func (map [string ]string ) error
40
40
kind kindOfAdd
41
41
labelsWithoutSelector bool
42
+ includeTemplates bool
42
43
}
43
44
44
45
// newCmdAddAnnotation adds one or more commonAnnotations to the kustomization file.
@@ -83,6 +84,9 @@ func newCmdAddLabel(fSys filesys.FileSystem, v func(map[string]string) error) *c
83
84
cmd .Flags ().BoolVar (& o .labelsWithoutSelector , "without-selector" , false ,
84
85
"using add labels without selector option" ,
85
86
)
87
+ cmd .Flags ().BoolVar (& o .includeTemplates , "include-templates" , false ,
88
+ "include labels in templates (requires --without-selector)" ,
89
+ )
86
90
return cmd
87
91
}
88
92
@@ -112,6 +116,9 @@ func (o *addMetadataOptions) validateAndParse(args []string) error {
112
116
if len (args ) < 1 {
113
117
return fmt .Errorf ("must specify %s" , o .kind )
114
118
}
119
+ if ! o .labelsWithoutSelector && o .includeTemplates {
120
+ return fmt .Errorf ("--without-selector flag must be specified for --include-templates to work" )
121
+ }
115
122
m , err := util .ConvertSliceToMap (args , o .kind .String ())
116
123
if err != nil {
117
124
return err
@@ -132,7 +139,11 @@ func (o *addMetadataOptions) addAnnotations(m *types.Kustomization) error {
132
139
133
140
func (o * addMetadataOptions ) addLabels (m * types.Kustomization ) error {
134
141
if o .labelsWithoutSelector {
135
- m .Labels = append (m .Labels , types.Label {Pairs : make (map [string ]string ), IncludeSelectors : false })
142
+ m .Labels = append (m .Labels , types.Label {
143
+ Pairs : make (map [string ]string ),
144
+ IncludeSelectors : false ,
145
+ IncludeTemplates : o .includeTemplates ,
146
+ })
136
147
return o .writeToMap (m .Labels [len (m .Labels )- 1 ].Pairs , label )
137
148
}
138
149
if m .CommonLabels == nil {
0 commit comments