@@ -133,6 +133,9 @@ func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*typ
133
133
if err != nil {
134
134
return "" , err
135
135
}
136
+ for i , overlay := range overlays {
137
+ errs = util .AppendErr (errs , validateOverlay (i , overlay ))
138
+ }
136
139
137
140
matches := make (map [* types.K8sObjectOverlay ]object.K8sObjects )
138
141
// Try to apply the defined overlays.
@@ -175,6 +178,16 @@ func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*typ
175
178
return ret .String (), errs .ToError ()
176
179
}
177
180
181
+ func validateOverlay (overlayIndex int , overlay * types.K8sObjectOverlay ) error {
182
+ var errs util.Errors
183
+ for patchIndex , patch := range overlay .Patches {
184
+ if patch .Value != "" && patch .Verbatim != "" {
185
+ errs = util .AppendErr (errs , fmt .Errorf ("value and verbatim cannot be used together in overlay %d patch %d" , overlayIndex , patchIndex ))
186
+ }
187
+ }
188
+ return errs .ToError ()
189
+ }
190
+
178
191
// applyPatches applies the given patches against the given object. It returns the resulting patched YAML if successful,
179
192
// or a list of errors otherwise.
180
193
func applyPatches (base * object.K8sObject , patches []* types.K8sObjectOverlayPatch ) (outYAML string , errs util.Errors ) {
@@ -189,25 +202,28 @@ func applyPatches(base *object.K8sObject, patches []*types.K8sObjectOverlayPatch
189
202
return "" , util .NewErrs (err )
190
203
}
191
204
for _ , p := range patches {
192
-
193
- var v = & structpb.Value {}
194
- if err := util .UnmarshalWithJSONPB (p .Value , v , false ); err != nil {
195
- errs = util .AppendErr (errs , err )
196
- continue
205
+ var value interface {}
206
+ if p .Verbatim != "" && p .Value == "" {
207
+ value = p .Verbatim
208
+ } else {
209
+ var v = & structpb.Value {}
210
+ if err := util .UnmarshalWithJSONPB (p .Value , v , false ); err != nil {
211
+ errs = util .AppendErr (errs , err )
212
+ continue
213
+ }
214
+ value = v .AsInterface ()
197
215
}
198
-
199
216
if strings .TrimSpace (p .Path ) == "" {
200
- scope .V (2 ).Info ("skipping empty path" , "value" , p . Value )
217
+ scope .V (2 ).Info ("skipping empty path" , "value" , value )
201
218
continue
202
219
}
203
- scope .Info ("applying" , "path" , p .Path , "value" , p . Value )
220
+ scope .Info ("applying" , "path" , p .Path , "value" , value )
204
221
inc , _ , err := tpath .GetPathContext (bo , util .PathFromString (p .Path ), true )
205
222
if err != nil {
206
223
errs = util .AppendErr (errs , err )
207
224
continue
208
225
}
209
-
210
- err = tpath .WritePathContext (inc , v .AsInterface (), false )
226
+ err = tpath .WritePathContext (inc , value , false )
211
227
if err != nil {
212
228
errs = util .AppendErr (errs , err )
213
229
}
0 commit comments