Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/go/pkg/synk/synk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"log/slog"
"reflect"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -410,6 +411,15 @@ func (s *Synk) applyAll(
return results, err
}

func validateNamespace(r *unstructured.Unstructured, optsNs string) error {
ns := r.GetNamespace()
allowed := []string{"", "kube-system", optsNs}
if slices.Contains(allowed, ns) {
return nil
}
return errors.Errorf("invalid namespace %q on %q, expected one of %v", ns, resourceKey(r), allowed)
}

// initialize a new ResourceSet version for the given name and prepare resources
// for it.
func (s *Synk) initialize(
Expand All @@ -432,8 +442,8 @@ func (s *Synk) initialize(
// so we can give validation errors in batch in the ResourceSet status.
if opts.EnforceNamespace {
for _, r := range regulars {
if ns := r.GetNamespace(); ns != "" && ns != opts.Namespace && ns != "kube-system" {
return nil, nil, errors.Errorf("invalid namespace %q on %q, expected %q or \"kube-system\"", ns, resourceKey(r), opts.Namespace)
if err := validateNamespace(r, opts.Namespace); err != nil {
return nil, nil, err
}
}
}
Expand Down
Loading