diff --git a/Makefile b/Makefile index 75764012e..84f1c1dfa 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ endif all: build # Run tests -test: fmt vet lint +test: vet lint go test -race -coverprofile=coverage.txt -covermode=atomic ./pkg/... ./cmd/... # Build manager binary @@ -66,6 +66,7 @@ run: fmt vet # Run go fmt against code fmt: go fmt ./... + ./hack/cue-fmt.sh # Run go vet against code vet: diff --git a/charts/vela-core/templates/defwithtemplate/route.yaml b/charts/vela-core/templates/defwithtemplate/route.yaml index 662fae8a2..9a8cf077f 100644 --- a/charts/vela-core/templates/defwithtemplate/route.yaml +++ b/charts/vela-core/templates/defwithtemplate/route.yaml @@ -16,28 +16,28 @@ spec: extension: template: | output: { - apiVersion: "standard.oam.dev/v1alpha1" - kind: "Route" - spec: { - host: parameter.domain + apiVersion: "standard.oam.dev/v1alpha1" + kind: "Route" + spec: { + host: parameter.domain - if parameter.issuer != "" { - tls: { - issuerName: parameter.issuer - } - } + if parameter.issuer != "" { + tls: { + issuerName: parameter.issuer + } + } - if parameter["rules"] != _|_ { - rules: parameter.rules - } - } + if parameter["rules"] != _|_ { + rules: parameter.rules + } + } } parameter: { - domain: *"" | string - issuer: *"" | string - rules?: [...{ - path: string - rewriteTarget: *"" | string - }] + domain: *"" | string + issuer: *"" | string + rules?: [...{ + path: string + rewriteTarget: *"" | string + }] } diff --git a/charts/vela-core/templates/defwithtemplate/task.yaml b/charts/vela-core/templates/defwithtemplate/task.yaml index d47e613bb..ea1e2d4ab 100644 --- a/charts/vela-core/templates/defwithtemplate/task.yaml +++ b/charts/vela-core/templates/defwithtemplate/task.yaml @@ -12,34 +12,33 @@ spec: extension: template: | output: { - apiVersion: "v1" - kind: "Job" - metadata: name: context.name - spec: { - parallelism: parameter.count - completions: parameter.count - template: spec: { - containers: [{ - name: context.name - image: parameter.image + apiVersion: "v1" + kind: "Job" + metadata: name: context.name + spec: { + parallelism: parameter.count + completions: parameter.count + template: spec: { + containers: [{ + name: context.name + image: parameter.image - if parameter["cmd"] != _|_ { - command: parameter.cmd - } - command: - }] - } - } + if parameter["cmd"] != _|_ { + command: parameter.cmd + } + }] + } + } } parameter: { - // +usage=specify number of tasks to run in parallel - // +short=c - count: *1 | int + // +usage=specify number of tasks to run in parallel + // +short=c + count: *1 | int - // +usage=specify app image - // +short=i - image: string + // +usage=specify app image + // +short=i + image: string - cmd?: [...string] + cmd?: [...string] } diff --git a/charts/vela-core/templates/defwithtemplate/webservice.yaml b/charts/vela-core/templates/defwithtemplate/webservice.yaml index 789f9f282..c5f5f4c55 100644 --- a/charts/vela-core/templates/defwithtemplate/webservice.yaml +++ b/charts/vela-core/templates/defwithtemplate/webservice.yaml @@ -12,71 +12,71 @@ spec: extension: template: | output: { - apiVersion: "apps/v1" - kind: "Deployment" - metadata: name: context.name - spec: { - replicas: 1 + apiVersion: "apps/v1" + kind: "Deployment" + metadata: name: context.name + spec: { + replicas: 1 - selector: matchLabels: { - "app.oam.dev/component": context.name - } + selector: matchLabels: { + "app.oam.dev/component": context.name + } - template: { - metadata: labels: { - "app.oam.dev/component": context.name - } + template: { + metadata: labels: { + "app.oam.dev/component": context.name + } - spec: { - containers: [{ - name: context.name - image: parameter.image + spec: { + containers: [{ + name: context.name + image: parameter.image - if parameter["cmd"] != _|_ { - command: parameter.cmd - } + if parameter["cmd"] != _|_ { + command: parameter.cmd + } - if parameter["env"] != _|_ { - env: parameter.env - } - - if context["config"] != _|_ { - env: [ - for k, v in context.config { - name: k - value: v - } - ] - } + if parameter["env"] != _|_ { + env: parameter.env + } - ports: [{ - containerPort: parameter.port - }] - }] - } - } - } + if context["config"] != _|_ { + env: [ + for k, v in context.config { + name: k + value: v + }, + ] + } + + ports: [{ + containerPort: parameter.port + }] + }] + } + } + } } parameter: { - // +usage=specify app image - // +short=i - image: string + // +usage=specify app image + // +short=i + image: string - cmd?: [...string] + cmd?: [...string] - // +usage=specify port for container - // +short=p - port: *6379 | int + // +usage=specify port for container + // +short=p + port: *6379 | int - env?: [...{ - name: string - value?: string - valueFrom?: { - secretKeyRef: { - name: string - key: string - } - } - }] + env?: [...{ + name: string + value?: string + valueFrom?: { + secretKeyRef: { + name: string + key: string + } + } + }] } diff --git a/charts/vela-core/templates/defwithtemplate/worker.yaml b/charts/vela-core/templates/defwithtemplate/worker.yaml index 65b6b7320..807099811 100644 --- a/charts/vela-core/templates/defwithtemplate/worker.yaml +++ b/charts/vela-core/templates/defwithtemplate/worker.yaml @@ -1,7 +1,7 @@ apiVersion: core.oam.dev/v1alpha2 kind: WorkloadDefinition metadata: - name: backend + name: worker annotations: definition.oam.dev/apiVersion: "apps/v1" definition.oam.dev/kind: "Deployment" @@ -12,45 +12,45 @@ spec: extension: template: | output: { - apiVersion: "apps/v1" - kind: "Deployment" - metadata: - name: context.name - spec: { - replicas: 1 - - selector: matchLabels: { - "app.oam.dev/component": context.name - } + apiVersion: "apps/v1" + kind: "Deployment" + metadata: + name: context.name + spec: { + replicas: 1 - template: { - metadata: labels: { - "app.oam.dev/component": context.name - } - - spec: { - containers: [{ - name: context.name - image: parameter.image + selector: matchLabels: { + "app.oam.dev/component": context.name + } - if parameter["cmd"] != _|_ { - command: parameter.cmd - } - }] - } - } + template: { + metadata: labels: { + "app.oam.dev/component": context.name + } - selector: - matchLabels: - "app.oam.dev/component": context.name - } + spec: { + containers: [{ + name: context.name + image: parameter.image + + if parameter["cmd"] != _|_ { + command: parameter.cmd + } + }] + } + } + + selector: + matchLabels: + "app.oam.dev/component": context.name + } } parameter: { - // +usage=specify app image - // +short=i - image: string + // +usage=specify app image + // +short=i + image: string - cmd?: [...string] + cmd?: [...string] } diff --git a/docs/README.md b/docs/README.md index 2e8dfc659..a67c94099 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,7 @@ Learn and use KubeVela with tutorials and user stories. **For Developers** - [Setting Up Deployment Environment](developers/config-enviroments.md) -- [Deploying Application](developers/deploy-app.md) +- [Initializing Application](developers/app-init.md) - [Setting Routes](developers/set-route.md) - [Setting Auto-scaling Policy](developers/set-autoscaling.md) - [Setting Rollout Strategy](developers/set-rollout.md) @@ -19,7 +19,7 @@ Learn and use KubeVela with tutorials and user stories. - [Check Application Logs](developers/check-logs.md) - [Execute Commands in Container](developers/exec-cmd.md) - [Port Forward to Container](developers/port-forward.md) -- [Setting Configurations in Application](developers/config-app.md) +- [Configuring data/env in Application](developers/config-app.md) - [Consuming Cloud Services](developers/cloud-service.md) **For Platform Engineers** diff --git a/docs/developers/app-init.md b/docs/developers/app-init.md new file mode 100644 index 000000000..59bc9c866 --- /dev/null +++ b/docs/developers/app-init.md @@ -0,0 +1,93 @@ +# Initializating Application + +## `vela init` + +To initialize and deploy an application with one service, run: + +> If you only want to initialize without deploying the app, add `--render-only` flag + +```console +$ vela init +Welcome to use KubeVela CLI! We're going to help you run applications through a couple of questions. + +Environment: default, namespace: default + +? Do you want to setup a domain for web service: +? Provide an email for production certification: +? What would you like to name your application: testapp +? Choose workload type for your service: webservice +? What would you name this webservice: testsvc +? specify app image crccheck/hello-world +? specify port for container 8000 +... +✅ Application Deployed Successfully! + - Name: testsvc + Type: webservice + HEALTHY Ready: 1/1 + Routes: + + Last Deployment: + Created at: ... + Updated at: ... +``` + +Check the application: + +```console +$ vela show testapp +About: + + Name: testapp + Created at: ... + Updated at: ... + + +Environment: + + Namespace: default + +Services: + + - Name: testsvc + WorkloadType: webservice + Arguments: + image: crccheck/hello-world + port: 8000 + Traits: +``` + +## Deploy Multiple Services + +You can also use KubeVela CLI to deploy multiple services for an application. + +Check the available workload types. + +```console +$ vela workloads +NAME DESCRIPTION +worker Backend worker without ports exposed +webservice Long running service with network routes +``` + +Deploy the first service named `frontend` with `Web Service` type: + +```console +$ vela svc deploy frontend --app testapp -t webservice --image crccheck/hello-world +App testapp deployed +``` + +> TODO auto generate a random application name, so --app testapp becomes optional + +Deploy the second service named `backend` with "Backend Worker" type: + +```console +$ vela svc deploy backend --app testapp2 -t worker --image crccheck/hello-world +App testapp2 deployed +``` + +```console +$ vela ls +SERVICE APP TYPE TRAITS STATUS CREATED-TIME +frontend testapp ... +backend testapp ... +``` diff --git a/docs/developers/config-app.md b/docs/developers/config-app.md index e69de29bb..aa8996648 100644 --- a/docs/developers/config-app.md +++ b/docs/developers/config-app.md @@ -0,0 +1,83 @@ +# Configuring Data/Env in Application + +`vela` provides a `config` command to manage config data. + +## `vela config set` + +```console +$ vela config set test a=b c=d +reading existing config data and merging with user input +config data saved successfully ✅ +``` + +## `vela config get` + +```console +$ vela config get test +Data: + a: b + c: d +``` + +## `vela config del` + +```console +$ vela config del test +config (test) deleted successfully +``` + +## `vela config ls` + +```console +$ vela config set test a=b +$ vela config set test2 c=d +$ vela config ls +NAME +test +test2 +``` + +## Configure env in application + +The config data can be set as the env in applications. + +```console +$ vela config set demo DEMO_HELLO=helloworld +``` + +Save the following to `vela.yaml` in current directory: + +```yaml +name: testapp +services: + env-config-demo: + image: heroku/nodejs-hello-world + config: demo +``` + +Then run: +```console +$ vela up +Parsing vela.yaml ... +Loading templates ... + +Rendering configs for service (env-config-demo)... +writing deploy config to (.vela/deploy.yaml) + +Applying deploy configs ... +Checking if app has been deployed... +app has not been deployed, creating a new deployment... +✅ app has been deployed 🚀🚀🚀 + Port forward: vela port-forward testapp + SSH: vela exec testapp + Logging: vela logs testapp + App status: vela status testapp + Service status: vela status testapp --svc env-config-demo +``` + +Check env var: + +``` +$ vela exec testapp -- printenv | grep DEMO_HELLO +DEMO_HELLO=helloworld +``` diff --git a/docs/developers/deploy-app.md b/docs/developers/deploy-app.md deleted file mode 100644 index 3b10d2c09..000000000 --- a/docs/developers/deploy-app.md +++ /dev/null @@ -1,71 +0,0 @@ -# Deploying Application - -## `vela app init` - -The simplest way to deploy an application with KubeVela is using `$ vela app init` . - -```console -$ vela app init -``` - -Check the application: - -```console -$ vela show myapp - About: - - Name: myapp - Created at: 2020-11-02 11:39:04.626416 +0800 CST - Updated at: 2020-11-02 11:39:04.627998 +0800 CST - - - Environment: - - Namespace: default - - Services: - - - Name: frontend - WorkloadType: webservice - Arguments: - port: 8000 - image: crccheck/hello-world - Traits: - - route: - domain: frontend.example.com - issuer: oam-env-default -``` - -## Deploy Application Step by Step - -You can also use KubeVela CLI to deploy a more complex micro-services application step by step, with detailed configurations. - -Check the available workload types. - -```console -$ vela workloads -TODO -``` - -Deploy the first service named `frontend` with `Web Service` type. - -```console -$ vela svc deploy frontend -t webservice --image crccheck/hello-world --app myapp -App myapp deployed -``` - -> TODO auto generate a random application name, so --app myapp becomes optional - -Deploy the second service named `backend` with "Backend Worker" type for the same application. - -```console -$ vela svc deploy backend -t backendworker --image crccheck/hello-world --app myapp -Creating backend -SUCCEED -``` - -```console -$ vela ls -SERVICE APP TYPE TRAITS STATUS CREATED-TIME -frontend myapp Deployed 2020-11-02 11:39:05 +0800 CST -``` diff --git a/docs/developers/references/traits/autoscaling.md b/docs/developers/references/traits/autoscaling.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/developers/references/traits/metrics.md b/docs/developers/references/traits/metrics.md new file mode 100644 index 000000000..8784ad583 --- /dev/null +++ b/docs/developers/references/traits/metrics.md @@ -0,0 +1,12 @@ +# Metrics + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Path** | **string** | the metric path of the service | [default to /metrics] +**Format** | **string** | +format of the metrics, default as prometheus | [default to prometheus] +**Scheme** | **string** | | [default to http] +**Enabled** | **bool** | | [default to true] +**Port** | **int32** | the port for metrics, will discovery automatically by default | [default to 0], >=1024 & <=65535 +**Selector** | **map[string]string** | the label selector for the pods, will discovery automatically by default | [optional] diff --git a/docs/developers/references/traits/rollout.md b/docs/developers/references/traits/rollout.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/developers/references/traits/route.md b/docs/developers/references/traits/route.md index e69de29bb..82cfd4c10 100644 --- a/docs/developers/references/traits/route.md +++ b/docs/developers/references/traits/route.md @@ -0,0 +1,17 @@ +# Route + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Domain** | **string** | | [default to ] +**Issuer** | **string** | | [default to ] +**Rules** | [**[]RouteRules**](routerules.md) | | [optional] + + +### RouteRules + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Path** | **string** | | +**RewriteTarget** | **string** | | [default to ] diff --git a/docs/developers/references/traits/scale.md b/docs/developers/references/traits/scale.md new file mode 100644 index 000000000..2cd068161 --- /dev/null +++ b/docs/developers/references/traits/scale.md @@ -0,0 +1,7 @@ +# Scaler + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Replica** | **int32** | | [default to 1] diff --git a/docs/developers/references/workload-types/backend-worker.md b/docs/developers/references/workload-types/backend-worker.md index e69de29bb..f00976d4a 100644 --- a/docs/developers/references/workload-types/backend-worker.md +++ b/docs/developers/references/workload-types/backend-worker.md @@ -0,0 +1,8 @@ +# Worker + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Cmd** | **[]string** | | [optional] +**Image** | **string** | pecify app image | diff --git a/docs/developers/references/workload-types/task.md b/docs/developers/references/workload-types/task.md index e69de29bb..9965a050e 100644 --- a/docs/developers/references/workload-types/task.md +++ b/docs/developers/references/workload-types/task.md @@ -0,0 +1,9 @@ +# Task + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Cmd** | **[]string** | | [optional] +**Count** | **int32** | specify number of tasks to run in parallel | [default to 1] +**Image** | **string** | specify app image | diff --git a/docs/developers/references/workload-types/web-service.md b/docs/developers/references/workload-types/web-service.md index e69de29bb..ba5a737e3 100644 --- a/docs/developers/references/workload-types/web-service.md +++ b/docs/developers/references/workload-types/web-service.md @@ -0,0 +1,33 @@ +# Webservice + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Cmd** | **[]string** | | [optional] +**Env** | [**[]WebserviceEnv**](#webserviceenv) | | [optional] +**Image** | **string** | specify app image | +**Port** | **int32** | specify port for container | [default to 6379] + + +### WebserviceEnv + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Name** | **string** | | +**Value** | **string** | | [optional] +**ValueFrom** | [**WebserviceValueFrom**](#webservicevaluefrom) | | [optional] + + +### WebserviceValueFrom + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**SecretKeyRef** | [**WebserviceValueFromSecretKeyRef**](#webservicevaluefromsecretkeyref) | | + +### WebserviceValueFromSecretKeyRef + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Name** | **string** | | +**Key** | **string** | | \ No newline at end of file diff --git a/docs/developers/set-route.md b/docs/developers/set-route.md index 66efcd6ee..d30a49d0f 100644 --- a/docs/developers/set-route.md +++ b/docs/developers/set-route.md @@ -6,7 +6,7 @@ from outside world via `route` feature. ```console $ vela svc ls NAME APP WORKLOAD TRAITS STATUS CREATED-TIME -frontend myapp webservice Deployed 2020-09-18 22:42:04 +0800 CST +frontend testapp webservice Deployed 2020-09-18 22:42:04 +0800 CST ``` ## `port-forward` @@ -14,7 +14,7 @@ frontend myapp webservice Deployed 2020-09-18 22:42:04 +0800 CST It will directly open browser for you. ```console -$ vela port-forward myapp +$ vela port-forward testapp Forwarding from 127.0.0.1:8080 -> 80 Forwarding from [::1]:8080 -> 80 @@ -32,7 +32,7 @@ Handling connection for 8080 You can manually configure it by setting domain parameter. ```console -$ vela route myapp --domain frontend.mycustom.domain +$ vela route testapp --domain frontend.mycustom.domain Adding route for app frontend Rendering configs for service (frontend)... @@ -56,7 +56,7 @@ $ curl -H "Host:frontend.mycustom.domain" 123.57.10.233 ### If you have domain set in environment ```console -$ vela route myapp +$ vela route testapp Adding route for app frontend Rendering configs for service (frontend)... diff --git a/docs/quick-start.md b/docs/quick-start.md index 9fdcbf13f..935ff95ed 100644 --- a/docs/quick-start.md +++ b/docs/quick-start.md @@ -14,7 +14,7 @@ Welcome to use KubeVela CLI! We're going to help you run applications through a Environment: default, namespace: default -? Do you want to setup a domain for web service: +? Do you want to setup a domain for web service: example.com ? Provide an email for production certification: ? What would you like to name your application: testapp ? Choose workload type for your service: webservice @@ -34,27 +34,14 @@ updateTime: ... name: testapp services: testsvc: + type: webservice image: crccheck/hello-world port: 8000 - type: webservice -``` - -## 2. Add Routing Config - -Add routing config under `route`: - -```yaml -services: - testsvc: - ... route: domain: testsvc.example.com - rules: - - path: /testapp - rewriteTarget: / ``` -## 3. Deploy Application +## 2. Deploy Application ```console $ vela up @@ -102,7 +89,7 @@ Services: > If not in kind cluster, replace localhost with ingress address ``` -$ curl -H "Host:testsvc.example.com" http://localhost/testapp +$ curl -H "Host:testsvc.example.com" http://localhost/ Hello World diff --git a/e2e/apiserver/apiserver_test.go b/e2e/apiserver/apiserver_test.go index e54d61f46..9aedb4047 100644 --- a/e2e/apiserver/apiserver_test.go +++ b/e2e/apiserver/apiserver_test.go @@ -53,7 +53,7 @@ var notExistedEnvMeta = apis.Environment{ } var webserviceWorkloadType = "webservice" -var backendWorkloadType = "backend" +var workerWorkloadType = "worker" var taskWorkloadType = "task" var _ = ginkgo.Describe("API", func() { @@ -210,7 +210,7 @@ var _ = ginkgo.Describe("API", func() { for _, i := range data { var workloadDefinition = i.(map[string]interface{}) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - gomega.Expect([]string{webserviceWorkloadType, backendWorkloadType, taskWorkloadType}).To(gomega.Or(gomega.ContainElement(workloadDefinition["name"]))) + gomega.Expect([]string{webserviceWorkloadType, workerWorkloadType, taskWorkloadType}).To(gomega.Or(gomega.ContainElement(workloadDefinition["name"]))) } }) diff --git a/hack/cue-fmt.sh b/hack/cue-fmt.sh new file mode 100755 index 000000000..73a2e6260 --- /dev/null +++ b/hack/cue-fmt.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +if ! cue version ; then + echo "Installing CUE..." + GO111MODULE=off go get -u cuelang.org/go/cmd/cue +fi + +echo "Formatting CUE templates..." +cue fmt ./hack/vela-templates/cue/* diff --git a/hack/vela-templates/cue/route.cue b/hack/vela-templates/cue/route.cue index c65da86d6..64221a7f3 100644 --- a/hack/vela-templates/cue/route.cue +++ b/hack/vela-templates/cue/route.cue @@ -1,25 +1,25 @@ output: { - apiVersion: "standard.oam.dev/v1alpha1" - kind: "Route" - spec: { - host: parameter.domain + apiVersion: "standard.oam.dev/v1alpha1" + kind: "Route" + spec: { + host: parameter.domain - if parameter.issuer != "" { - tls: { - issuerName: parameter.issuer - } - } + if parameter.issuer != "" { + tls: { + issuerName: parameter.issuer + } + } - if parameter["rules"] != _|_ { - rules: parameter.rules - } - } + if parameter["rules"] != _|_ { + rules: parameter.rules + } + } } parameter: { - domain: *"" | string - issuer: *"" | string - rules?: [...{ - path: string - rewriteTarget: *"" | string - }] + domain: *"" | string + issuer: *"" | string + rules?: [...{ + path: string + rewriteTarget: *"" | string + }] } diff --git a/hack/vela-templates/cue/task.cue b/hack/vela-templates/cue/task.cue index e9dd454af..4049fc876 100644 --- a/hack/vela-templates/cue/task.cue +++ b/hack/vela-templates/cue/task.cue @@ -1,31 +1,30 @@ output: { - apiVersion: "v1" - kind: "Job" - metadata: name: context.name - spec: { - parallelism: parameter.count - completions: parameter.count - template: spec: { - containers: [{ - name: context.name - image: parameter.image + apiVersion: "v1" + kind: "Job" + metadata: name: context.name + spec: { + parallelism: parameter.count + completions: parameter.count + template: spec: { + containers: [{ + name: context.name + image: parameter.image - if parameter["cmd"] != _|_ { - command: parameter.cmd - } - command: - }] - } - } + if parameter["cmd"] != _|_ { + command: parameter.cmd + } + }] + } + } } parameter: { - // +usage=specify number of tasks to run in parallel - // +short=c - count: *1 | int + // +usage=specify number of tasks to run in parallel + // +short=c + count: *1 | int - // +usage=specify app image - // +short=i - image: string + // +usage=specify app image + // +short=i + image: string - cmd?: [...string] + cmd?: [...string] } diff --git a/hack/vela-templates/cue/webservice.cue b/hack/vela-templates/cue/webservice.cue index e60a9a506..9dd01fc54 100644 --- a/hack/vela-templates/cue/webservice.cue +++ b/hack/vela-templates/cue/webservice.cue @@ -1,68 +1,68 @@ output: { - apiVersion: "apps/v1" - kind: "Deployment" - metadata: name: context.name - spec: { - replicas: 1 + apiVersion: "apps/v1" + kind: "Deployment" + metadata: name: context.name + spec: { + replicas: 1 - selector: matchLabels: { - "app.oam.dev/component": context.name - } + selector: matchLabels: { + "app.oam.dev/component": context.name + } - template: { - metadata: labels: { - "app.oam.dev/component": context.name - } + template: { + metadata: labels: { + "app.oam.dev/component": context.name + } - spec: { - containers: [{ - name: context.name - image: parameter.image + spec: { + containers: [{ + name: context.name + image: parameter.image - if parameter["cmd"] != _|_ { - command: parameter.cmd - } + if parameter["cmd"] != _|_ { + command: parameter.cmd + } - if parameter["env"] != _|_ { - env: parameter.env - } - - if context["config"] != _|_ { - env: [ - for k, v in context.config { - name: k - value: v - } - ] - } + if parameter["env"] != _|_ { + env: parameter.env + } - ports: [{ - containerPort: parameter.port - }] - }] - } - } - } + if context["config"] != _|_ { + env: [ + for k, v in context.config { + name: k + value: v + }, + ] + } + + ports: [{ + containerPort: parameter.port + }] + }] + } + } + } } parameter: { - // +usage=specify app image - // +short=i - image: string + // +usage=specify app image + // +short=i + image: string - cmd?: [...string] + cmd?: [...string] - // +usage=specify port for container - // +short=p - port: *6379 | int + // +usage=specify port for container + // +short=p + port: *6379 | int - env?: [...{ - name: string - value?: string - valueFrom?: { - secretKeyRef: { - name: string - key: string - } - } - }] + env?: [...{ + name: string + value?: string + valueFrom?: { + secretKeyRef: { + name: string + key: string + } + } + }] } diff --git a/hack/vela-templates/cue/worker.cue b/hack/vela-templates/cue/worker.cue index a6bc5fc7e..6bdffd596 100644 --- a/hack/vela-templates/cue/worker.cue +++ b/hack/vela-templates/cue/worker.cue @@ -1,42 +1,42 @@ output: { - apiVersion: "apps/v1" - kind: "Deployment" - metadata: - name: context.name - spec: { - replicas: 1 - - selector: matchLabels: { - "app.oam.dev/component": context.name - } + apiVersion: "apps/v1" + kind: "Deployment" + metadata: + name: context.name + spec: { + replicas: 1 - template: { - metadata: labels: { - "app.oam.dev/component": context.name - } - - spec: { - containers: [{ - name: context.name - image: parameter.image + selector: matchLabels: { + "app.oam.dev/component": context.name + } - if parameter["cmd"] != _|_ { - command: parameter.cmd - } - }] - } - } + template: { + metadata: labels: { + "app.oam.dev/component": context.name + } - selector: - matchLabels: - "app.oam.dev/component": context.name - } + spec: { + containers: [{ + name: context.name + image: parameter.image + + if parameter["cmd"] != _|_ { + command: parameter.cmd + } + }] + } + } + + selector: + matchLabels: + "app.oam.dev/component": context.name + } } parameter: { - // +usage=specify app image - // +short=i - image: string + // +usage=specify app image + // +short=i + image: string - cmd?: [...string] + cmd?: [...string] } diff --git a/hack/vela-templates/definitions/worker.yaml b/hack/vela-templates/definitions/worker.yaml index cd45ff05e..ab92b1b0f 100644 --- a/hack/vela-templates/definitions/worker.yaml +++ b/hack/vela-templates/definitions/worker.yaml @@ -1,7 +1,7 @@ apiVersion: core.oam.dev/v1alpha2 kind: WorkloadDefinition metadata: - name: backend + name: worker annotations: definition.oam.dev/apiVersion: "apps/v1" definition.oam.dev/kind: "Deployment"