Skip to content

Commit

Permalink
move to variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
santinoncs committed Oct 9, 2021
1 parent 1bf897d commit 6f552f3
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 17 deletions.
5 changes: 2 additions & 3 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ func main() {
flag.IntVar(&webhookServerPort, "webhook-server-port", 443, "The port that the webhook server serves at.")
flag.Var(&unpropagatedAnnotations, "unpropagated-annotation", "An annotation that, if present, will be stripped out of any propagated copies of an object. May be specified multiple times, with each instance specifying one annotation. See the user guide for more information.")
flag.Var(&excludedNamespaces, "excluded-namespace", "A namespace that, if present, will be excluded from HNC management. May be specified multiple times, with each instance specifying one namespace. See the user guide for more information.")
flag.StringVar(&includedNamespacesRegex, "included-namespace-regex", ".*", "Namespace regular expression. Namespaces that match this regexp will be included and handle by HNC. As it is a regex, this parameter cannot be specified multiple times.")

flag.StringVar(&includedNamespacesRegex, "included-namespace-regex", ".*", "Namespace regular expression. Namespaces that match this regexp will be included and handle by HNC. As it is a regex, this parameter cannot be specified multiple times. Implicit wrapping of the expression \"^...$\" is done here")
flag.BoolVar(&restartOnSecretRefresh, "cert-restart-on-secret-refresh", false, "Kills the process when secrets are refreshed so that the pod can be restarted (secrets take up to 60s to be updated by running pods)")
flag.Parse()
// Assign the array args to the configuration variables after the args are parsed.
config.UnpropagatedAnnotations = unpropagatedAnnotations

config.SetNamespaces(includedNamespacesRegex, excludedNamespaces)
config.SetNamespaces(includedNamespacesRegex, excludedNamespaces...)

// Enable OpenCensus exporters to export metrics
// to Stackdriver Monitoring.
Expand Down
2 changes: 1 addition & 1 deletion internal/config/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"regexp"
)

func SetNamespaces(regex string, excluded []string) {
func SetNamespaces(regex string, excluded ...string) {

if regex == "" {
regex = ".*"
Expand Down
3 changes: 2 additions & 1 deletion internal/config/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ func TestIsNamespaceIncluded(t *testing.T) {
{name: "bar", regex: "foo-.*", excludeNamespaces: []string{"bar"}, expect: false},
{name: "bar", regex: ".*", excludeNamespaces: []string{"bar"}, expect: false},
{name: "foo", regex: ".*", excludeNamespaces: []string{"bar"}, expect: true},
{name: "foo", regex: ".*", excludeNamespaces: []string{"bar", "foo"}, expect: false},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)

// Test
SetNamespaces(tc.regex, tc.excludeNamespaces)
SetNamespaces(tc.regex, tc.excludeNamespaces...)
isIncluded := IsNamespaceIncluded(tc.name)

// Report
Expand Down
2 changes: 1 addition & 1 deletion internal/mutators/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestMutateNamespaceIncludedLabel(t *testing.T) {
m := &Namespace{}
l := zap.New()
config.SetNamespaces("", []string{"excluded"})
config.SetNamespaces("", "excluded")

tests := []struct {
name string
Expand Down
1 change: 0 additions & 1 deletion internal/reconcilers/anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (r *AnchorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

// Always delete anchor (and any other HNC CRs) in the excluded namespaces and
// early exit.

if !config.IsNamespaceIncluded(pnm) {
// Since the anchors in the excluded namespaces are never synced by HNC,
// there are no finalizers on the anchors that we can delete them without
Expand Down
6 changes: 3 additions & 3 deletions internal/reconcilers/anchor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Anchor", func() {
BeforeEach(func() {
fooName = createNS(ctx, "foo")
barName = createNSName("bar")
config.SetNamespaces("", []string{})
config.SetNamespaces("")
})

It("should create an subnamespace and update the hierarchy according to the anchor", func() {
Expand Down Expand Up @@ -52,14 +52,14 @@ var _ = Describe("Anchor", func() {
})

It("should remove the anchor in an excluded namespace", func() {
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")
kube_system_anchor_bar := newAnchor(barName, "kube-system")
updateAnchor(ctx, kube_system_anchor_bar)
Eventually(canGetAnchor(ctx, barName, "kube-system")).Should(Equal(false))
})

It("should set the anchor.status.state to Forbidden if the subnamespace is an excluded namespace", func() {
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")
foo_anchor_kube_system := newAnchor("kube-system", fooName)
updateAnchor(ctx, foo_anchor_kube_system)
Eventually(getAnchorState(ctx, fooName, "kube-system")).Should(Equal(api.Forbidden))
Expand Down
8 changes: 4 additions & 4 deletions internal/reconcilers/hierarchy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Hierarchy", func() {
BeforeEach(func() {
fooName = createNS(ctx, "foo")
barName = createNS(ctx, "bar")
config.SetNamespaces("", []string{})
config.SetNamespaces("")
})

It("should set a child on the parent", func() {
Expand All @@ -34,7 +34,7 @@ var _ = Describe("Hierarchy", func() {

It("should remove the hierarchyconfiguration singleton in an excluded namespacee", func() {
// Set the excluded-namespace "kube-system"'s parent to "bar".
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")
exHier := newHierarchy("kube-system")
exHier.Spec.Parent = barName
updateHierarchy(ctx, exHier)
Expand All @@ -45,7 +45,7 @@ var _ = Describe("Hierarchy", func() {

It("should set IllegalParent condition if the parent is an excluded namespace", func() {
// Set bar's parent to the excluded-namespace "kube-system".
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")
barHier := newHierarchy(barName)
barHier.Spec.Parent = "kube-system"
updateHierarchy(ctx, barHier)
Expand Down Expand Up @@ -382,7 +382,7 @@ var _ = Describe("Hierarchy", func() {
})

It("should remove included-namespace namespace labels from excluded namespaces", func() {
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")
kubeSystem := getNamespace(ctx, "kube-system")

// Add additional label "other:other" to verify the labels are updated.
Expand Down
2 changes: 1 addition & 1 deletion internal/validators/anchor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestCreateSubnamespaces(t *testing.T) {
// namespace "c".
f := foresttest.Create("-Aa")
h := &Anchor{Forest: f}
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion internal/validators/hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestStructure(t *testing.T) {
h := &Hierarchy{Forest: f}
l := zap.New()
// For this unit test, we only set `kube-system` as an excluded namespace.
config.SetNamespaces("", []string{"kube-system"})
config.SetNamespaces("", "kube-system")

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion internal/validators/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func setSubAnnotation(ns *corev1.Namespace, pnm string) {
func TestIllegalIncludedNamespaceNamespace(t *testing.T) {
f := foresttest.Create("-a-c") // a <- b; c <- d
vns := &Namespace{Forest: f}
config.SetNamespaces("", []string{"excluded"})
config.SetNamespaces("", "excluded")

tests := []struct {
name string
Expand Down

0 comments on commit 6f552f3

Please sign in to comment.