Skip to content

Commit

Permalink
Poll multiple times that the pvc is deleted in TestPipelineRun
Browse files Browse the repository at this point in the history
Let's poll for up to 10mn that the PersistentVolumeClaims has the
DeletionTimestamp set.

Fixes tektoncd#915

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed May 30, 2019
1 parent 30aceb7 commit 8b5c155
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/tektoncd/pipeline/pkg/artifacts"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/knative/pkg/apis"
knativetest "github.com/knative/pkg/test"
Expand Down Expand Up @@ -175,14 +176,22 @@ func TestPipelineRun(t *testing.T) {
if len(events) != td.expectedNumberOfEvents {
t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of receieved events : %#v", td.expectedNumberOfEvents, len(events), events)
}
// Check to make sure the PipelineRun's artifact storage PVC has been "deleted" at the end of the run.
pvc, err := c.KubeClient.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(artifacts.GetPVCName(pipelineRun), metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
t.Fatalf("Error looking up PVC %s for PipelineRun %s: %s", artifacts.GetPVCName(pipelineRun), prName, err)

// Wait for up to 10 minutes and restart every second to check if
// the PersistentVolumeClaims has the DeletionTimestamp
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
// Check to make sure the PipelineRun's artifact storage PVC has been "deleted" at the end of the run.
pvc, errWait := c.KubeClient.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(artifacts.GetPVCName(pipelineRun), metav1.GetOptions{})
if errWait != nil && !errors.IsNotFound(errWait) {
return true, fmt.Errorf("Error looking up PVC %s for PipelineRun %s: %s", artifacts.GetPVCName(pipelineRun), prName, errWait)
}
// If not found and pvc.DeletionTimestamp then we are okay since it got clened up
if errors.IsNotFound(errWait) && pvc.DeletionTimestamp == nil {
return true, nil
}
} else if pvc.DeletionTimestamp == nil {
t.Fatalf("PVC %s still exists after PipelineRun %s has completed: %v", artifacts.GetPVCName(pipelineRun), prName, pvc)
return pvc.DeletionTimestamp != nil, nil
}); err != nil {
t.Fatalf("Error while waiting for the PVC to be set as deleted: %s: %s: %s", artifacts.GetPVCName(pipelineRun), err, prName)
}
t.Logf("Successfully finished test %q", td.name)
})
Expand Down

0 comments on commit 8b5c155

Please sign in to comment.