From d9f7f26e7942dec93afd5cff78e5c627f716b139 Mon Sep 17 00:00:00 2001 From: cc-datum Date: Thu, 30 Oct 2025 01:54:34 -0600 Subject: [PATCH] feat: add leader election candidate namespace support --- cmd/milo/controller-manager/controllermanager.go | 5 ++++- config/controller-manager/base/deployment.yaml | 3 +++ internal/infra-cluster/client.go | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/milo/controller-manager/controllermanager.go b/cmd/milo/controller-manager/controllermanager.go index 75fc3263..33230c6b 100644 --- a/cmd/milo/controller-manager/controllermanager.go +++ b/cmd/milo/controller-manager/controllermanager.go @@ -288,6 +288,9 @@ func NewOptions() (*Options, error) { KubeControllerManagerOptions: baseOpts, InfraCluster: &infracluster.Options{ KubeconfigFile: baseOpts.Generic.ClientConnection.Kubeconfig, + LeaderElection: &infracluster.LeaderElectionConfig{ + CandidateNamespace: "datum-system", + }, }, ControlPlane: &controlplane.Options{}, } @@ -677,7 +680,7 @@ func Run(ctx context.Context, c *config.CompletedConfig, opts *Options) error { // Start lease candidate controller for coordinated leader election leaseCandidate, waitForSync, err := leaderelection.NewCandidate( c.Client, - "datum-system", + opts.InfraCluster.LeaderElection.CandidateNamespace, id, "datum-controller-manager", binaryVersion.FinalizeVersion(), diff --git a/config/controller-manager/base/deployment.yaml b/config/controller-manager/base/deployment.yaml index bf919b7b..18e801bb 100644 --- a/config/controller-manager/base/deployment.yaml +++ b/config/controller-manager/base/deployment.yaml @@ -31,6 +31,7 @@ spec: - --leader-elect-renew-deadline=10s - --leader-elect-retry-period=2s - --leader-elect-resource-namespace=$(LEADER_ELECT_RESOURCE_NAMESPACE) + - --leader-election-candidate-namespace=$(LEADER_ELECTION_CANDIDATE_NAMESPACE) - --authentication-skip-lookup - --client-ca-file=$(CLIENT_CA_FILE) - --secure-port=6443 @@ -45,6 +46,8 @@ spec: env: - name: LEADER_ELECT_RESOURCE_NAMESPACE value: milo-system + - name: LEADER_ELECTION_CANDIDATE_NAMESPACE + value: datum-system # Default to INFO level logging - name: LOG_LEVEL value: "4" diff --git a/internal/infra-cluster/client.go b/internal/infra-cluster/client.go index 2b1cb584..2c12ece2 100644 --- a/internal/infra-cluster/client.go +++ b/internal/infra-cluster/client.go @@ -8,14 +8,21 @@ import ( "k8s.io/client-go/tools/clientcmd" ) +type LeaderElectionConfig struct { + CandidateNamespace string +} + // Options defines the configuration options available for modifying the // behavior of the infrastructure cluster client. type Options struct { KubeconfigFile string + LeaderElection *LeaderElectionConfig } func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.KubeconfigFile, "infra-cluster-kubeconfig", "-", "The path to the kubeconfig file for the infrastructure cluster. Use '-' to use the in-cluster config.") + fs.StringVar(&o.LeaderElection.CandidateNamespace, "leader-election-candidate-namespace", o.LeaderElection.CandidateNamespace, "The candidate namespace in which the leader election will be created.") + } func (o *Options) GetClient() (*rest.Config, error) {