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 reconstruction of CSI volumes #117804

Merged

Conversation

jsafrane
Copy link
Member

@jsafrane jsafrane commented May 5, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

During CSI volume reconstruction it's not possible to tell, if the volume is attachable or not - CSIDriver instance may not be available, because kubelet may not have connection to the API server at that time.

Therefore remove all calls to FindAttachablePluginBySpec here:

  • Reorder reconstructVolume not to call FindAttachablePluginBySpec for CSI volumes. It's just a simple refactoring.
  • Add uncertain attach-abilty state during reconstruction, so volume reconstruction can finish without an API server. When the API server becomes available, then set attach-ability based on CSIDriver instances and allow unmounting of volumes.

Which issue(s) this PR fixes:

Fixes: #117745

Special notes for your reviewer:

WIP:

Does this PR introduce a user-facing change?

Fixed kubelet startup getting stuck with `NewVolumeManagerReconstruction` feature enabled and a CSI volume present in /var/lib/kubelet/pods.

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


@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 5, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jsafrane

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 5, 2023
@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 5, 2023
@bart0sh bart0sh added this to WIP in SIG Node PR Triage May 7, 2023
@jsafrane jsafrane force-pushed the fix-csi-attachable-reconstruction branch 3 times, most recently from 1a5d763 to b6e0f35 Compare May 15, 2023 12:38
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 15, 2023
@jsafrane jsafrane changed the title WIP: Fix reconstruction of CSI volumes Fix reconstruction of CSI volumes May 15, 2023
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 15, 2023
@jsafrane
Copy link
Member Author

Added unit test and removed WIP:

@bart0sh bart0sh moved this from WIP to Needs Reviewer in SIG Node PR Triage May 17, 2023
@bart0sh
Copy link
Contributor

bart0sh commented May 17, 2023

/triage accepted
/priority important-soon

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels May 17, 2023
@dims
Copy link
Member

dims commented Jun 15, 2023

/assign @msau42 @xing-yang

return asw.addVolume(volumeName, volumeSpec, devicePath)

pluginIsAttachable := volumeAttachabilityFalse
if attachablePlugin, err := asw.volumePluginMgr.FindAttachablePluginBySpec(volumeSpec); err == nil && attachablePlugin != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any concern of marking the volume attachability as false if there's a temporary error?

Copy link
Member

Choose a reason for hiding this comment

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

Good point, though we always treated temporary here as attachability: false. We could choose to mark it uncertain I guess, but then we have to worry about secondary side effect.

For the time being, we should keep this as it is and may be make a follow up issue for fixing this.

@msau42
Copy link
Member

msau42 commented Jun 15, 2023

/assign @gnufied

pkg/kubelet/volumemanager/cache/actual_state_of_world.go Outdated Show resolved Hide resolved
return asw.addVolume(volumeName, volumeSpec, devicePath)

pluginIsAttachable := volumeAttachabilityFalse
if attachablePlugin, err := asw.volumePluginMgr.FindAttachablePluginBySpec(volumeSpec); err == nil && attachablePlugin != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Good point, though we always treated temporary here as attachability: false. We could choose to mark it uncertain I guess, but then we have to worry about secondary side effect.

For the time being, we should keep this as it is and may be make a follow up issue for fixing this.

reconstructVolume() is called when kubelet may not have connection to the
API server yet, therefore it cannot get CSIDriver instances to figure out
if a CSI volume is attachable or not.

Refactor reconstructVolume(), so it does not need
FindAttachablePluginBySpec for CSI volumes, because all of them are
deviceMountable (i.e. FindDeviceMountablePluginBySpec always returns the
CSI volume plugin).
@jsafrane jsafrane force-pushed the fix-csi-attachable-reconstruction branch 3 times, most recently from 0bdee5a to 85b3fda Compare June 23, 2023 16:09
@@ -525,6 +525,54 @@ func TestActualStateOfWorld_FoundDuringReconstruction(t *testing.T) {
return nil
},
},
{
name: "uncertain attachability is resolved to attachable",
Copy link
Contributor

Choose a reason for hiding this comment

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

what case this uncertain attachability is resolved to attachable?

Copy link
Member

Choose a reason for hiding this comment

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

So when we first build ASOW during reconsturction without API server connectivity we can't know atttachability of CSI volumes and hence "attachable" property is uncertain.

So reconciler continuously tries to fix that state and assuming once kubelet is able to talk to api-server uncertain attachability will be resolved.

SyncReconstructedVolume(volumeName v1.UniqueVolumeName, podName volumetypes.UniquePodName, outerVolumeSpecName string)

// Add the specified volume to ASW as uncertainly attached.
AddReconstructedVolume(volumeName v1.UniqueVolumeName, volumeSpec *volume.Spec, nodeName types.NodeName, devicePath string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

if this function is only adding volumeAttachabilityUncertain state, how about put this information into the name too?
like AddAttachUncertainReconstructedVolume?

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to AddAttachUncertainReconstructedVolume

During CSI volume reconstruction it's not possible to tell, if the volume
is attachable or not - CSIDriver instance may not be available, because
kubelet may not have connection to the API server at that time.

Adding uncertain state during reconstruction + adding a correct state when
the API server is available.
node.status.volumesInUse should report only attachable volumes, therefore
it needs to wait for the reconciler to update uncertain attachability of
volumes from the API server.
@jsafrane jsafrane force-pushed the fix-csi-attachable-reconstruction branch from 85b3fda to 7cd60df Compare July 11, 2023 08:32
To volumesNeedUpdateFromNodeStatus - because both devicePath and uncertain
attach-ability needs to be fixed from node status.
to be in sync with volumesNeedUpdateFromNodeStatus.
@jsafrane
Copy link
Member Author

I also renamed volumesNeedDevicePath to volumesNeedUpdateFromNodeStatus and updateReconstructedFromAPIServer() to updateReconstructedFromNodeStatus to reflect better what they actually do - see the last 2 commits.

@jsafrane
Copy link
Member Author

/retest

@jingxu97
Copy link
Contributor

/lgtm

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

LGTM label has been added.

Git tree hash: 9c693654e6be61e8059307591c407efe8dddd4c2

@k8s-ci-robot k8s-ci-robot merged commit ac07b46 into kubernetes:master Jul 12, 2023
16 checks passed
SIG Node PR Triage automation moved this from Needs Reviewer to Done Jul 12, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jul 12, 2023
k8s-ci-robot added a commit that referenced this pull request Aug 4, 2023
…7804-upstream-release-1.27

Automated cherry pick of #117804: Refactor FindAttachablePluginBySpec out of CSI code path
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. area/kubelet 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. 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/node Categorizes an issue or PR as relevant to SIG Node. 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
Archived in project
Development

Successfully merging this pull request may close these issues.

kubelet (1.27.1) fails to mount a hostPath volume for a static pod
8 participants