Skip to content
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

Use leader election library from csi-lib-utils #135

Merged
merged 5 commits into from
Apr 5, 2019

Conversation

andrewsykim
Copy link
Contributor

@andrewsykim andrewsykim commented Mar 29, 2019

Also adds support for lease based leader election which will be the preferred resource for leader election. We still need to support ConfigMap based leader election for backwards compatibility.

Leader election now optionally uses Lease object instead of ConfigMap. This change requires change of RBAC rules.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 29, 2019
@andrewsykim
Copy link
Contributor Author

/assign @msau42 @xing-yang

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 29, 2019
@andrewsykim andrewsykim force-pushed the leaderelection branch 3 times, most recently from e737962 to 066e5ac Compare March 29, 2019 19:21
@@ -60,6 +61,7 @@ var (
timeout = flag.Duration("timeout", 15*time.Second, "Timeout for waiting for attaching or detaching the volume.")

enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
leaderElectionType = flag.String("leader-election-type", "configmap", "the type of leader election, options are 'configmap' (default) or 'lease' (recommended)")
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where this attacher runs.")
leaderElectionIdentity = flag.String("leader-election-identity", "", "Unique identity of this attacher. Typically name of the pod where the attacher runs.")
Copy link
Contributor Author

@andrewsykim andrewsykim Mar 29, 2019

Choose a reason for hiding this comment

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

I don't think identity is needed anymore since the lib will use the hostname if it's not set. Should we deprecate the flag here now and default to whatever is in csi-lib-utils?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please deprecate it (print a warning when it's used)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, thank you!

@msau42
Copy link
Collaborator

msau42 commented Mar 29, 2019

/assign @jsafrane

Copy link
Contributor

@jsafrane jsafrane left a comment

Choose a reason for hiding this comment

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

The code looks ok, please deprecate leader-election-identity and update README.md.

@@ -60,6 +61,7 @@ var (
timeout = flag.Duration("timeout", 15*time.Second, "Timeout for waiting for attaching or detaching the volume.")

enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
leaderElectionType = flag.String("leader-election-type", "configmap", "the type of leader election, options are 'configmap' (default) or 'lease' (recommended)")
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where this attacher runs.")
leaderElectionIdentity = flag.String("leader-election-identity", "", "Unique identity of this attacher. Typically name of the pod where the attacher runs.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please deprecate it (print a warning when it's used)

@andrewsykim
Copy link
Contributor Author

/hold

Waiting for kubernetes-csi/csi-lib-utils#24

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 1, 2019
@pohly
Copy link
Contributor

pohly commented Apr 2, 2019

How does that affect RBAC rules?

@msau42
Copy link
Collaborator

msau42 commented Apr 2, 2019

Good point. RBAC rules need to be updated to add Lease. (we still need to keep the configmap rules for backwards compat), but drivers can decide to further refine them as needed.

@pohly
Copy link
Contributor

pohly commented Apr 2, 2019

(we still need to keep the configmap rules for backwards compat)

In which case does that help? If the current code no longer needs them, then they can be removed.

No-one should be using these updated RBAC rules with an older sidecar release, that's not part of our compatibility guarantees.

@msau42
Copy link
Collaborator

msau42 commented Apr 2, 2019

The current code still has to support the old leaderelection method for backwards compatibility. So we still need rules for both ways.

@@ -42,9 +42,7 @@ Note that the external-attacher does not scale with more replicas. Only one exte

* `--leader-election`: Enables leader election. This is useful when there are multiple replicas of the same external-attacher running for one CSI driver. Only one of them may be active (=leader). A new leader will be re-elected when current leader dies or becomes unresponsive for ~15 seconds.

* `--leader-election-namespace <namespace>`: Namespace where the external-attacher runs and where leader election object will be created. It is recommended that this parameter is populated from Kubernetes DownwardAPI.

* `--leader-election-identity <id>`: Unique identity of this replica of external-attacher container. It must be unique among all running replicas of the external-attacher. Pod name populated from Kubernetes DownwardAPI is recommended.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this to the Deprecated arguments section

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry one more nit. This should be moved to the "Deprecated arguments" section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, done

@@ -51,7 +51,7 @@ roleRef:
apiGroup: rbac.authorization.k8s.io

---
# Attacher must be able to work with config map in current namespace
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also add a comment that a driver only needs to include one of these rules depending on which leader election method it chose

README.md Outdated
* `--leader-election-namespace <namespace>`: Namespace where the external-attacher runs and where leader election object will be created. It is recommended that this parameter is populated from Kubernetes DownwardAPI.

* `--leader-election-identity <id>`: Unique identity of this replica of external-attacher container. It must be unique among all running replicas of the external-attacher. Pod name populated from Kubernetes DownwardAPI is recommended.
* `--leader-election-type`: The resource type to use for leader election, options are 'configmaps' (default) or 'leases' (recommended)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we deprecate the "configmap" option?

@msau42
Copy link
Collaborator

msau42 commented Apr 2, 2019

Vendor commit msg needs to be updated.

Also, could you add an entry to the Changelog file?

CHANGELOG-1.1.md Outdated
@@ -16,6 +16,8 @@

## Other notable changes

* Add support for Lease based leader election. Enable this by setting `--leader-election-type=leases` ([#135](https://github.com/kubernetes-csi/external-attacher/pull/135))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can probably go under "Notable features"

CHANGELOG-1.1.md Outdated
@@ -16,6 +16,8 @@

## Other notable changes

* Add support for Lease based leader election. Enable this by setting `--leader-election-type=leases` ([#135](https://github.com/kubernetes-csi/external-attacher/pull/135))
* --leader-election-identity is now deprecated. Setting this flag will do nothing now. ([#135](https://github.com/kubernetes-csi/external-attacher/pull/135))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should go under "Deprecations"

@andrewsykim andrewsykim force-pushed the leaderelection branch 2 times, most recently from df8bbcc to 58cd406 Compare April 2, 2019 20:59
@@ -38,17 +38,11 @@ spec:
- "--v=5"
- "--csi-address=$(ADDRESS)"
- "--leader-election"
- "--leader-election-namespace=$(MY_NAMESPACE)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this example use lease?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it should. Originally left that out since I didn't want anyone re-deploying this on an existing deployment but I don't think that'll be a problem

CHANGELOG-1.1.md Outdated
@@ -3,6 +3,7 @@
# Deprecations

* Command line flag `-connection-timeout` is deprecated and has no effect.
* --leader-election-identity is now deprecated. Setting this flag will have no effect on leader election. ([#135](https://github.com/kubernetes-csi/external-attacher/pull/135))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you follow the style of the above?

@@ -3,6 +3,7 @@
# Deprecations

* Command line flag `-connection-timeout` is deprecated and has no effect.
* Command line flag `--leader-election-identity` is deprecated and has no effect.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we also deprecate the "configmaps" option?

@pohly
Copy link
Contributor

pohly commented Apr 3, 2019

The current code still has to support the old leaderelection method for backwards compatibility. So we still need rules for both ways.

It would be useful to document that in the RBAC file: someone might want to remove the parts that they don't need because they only use one mode.

// Name of config map with leader election lock
lockName := "external-attacher-leader-" + csiAttacher
if *leaderElectionType == "configmaps" {
le = leaderelection.NewLeaderElectionWithConfigMaps(clientset, lockName, run)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also print out a warning message saying that the configmap option is deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -60,14 +62,20 @@ var (
timeout = flag.Duration("timeout", 15*time.Second, "Timeout for waiting for attaching or detaching the volume.")

enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where this attacher runs.")
leaderElectionIdentity = flag.String("leader-election-identity", "", "Unique identity of this attacher. Typically name of the pod where the attacher runs.")
leaderElectionType = flag.String("leader-election-type", "configmap", "the type of leader election, options are 'configmaps' (default) or 'leases' (recommended)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also add a note here that configmaps is deprecated.

Gopkg.toml Outdated
name = "github.com/container-storage-interface/spec"
version = "1.0.0"
version = "=1.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be updated to 1.1.0 to be consistent with csi-lib-utils 0.6.1.
"override" should be changed to "constraint".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgrading to 1.1.0 breaks a bunch of tests which I don't want to be fixing in this PR, hence the override

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go test `go list ./... | grep -v 'vendor' `
# github.com/kubernetes-csi/external-attacher/vendor/github.com/kubernetes-csi/csi-test/driver
vendor/github.com/kubernetes-csi/csi-test/driver/mock.go:41:5: cannot use servers.Controller (type *MockControllerServer) as type csi.ControllerServer in field value:
	*MockControllerServer does not implement csi.ControllerServer (missing ControllerExpandVolume method)
vendor/github.com/kubernetes-csi/csi-test/driver/mock.go:42:5: cannot use servers.Node (type *MockNodeServer) as type csi.NodeServer in field value:
	*MockNodeServer does not implement csi.NodeServer (missing NodeExpandVolume method)
?   	github.com/kubernetes-csi/external-attacher/cmd/csi-attacher	[no test files]
FAIL	github.com/kubernetes-csi/external-attacher/pkg/attacher [build failed]
ok  	github.com/kubernetes-csi/external-attacher/pkg/controller	1.451s
make: *** [test-go] Error 2

I can fix this in a follow-up PR

Copy link
Contributor

Choose a reason for hiding this comment

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

That should go away if you also update csi-test to 2.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, thanks, updated now

@andrewsykim andrewsykim force-pushed the leaderelection branch 2 times, most recently from 42e663b to 1bd3b71 Compare April 3, 2019 23:43
Gopkg.toml Outdated
@@ -1,16 +1,16 @@
# List of dependecies for CSI attacher

[[constraint]]
[[override]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be constraint now?

CHANGELOG-1.1.md Outdated
@@ -3,6 +3,8 @@
## Deprecations

* Command line flag `-connection-timeout` is deprecated and has no effect.
* Command line flag `--leader-election-identity` is deprecated and has no effect.
* Command line argument `configmaps` for flag `--leader-election-type` is deprecated in favor of `--leader-election-type=leases`. The default is still `configmaps` for backwards compatibility reasons but will be switched to `leases` in a future release.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought of another way to document this. What do you think of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks much better, I'll update :)

README.md Outdated
@@ -57,10 +57,6 @@ Note that the external-attacher does not scale with more replicas. Only one exte

* `--leader-election`: Enables leader election. This is useful when there are multiple replicas of the same external-attacher running for one CSI driver. Only one of them may be active (=leader). A new leader will be re-elected when current leader dies or becomes unresponsive for ~15 seconds.

* `--leader-election-namespace <namespace>`: Namespace where the external-attacher runs and where leader election object will be created. It is recommended that this parameter is populated from Kubernetes DownwardAPI.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We still need to keep the namespace argument right? Do we have to deprecate this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, yeah we need to keep this here. I'm not sure about deprecation though since you can run external-attacher outside the cluster.

@msau42
Copy link
Collaborator

msau42 commented Apr 4, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 4, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewsykim, msau42

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 4, 2019
@msau42
Copy link
Collaborator

msau42 commented Apr 5, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 5, 2019
@k8s-ci-robot k8s-ci-robot merged commit 70a1411 into kubernetes-csi:master Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants