Skip to content

Commit

Permalink
fix: remove WorkflowSpec VolumeClaimTemplates patch key (#11662)
Browse files Browse the repository at this point in the history
Signed-off-by: sunyeongchoi <sn0716@naver.com>
  • Loading branch information
sunyeongchoi authored and terrytangyuan committed Oct 19, 2023
1 parent fe88053 commit 4d09777
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 17 deletions.
4 changes: 1 addition & 3 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7417,9 +7417,7 @@
"items": {
"$ref": "#/definitions/io.k8s.api.core.v1.PersistentVolumeClaim"
},
"type": "array",
"x-kubernetes-patch-merge-key": "name",
"x-kubernetes-patch-strategy": "merge"
"type": "array"
},
"volumes": {
"description": "Volumes is a list of volumes that can be mounted by containers in a io.argoproj.workflow.v1alpha1.",
Expand Down
4 changes: 1 addition & 3 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11330,9 +11330,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/io.k8s.api.core.v1.PersistentVolumeClaim"
},
"x-kubernetes-patch-merge-key": "name",
"x-kubernetes-patch-strategy": "merge"
}
},
"volumes": {
"description": "Volumes is a list of volumes that can be mounted by containers in a io.argoproj.workflow.v1alpha1.",
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/workflow/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions pkg/apis/workflow/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ type WorkflowSpec struct {
// VolumeClaimTemplates is a list of claims that containers are allowed to reference.
// The Workflow controller will create the claims at the beginning of the workflow
// and delete the claims upon completion of the workflow
// +patchStrategy=merge
// +patchMergeKey=name
VolumeClaimTemplates []apiv1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,6,opt,name=volumeClaimTemplates"`
VolumeClaimTemplates []apiv1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty" protobuf:"bytes,6,opt,name=volumeClaimTemplates"`

// Parallelism limits the max total parallel pods that can execute at the same time in a workflow
Parallelism *int64 `json:"parallelism,omitempty" protobuf:"bytes,7,opt,name=parallelism"`
Expand Down
70 changes: 70 additions & 0 deletions workflow/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/api/resource"

"github.com/argoproj/pkg/sync"
"github.com/stretchr/testify/assert"
authorizationv1 "k8s.io/api/authorization/v1"
Expand Down Expand Up @@ -110,6 +112,41 @@ spec:
args: ["hello world"]
`

var testDefaultVolumeClaimTemplateWf = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: hello-world
labels:
foo: bar
spec:
volumeClaimTemplates:
- metadata:
name: workdir
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Mi
storageClassName: local-path
entrypoint: whalesay
serviceAccountName: whalesay
templates:
- name: whalesay
metadata:
annotations:
annotationKey1: "annotationValue1"
annotationKey2: "annotationValue2"
labels:
labelKey1: "labelValue1"
labelKey2: "labelValue2"
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["hello world"]
`

var testDefaultWfTTL = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down Expand Up @@ -294,6 +331,30 @@ func newControllerWithComplexDefaults() (context.CancelFunc, *WorkflowController
return cancel, controller
}

func newControllerWithDefaultsVolumeClaimTemplate() (context.CancelFunc, *WorkflowController) {
cancel, controller := newController(func(controller *WorkflowController) {
controller.Config.WorkflowDefaults = &wfv1.Workflow{
Spec: wfv1.WorkflowSpec{
VolumeClaimTemplates: []apiv1.PersistentVolumeClaim{{
ObjectMeta: metav1.ObjectMeta{
Name: "workdir",
},
Spec: apiv1.PersistentVolumeClaimSpec{
AccessModes: []apiv1.PersistentVolumeAccessMode{apiv1.ReadWriteOnce},
Resources: apiv1.ResourceRequirements{
Requests: apiv1.ResourceList{
apiv1.ResourceStorage: resource.MustParse("1Mi"),
},
},
StorageClassName: pointer.String("local-path"),
},
}},
},
}
})
return cancel, controller
}

func unmarshalArtifact(yamlStr string) *wfv1.Artifact {
var artifact wfv1.Artifact
wfv1.MustUnmarshal([]byte(yamlStr), &artifact)
Expand Down Expand Up @@ -496,6 +557,15 @@ func TestAddingWorkflowDefaultComplexTwo(t *testing.T) {
assert.Contains(t, workflow.Annotations, "annotation")
}

func TestAddingWorkflowDefaultVolumeClaimTemplate(t *testing.T) {
cancel, controller := newControllerWithDefaultsVolumeClaimTemplate()
defer cancel()
workflow := wfv1.MustUnmarshalWorkflow(testDefaultWf)
err := controller.setWorkflowDefaults(workflow)
assert.NoError(t, err)
assert.Equal(t, workflow, wfv1.MustUnmarshalWorkflow(testDefaultVolumeClaimTemplateWf))
}

func TestNamespacedController(t *testing.T) {
kubeClient := fake.Clientset{}
allowed := false
Expand Down

0 comments on commit 4d09777

Please sign in to comment.