From bc6a60dde2f46e5f0157bbcb16278419c717acdb Mon Sep 17 00:00:00 2001 From: Yue Wang Date: Sun, 11 Apr 2021 15:18:48 +0900 Subject: [PATCH] add volumes definition in worker/webservice (#1459) Signed-off-by: roywang --- .../templates/defwithtemplate/webservice.yaml | 75 +++++++++++++++++ .../templates/defwithtemplate/worker.yaml | 83 +++++++++++++++++++ .../app-with-volumes/app-websvc-volumes.yaml | 38 +++++++++ .../app-with-volumes/app-worker-volumes.yaml | 38 +++++++++ hack/vela-templates/cue/webservice.cue | 75 +++++++++++++++++ hack/vela-templates/cue/worker.cue | 83 +++++++++++++++++++ 6 files changed, 392 insertions(+) create mode 100644 docs/examples/app-with-volumes/app-websvc-volumes.yaml create mode 100644 docs/examples/app-with-volumes/app-worker-volumes.yaml diff --git a/charts/vela-core/templates/defwithtemplate/webservice.yaml b/charts/vela-core/templates/defwithtemplate/webservice.yaml index 35853ed08..887c1a8b2 100644 --- a/charts/vela-core/templates/defwithtemplate/webservice.yaml +++ b/charts/vela-core/templates/defwithtemplate/webservice.yaml @@ -62,7 +62,50 @@ spec: cpu: parameter.cpu } } + + if parameter["volumes"] != _|_ { + volumeMounts: [ for v in parameter.volumes { + { + mountPath: v.mountPath + name: v.name + }}] + } }] + + if parameter["volumes"] != _|_ { + volumes: [ for v in parameter.volumes { + { + name: v.name + if v.type == "pvc" { + persistentVolumeClaim: { + claimName: v.claimName + } + } + if v.type == "configMap" { + configMap: { + defaultMode: v.defaultMode + name: v.cmName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "secret" { + secret: { + defaultMode: v.defaultMode + secretName: v.secretName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "emptyDir" { + emptyDir: { + medium: v.medium + } + } + }}] + } } } } @@ -100,5 +143,37 @@ spec: // If addRevisionLabel is true, the appRevision label will be added to the underlying pods addRevisionLabel: *false | bool + + // +usage=Declare volumes and volumeMounts + volumes?: [...{ + name: string + mountPath: string + // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir" + type: "pvc" | "configMap" | "secret" | "emptyDir" + if type == "pvc" { + claimName: string + } + if type == "configMap" { + defaultMode: *420 | int + cmName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "secret" { + defaultMode: *420 | int + secretName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "emptyDir" { + medium: *"" | "Memory" + } + }] } diff --git a/charts/vela-core/templates/defwithtemplate/worker.yaml b/charts/vela-core/templates/defwithtemplate/worker.yaml index 824ed683c..4f3a12ae2 100644 --- a/charts/vela-core/templates/defwithtemplate/worker.yaml +++ b/charts/vela-core/templates/defwithtemplate/worker.yaml @@ -35,7 +35,59 @@ spec: if parameter["cmd"] != _|_ { command: parameter.cmd } + + if parameter["volumes"] != _|_ { + volumeMounts: [ for v in parameter.volumes { + { + mountPath: v.mountPath + name: v.name + } + }] + } + + if parameter["volumes"] != _|_ { + volumeMounts: [ for v in parameter.volumes { + { + mountPath: v.mountPath + name: v.name + }}] + } }] + + if parameter["volumes"] != _|_ { + volumes: [ for v in parameter.volumes { + { + name: v.name + if v.type == "pvc" { + persistentVolumeClaim: { + claimName: v.claimName + } + } + if v.type == "configMap" { + configMap: { + defaultMode: v.defaultMode + name: v.cmName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "secret" { + secret: { + defaultMode: v.defaultMode + secretName: v.secretName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "emptyDir" { + emptyDir: { + medium: v.medium + } + } + }}] + } } } } @@ -47,5 +99,36 @@ spec: image: string // +usage=Commands to run in the container cmd?: [...string] + // +usage=Declare volumes and volumeMounts + volumes?: [...{ + name: string + mountPath: string + // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir" + type: "pvc" | "configMap" | "secret" | "emptyDir" + if type == "pvc" { + claimName: string + } + if type == "configMap" { + defaultMode: *420 | int + cmName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "secret" { + defaultMode: *420 | int + secretName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "emptyDir" { + medium: *"" | "Memory" + } + }] } diff --git a/docs/examples/app-with-volumes/app-websvc-volumes.yaml b/docs/examples/app-with-volumes/app-websvc-volumes.yaml new file mode 100644 index 000000000..e9b6918b4 --- /dev/null +++ b/docs/examples/app-with-volumes/app-websvc-volumes.yaml @@ -0,0 +1,38 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: app-webservice +spec: + components: + - name: mywebsvc + type: webservice + properties: + image: "busybox" + cmd: + - sleep + - "1000" + volumes: + - name: "my-pvc" + mountPath: "/var/www/html1" + type: "pvc" + claimName: "myclaim" + - name: "my-cm" + mountPath: "/var/www/html2" + type: "configMap" + cmName: "myCmName" + items: + - key: "k1" + path: "./a1" + - key: "k2" + path: "./a2" + - name: "my-cm-noitems" + mountPath: "/var/www/html22" + type: "configMap" + cmName: "myCmName2" + - name: "mysecret" + type: "secret" + mountPath: "/var/www/html3" + secretName: "mysecret" + - name: "my-empty-dir" + type: "emptyDir" + mountPath: "/var/www/html4" diff --git a/docs/examples/app-with-volumes/app-worker-volumes.yaml b/docs/examples/app-with-volumes/app-worker-volumes.yaml new file mode 100644 index 000000000..76b21c8ba --- /dev/null +++ b/docs/examples/app-with-volumes/app-worker-volumes.yaml @@ -0,0 +1,38 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: app-worker +spec: + components: + - name: myworker + type: worker + properties: + image: "busybox" + cmd: + - sleep + - "1000" + volumes: + - name: "my-pvc" + mountPath: "/var/www/html1" + type: "pvc" + claimName: "myclaim" + - name: "my-cm" + mountPath: "/var/www/html2" + type: "configMap" + cmName: "myCmName" + items: + - key: "k1" + path: "./a1" + - key: "k2" + path: "./a2" + - name: "my-cm-noitems" + mountPath: "/var/www/html22" + type: "configMap" + cmName: "myCmName2" + - name: "mysecret" + type: "secret" + mountPath: "/var/www/html3" + secretName: "mysecret" + - name: "my-empty-dir" + type: "emptyDir" + mountPath: "/var/www/html4" diff --git a/hack/vela-templates/cue/webservice.cue b/hack/vela-templates/cue/webservice.cue index 7ad988249..9e9382679 100644 --- a/hack/vela-templates/cue/webservice.cue +++ b/hack/vela-templates/cue/webservice.cue @@ -46,7 +46,50 @@ output: { cpu: parameter.cpu } } + + if parameter["volumes"] != _|_ { + volumeMounts: [ for v in parameter.volumes { + { + mountPath: v.mountPath + name: v.name + }}] + } }] + + if parameter["volumes"] != _|_ { + volumes: [ for v in parameter.volumes { + { + name: v.name + if v.type == "pvc" { + persistentVolumeClaim: { + claimName: v.claimName + } + } + if v.type == "configMap" { + configMap: { + defaultMode: v.defaultMode + name: v.cmName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "secret" { + secret: { + defaultMode: v.defaultMode + secretName: v.secretName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "emptyDir" { + emptyDir: { + medium: v.medium + } + } + }}] + } } } } @@ -84,4 +127,36 @@ parameter: { // If addRevisionLabel is true, the appRevision label will be added to the underlying pods addRevisionLabel: *false | bool + + // +usage=Declare volumes and volumeMounts + volumes?: [...{ + name: string + mountPath: string + // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir" + type: "pvc" | "configMap" | "secret" | "emptyDir" + if type == "pvc" { + claimName: string + } + if type == "configMap" { + defaultMode: *420 | int + cmName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "secret" { + defaultMode: *420 | int + secretName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "emptyDir" { + medium: *"" | "Memory" + } + }] } diff --git a/hack/vela-templates/cue/worker.cue b/hack/vela-templates/cue/worker.cue index 9b94cfe59..f12f5607d 100644 --- a/hack/vela-templates/cue/worker.cue +++ b/hack/vela-templates/cue/worker.cue @@ -19,7 +19,59 @@ output: { if parameter["cmd"] != _|_ { command: parameter.cmd } + + if parameter["volumes"] != _|_ { + volumeMounts: [ for v in parameter.volumes { + { + mountPath: v.mountPath + name: v.name + } + }] + } + + if parameter["volumes"] != _|_ { + volumeMounts: [ for v in parameter.volumes { + { + mountPath: v.mountPath + name: v.name + }}] + } }] + + if parameter["volumes"] != _|_ { + volumes: [ for v in parameter.volumes { + { + name: v.name + if v.type == "pvc" { + persistentVolumeClaim: { + claimName: v.claimName + } + } + if v.type == "configMap" { + configMap: { + defaultMode: v.defaultMode + name: v.cmName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "secret" { + secret: { + defaultMode: v.defaultMode + secretName: v.secretName + if v.items != _|_ { + items: v.items + } + } + } + if v.type == "emptyDir" { + emptyDir: { + medium: v.medium + } + } + }}] + } } } } @@ -31,4 +83,35 @@ parameter: { image: string // +usage=Commands to run in the container cmd?: [...string] + // +usage=Declare volumes and volumeMounts + volumes?: [...{ + name: string + mountPath: string + // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir" + type: "pvc" | "configMap" | "secret" | "emptyDir" + if type == "pvc" { + claimName: string + } + if type == "configMap" { + defaultMode: *420 | int + cmName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "secret" { + defaultMode: *420 | int + secretName: string + items?: [...{ + key: string + path: string + mode: *511 | int + }] + } + if type == "emptyDir" { + medium: *"" | "Memory" + } + }] }