Skip to content

Commit

Permalink
Allow optional patches
Browse files Browse the repository at this point in the history
  • Loading branch information
ludydoo committed Jun 10, 2024
1 parent 1e32b63 commit 74a2a4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 74a2a4f

Please sign in to comment.