Skip to content

Ansible/Helm new layouts should work with controller-runtime leader election #3356

@camilamacedo86

Description

@camilamacedo86

Feature Request

The new helm layout is working with the current/legacy image of the operator-sdk helm. This image is not using the controller-runtime implementation for the leader election.

We need to:

  • Add the both flags to the run
  • Change the main implementation to use the leader election as it is in the GO type. See:
        
	pflag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
		"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
	pflag.StringVar(&leaderElectionID, "leader-election-id", "",
		"Name of the configmap that is used for holding the leader lock.")
	pflag.StringVar(&leaderElectionNamespace, "leader-election-namespace", "",
		"Namespace in which to create the leader election configmap for holding the leader lock (required if running locally).")  



        // Deprecated: OPERATOR_NAME environment variable is an artifact of the legacy operator-sdk project scaffolding.
	//   Flag `--leader-election-id` should be used instead.
	if operatorName, found := os.LookupEnv("OPERATOR_NAME"); found {
		setupLog.Info("environment variable OPERATOR_NAME has been deprecated, use --leader-election-id instead.")
		if pflag.Lookup("leader-election-id").Changed {
			setupLog.Info("ignoring OPERATOR_NAME environment variable since --leader-election-id is set")
		} else {
			leaderElectionID = operatorName
		}
	}

       options := ctrl.Options{
		MetricsBindAddress:      metricsAddr,
		LeaderElection:          enableLeaderElection,
		LeaderElectionID:        leaderElectionID,
		LeaderElectionNamespace: leaderElectionNamespace,
		NewClient:               manager.NewDelegatingClientFunc(),
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.kubebuilder-integrationRelates to rewriting the SDK in Kubebuilder plugin formlanguage/ansibleIssue is related to an Ansible operator projectlanguage/helmIssue is related to a Helm operator project

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions