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 1092924 commit a9c9a0a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
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 @@ -118,6 +118,7 @@ func init() {
stringFlag(flags, "replan-comment-msg", "comment message which re-triggers kubechecks on PR.",
newStringOpts().
withDefault("kubechecks again"))
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 @@ -67,6 +67,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 @@ -291,7 +292,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 a9c9a0a

Please sign in to comment.