Skip to content

Commit 2a6b470

Browse files
authored
Merge pull request #297 from yangspirit/release-0.4
fix(labelcontroller): add leader-election-namespace flag
2 parents 63f7825 + 4b82e97 commit 2a6b470

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

cmd/csi_driver/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ import (
3030
)
3131

3232
var (
33-
endpoint = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")
34-
nodeID = flag.String("nodeid", "", "node id")
35-
runController = flag.Bool("controller", false, "run controller service")
36-
runNode = flag.Bool("node", false, "run node service")
37-
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
38-
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
39-
lustreAPIEndpoint = flag.String("lustre-endpoint", "", "Lustre API service endpoint, supported values are autopush, staging and prod.")
40-
cloudConfigFilePath = flag.String("cloud-config", "", "Path to GCE cloud provider config")
41-
enableLegacyLustrePort = flag.Bool("enable-legacy-lustre-port", false, "If set to true, the CSI driver controller will provision Lustre instance with the gkeSupportEnabled flag")
42-
enableLabelController = flag.Bool("enable-label-controller", true, "If true, the label controller will be started.")
33+
endpoint = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")
34+
nodeID = flag.String("nodeid", "", "node id")
35+
runController = flag.Bool("controller", false, "run controller service")
36+
runNode = flag.Bool("node", false, "run node service")
37+
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
38+
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
39+
lustreAPIEndpoint = flag.String("lustre-endpoint", "", "Lustre API service endpoint, supported values are autopush, staging and prod.")
40+
cloudConfigFilePath = flag.String("cloud-config", "", "Path to GCE cloud provider config")
41+
enableLegacyLustrePort = flag.Bool("enable-legacy-lustre-port", false, "If set to true, the CSI driver controller will provision Lustre instance with the gkeSupportEnabled flag")
42+
enableLabelController = flag.Bool("enable-label-controller", true, "If true, the label controller will be started.")
43+
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where the leader election resource will be created. Required for out-of-cluster deployments.")
4344

4445
// These are set at compile time.
4546
version = "unknown"
@@ -97,7 +98,7 @@ func main() {
9798
if *enableLabelController {
9899
go func() {
99100
// Pass empty string for kubeconfig to let controller-runtime handle the flag
100-
if err := labelcontroller.Start(ctx, cloudProvider, &mm); err != nil {
101+
if err := labelcontroller.Start(ctx, cloudProvider, &mm, *leaderElectionNamespace); err != nil {
101102
klog.Errorf("Label controller failed: %v", err)
102103
}
103104
}()

pkg/labelcontroller/label_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (r *PvReconciler) Reconcile(ctx context.Context, request reconcile.Request)
108108
return reconcile.Result{}, nil
109109
}
110110

111-
func Start(ctx context.Context, cloud *lustre.Cloud, mm *metrics.Manager) error {
111+
func Start(ctx context.Context, cloud *lustre.Cloud, mm *metrics.Manager, leaderElectionNamespace string) error {
112112
log.SetLogger(zap.New())
113113

114114
cfg, err := ctrl.GetConfig()
@@ -117,9 +117,10 @@ func Start(ctx context.Context, cloud *lustre.Cloud, mm *metrics.Manager) error
117117
}
118118

119119
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
120-
Logger: log.Log.WithName("label-controller"),
121-
LeaderElection: true,
122-
LeaderElectionID: leaderElectionID,
120+
Logger: log.Log.WithName("label-controller"),
121+
LeaderElection: true,
122+
LeaderElectionID: leaderElectionID,
123+
LeaderElectionNamespace: leaderElectionNamespace,
123124
})
124125
if err != nil {
125126
return fmt.Errorf("unable to start manager: %w", err)

0 commit comments

Comments
 (0)