Skip to content

Commit fa7b906

Browse files
kcp-ci-botxrstf
authored andcommitted
[release-0.1] cherrypick #4: add --leader-election-namespace flag
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent 38e798b commit fa7b906

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cmd/init-agent/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func setupManager(ctx context.Context, cfg *rest.Config, opts *Options) (manager
154154
},
155155
Metrics: metricsserver.Options{BindAddress: opts.MetricsAddr},
156156
LeaderElection: opts.EnableLeaderElection,
157-
LeaderElectionID: "TODO",
158-
LeaderElectionNamespace: "le-ns-todo",
157+
LeaderElectionID: "init-agent.kcp.io",
158+
LeaderElectionNamespace: opts.LeaderElectionNamespace,
159159
HealthProbeBindAddress: opts.HealthAddr,
160160
})
161161
}

cmd/init-agent/options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ type Options struct {
4343
// manage coordination/v1 leases)
4444
EnableLeaderElection bool
4545

46+
// LeaderElectionNamespace is the Kubernetes namespace in which the leader
47+
// election lease will be created.
48+
LeaderElectionNamespace string
49+
4650
InitTargetSelectorString string
4751
InitTargetSelector labels.Selector
4852

@@ -66,6 +70,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
6670
flags.StringVar(&o.ConfigWorkspace, "config-workspace", o.ConfigWorkspace, "kcp workspace or cluster where the InitTargets live that should be processed")
6771
flags.StringVar(&o.InitTargetSelectorString, "init-target-selector", o.InitTargetSelectorString, "restrict to only process InitTargets matching this label selector (optional)")
6872
flags.BoolVar(&o.EnableLeaderElection, "enable-leader-election", o.EnableLeaderElection, "whether to perform leader election")
73+
flags.StringVar(&o.LeaderElectionNamespace, "leader-election-namespace", o.LeaderElectionNamespace, "Kubernetes namespace for the leader election lease")
6974
flags.StringVar(&o.MetricsAddr, "metrics-address", o.MetricsAddr, "host and port to serve Prometheus metrics via /metrics (HTTP)")
7075
flags.StringVar(&o.HealthAddr, "health-address", o.HealthAddr, "host and port to serve probes via /readyz and /healthz (HTTP)")
7176
}
@@ -81,6 +86,10 @@ func (o *Options) Validate() error {
8186
errs = append(errs, errors.New("--config-workspace is required"))
8287
}
8388

89+
if o.EnableLeaderElection && len(o.LeaderElectionNamespace) == 0 {
90+
errs = append(errs, errors.New("--leader-election-namespace is required when --enable-leader-election is true"))
91+
}
92+
8493
if s := o.InitTargetSelectorString; len(s) > 0 {
8594
if _, err := labels.Parse(s); err != nil {
8695
errs = append(errs, fmt.Errorf("invalid --init-target-selector %q: %w", s, err))

0 commit comments

Comments
 (0)