Skip to content

Adding leader election to controllers in staging rc #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# for external-provisioner
- op: add
path: /spec/template/spec/containers/0/args/-
value: "--enable-leader-election"

- op: add
path: /spec/template/spec/containers/0/args/-
value: "--leader-election-type=leases"

- op: add
path: /spec/template/spec/containers/0/args/-
value: "--leader-election-namespace=$(PDCSI_NAMESPACE)"

- op: add
path: /spec/template/spec/containers/0/env
value:
- name: PDCSI_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace


# # for external-attacher
- op: add
path: /spec/template/spec/containers/1/args/-
value: "--leader-election"

- op: add
path: /spec/template/spec/containers/1/args/-
value: "--leader-election-namespace=$(PDCSI_NAMESPACE)"

- op: add
path: /spec/template/spec/containers/1/env
value:
- name: PDCSI_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace


# # for external-resizer
- op: add
path: /spec/template/spec/containers/2/args/-
value: "--leader-election"

- op: add
path: /spec/template/spec/containers/2/args/-
value: "--leader-election-namespace=$(PDCSI_NAMESPACE)"

- op: add
path: /spec/template/spec/containers/2/env
value:
- name: PDCSI_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace


# for external-snapshotter
- op: add
path: /spec/template/spec/containers/3/args/-
value: "--leader-election"

- op: add
path: /spec/template/spec/containers/3/args/-
value: "--leader-election-namespace=$(PDCSI_NAMESPACE)"

- op: add
path: /spec/template/spec/containers/3/env
value:
- name: PDCSI_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ images:
- name: gke.gcr.io/csi-snapshotter
newName: gcr.io/gke-release-staging/csi-snapshotter
newTag: "v2.1.1-gke.0"

resources:
- leader-election-rbac.yaml

patchesJson6902:
- target:
group: apps
version: v1
kind: StatefulSet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to switch to a Deployment as well? I think it's not easily done without modifying the base too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards optimizing for the common case of 1 replica. I think this is the common case, but if we have indicators otherwise we could change it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's set the pod management policy to "parallel" then? That way the statefulset won't get stuck if one of the replicas fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looking at the design doc again, StatefulSet is good for a dedicated node, which is probably usually not the case for this deployment. I can switch it to Deployment.

At some point I managed to change the kind with a Kustomize JSON patch. Will see if I can still do it :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this low risk enough to just do it in the base. There's probably other spec differences between StatefulSet and Deployment too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the patching figured out. I pushed a new version

I believe the default of maxUnavailable = 25% (rounded down, so 0) and maxSurge = 25% (rounded up, so 1) is OK - a new replica will be created first, in standby, before the old replica is deleted.

name: csi-gce-pd-controller
path: enable-leader-election.yaml
- target:
group: apps
version: v1
kind: StatefulSet
name: csi-gce-pd-controller
path: statefulset-to-deployment.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agh sorry, added

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-gce-pd-leaderelection-role
namespace: gce-pd-csi-driver
labels:
k8s-app: gcp-compute-persistent-disk-csi-driver
rules:
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "watch", "list", "delete", "update", "create"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-gce-pd-controller-leaderelection-binding
namespace: gce-pd-csi-driver
labels:
k8s-app: gcp-compute-persistent-disk-csi-driver
subjects:
- kind: ServiceAccount
name: csi-gce-pd-controller-sa
roleRef:
kind: Role
name: csi-gce-pd-leaderelection-role
apiGroup: rbac.authorization.k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- op: remove
path: "/spec/serviceName"
- op: remove
path: "/spec/volumeClaimTemplates"
- op: replace
path: /kind
value: Deployment