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
26 changes: 26 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package main
import (
"crypto/tls"
"flag"
"fmt"
"os"
"strings"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand All @@ -33,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/validation"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
Expand Down Expand Up @@ -71,6 +74,7 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool
var tlsOpts []func(*tls.Config)
var watchNamespaces []string
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -88,6 +92,21 @@ func main() {
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
seenNamespaces := make(map[string]struct{})
flag.Func("watch-namespace", "Namespace to watch (repeatable; omit for cluster-wide)", func(s string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can users set this watch-namespace envvar from helm or operator env? i think we need to document that part

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a draft PR for the helm chart here: valkey-io/valkey-helm#172

Is that what you had in mind?

For env var, can any of these arguments today be set via env var? I hadn't had that in scope.

if s == "" {
return fmt.Errorf("watch-namespace value must not be empty")
}
if errs := validation.IsDNS1123Label(s); len(errs) > 0 {
return fmt.Errorf("watch-namespace %q is not a valid namespace name: %s", s, strings.Join(errs, "; "))
}
if _, dup := seenNamespaces[s]; dup {
return fmt.Errorf("watch-namespace %q specified more than once", s)
}
seenNamespaces[s] = struct{}{}
watchNamespaces = append(watchNamespaces, s)
return nil
})
opts := zap.Options{
Development: true,
StacktraceLevel: zapcore.FatalLevel,
Expand Down Expand Up @@ -185,6 +204,13 @@ func main() {
&corev1.Pod{}: {Label: managedBySelector},
},
}
if len(watchNamespaces) > 0 {
setupLog.Info("Restricting cache to namespaces", "namespaces", watchNamespaces)
cacheOpts.DefaultNamespaces = make(map[string]cache.Config, len(watchNamespaces))
for _, ns := range watchNamespaces {
cacheOpts.DefaultNamespaces[ns] = cache.Config{}
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand Down