Skip to content

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

Open
@camilamacedo86

Description

@camilamacedo86

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedkind/documentationCategorizes issue or PR as related to documentation.language/goIssue is related to a Go operator projectlifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions