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

[TEP-0135] Purge finalizer and delete PVC #6940

Conversation

QuanZhang-William
Copy link
Member

@QuanZhang-William QuanZhang-William commented Jul 18, 2023

Changes

Part of #6740 and partially completes the PVC deletion behavior discussion.

Prior to this commit, the PVCs created from PipelineRun's VolumeClaimTemplate are not auto deleted when the owning PipelineRun is completed.

This commit updates the cleanupAffinityAssistantsAndPVCs function to remove the kubernetes.io/pvc-protection finalizer protection (so that the pvc is allowed to be deleted while the pod consuming it is not deleted). The function then explicitly delete such PVCs when cleaning up the Affinity Assistants at the PipelineRun completion time.

This change is NOT applied to coschedule: workspaces mode as there is backward compatability concern. See more details in this discussion

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Jul 18, 2023
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 18, 2023
@QuanZhang-William
Copy link
Member Author

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 18, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 94.9% -2.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 83.3% -6.7

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 94.9% -2.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 83.3% -6.7

@lbernick lbernick self-assigned this Jul 18, 2023
@lbernick
Copy link
Member

My understanding is that the finalizer prevents PVCs from being deleted when the underlying PVs still exist (not when they are still bound to a pod). If we remove the finalizer and delete the PVC, won't there still be a PV taking up storage space? Can we delete the PV as well?

@jimmyjones2
Copy link
Contributor

@lbernick Kubernetes puts the finalizer on PVCs when there is a pod referencing it (including finished pods) to prevent deletion. Previous to this feature you could delete PVCs that were currently in use by a pod! A number of projects that manage pods themselves remove this finalizer, as they "know" the PVC is no longer needed.

Deleting a PVC with the finalizer removed will cause the underlying PV to be deleted as normal.

The finalizer is also used on a PV to prevent them from being deleted if there is an associated PVC using it, but this PR isn't touching that.

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#storage-object-in-use-protection

Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

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

thanks for the explanation @jimmyjones2! Quan, can you double check that PVs are deleted with this PR when the PVCs are deleted?

pkg/reconciler/pipelinerun/affinity_assistant_test.go Outdated Show resolved Hide resolved
pkg/reconciler/pipelinerun/affinity_assistant_test.go Outdated Show resolved Hide resolved
pkg/reconciler/volumeclaim/pvchandler.go Show resolved Hide resolved
pkg/reconciler/volumeclaim/pvchandler.go Show resolved Hide resolved
pkg/reconciler/volumeclaim/pvchandler.go Show resolved Hide resolved
@QuanZhang-William
Copy link
Member Author

thanks for the explanation @jimmyjones2! Quan, can you double check that PVs are deleted with this PR when the PVCs are deleted?

Thanks for the explanation @jimmyjones2! @lbernick , yes I doubled checked that the PV and PVCs are deleted when the PR is completed:

k get pr -w
NAME                                    SUCCEEDED   REASON    STARTTIME   COMPLETIONTIME
demo-pipeline-run-template-only-kqntk   Unknown     Running   38s         
demo-pipeline-run-template-only-kqntk   True        Succeeded   54s         0s

k get pvc
No resources found in default namespace.

k get pv
No resources found

@QuanZhang-William QuanZhang-William force-pushed the tep-0135-cleanup-aa-per-pipelinerun branch from 56ebb88 to 100d575 Compare July 19, 2023 18:35
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 96.5% 94.4% -2.1
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 83.3% -6.7

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 96.5% 94.4% -2.1
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 83.3% -6.7

pkg/reconciler/pipelinerun/affinity_assistant_test.go Outdated Show resolved Hide resolved
pkg/reconciler/volumeclaim/pvchandler.go Outdated Show resolved Hide resolved
pkg/reconciler/volumeclaim/pvchandler.go Show resolved Hide resolved
pkg/reconciler/volumeclaim/pvchandler_test.go Outdated Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 19, 2023
Part of [tektoncd#6740][tektoncd#6740], developed based on Priti's [prototype][prototype] and partially completes the PVC deletion behavior [discussion][discussion].

Prior to this commit, the `PVCs` created from `PipelineRun's` `VolumeClaimTemplate` are not auto deleted when the owning `PipelineRun` is completed.
This commit updates the `cleanupAffinityAssistantsAndPVCs` function to remove the `kubernetes.io/pvc-protection` finalizer protection (so that the pvc is allowed to be deleted while the pod consuming it is not deleted).
The function then explicitly delete such `PVC` when cleaning up the `Affinity Assistants` at pr completion time.

This change is NOT applied to `coschedule: workspaces` mode as there is backward compatability concern. See more details in this [discussion][discussion]

[tektoncd#6740]: tektoncd#6740
[prototype]: tektoncd#6635
[discussion]: tektoncd#6741 (comment)
@QuanZhang-William QuanZhang-William force-pushed the tep-0135-cleanup-aa-per-pipelinerun branch from 100d575 to deb51df Compare July 19, 2023 18:53
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 96.5% 94.4% -2.1
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 83.3% -6.7

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 96.5% 94.4% -2.1
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 83.3% -6.7

@QuanZhang-William
Copy link
Member Author

/test pull-tekton-pipeline-alpha-integration-tests

due to timeout

Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 20, 2023
@tekton-robot tekton-robot merged commit 84b8621 into tektoncd:main Jul 20, 2023
2 checks passed
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants