diff --git a/pkg/patch/patch.go b/pkg/patch/patch.go index fce0c41..b20e0a1 100644 --- a/pkg/patch/patch.go +++ b/pkg/patch/patch.go @@ -160,6 +160,10 @@ func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*typ // Each overlay should have exactly one match in the output manifest. switch { case len(matches[overlay]) == 0: + if overlay.Optional { + scope.V(2).Info("overlay for %s:%s is optional and does not match any object in output manifest", overlay.Kind, overlay.Name) + continue + } errs = util.AppendErr(errs, fmt.Errorf("overlay for %s:%s does not match any object in output manifest. Available objects are:\n%s", overlay.Kind, overlay.Name, strings.Join(objs.Keys(), "\n"))) case len(matches[overlay]) > 1: diff --git a/pkg/types/overlay.go b/pkg/types/overlay.go index 09ba70c..c2c7418 100644 --- a/pkg/types/overlay.go +++ b/pkg/types/overlay.go @@ -23,6 +23,8 @@ type K8sObjectOverlay struct { Name string `json:"name,omitempty"` // List of patches to apply to resource. Patches []*K8sObjectOverlayPatch `json:"patches,omitempty"` + // Optional marks the overlay as optional. If the resource does not exist, the overlay is ignored. + Optional bool `json:"optional,omitempty"` } type K8sObjectOverlayPatch struct {