diff --git a/localdev/kubechecks/values.yaml b/localdev/kubechecks/values.yaml index 9e5473e3..f1ab5f66 100644 --- a/localdev/kubechecks/values.yaml +++ b/localdev/kubechecks/values.yaml @@ -1,6 +1,7 @@ configMap: create: true env: + GRPC_ENFORCE_ALPN_ENABLED: false KUBECHECKS_LOG_LEVEL: debug KUBECHECKS_ENABLE_WEBHOOK_CONTROLLER: "false" KUBECHECKS_ARGOCD_API_INSECURE: "true" diff --git a/pkg/config/config.go b/pkg/config/config.go index b158cf93..3d00b832 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -2,6 +2,7 @@ package config import ( "reflect" + "strings" "time" "github.com/mitchellh/mapstructure" @@ -105,6 +106,12 @@ func NewWithViper(v *viper.Viper) (ServerConfig, error) { return time.ParseDuration(input) } + if in.String() == "string" && out.String() == "[]string" { + input := value.(string) + ns := strings.Split(input, ",") + return ns, nil + } + return value, nil } }); err != nil { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 2227f484..0c59053b 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -19,6 +19,7 @@ func TestNew(t *testing.T) { v.Set("argocd-api-plaintext", "true") v.Set("worst-conftest-state", "warning") v.Set("repo-refresh-interval", "10m") + v.Set("allowed-namespaces", "default,kube-system") cfg, err := NewWithViper(v) require.NoError(t, err) @@ -27,4 +28,5 @@ func TestNew(t *testing.T) { assert.Equal(t, true, cfg.ArgoCDPlainText) assert.Equal(t, pkg.StateWarning, cfg.WorstConfTestState, "worst states can be overridden") assert.Equal(t, time.Minute*10, cfg.RepoRefreshInterval) + assert.Equal(t, []string{"default", "kube-system"}, cfg.AllowedNamespaces) } diff --git a/pkg/events/check.go b/pkg/events/check.go index 8e355a81..3a608081 100644 --- a/pkg/events/check.go +++ b/pkg/events/check.go @@ -292,16 +292,11 @@ func (ce *CheckEvent) Process(ctx context.Context) error { ce.logger.Info().Msgf("adding %d apps to the queue", len(ce.affectedItems.Applications)) // Produce apps onto channel for _, app := range ce.affectedItems.Applications { - if len(ce.ctr.Config.AllowedNamespaces) > 0 { - ns := strings.Split(ce.ctr.Config.AllowedNamespaces[0], ",") - if slices.Contains(ns, app.Spec.Destination.Namespace) { - ce.queueApp(app) - } else { - ce.logger.Info().Msgf("skipping app %s, namespace %s not allowed", app.Name, app.Spec.Destination.Namespace) - } - } else { - ce.queueApp(app) + if len(ce.ctr.Config.AllowedNamespaces) > 0 && !slices.Contains(ce.ctr.Config.AllowedNamespaces, app.Spec.Destination.Namespace) { + ce.logger.Info().Msgf("skipping app %s, namespace %s not allowed", app.Name, app.Spec.Destination.Namespace) + continue } + ce.queueApp(app) } ce.wg.Wait()