operator-sdk icon indicating copy to clipboard operation
operator-sdk copied to clipboard

doc: how to use the SDK leader election with new layout

Open camilamacedo86 opened this issue 5 years ago • 3 comments

We speak over it in the Migration guide to +1.0.0 but we need to have a doc for ti with details steps and just link in the migration guide. See: https://master.sdk.operatorframework.io/docs/building-operators/golang/project_migration_guide/#migrate-maingo.

Steps required to make it work on the cluster

  • Import the lib

go get -u github.com/operator-framework/operator-lib

  • Update main.go which will be as:
ctx := context.TODO()
	// Become the leader before proceeding
	err := leader.Become(ctx, "anyproject-lock")
	if err != nil {
		os.Exit(1)
	}

	mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
		Scheme:             scheme,
		MetricsBindAddress: metricsAddr,
		Port:               9443,
	})
	if err != nil {
		setupLog.Error(err, "unable to start manager")
		os.Exit(1)
	}
  • Update the manager.yaml file with:
...
    spec:
      containers:
      - command:
        - /manager
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
...

  • Add rbac permission to the controllers

+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list

  • Run make manifests

camilamacedo86 avatar Aug 07 '20 11:08 camilamacedo86

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot avatar Nov 05 '20 13:11 openshift-bot

/lifecycle frozen

camilamacedo86 avatar Nov 05 '20 13:11 camilamacedo86

Blocked on https://github.com/operator-framework/operator-lib/issues/48.

estroz avatar Mar 17 '21 18:03 estroz