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

fix: Exceeding quota with volumeClaimTemplates #3490

Merged
merged 26 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1dc113d
fix: Exceeding quota with volumeClaimTemplates
sarabala1979 Jul 15, 2020
94746b2
Update steps.yaml
sarabala1979 Jul 15, 2020
5f324e6
Merge branch 'master' into pvcquota
sarabala1979 Jul 16, 2020
fe66eab
Added e2e test
sarabala1979 Jul 16, 2020
dce4ce4
Update operator.go
sarabala1979 Jul 16, 2020
2c99799
Merge branch 'master' into pvcquota
sarabala1979 Jul 16, 2020
79d68e7
Merge branch 'master' into pvcquota
sarabala1979 Jul 16, 2020
db98a40
Merge branch 'master' into pvcquota
sarabala1979 Jul 16, 2020
e606b98
Merge branch 'master' into pvcquota
sarabala1979 Jul 17, 2020
794cd6f
addressed comments
sarabala1979 Jul 20, 2020
068c7f9
Merge branch 'pvcquota' of https://github.com/sarabala1979/argo into …
sarabala1979 Jul 20, 2020
31a60f3
Update operator.go
sarabala1979 Jul 20, 2020
690671c
Merge branch 'master' into pvcquota
sarabala1979 Jul 20, 2020
7b8e75e
Merge branch 'master' into pvcquota
sarabala1979 Jul 21, 2020
2265969
Merge branch 'master' into pvcquota
alexec Jul 21, 2020
fc00a5b
refactored
sarabala1979 Jul 21, 2020
f9893fd
Merge branch 'pvcquota' of https://github.com/sarabala1979/argo into …
sarabala1979 Jul 21, 2020
601bc98
Merge branch 'master' into pvcquota
sarabala1979 Jul 21, 2020
c81fbaa
Update util.go
sarabala1979 Jul 21, 2020
c9108d3
Update storage-limit.yaml
sarabala1979 Jul 21, 2020
4b0c64e
Merge branch 'master' into pvcquota
sarabala1979 Jul 21, 2020
812d9ed
Update storage-limit.yaml
sarabala1979 Jul 22, 2020
b271d72
Update storage-limit.yaml
sarabala1979 Jul 22, 2020
6c81202
Merge branch 'master' into pvcquota
sarabala1979 Jul 22, 2020
939f171
Merge branch 'master' into pvcquota
sarabala1979 Jul 22, 2020
b52909a
Merge branch 'master' into pvcquota
sarabala1979 Jul 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/e2e/fixtures/when.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type When struct {
cronWorkflowName string
kubeClient kubernetes.Interface
resourceQuota *corev1.ResourceQuota
storageQuota *corev1.ResourceQuota
configMap *corev1.ConfigMap
}

Expand Down Expand Up @@ -227,6 +228,24 @@ func (w *When) MemoryQuota(quota string) *When {
return w
}

func (w *When) StorageQuota(quota string) *When {
obj, err := util.CreateHardStorageQuota(w.kubeClient, "argo", "storage-quota", quota)
if err != nil {
w.t.Fatal(err)
}
w.storageQuota = obj
return w
}

func (w *When) DeleteStorageQuota() *When {
err := util.DeleteQuota(w.kubeClient, w.storageQuota)
if err != nil {
w.t.Fatal(err)
}
w.storageQuota = nil
return w
}

func (w *When) DeleteQuota() *When {
err := util.DeleteQuota(w.kubeClient, w.resourceQuota)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package e2e

import (
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -639,6 +640,24 @@ spec:
})
}

func (s *FunctionalSuite) TestStorageQuotaLimit() {
s.Given().
Workflow("@testdata/storage-limit.yaml").
When().
StorageQuota("5Mi").
SubmitWorkflow().
WaitForWorkflowToStart(5*time.Second).
WaitForWorkflowCondition(func(wf *wfv1.Workflow) bool {
return strings.Contains(wf.Status.Message, "Waiting for a PVC to be created")
}, "PVC pending", 10*time.Second).
DeleteStorageQuota().
WaitForWorkflow(30 * time.Second).
Then().
ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, wfv1.NodeSucceeded, status.Phase)
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
})
}

func TestFunctionalSuite(t *testing.T) {
suite.Run(t, new(FunctionalSuite))
}
24 changes: 24 additions & 0 deletions test/e2e/testdata/storage-limit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: storage-quota-limit
labels:
argo-e2e: true
spec:
serviceAccountName: argo
entrypoint: wait
volumeClaimTemplates: # define volume, same syntax as k8s Pod spec
- metadata:
name: workdir1 # name of volume claim
spec:
accessModes: [ "ReadWriteMany" ]
resources:
requests:
storage: 20Mi

templates:
- name: wait
script:
image: alpine:latest
command: [sh, -c]
args: ["echo", "10s"]
18 changes: 15 additions & 3 deletions test/util/resourcequota.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ import (
)

func CreateHardMemoryQuota(clientset kubernetes.Interface, namespace, name, memoryLimit string) (*corev1.ResourceQuota, error) {
resourceList := corev1.ResourceList{
corev1.ResourceLimitsMemory: resource.MustParse(memoryLimit),
}
return CreateResourceQuota(clientset, namespace, name, resourceList)
}

