Skip to content

Commit

Permalink
watch desired namespaces (#355)
Browse files Browse the repository at this point in the history
* watch desired namespaces

* remove unused image
  • Loading branch information
MegaByte875 authored Oct 19, 2023
1 parent 2e59254 commit bd369e2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
command:
- /usr/local/bin/controller-manager
args:
{{- if .Values.watchNamespaces }}
- --watch-namespaces={{ .Values.watchNamespaces }}
{{- end }}
- --sync-period={{ .Values.syncPeriod }}
- --concurrent-nebulacluster-syncs={{ .Values.concurrentNebulaClusterSyncs }}
- --concurrent-nebularestore-syncs={{ .Values.concurrentNebulaRestoreSyncs }}
Expand Down Expand Up @@ -76,6 +79,9 @@ spec:
command:
- /usr/local/bin/autoscaler
args:
{{- if .Values.watchNamespaces }}
- --watch-namespaces={{ .Values.watchNamespaces }}
{{- end }}
- --concurrent-autoscaler-syncs={{ .Values.concurrentAutoscalerSyncs }}
- --health-probe-bind-address=:8091
- --metrics-bind-address=:8090
Expand Down
7 changes: 4 additions & 3 deletions charts/nebula-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ image:
nebulaOperator:
image: vesoft/nebula-operator:latest
imagePullPolicy: Always
kubeRBACProxy:
image: bitnami/kube-rbac-proxy:0.14.2
imagePullPolicy: Always

imagePullSecrets: [ ]
kubernetesClusterDomain: ""
Expand Down Expand Up @@ -49,6 +46,10 @@ enableKruiseScheme: false
# Period at which the controller forces the repopulation of its local object stores. (default 0h30m0s)
syncPeriod: 0h30m0s

# Namespaces restricts the controller watches for updates to Kubernetes objects. If empty, all namespaces are watched.
# e.g. ns1,ns2,ns3
watchNamespaces: ""

# The number of NebulaCluster objects that are allowed to sync concurrently. (default 5)
concurrentNebulaClusterSyncs: 5

Expand Down
12 changes: 9 additions & 3 deletions cmd/autoscaler/app/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func Run(ctx context.Context, opts *options.Options) error {

profileflag.ListenAndServe(opts.ProfileOpts)

if len(opts.Namespaces) == 0 {
klog.Info("nebula-autoscaler watches all namespaces")
} else {
klog.Infof("nebula-autoscaler watches namespaces %v", opts.Namespaces)
}

cfg, err := ctrlruntime.GetConfig()
if err != nil {
panic(err)
Expand All @@ -105,7 +111,7 @@ func Run(ctx context.Context, opts *options.Options) error {

Cache: cache.Options{
SyncPeriod: &opts.HPAOpts.HorizontalPodAutoscalerSyncPeriod.Duration,
//Namespaces: opts.Namespaces,
Namespaces: opts.Namespaces,
},
Controller: config.Controller{
GroupKindConcurrency: map[string]int{
Expand All @@ -117,7 +123,7 @@ func Run(ctx context.Context, opts *options.Options) error {

mgr, err := ctrlruntime.NewManager(cfg, ctrlOptions)
if err != nil {
klog.Errorf("Failed to build controller manager: %v", err)
klog.Errorf("Failed to build nebula-autoscaler: %v", err)
return err
}

Expand Down Expand Up @@ -146,7 +152,7 @@ func Run(ctx context.Context, opts *options.Options) error {
}

if err := mgr.Start(ctx); err != nil {
klog.Errorf("controller manager exits unexpectedly: %v", err)
klog.Errorf("nebula-autoscaler exits unexpectedly: %v", err)
return err
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/autoscaler/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var (
)

type Options struct {
// Namespaces restricts the cache's ListWatch to the desired namespaces
// Default watches all namespaces
Namespaces []string

// LeaderElection defines the configuration of leader election client.
LeaderElection cbc.LeaderElectionConfiguration

Expand Down Expand Up @@ -108,4 +112,5 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.MetricsBindAddress, "metrics-bind-address", ":8080", "The TCP address that the controller should bind to for serving prometheus metrics(e.g. 127.0.0.1:8080, :8080). It can be set to \"0\" to disable the metrics serving.")
flags.StringVar(&o.HealthProbeBindAddress, "health-probe-bind-address", ":8081", "The TCP address that the controller should bind to for serving health probes.(e.g. 127.0.0.1:8081, :8081). It can be set to \"0\" to disable the health probe serving.")

flags.StringSliceVar(&o.Namespaces, "watch-namespaces", nil, "Namespaces restricts the controller watches for updates to Kubernetes objects. If empty, all namespaces are watched. Multiple namespaces seperated by comma.(e.g. ns1,ns2,ns3).")
}
10 changes: 8 additions & 2 deletions cmd/controller-manager/app/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func Run(ctx context.Context, opts *options.Options) error {
klog.Info("register openkruise scheme")
}

if len(opts.Namespaces) == 0 {
klog.Info("nebula-controller-manager watches all namespaces")
} else {
klog.Infof("nebula-controller-manager watches namespaces %v", opts.Namespaces)
}

cfg, err := ctrlruntime.GetConfig()
if err != nil {
panic(err)
Expand All @@ -115,7 +121,7 @@ func Run(ctx context.Context, opts *options.Options) error {
MetricsBindAddress: opts.MetricsBindAddress,
Cache: cache.Options{
SyncPeriod: &opts.SyncPeriod.Duration,
//Namespaces: opts.Namespaces,
Namespaces: opts.Namespaces,
},
Controller: config.Controller{
GroupKindConcurrency: map[string]int{
Expand Down Expand Up @@ -181,7 +187,7 @@ func Run(ctx context.Context, opts *options.Options) error {
}

if err := mgr.Start(ctx); err != nil {
klog.Errorf("controller manager exits unexpectedly: %v", err)
klog.Errorf("nebula-controller-manager exits unexpectedly: %v", err)
return err
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Options struct {

// Namespaces restricts the cache's ListWatch to the desired namespaces
// Default watches all namespaces
Namespaces string
Namespaces []string

// MetricsBindAddress is the TCP address that the controller should bind to
// for serving prometheus metrics.
Expand Down Expand Up @@ -109,7 +109,8 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
"The duration the clients should wait between attempting acquisition and renewal "+
"of a leadership. This is only applicable if leader election is enabled.")

flags.DurationVar(&o.SyncPeriod.Duration, "sync-period", 0, " Period at which the controller forces the repopulation of its local object stores.")
flags.DurationVar(&o.SyncPeriod.Duration, "sync-period", 0, "Period at which the controller forces the repopulation of its local object stores.")
flags.StringSliceVar(&o.Namespaces, "watch-namespaces", nil, "Namespaces restricts the controller watches for updates to Kubernetes objects. If empty, all namespaces are watched. Multiple namespaces seperated by comma.(e.g. ns1,ns2,ns3).")
flags.StringVar(&o.MetricsBindAddress, "metrics-bind-address", ":8080", "The TCP address that the controller should bind to for serving prometheus metrics(e.g. 127.0.0.1:8080, :8080). It can be set to \"0\" to disable the metrics serving.")
flags.StringVar(&o.HealthProbeBindAddress, "health-probe-bind-address", ":8081", "The TCP address that the controller should bind to for serving health probes.(e.g. 127.0.0.1:8081, :8081). It can be set to \"0\" to disable the health probe serving.")
flags.IntVar(&o.ConcurrentNebulaClusterSyncs, "concurrent-nebulacluster-syncs", 5, "The number of NebulaCluster objects that are allowed to sync concurrently.")
Expand Down

0 comments on commit bd369e2

Please sign in to comment.