From b2cae850cf80e7d9c537fec18cc9af1ca832f685 Mon Sep 17 00:00:00 2001 From: ricky Date: Mon, 3 Apr 2023 18:58:32 +0800 Subject: [PATCH] feat: support pool-coordinator component work in specified namespace Signed-off-by: ricky --- charts/openyurt/templates/yurt-manager.yaml | 1 + cmd/yurt-manager/app/options/generic.go | 6 ++++-- pkg/controller/apis/config/types.go | 1 + .../poolcoordinator/cert/poolcoordinatorcert_controller.go | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/charts/openyurt/templates/yurt-manager.yaml b/charts/openyurt/templates/yurt-manager.yaml index 509c223bf5a..f549c5d8723 100644 --- a/charts/openyurt/templates/yurt-manager.yaml +++ b/charts/openyurt/templates/yurt-manager.yaml @@ -57,6 +57,7 @@ spec: - --health-probe-addr=:{{ .Values.yurtManager.healthProbe.port }} - --logtostderr=true - --v={{ .Values.yurtManager.log.level }} + - --working-namespace={{ .Release.Namespace | quote }} command: - /usr/local/bin/yurt-manager image: {{ .Values.yurtManager.image.repository }}:{{ .Values.yurtManager.image.tag }} diff --git a/cmd/yurt-manager/app/options/generic.go b/cmd/yurt-manager/app/options/generic.go index e18c166073b..10027c11b06 100644 --- a/cmd/yurt-manager/app/options/generic.go +++ b/cmd/yurt-manager/app/options/generic.go @@ -36,6 +36,7 @@ func NewGenericOptions() *GenericOptions { LeaderElectionNamespace: "kube-system", RestConfigQPS: 30, RestConfigBurst: 50, + WorkingNamespace: "kube-system", }, } } @@ -61,9 +62,10 @@ func (o *GenericOptions) ApplyTo(cfg *config.GenericConfiguration) error { cfg.HealthProbeAddr = o.HealthProbeAddr cfg.EnableLeaderElection = o.EnableLeaderElection - cfg.LeaderElectionNamespace = o.LeaderElectionNamespace + cfg.LeaderElectionNamespace = o.WorkingNamespace cfg.RestConfigQPS = o.RestConfigQPS cfg.RestConfigBurst = o.RestConfigBurst + cfg.WorkingNamespace = o.WorkingNamespace return nil } @@ -78,8 +80,8 @@ func (o *GenericOptions) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.MetricsAddr, "metrics-addr", o.MetricsAddr, "The address the metric endpoint binds to.") fs.StringVar(&o.HealthProbeAddr, "health-probe-addr", o.HealthProbeAddr, "The address the healthz/readyz endpoint binds to.") fs.BoolVar(&o.EnableLeaderElection, "enable-leader-election", o.EnableLeaderElection, "Whether you need to enable leader election.") - fs.StringVar(&o.LeaderElectionNamespace, "leader-election-namespace", o.LeaderElectionNamespace, "This determines the namespace in which the leader election configmap/leases will be created, it will use in-cluster namespace if empty.") fs.IntVar(&o.RestConfigQPS, "rest-config-qps", o.RestConfigQPS, "rest-config-qps.") fs.IntVar(&o.RestConfigBurst, "rest-config-burst", o.RestConfigBurst, "rest-config-burst.") + fs.StringVar(&o.WorkingNamespace, "working-namespace", o.WorkingNamespace, "The namespace where the yurt-manager is working.") } diff --git a/pkg/controller/apis/config/types.go b/pkg/controller/apis/config/types.go index d01b44427d3..3d226ffeead 100644 --- a/pkg/controller/apis/config/types.go +++ b/pkg/controller/apis/config/types.go @@ -56,4 +56,5 @@ type GenericConfiguration struct { LeaderElectionNamespace string RestConfigQPS int RestConfigBurst int + WorkingNamespace string } diff --git a/pkg/controller/poolcoordinator/cert/poolcoordinatorcert_controller.go b/pkg/controller/poolcoordinator/cert/poolcoordinatorcert_controller.go index 82a6f15e204..9a92f020f2a 100644 --- a/pkg/controller/poolcoordinator/cert/poolcoordinatorcert_controller.go +++ b/pkg/controller/poolcoordinator/cert/poolcoordinatorcert_controller.go @@ -44,6 +44,7 @@ func init() { var ( concurrentReconciles = 3 + PoolcoordinatorNS = "kube-system" ) const ( @@ -53,7 +54,6 @@ const ( certDir = "/tmp" ComponentName = "yurt-controller-manager_poolcoordinator" - PoolcoordinatorNS = "kube-system" PoolcoordinatorAPIServerSVC = "pool-coordinator-apiserver" PoolcoordinatorETCDSVC = "pool-coordinator-etcd" @@ -203,6 +203,10 @@ func Add(c *appconfig.CompletedConfig, mgr manager.Manager) error { return err } + // init global variables + cfg := c.ComponentConfig.Generic + PoolcoordinatorNS = cfg.WorkingNamespace + // init PoolCoordinator // prepare some necessary assets (CA, certs, kubeconfigs) for pool-coordinator err = initPoolCoordinator(r.Client, nil)