Skip to content

Commit 74a2a4f

Browse files
committed
Allow optional patches
1 parent 1e32b63 commit 74a2a4f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pkg/patch/patch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*typ
160160
// Each overlay should have exactly one match in the output manifest.
161161
switch {
162162
case len(matches[overlay]) == 0:
163+
if overlay.Optional {
164+
scope.V(2).Info("overlay for %s:%s is optional and does not match any object in output manifest", overlay.Kind, overlay.Name)
165+
continue
166+
}
163167
errs = util.AppendErr(errs, fmt.Errorf("overlay for %s:%s does not match any object in output manifest. Available objects are:\n%s",
164168
overlay.Kind, overlay.Name, strings.Join(objs.Keys(), "\n")))
165169
case len(matches[overlay]) > 1:

pkg/types/overlay.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type K8sObjectOverlay struct {
2323
Name string `json:"name,omitempty"`
2424
// List of patches to apply to resource.
2525
Patches []*K8sObjectOverlayPatch `json:"patches,omitempty"`
26+
// Optional marks the overlay as optional. If the resource does not exist, the overlay is ignored.
27+
Optional bool `json:"optional,omitempty"`
2628
}
2729

2830
type K8sObjectOverlayPatch struct {

0 commit comments

Comments
 (0)