@@ -133,6 +133,9 @@ func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*typ
133133 if err != nil {
134134 return "" , err
135135 }
136+ for i , overlay := range overlays {
137+ errs = util .AppendErr (errs , validateOverlay (i , overlay ))
138+ }
136139
137140 matches := make (map [* types.K8sObjectOverlay ]object.K8sObjects )
138141 // Try to apply the defined overlays.
@@ -175,6 +178,16 @@ func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*typ
175178 return ret .String (), errs .ToError ()
176179}
177180
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+
178191// applyPatches applies the given patches against the given object. It returns the resulting patched YAML if successful,
179192// or a list of errors otherwise.
180193func applyPatches (base * object.K8sObject , patches []* types.K8sObjectOverlayPatch ) (outYAML string , errs util.Errors ) {
@@ -189,25 +202,28 @@ func applyPatches(base *object.K8sObject, patches []*types.K8sObjectOverlayPatch
189202 return "" , util .NewErrs (err )
190203 }
191204 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 ()
197215 }
198-
199216 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 )
201218 continue
202219 }
203- scope .Info ("applying" , "path" , p .Path , "value" , p . Value )
220+ scope .Info ("applying" , "path" , p .Path , "value" , value )
204221 inc , _ , err := tpath .GetPathContext (bo , util .PathFromString (p .Path ), true )
205222 if err != nil {
206223 errs = util .AppendErr (errs , err )
207224 continue
208225 }
209-
210- err = tpath .WritePathContext (inc , v .AsInterface (), false )
226+ err = tpath .WritePathContext (inc , value , false )
211227 if err != nil {
212228 errs = util .AppendErr (errs , err )
213229 }
0 commit comments