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

Enable Attach/Detach Controller #26351

Conversation

saad-ali
Copy link
Member

@saad-ali saad-ali commented May 26, 2016

This PR contains changes to enable the attach/detach controller introduced in #25457 (proposed in #20262).

Specifically it:

  • Introduces a new enable-controller-attach-detach kubelet flag to enable control by attach/detach controller. Default enabled.
  • Removes all references SafeToDetach annotation from controller.
  • Adds the new VolumesInUse field to the Node Status API object.
  • Modifies the controller to use VolumesInUse instead of SafeToDetach annotation to gate detachment.
  • Modifies kubelet to set VolumesInUse before Mount and after Unmount.
  • Have controller process detaches before attaches so that volumes referenced by pods that are rescheduled to a different node are detached first.
  • Fix misc bugs in controller.
  • Modify GCE attacher to: remove retries, remove mutex, and not fail if volume is already attached or already detached.

Fixes #14642, #19953

Kubernetes v1.3 introduces a new Attach/Detach Controller. This controller manages attaching and detaching of volumes on-behalf of nodes. 

This ensures that attachment and detachment of volumes is independent of any single nodes’ availability. Meaning, if a node or kubelet becomes unavailable for any reason, the volumes attached to that node will be detached so they are free to be attached to other nodes.

Specifically the new controller watches the API server for scheduled pods. It processes each pod and ensures that any volumes that implement the volume Attacher interface are attached to the node their pod is scheduled to.

When a pod is deleted, the controller waits for the volume to be safely unmounted by kubelet. It does this by waiting for the volume to no longer be present in the nodes Node.Status.VolumesInUse list. If the volume is not safely unmounted by kubelet within a pre-configured duration (3 minutes in Kubernetes v1.3), the controller unilaterally detaches the volume (this prevents volumes from getting stranded on nodes that become unavailable).

In order to remain backwards compatible, the new controller only manages attach/detach of volumes that are scheduled to nodes that opt-in to controller management. Nodes running v1.3 or higher of Kubernetes opt-in to controller management by default by setting the "volumes.kubernetes.io/controller-managed-attach-detach" annotation on the Node object on startup. This behavior is gated by a new kubelet flag, "enable-controller-attach-detach,” (default true).

In order to safely upgrade an existing Kubernetes cluster without interruption of volume attach/detach logic:
* First upgrade the master to Kubernetes v1.3.
    * This will start the new attach/detach controller.
    * The new controller will initially ignore volumes for all nodes since they lack the "volumes.kubernetes.io/controller-managed-attach-detach" annotation.
* Then upgrade nodes to Kubernetes v1.3.
    * As nodes are upgraded, they will automatically, by default, opt-in to attach/detach controller management, which will cause the controller to start managing attaches/detaches for volumes that get scheduled to those nodes.

@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/old-docs size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 26, 2016
@saad-ali saad-ali force-pushed the attachDetachControllerKubeletChanges branch from 9d1e678 to 57da768 Compare May 26, 2016 18:31
Random-Liu added a commit to Random-Liu/kubernetes that referenced this pull request May 26, 2016
@saad-ali saad-ali force-pushed the attachDetachControllerKubeletChanges branch from 57da768 to 87ccfdc Compare May 26, 2016 22:20
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 26, 2016
alex-mohr added a commit that referenced this pull request May 26, 2016
Temporarily disable node-problem-detector to unblock #26351
@saad-ali saad-ali force-pushed the attachDetachControllerKubeletChanges branch 2 times, most recently from bb27c79 to cacfb2a Compare May 27, 2016 08:05
@saad-ali saad-ali assigned thockin and unassigned bgrant0607 May 27, 2016
@saad-ali saad-ali added this to the v1.3 milestone May 27, 2016
@saad-ali saad-ali added the priority/backlog Higher priority than priority/awaiting-more-evidence. label May 27, 2016
@saad-ali
Copy link
Member Author

Ran all the PD tests back to back overnight with these changes, and zero failures. Woo hoo :)

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 28, 2016
@saad-ali saad-ali force-pushed the attachDetachControllerKubeletChanges branch from cacfb2a to e3b064c Compare May 29, 2016 23:36
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 29, 2016
@k8s-github-robot
Copy link

@saad-ali
You must link to the test flake issue which caused you to request this manual re-test.
Re-test requests should be in the form of: k8s-bot test this issue: #<number>
Here is the list of open test flakes.

@saad-ali
Copy link
Member Author

