Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cmd/init-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func setupManager(ctx context.Context, cfg *rest.Config, opts *Options) (manager
},
Metrics: metricsserver.Options{BindAddress: opts.MetricsAddr},
LeaderElection: opts.EnableLeaderElection,
LeaderElectionID: "TODO",
LeaderElectionNamespace: "le-ns-todo",
LeaderElectionID: "init-agent.kcp.io",
LeaderElectionNamespace: opts.LeaderElectionNamespace,
HealthProbeBindAddress: opts.HealthAddr,
})
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/init-agent/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type Options struct {
// manage coordination/v1 leases)
EnableLeaderElection bool

// LeaderElectionNamespace is the Kubernetes namespace in which the leader
// election lease will be created.
LeaderElectionNamespace string

InitTargetSelectorString string
InitTargetSelector labels.Selector

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

if o.EnableLeaderElection && len(o.LeaderElectionNamespace) == 0 {
errs = append(errs, errors.New("--leader-election-namespace is required when --enable-leader-election is true"))
}

if s := o.InitTargetSelectorString; len(s) > 0 {
if _, err := labels.Parse(s); err != nil {
errs = append(errs, fmt.Errorf("invalid --init-target-selector %q: %w", s, err))
Expand Down