-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 race condition in PVC deletion #7149
Fix race condition in PVC deletion #7149
Conversation
2b52afc
to
5e40cff
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
@@ -243,35 +242,3 @@ func TestCreateExistPersistentVolumeClaims(t *testing.T) { | |||
t.Fatalf("unexpected PVC name on created PVC; expected: %s got: %s", expectedPVCName, pvcList.Items[0].Name) | |||
} | |||
} | |||
|
|||
func TestPurgeFinalizerAndDeletePVCForWorkspace(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this test deleted? it should still be valid no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the simple client set cannot mock the pvc with finalizer scenario. Specifically, the pvcs
are already successfully deleted in the first API call, so the second call to remove finalizer will fail since the pvc
is already deleted.
I could potentially use some expected errors in the test case to compare, but I feel it is quite confusing. And the functionality is already covered by integration test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, one way to do this could be to use something like PrependReactor
for the delete call and have it set the deletionTimestamp
instead of deleting the object
not exactly the same thing, but similar:
pipeline/pkg/reconciler/pipelinerun/affinity_assistant_test.go
Lines 435 to 438 in f5578a8
c.KubeClientSet.CoreV1().(*fake.FakeCoreV1).PrependReactor("create", "persistentvolumeclaims", | |
func(action testing2.Action) (handled bool, ret runtime.Object, err error) { | |
return true, &corev1.PersistentVolumeClaim{}, errors.New("error creating persistentvolumeclaims") | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the advice, I have added the test back with your suggestion. PTAL!
return pollImmediateWithContext(ctx, func() (bool, error) { | ||
pvcList, err := c.KubeClient.CoreV1().PersistentVolumeClaims(namespace).List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
return true, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding docString here for the indications of the bool error being returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it just follows the expected function signature, and k8s does have docstring for it:
// ConditionFunc returns true if the condition is satisfied, or an error |
5e40cff
to
097cfd0
Compare
/lgtm |
/test pull-tekton-pipeline-go-coverage |
fixes [tektoncd#7138][tektoncd#7138]. In `coschedule:pipelineruns` mode, the `pvcs` created by `VolumeClaimTemplate` should be automatically deleted when the owning `pipelinerun` is completed. To delete a `pvc` used by a pod (pipelinerun), the [kubernetes.io/pvc-protection][finalizer] finalizer must be removed. Prior to this commit, the Tekton reconciler attempted to remove the `kubernetes.io/pvc-protection` finalizer first and then deletes the created pvcs. This results in race condition since `PVCProtectionController` tries to add back the finalizer if the `pvc` is in `bounded` status . If the add back action happens before the PVC deletion call is completed, the `PVC` will be left in `terminating` status. This commit changes the reconciler to delete the `PVC` first and then removes the `finalizer` to fix the race condition. This commit removes `TestPurgeFinalizerAndDeletePVCForWorkspace` UT, since the finalizer behavior cannot be mocked when a PVC is deleted. This commit also adds integration test to cover this scenario. /kind bug [tektoncd#7138]: tektoncd#7138 [finalizer]: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#storage-object-in-use-protection
097cfd0
to
c5a2c80
Compare
Nicely done! thanks @QuanZhang-William |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dibyom, Yongxuanzhang 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 |
/lgtm |
Changes
fixes #7138. In
coschedule:pipelineruns
mode, thepvcs
created byVolumeClaimTemplate
should be automatically deleted when the owningpipelinerun
is completed. To delete apvc
used by a pod (pipelinerun), the kubernetes.io/pvc-protection finalizer must be removed.Prior to this commit, the Tekton reconciler attempted to remove the
kubernetes.io/pvc-protection
finalizer first and then deletes the created pvcs. This results in race condition sincePVCProtectionController
tries to add back the finalizer if thepvc
is inbounded
status . If the add back action happens before the PVC deletion call is completed, thePVC
will be left interminating
status.This commit changes the reconciler to delete the
PVC
first and then removes thefinalizer
to fix the race condition. This commit also adds integration test to validatepvc
status when apipelinerun
is completed./kind bug
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes