Skip to content

Commit

Permalink
Leader Election in Custom Controller (#3696)
Browse files Browse the repository at this point in the history
* Leader Election in Custom Controller
  • Loading branch information
Kalaiselvi84 committed Mar 14, 2024
1 parent 3c9be12 commit e4a3fa1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/custom-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

REPOSITORY ?=
PROD_REPO ?= us-docker.pkg.dev/agones-images/examples
version := 0.1
version := 0.2
ifeq ($(REPOSITORY),)
server_tag := custom-controller:$(version)
else
Expand Down
7 changes: 5 additions & 2 deletions examples/custom-controller/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ rules:
- apiGroups: ["agones.dev"]
resources: ["gameservers"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -49,7 +52,7 @@ metadata:
name: custom-controller
namespace: agones-system
spec:
replicas: 1
replicas: 2
selector:
matchLabels:
app: custom-controller
Expand All @@ -61,5 +64,5 @@ spec:
serviceAccountName: custom-controller-sa
containers:
- name: custom-controller
image: us-docker.pkg.dev/agones-images/examples/custom-controller:0.1
image: us-docker.pkg.dev/agones-images/examples/custom-controller:0.2
imagePullPolicy: Always
7 changes: 6 additions & 1 deletion examples/custom-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

ctrl.Log.Info("Starting controller manager.")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
LeaderElection: true,
LeaderElectionResourceLock: "leases",
LeaderElectionNamespace: "agones-system",
LeaderElectionID: "custom-controller-leader",
})
if err != nil {
ctrl.Log.Error(err, "Unable to start manager")
os.Exit(1)
Expand Down

0 comments on commit e4a3fa1

Please sign in to comment.