func CreateHardStorageQuota(clientset kubernetes.Interface, namespace, name, storageLimit string) (*corev1.ResourceQuota, error) {
resourceList := corev1.ResourceList{
"requests.storage": resource.MustParse(storageLimit),
}
return CreateResourceQuota(clientset, namespace, name, resourceList)
}

func CreateResourceQuota(clientset kubernetes.Interface, namespace, name string, rl corev1.ResourceList) (*corev1.ResourceQuota, error) {
return clientset.CoreV1().ResourceQuotas(namespace).Create(&corev1.ResourceQuota{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{"argo-e2e": "true"},
},
Spec: corev1.ResourceQuotaSpec{
Hard: corev1.ResourceList{
corev1.ResourceLimitsMemory: resource.MustParse(memoryLimit),
},
Hard: rl,
},
})
}
Expand Down
21 changes: 14 additions & 7 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,21 @@ func (woc *wfOperationCtx) operate() {

err = woc.createPVCs()
if err != nil {
if apierr.IsForbidden(err) {
// Error was most likely caused by a lack of resources.
// In this case, Workflow will be in pending state and requeue.
woc.markWorkflowPhase(wfv1.NodePending, false, fmt.Sprintf("Waiting for a PVC to be created. %v", err))
woc.requeue(10)
return
}
msg := "pvc create error"
woc.log.WithError(err).Error(msg)
woc.markWorkflowError(err, true)
woc.eventRecorder.Event(woc.wf, apiv1.EventTypeWarning, "WorkflowFailed", fmt.Sprintf("%s %s: %+v", woc.wf.ObjectMeta.Name, msg, err))
return
} else if woc.wf.Status.Phase == wfv1.NodePending {
// Workflow might be in pending state if previous PVC creation is forbidden
woc.markWorkflowRunning()
}

node, err := woc.executeTemplate(woc.wf.ObjectMeta.Name, execTmplRef, tmplCtx, execArgs, &executeTemplateOpts{})
Expand Down Expand Up @@ -1226,8 +1236,8 @@ func inferFailedReason(pod *apiv1.Pod) (wfv1.NodePhase, string) {
}

func (woc *wfOperationCtx) createPVCs() error {
if woc.wf.Status.Phase != wfv1.NodeRunning {
// Only attempt to create PVCs if workflow transitioned to Running state
if !(woc.wf.Status.Phase == wfv1.NodePending || woc.wf.Status.Phase == wfv1.NodeRunning) {
// Only attempt to create PVCs if workflow is in Pending or Running state
// (e.g. passed validation, or didn't already complete)
return nil
}
Expand All @@ -1236,9 +1246,6 @@ func (woc *wfOperationCtx) createPVCs() error {
// This will also handle the case where workflow has no volumeClaimTemplates.
return nil
}
if len(woc.wf.Status.PersistentVolumeClaims) == 0 {
woc.wf.Status.PersistentVolumeClaims = make([]apiv1.Volume, len(woc.wfSpec.VolumeClaimTemplates))
}
pvcClient := woc.controller.kubeclientset.CoreV1().PersistentVolumeClaims(woc.wf.ObjectMeta.Namespace)
for i, pvcTmpl := range woc.wfSpec.VolumeClaimTemplates {
if pvcTmpl.ObjectMeta.Name == "" {
Expand Down Expand Up @@ -1290,7 +1297,7 @@ func (woc *wfOperationCtx) createPVCs() error {
},
},
}
woc.wf.Status.PersistentVolumeClaims[i] = vol
woc.wf.Status.PersistentVolumeClaims = append(woc.wf.Status.PersistentVolumeClaims, vol)
woc.updated = true
}
return nil
Expand Down Expand Up @@ -1673,7 +1680,7 @@ func (woc *wfOperationCtx) hasDaemonNodes() bool {
}

func (woc *wfOperationCtx) markWorkflowRunning() {
woc.markWorkflowPhase(wfv1.NodeRunning, false)
woc.markWorkflowPhase(wfv1.NodeRunning, false, "")
Copy link
Member Author

Choose a reason for hiding this comment

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

Previous error/pending message needs to clear on running phase

}

func (woc *wfOperationCtx) markWorkflowSuccess() {
Expand Down
2 changes: 1 addition & 1 deletion workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4101,7 +4101,7 @@ status:
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
assert.Equal(t, wfv1.NodePending, woc.wf.Status.Phase)
assert.Equal(t, wfv1.NodeRunning, woc.wf.Status.Phase)
Copy link
Member Author

Choose a reason for hiding this comment

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

Resubmit will memoization wf phase should be running after operate function. I will create separate PR to fix the phase in memorization

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Copy link
Contributor

Choose a reason for hiding this comment

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

if there is another bug fix - can we combine into a single valid PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure I will fix the memoization bug also in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

As per @jessesuen discussed, just need to fix the phase in resubmit memorized scenario.

for _, node := range woc.wf.Status.Nodes {
switch node.TemplateName {
case "main":
Expand Down