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

Fix VolumeAttachment garbage collection for migrated PVs #102176

Conversation

timebertt
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR builds on #101737 to also cleanup dangling VolumeAttachments after completed migration to CSI (like described in #102097).

Which issue(s) this PR fixes:

Fixes #102097

Special notes for your reviewer:

/sig storage

I validated the change on our clusters, where we observed the issue (AWS/GCP, k8s v1.18/v1.19). On startup, kube-controller-manager now marks the old VolumeAttachments as uncertain and later detaches them, e.g.:

{"log":"Marking volume attachment as uncertain as volume:\"kubernetes.io/csi/pd.csi.storage.gke.io^projects/UNSPECIFIED/zones/europe-west1-b/disks/pvc-some-id\" (\"some-node\") is not attached (Detached)","pid":"1","severity":"INFO","source":"attach_detach_controller.go:766"}
{"log":"attacherDetacher.DetachVolume started for volume \"pvc-some-id\" (UniqueName: \"kubernetes.io/csi/pd.csi.storage.gke.io^projects/UNSPECIFIED/zones/europe-west1-b/disks/pvc-some-id\") on node \"some-node\" This volume is not safe to detach, but maxWaitForUnmountDuration 6m0s expired, force detaching","pid":"1","severity":"WARN","source":"reconciler.go:222"}
{"log":"DetachVolume.Detach succeeded for volume \"pvc-some-id\" (UniqueName: \"kubernetes.io/csi/pd.csi.storage.gke.io^projects/UNSPECIFIED/zones/europe-west1-b/disks/pvc-some-id\") on node \"some-node\" ","pid":"1","severity":"INFO","source":"operation_generator.go:472"}

Does this PR introduce a user-facing change?

Fixed garbage collection of dangling VolumeAttachments for PersistentVolumes migrated to CSI on startup of kube-controller-manager.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 20, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @timebertt!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @timebertt. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 20, 2021
@k8s-ci-robot k8s-ci-robot added the sig/apps Categorizes an issue or PR as relevant to SIG Apps. label May 20, 2021
@timebertt
Copy link
Contributor Author

/cc @Jiawei0227
if you want to have a look :)

@Jiawei0227
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 20, 2021
Copy link
Contributor

@Jiawei0227 Jiawei0227 left a comment

Choose a reason for hiding this comment

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

/lgtm
Thanks for the fix! I think this is looking good to me. Just want to understand the issue more, this only happens if there is indeed dangling attachment in the system, right? in a normal sequence, after CSI migration, the Pod should still able to detach this volume?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 20, 2021
@Jiawei0227
Copy link
Contributor

/retest

1 similar comment
@Jiawei0227
Copy link
Contributor

/retest

@timebertt timebertt force-pushed the fix/volumeattachment-migrated-volumes branch from 4fe6f5c to 59b2511 Compare May 21, 2021 06:10
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 21, 2021
@timebertt
Copy link
Contributor Author

Just want to understand the issue more, this only happens if there is indeed dangling attachment in the system, right? in a normal sequence, after CSI migration, the Pod should still able to detach this volume?

Yes, this bug is a real edge case, it doesn't happen in a normal sequence.

In all cases, where we observed the bug, kube-controller-manager was restarted while an attach/detach operation was in progress, e.g. because a StatefulSet pod was rolled/restarted (like described in #96617). What happens on startup then, is that it tries to process the old VolumeAttachment, but it can't find a responsible volume plugin (AWS/GCP is unregistered and CSI doesn't feel responsible as the volume was created by in-tree plugins), here:

plugin, err := adc.volumePluginMgr.FindAttachablePluginBySpec(volumeSpec)
if err != nil || plugin == nil {
// Currently VA objects are created for CSI volumes only. nil plugin is unexpected, generate a warning
klog.Warningf(
"Skipping processing the volume %q on nodeName: %q, no attacher interface found. err=%v",
*pvName,
nodeName,
err)
continue
}

If the pod was scheduled on another node, then the Volume won't be detached on the old node as the old VolumeAttachment is not cleaned up, which leads to exclusive attach errors.

This is quite hard to reproduce, because it has to happen in a very precise timing (which in large scale environments can of course happen more frequently).
Does this help? :)

@timebertt
Copy link
Contributor Author

/retest

1 similar comment
@Jiawei0227
Copy link
Contributor

/retest

@Jiawei0227
Copy link
Contributor

This is quite hard to reproduce, because it has to happen in a very precise timing (which in large scale environments can of course happen more frequently).
Does this help? :)

Thanks a lot! This is very helpful info.
/lgtm
/cc @gnufied
For approval.

@k8s-ci-robot k8s-ci-robot requested a review from gnufied May 21, 2021 17:59
@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 27, 2021
@timebertt timebertt force-pushed the fix/volumeattachment-migrated-volumes branch from 59b2511 to 6547df8 Compare May 28, 2021 06:03
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2021
@timebertt timebertt force-pushed the fix/volumeattachment-migrated-volumes branch from 6547df8 to cd37092 Compare May 28, 2021 06:35
@timebertt
Copy link
Contributor Author

/retest

1 similar comment
@timebertt
Copy link
Contributor Author

/retest

@gnufied
Copy link
Member

gnufied commented May 28, 2021

/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 May 28, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnufied, timebertt

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 May 28, 2021
@gnufied
Copy link
Member

gnufied commented May 28, 2021

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 28, 2021
@k8s-ci-robot k8s-ci-robot merged commit ffbb85c into kubernetes:master May 28, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone May 28, 2021
@timebertt timebertt deleted the fix/volumeattachment-migrated-volumes branch May 29, 2021 08:21
k8s-ci-robot added a commit that referenced this pull request Jun 8, 2021
…02176-origin-release-1.20

Automated cherry pick of #102176: Fix VolumeAttachment garbage collection for migrated PVs
k8s-ci-robot added a commit that referenced this pull request Jun 8, 2021
…02176-origin-release-1.19

Automated cherry pick of #102176: Fix VolumeAttachment garbage collection for migrated PVs
k8s-ci-robot added a commit that referenced this pull request Jun 8, 2021
…02176-origin-release-1.21

Automated cherry pick of #102176: Fix VolumeAttachment garbage collection for migrated PVs
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. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Garbage collect VolumeAttachments of migrated in-tree volumes
6 participants