diff --git a/api/jsonschema/schema.json b/api/jsonschema/schema.json index aac83e9b660e..2b38c630987a 100644 --- a/api/jsonschema/schema.json +++ b/api/jsonschema/schema.json @@ -7499,9 +7499,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.", diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index ff2f319fe588..60f60a33b470 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -11422,9 +11422,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.", diff --git a/pkg/apis/workflow/v1alpha1/generated.proto b/pkg/apis/workflow/v1alpha1/generated.proto index 9421a898d9ed..77f248a90006 100644 --- a/pkg/apis/workflow/v1alpha1/generated.proto +++ b/pkg/apis/workflow/v1alpha1/generated.proto @@ -1916,8 +1916,6 @@ message WorkflowSpec { // 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 repeated k8s.io.api.core.v1.PersistentVolumeClaim volumeClaimTemplates = 6; // Parallelism limits the max total parallel pods that can execute at the same time in a workflow diff --git a/pkg/apis/workflow/v1alpha1/openapi_generated.go b/pkg/apis/workflow/v1alpha1/openapi_generated.go index 37c93e7e7e51..fb2c39e4628a 100644 --- a/pkg/apis/workflow/v1alpha1/openapi_generated.go +++ b/pkg/apis/workflow/v1alpha1/openapi_generated.go @@ -7375,12 +7375,6 @@ func schema_pkg_apis_workflow_v1alpha1_WorkflowSpec(ref common.ReferenceCallback }, }, "volumeClaimTemplates": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-patch-merge-key": "name", - "x-kubernetes-patch-strategy": "merge", - }, - }, SchemaProps: spec.SchemaProps{ Description: "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", Type: []string{"array"}, diff --git a/pkg/apis/workflow/v1alpha1/workflow_types.go b/pkg/apis/workflow/v1alpha1/workflow_types.go index 514b01ba3fd3..a487ff31f4e5 100644 --- a/pkg/apis/workflow/v1alpha1/workflow_types.go +++ b/pkg/apis/workflow/v1alpha1/workflow_types.go @@ -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"` diff --git a/workflow/controller/controller_test.go b/workflow/controller/controller_test.go index 52dedf039e8c..a89356c821b6 100644 --- a/workflow/controller/controller_test.go +++ b/workflow/controller/controller_test.go @@ -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" @@ -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 @@ -295,6 +332,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) @@ -497,6 +558,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