Skip to content

Commit

Permalink
Allow the option to run kubechecks in namespaced scope
Browse files Browse the repository at this point in the history
Signed-off-by: Abhi Kapoor <[email protected]>
  • Loading branch information
abhi-kapoor committed Dec 7, 2024
1 parent dd1ca0f commit 532b9ae
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/kubechecks/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: kubechecks
description: A Helm chart for kubechecks
version: 0.4.5
version: 0.4.6
type: application
maintainers:
- name: zapier
1 change: 1 addition & 0 deletions charts/kubechecks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ commonLabels: {}
configMap:
create: false
env: {}
# KUBECHECKS_ALLOWED_NAMESPACES: default,namespace-a
# KUBECHECKS_ARGOCD_API_INSECURE: "false"
# KUBECHECKS_ARGOCD_API_PATH_PREFIX: /
# KUBECHECKS_ARGOCD_API_NAMESPACE: argocd
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func init() {
stringFlag(flags, "worst-hooks-state", "The worst state that can be returned from the hooks renderer.",
newStringOpts().
withDefault("panic"))
stringSliceFlag(flags, "allowed-namespaces", "Run Kubechecks in namespaced scope instead of cluster scope by specifying the namespaces to monitor.")

panicIfError(viper.BindPFlags(flags))
setupLogOutput()
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type ServerConfig struct {
WorstPreupgradeState pkg.CommitState `mapstructure:"worst-preupgrade-state"`

// misc
AllowedNamespaces []string `mapstructure:"allowed-namespaces"`
FallbackK8sVersion string `mapstructure:"fallback-k8s-version"`
LabelFilter string `mapstructure:"label-filter"`
LogLevel zerolog.Level `mapstructure:"log-level"`
Expand Down
12 changes: 11 additions & 1 deletion pkg/events/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -286,7 +287,16 @@ 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 {
ce.queueApp(app)
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)
}
}

ce.wg.Wait()
Expand Down

0 comments on commit 532b9ae

Please sign in to comment.