@k8s-merge-robot you're drunk, go home

@saad-ali
Copy link
Member Author

@k8s-bot unit test this issue: #26256

To make merge-bot happy

@pmorie
Copy link
Member

pmorie commented Jun 1, 2016

@saad-ali seems like this should have a release note to me, agree?

@pmorie
Copy link
Member

pmorie commented Jun 1, 2016

There is a bug here in the mount/unmount code that prevents resetting `VolumeInUse in some cases, this will be fixed by mount/unmount refactor.

Link?

if err != nil {
glog.V(10).Infof(
"Failed to delete volume %q for pod %q/%q from desiredStateOfWorld. GetUniqueVolumeName failed with %v",
"Failed to delete volume %q for pod %q/%q from desiredStateOfWorld. GenerateUniqueDeviceName failed with %v",
Copy link
Member

Choose a reason for hiding this comment

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

Nit: log messages are supposed to start with lowercase letters -- no need to fix now, perhaps in a follow up.

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that rule is for error strings, since they may be concatenated at a higher level before being printed. But log messages are basically the end of the line so it is ok to capitalize in a way that makes it user readable.

GoLang guidence (https://github.com/golang/go/wiki/CodeReviewComments#error-strings) seems to align with this: This does not apply to logging, which is implicitly line-oriented and not combined inside other messages.

@saad-ali
Copy link
Member Author

saad-ali commented Jun 2, 2016

@saad-ali seems like this should have a release note to me, agree?

Yep, added release not to PR.

Link?

No issue to track it since all the kubelet code for mount/unmount/attach/detach is being rewritten. Mondo PR based on this PR is pending. It removes this note and fixes the issue.

@saad-ali saad-ali force-pushed the attachDetachControllerKubeletChanges branch from e3b064c to 0f92bb4 Compare June 2, 2016 00:48
@saad-ali
Copy link
Member Author

saad-ali commented Jun 2, 2016

Thanks Paul! Feedback addressed, PTAL

Will squash commits on LGTM

@@ -83,6 +84,11 @@ type ActualStateOfWorld interface {
// reflecting which volumes are attached to which nodes based on the
// current actual state of the world.
GetAttachedVolumes() []AttachedVolume
Copy link
Member

Choose a reason for hiding this comment

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

Does anything actually use the global list of attached volumes now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this list is used by the reconciler

This PR contains Kubelet changes to enable attach/detach controller control.
* It introduces a new "enable-controller-attach-detach" kubelet flag to
  enable control by controller. Default enabled.
* It removes all references "SafeToDetach" annoation from controller.
* It adds the new VolumesInUse field to the Node Status API object.
* It modifies the controller to use VolumesInUse instead of SafeToDetach
  annotation to gate detachment.
* There is a bug in node-problem-detector that causes VolumesInUse to
  get reset every 30 seconds. Issue kubernetes/node-problem-detector#9
  opened to fix that.
@saad-ali saad-ali force-pushed the attachDetachControllerKubeletChanges branch from 0f92bb4 to 9dbe943 Compare June 2, 2016 23:47
@saad-ali
Copy link
Member Author

saad-ali commented Jun 2, 2016

Thanks Paul. Added comments to test. PTAL

@saad-ali
Copy link
Member Author

saad-ali commented Jun 3, 2016

@k8s-bot unit test this issue: #25845

@k8s-bot
Copy link

k8s-bot commented Jun 3, 2016

GCE e2e build/test passed for commit 9dbe943.

attachedVolumes := asw.GetAttachedVolumesForNode(nodeName)

// Assert
if len(attachedVolumes) != 1 {
Copy link
Member

Choose a reason for hiding this comment

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

for stuff like this i like to use this syntax:

if l := len(attachedVolumes); l != 1 {
  t.Fatalf("bla bla %v", l)
}

..but you can do that in a follow up if you so choose.

@pmorie pmorie added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 3, 2016
@pmorie
Copy link
Member

pmorie commented Jun 3, 2016

LGTM, looking forward to reading the next chapter of this tale.

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Jun 3, 2016

GCE e2e build/test passed for commit 9dbe943.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 75ef1ca into kubernetes:master Jun 3, 2016
@saad-ali saad-ali changed the title Attach/Detach Controller Kubelet Changes Enable Attach/Detach Controller Jun 19, 2016
@saad-ali saad-ali deleted the attachDetachControllerKubeletChanges branch August 15, 2016 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Problem rescheduling POD with GCE PD disk attached
7 participants