From 66fb99954ef4bea86ba0cb11498597ed3efe32aa Mon Sep 17 00:00:00 2001 From: Jianbo Sun Date: Fri, 29 Jan 2021 14:56:38 +0800 Subject: [PATCH] fix quick start guide as we don't have route trait installed as default (#954) * fix quick start guide as we don't have route trait installed as default * add a description for ingress trait --- .../templates/defwithtemplate/ingress.yaml | 60 +++++++++++++++++++ .../templates/defwithtemplate/worker.yaml | 4 -- docs/en/design.md | 4 +- docs/en/quick-start.md | 5 +- docs/examples/registry/ingress.yaml | 50 ---------------- docs/examples/vela.yaml | 6 +- hack/vela-templates/cue/ingress.cue | 45 ++++++++++++++ hack/vela-templates/cue/worker.cue | 4 -- hack/vela-templates/definitions/ingress.yaml | 13 ++++ 9 files changed, 127 insertions(+), 64 deletions(-) create mode 100644 charts/vela-core/templates/defwithtemplate/ingress.yaml delete mode 100644 docs/examples/registry/ingress.yaml create mode 100644 hack/vela-templates/cue/ingress.cue create mode 100644 hack/vela-templates/definitions/ingress.yaml diff --git a/charts/vela-core/templates/defwithtemplate/ingress.yaml b/charts/vela-core/templates/defwithtemplate/ingress.yaml new file mode 100644 index 000000000..51bc22e87 --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/ingress.yaml @@ -0,0 +1,60 @@ +# Code generated by KubeVela templates. DO NOT EDIT. +apiVersion: core.oam.dev/v1alpha2 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Configures K8s ingress and service to enable web traffic for your service. + Please use route trait in cap center for advanced usage." + name: ingress +spec: + appliesToWorkloads: + - webservice + - worker + extension: + template: | + parameter: { + domain: string + http: [string]: int + } + + // trait template can have multiple outputs in one trait + outputs: service: { + apiVersion: "v1" + kind: "Service" + metadata: + name: context.name + spec: { + selector: + "app.oam.dev/component": context.name + ports: [ + for k, v in parameter.http { + port: v + targetPort: v + }, + ] + } + } + + outputs: ingress: { + apiVersion: "networking.k8s.io/v1beta1" + kind: "Ingress" + metadata: + name: context.name + spec: { + rules: [{ + host: parameter.domain + http: { + paths: [ + for k, v in parameter.http { + path: k + backend: { + serviceName: context.name + servicePort: v + } + }, + ] + } + }] + } + } + diff --git a/charts/vela-core/templates/defwithtemplate/worker.yaml b/charts/vela-core/templates/defwithtemplate/worker.yaml index 3f37eaa70..77e3f6e03 100644 --- a/charts/vela-core/templates/defwithtemplate/worker.yaml +++ b/charts/vela-core/templates/defwithtemplate/worker.yaml @@ -34,10 +34,6 @@ spec: }] } } - - selector: - matchLabels: - "app.oam.dev/component": context.name } } diff --git a/docs/en/design.md b/docs/en/design.md index 414752061..cb62ea5dc 100644 --- a/docs/en/design.md +++ b/docs/en/design.md @@ -103,13 +103,13 @@ services: type: webservice image: oamdev/testapp:v1 - route: + ingress: domain: example.com http: # match the longest prefix "/": 8080 ``` -This `appfile` is composed of a `frontend` component including workload type of `Web Service` and a `route` trait. Developer fills in the values based on the independent schema documentations for such workload type and trait. KubeVela will check the corresponding definition objects in OAM Kubernetes runtime to validate and generate the final Kubernetes resources. This is how we make the user interface of KubeVela highly extensible. +This `appfile` is composed of a `frontend` component including workload type of `Web Service` and a `ingress` trait. Developer fills in the values based on the independent schema documentations for such workload type and trait. KubeVela will check the corresponding definition objects in OAM Kubernetes runtime to validate and generate the final Kubernetes resources. This is how we make the user interface of KubeVela highly extensible. In order to make building such high level abstractions easier, we adopted [CUElang](https://github.com/cuelang/cue) in the OAM Kubernetes runtime for creating the "last mile" abstractions (i.e., eliminating non user facing fields or merging multiple objects into one). All the abstractions in `appfile` are essentially defined by the CUE templates saved in the OAM Control Plane Objects. The platform builders can modify those templates at any time. The updates will take effect immediately in the schema of the `appfile`. diff --git a/docs/en/quick-start.md b/docs/en/quick-start.md index f2a4a2eeb..b1b27acfa 100644 --- a/docs/en/quick-start.md +++ b/docs/en/quick-start.md @@ -45,8 +45,9 @@ Services: Last Deployment: Created at: ... Updated at: ... - Routes: - - route: Visiting URL: http://testsvc.example.com IP: localhost + Traits: + - ✅ ingress: domain=testsvc.example.com + http=map[/:8000] ``` **In [kind cluster setup](./install.md#kind)**, you can visit the service via localhost. In other setups, replace localhost with ingress address accordingly. diff --git a/docs/examples/registry/ingress.yaml b/docs/examples/registry/ingress.yaml deleted file mode 100644 index f66af09ea..000000000 --- a/docs/examples/registry/ingress.yaml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: core.oam.dev/v1alpha2 -kind: TraitDefinition -metadata: - name: ingress -spec: - extension: - template: | - parameter: { - domain: string - http: [string]: int - } - - // trait template can have multiple outputs in one trait - outputs: service: { - apiVersion: "v1" - kind: "Service" - spec: { - selector: - app: context.name - ports: [ - for k, v in parameter.http { - port: v - targetPort: v - } - ] - } - } - - outputs: ingress: { - apiVersion: "networking.k8s.io/v1beta1" - kind: "Ingress" - metadata: - name: context.name - spec: { - rules: [{ - host: parameter.domain - http: { - paths: [ - for k, v in parameter.http { - path: k - backend: { - serviceName: context.name - servicePort: v - } - } - ] - } - }] - } - } \ No newline at end of file diff --git a/docs/examples/vela.yaml b/docs/examples/vela.yaml index a6961b7fe..6e013e8f4 100644 --- a/docs/examples/vela.yaml +++ b/docs/examples/vela.yaml @@ -4,5 +4,7 @@ services: type: webservice image: crccheck/hello-world port: 8000 - route: - domain: testsvc.example.com \ No newline at end of file + ingress: + domain: testsvc.example.com + http: + "/": 8000 \ No newline at end of file diff --git a/hack/vela-templates/cue/ingress.cue b/hack/vela-templates/cue/ingress.cue new file mode 100644 index 000000000..63e40f069 --- /dev/null +++ b/hack/vela-templates/cue/ingress.cue @@ -0,0 +1,45 @@ +parameter: { + domain: string + http: [string]: int +} + +// trait template can have multiple outputs in one trait +outputs: service: { + apiVersion: "v1" + kind: "Service" + metadata: + name: context.name + spec: { + selector: + "app.oam.dev/component": context.name + ports: [ + for k, v in parameter.http { + port: v + targetPort: v + }, + ] + } +} + +outputs: ingress: { + apiVersion: "networking.k8s.io/v1beta1" + kind: "Ingress" + metadata: + name: context.name + spec: { + rules: [{ + host: parameter.domain + http: { + paths: [ + for k, v in parameter.http { + path: k + backend: { + serviceName: context.name + servicePort: v + } + }, + ] + } + }] + } +} diff --git a/hack/vela-templates/cue/worker.cue b/hack/vela-templates/cue/worker.cue index a9651601e..9b94cfe59 100644 --- a/hack/vela-templates/cue/worker.cue +++ b/hack/vela-templates/cue/worker.cue @@ -22,10 +22,6 @@ output: { }] } } - - selector: - matchLabels: - "app.oam.dev/component": context.name } } diff --git a/hack/vela-templates/definitions/ingress.yaml b/hack/vela-templates/definitions/ingress.yaml new file mode 100644 index 000000000..6a460e661 --- /dev/null +++ b/hack/vela-templates/definitions/ingress.yaml @@ -0,0 +1,13 @@ +apiVersion: core.oam.dev/v1alpha2 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Configures K8s ingress and service to enable web traffic for your service. + Please use route trait in cap center for advanced usage." + name: ingress +spec: + appliesToWorkloads: + - webservice + - worker + extension: + template: |