From 3be63bba91117272b2704953d2255d73ddbd304f Mon Sep 17 00:00:00 2001 From: yangsoon Date: Fri, 16 Apr 2021 13:58:42 +0800 Subject: [PATCH] add end-user/labels.md (#1505) --- .../defwithtemplate/annotations.yaml | 24 +++++++ .../templates/defwithtemplate/labels.yaml | 24 +++++++ docs/en/end-user/labels.md | 72 ++++++++++++++++++- hack/vela-templates/cue/annotations.cue | 8 +++ hack/vela-templates/cue/labels.cue | 8 +++ .../definitions/annotations.yaml | 14 ++++ hack/vela-templates/definitions/labels.yaml | 14 ++++ 7 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 charts/vela-core/templates/defwithtemplate/annotations.yaml create mode 100644 charts/vela-core/templates/defwithtemplate/labels.yaml create mode 100644 hack/vela-templates/cue/annotations.cue create mode 100644 hack/vela-templates/cue/labels.cue create mode 100644 hack/vela-templates/definitions/annotations.yaml create mode 100644 hack/vela-templates/definitions/labels.yaml diff --git a/charts/vela-core/templates/defwithtemplate/annotations.yaml b/charts/vela-core/templates/defwithtemplate/annotations.yaml new file mode 100644 index 000000000..504e2bf2c --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/annotations.yaml @@ -0,0 +1,24 @@ +# Code generated by KubeVela templates. DO NOT EDIT. +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Add annotations for your Workload." + name: annotations + namespace: {{.Values.systemDefinitionNamespace}} +spec: + appliesToWorkloads: + - webservice + - worker + schematic: + cue: + template: |- + patch: { + spec: template: metadata: annotations: { + for k, v in parameter { + "\(k)": v + } + } + } + parameter: [string]: string + diff --git a/charts/vela-core/templates/defwithtemplate/labels.yaml b/charts/vela-core/templates/defwithtemplate/labels.yaml new file mode 100644 index 000000000..8e738a486 --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/labels.yaml @@ -0,0 +1,24 @@ +# Code generated by KubeVela templates. DO NOT EDIT. +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Add labels for your Workload." + name: labels + namespace: {{.Values.systemDefinitionNamespace}} +spec: + appliesToWorkloads: + - webservice + - worker + schematic: + cue: + template: |- + patch: { + spec: template: metadata: labels: { + for k, v in parameter { + "\(k)": v + } + } + } + parameter: [string]: string + diff --git a/docs/en/end-user/labels.md b/docs/en/end-user/labels.md index 3ceee54cf..06724b2d8 100644 --- a/docs/en/end-user/labels.md +++ b/docs/en/end-user/labels.md @@ -2,7 +2,73 @@ title: Labels and Annotations --- -TBD, Content Overview: +We will introduce how to add labels and annotations to your Application. -1. deploy a helm chart based application. -2. Add Patch labels and annotations trait(2 traits) example. +## List Traits + +```bash +kubectl get trait -n vela-system +NAME APPLIES-TO DESCRIPTION AGE +annotations ["webservice","worker"] Add annotations for your Workload. 24h +cpuscaler ["webservice","worker"] configure k8s HPA with CPU metrics for Deployment 24h +ingress ["webservice","worker"] Configures K8s ingress and service to enable web traffic for your service. Please use route trait in cap center for advanced usage. 24h +labels ["webservice","worker"] Add labels for your Workload. 24h +scaler ["webservice","worker"] Configures replicas for your service by patch replicas field. 24h +sidecar ["webservice","worker"] inject a sidecar container into your app 24h +``` + +You can use `label` and `annotations` traits to add labels and annotations for your workload. + +## Apply Application + +Let's use `label` and `annotations` traits in your Application. + +```shell +# myapp.yaml +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: myapp +spec: + components: + - name: express-server + type: webservice + properties: + image: crccheck/hello-world + port: 8000 + traits: + - type: labels + properties: + "release": "stable" + - type: annotations + properties: + "description": "web application" +``` + +Apply this Application. + +```shell +kubectl apply -f myapp.yaml +``` + +Check the workload has been created successfully. + +```bash +$ kubectl get deployments +NAME READY UP-TO-DATE AVAILABLE AGE +express-server 1/1 1 1 15s +``` + +Check the `labels` trait. + +```bash +$ kubectl get deployments express-server -o jsonpath='{.spec.template.metadata.labels}' +{"app.oam.dev/component":"express-server","release": "stable"} +``` + +Check the `annotations` trait. + +```bash +$ kubectl get deployments express-server -o jsonpath='{.spec.template.metadata.annotations}' +{"description":"web application"} +``` diff --git a/hack/vela-templates/cue/annotations.cue b/hack/vela-templates/cue/annotations.cue new file mode 100644 index 000000000..4d9e143c3 --- /dev/null +++ b/hack/vela-templates/cue/annotations.cue @@ -0,0 +1,8 @@ +patch: { + spec: template: metadata: annotations: { + for k, v in parameter { + "\(k)": v + } + } +} +parameter: [string]: string diff --git a/hack/vela-templates/cue/labels.cue b/hack/vela-templates/cue/labels.cue new file mode 100644 index 000000000..fb1710dd0 --- /dev/null +++ b/hack/vela-templates/cue/labels.cue @@ -0,0 +1,8 @@ +patch: { + spec: template: metadata: labels: { + for k, v in parameter { + "\(k)": v + } + } +} +parameter: [string]: string diff --git a/hack/vela-templates/definitions/annotations.yaml b/hack/vela-templates/definitions/annotations.yaml new file mode 100644 index 000000000..40bb182af --- /dev/null +++ b/hack/vela-templates/definitions/annotations.yaml @@ -0,0 +1,14 @@ +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Add annotations for your Workload." + name: annotations + namespace: {{.Values.systemDefinitionNamespace}} +spec: + appliesToWorkloads: + - webservice + - worker + schematic: + cue: + template: |- diff --git a/hack/vela-templates/definitions/labels.yaml b/hack/vela-templates/definitions/labels.yaml new file mode 100644 index 000000000..64821a72e --- /dev/null +++ b/hack/vela-templates/definitions/labels.yaml @@ -0,0 +1,14 @@ +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Add labels for your Workload." + name: labels + namespace: {{.Values.systemDefinitionNamespace}} +spec: + appliesToWorkloads: + - webservice + - worker + schematic: + cue: + template: |-