Skip to content

Commit

Permalink
chore: Added unittest for PVC exceed quota Closes argoproj#3561 (argo…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarabala1979 authored Aug 25, 2020
1 parent 4e42208 commit 04898fe
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import (
apierr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/fake"
batchfake "k8s.io/client-go/kubernetes/typed/batch/v1/fake"
k8stesting "k8s.io/client-go/testing"
"sigs.k8s.io/yaml"

"github.com/argoproj/argo/config"
Expand Down Expand Up @@ -4594,3 +4598,49 @@ func Test_processItem(t *testing.T) {
assert.Equal(t, `task-name(0:json:{"number":2,"string":"foo","list":[0,"1"]},list:[0,"1"],number:2,string:foo)`, newTaskName)
}
}

var wfWithPVC = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: storage-quota-limit
spec:
entrypoint: wait
volumeClaimTemplates: # define volume, same syntax as k8s Pod spec
- metadata:
name: workdir1 # name of volume claim
spec:
accessModes: [ "ReadWriteMany" ]
resources:
requests:
storage: 10Gi
templates:
- name: wait
script:
image: argoproj/argosay:v2
args: [echo, ":) Hello Argo!"]
`

func TestStorageQuota(t *testing.T) {
wf := unmarshalWF(wfWithPVC)

cancel, controller := newController(wf)
defer cancel()

controller.kubeclientset.(*fake.Clientset).BatchV1().(*batchfake.FakeBatchV1).Fake.PrependReactor("create", "persistentvolumeclaims", func(action k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, apierr.NewForbidden(schema.GroupResource{Group: "test", Resource: "test1"}, "test", nil)
})

woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
assert.Equal(t, wfv1.NodePending, woc.wf.Status.Phase)
assert.Contains(t, woc.wf.Status.Message, "Waiting for a PVC to be created.")

controller.kubeclientset.(*fake.Clientset).BatchV1().(*batchfake.FakeBatchV1).Fake.PrependReactor("create", "persistentvolumeclaims", func(action k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, apierr.NewBadRequest("BadRequest")
})

woc.operate()
assert.Equal(t, wfv1.NodeError, woc.wf.Status.Phase)
assert.Contains(t, woc.wf.Status.Message, "BadRequest")
}

0 comments on commit 04898fe

Please sign in to comment.