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 28, 2019
1 parent 30aceb7 commit cde21fc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 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,15 +176,23 @@ 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 {

// Wait for up to 10 minutes and restart every 30seconds 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)
}
return pvc.DeletionTimestamp == nil, errWait
}); err != nil {
if !errors.IsNotFound(err) {
t.Fatalf("Error looking up PVC %s for PipelineRun %s: %s", artifacts.GetPVCName(pipelineRun), prName, err)
pvc, _ := c.KubeClient.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(artifacts.GetPVCName(pipelineRun), metav1.GetOptions{})
t.Fatalf("Error while waiting for the PVC to be set as deleted: %s: %s: %s %v", artifacts.GetPVCName(pipelineRun), err, prName, pvc)
}
} else if pvc.DeletionTimestamp == nil {
t.Fatalf("PVC %s still exists after PipelineRun %s has completed: %v", artifacts.GetPVCName(pipelineRun), prName, pvc)
}

t.Logf("Successfully finished test %q", td.name)
})
}
Expand Down

0 comments on commit cde21fc

Please sign in to comment.