mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
fix docs example (#1316)
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: nworker
|
||||
annotations:
|
||||
definition.oam.dev/description: "Describes long-running, scalable, containerized services that running at backend. They do NOT have network endpoint to receive external network traffic."
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
status:
|
||||
healthPolicy: |
|
||||
isHealth: (context.output.status.readyReplicas > 0) && (context.output.status.readyReplicas == context.output.status.replicas)
|
||||
@@ -68,7 +70,7 @@ spec:
|
||||
|
||||
|
||||
---
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: ingress
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Application Example
|
||||
|
||||
In this Demo, Application application-sample will be converted to appconfig and component
|
||||
In this Demo, Application application-sample will be converted to appcontext and component
|
||||
|
||||
The fields in the application spec come from the parametes defined in the definition template
|
||||
, so we must install Definition at first
|
||||
|
||||
Step 1: Install Workload Definition & Trait Definition
|
||||
Step 1: Install ComponentDefinition & Trait Definition
|
||||
```
|
||||
kubectl apply -f template.yaml
|
||||
```
|
||||
@@ -18,87 +18,99 @@ Step 3: View the application status
|
||||
kubectl get -f application-sample.yaml -oyaml
|
||||
|
||||
// You can see the following
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
annotations:
|
||||
kubectl.kubernetes.io/last-applied-configuration: |
|
||||
{"apiVersion":"core.oam.dev/v1alpha2","kind":"Application","metadata":{"annotations":{},"name":"application-sample","namespace":"oam-test"},"spec":{"template":"services:\n myweb:\n type: worker\n image: \"busybox\"\n cmd:\n - sleep\n - \"1000\"\n scaler:\n replicas: 10"}}
|
||||
name: application-sample
|
||||
namespace: oam-test
|
||||
{"apiVersion":"core.oam.dev/v1beta1","kind":"Application","metadata":{"annotations":{},"name":"application-sample","namespace":"default"},"spec":{"components":[{"name":"myweb","properties":{"cmd":["sleep","1000"],"image":"busybox"},"traits":[{"properties":{"replicas":10},"type":"scaler"},{"properties":{"image":"nginx","name":"sidecar-test"},"type":"sidecar"},{"properties":{"http":{"server":80}},"type":"kservice"}],"type":"worker"}]}}
|
||||
...
|
||||
spec:
|
||||
components:
|
||||
- name: myweb
|
||||
type: worker
|
||||
settings:
|
||||
image: "busybox"
|
||||
cmd:
|
||||
- sleep
|
||||
- "1000"
|
||||
traits:
|
||||
- name: scaler
|
||||
properties:
|
||||
replicas: 10
|
||||
- name: sidercar
|
||||
properties:
|
||||
name: "sidecar-test"
|
||||
image: "nginx"
|
||||
- name: kservice
|
||||
properties:
|
||||
http:
|
||||
server: 80
|
||||
- name: myweb
|
||||
properties:
|
||||
cmd:
|
||||
- sleep
|
||||
- "1000"
|
||||
image: busybox
|
||||
traits:
|
||||
- properties:
|
||||
replicas: 10
|
||||
type: scaler
|
||||
- properties:
|
||||
image: nginx
|
||||
name: sidecar-test
|
||||
type: sidecar
|
||||
- properties:
|
||||
http:
|
||||
server: 80
|
||||
type: kservice
|
||||
type: worker
|
||||
status:
|
||||
batchRollingState: ""
|
||||
components:
|
||||
- apiVersion: core.oam.dev/v1alpha2
|
||||
kind: Component
|
||||
name: myweb
|
||||
conditions:
|
||||
- lastTransitionTime: "2020-12-02T12:12:52Z"
|
||||
reason: Available
|
||||
- reason: Available
|
||||
status: "True"
|
||||
type: Parsed
|
||||
- lastTransitionTime: "2020-12-02T12:12:52Z"
|
||||
reason: Available
|
||||
- reason: Available
|
||||
status: "True"
|
||||
type: Built
|
||||
- lastTransitionTime: "2020-12-02T12:12:52Z"
|
||||
reason: Available
|
||||
- reason: Available
|
||||
status: "True"
|
||||
type: Applied
|
||||
status: running
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
Step 4: View the oam CR generated by application
|
||||
|
||||
```
|
||||
kubectl get appconfig/application-sample -oyaml
|
||||
kubectl get appcontext/application-sample -oyaml
|
||||
|
||||
// appconfig is as follows
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: ApplicationConfiguration
|
||||
kind: ApplicationContext
|
||||
metadata:
|
||||
annotations:
|
||||
kubectl.kubernetes.io/last-applied-configuration: |
|
||||
{"apiVersion":"core.oam.dev/v1beta1","kind":"Application","metadata":{"annotations":{},"name":"application-sample","namespace":"default"},"spec":{"components":[{"name":"myweb","properties":{"cmd":["sleep","1000"],"image":"busybox"},"traits":[{"properties":{"replicas":10},"type":"scaler"},{"properties":{"image":"nginx","name":"sidecar-test"},"type":"sidecar"},{"properties":{"http":{"server":80}},"type":"kservice"}],"type":"worker"}]}}
|
||||
generation: 1
|
||||
labels:
|
||||
application.oam.dev: application-sample
|
||||
app.oam.dev/app-revision-hash: 99749f6e7a78024b
|
||||
name: application-sample
|
||||
namespace: oam-test
|
||||
namespace: default
|
||||
ownerReferences:
|
||||
- apiVersion: core.oam.dev/v1alpha2
|
||||
- apiVersion: core.oam.dev/v1beta1
|
||||
controller: true
|
||||
kind: Application
|
||||
name: application-sample
|
||||
uid: dca7acc3-664c-422b-aa52-4fe012e37974
|
||||
spec:
|
||||
components:
|
||||
- componentName: myweb
|
||||
...
|
||||
spec:
|
||||
applicationRevisionName: application-sample-v1
|
||||
status:
|
||||
conditions:
|
||||
- reason: ReconcileSuccess
|
||||
status: "True"
|
||||
type: Synced
|
||||
dependency: {}
|
||||
observedGeneration: 0
|
||||
workloads:
|
||||
- appliedComponentRevision: myweb-v1
|
||||
componentName: myweb
|
||||
componentRevisionName: myweb-v1
|
||||
traits:
|
||||
- trait:
|
||||
- traitRef:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: myweb
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: myweb
|
||||
name: myweb
|
||||
workloadRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: myweb-v1
|
||||
|
||||
kubectl get component/myweb -oyaml
|
||||
|
||||
@@ -106,20 +118,26 @@ kubectl get component/myweb -oyaml
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: Component
|
||||
metadata:
|
||||
generation: 1
|
||||
labels:
|
||||
application.oam.dev: application-sample
|
||||
app.oam.dev/name: application-sample
|
||||
name: myweb
|
||||
namespace: oam-test
|
||||
namespace: default
|
||||
ownerReferences:
|
||||
- apiVersion: core.oam.dev/v1alpha2
|
||||
- apiVersion: core.oam.dev/v1beta1
|
||||
controller: true
|
||||
kind: Application
|
||||
name: application-sample
|
||||
uid: dca7acc3-664c-422b-aa52-4fe012e37974
|
||||
...
|
||||
spec:
|
||||
workload:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app.oam.dev/component: myweb
|
||||
app.oam.dev/name: application-sample
|
||||
workload.oam.dev/type: worker
|
||||
spec:
|
||||
replicas: 10
|
||||
selector:
|
||||
@@ -137,10 +155,12 @@ spec:
|
||||
- "1000"
|
||||
image: busybox
|
||||
name: myweb
|
||||
- command:
|
||||
- sleep
|
||||
- "1000"
|
||||
image: busybox
|
||||
name: test-sidecar
|
||||
- image: nginx
|
||||
name: sidecar-test
|
||||
status:
|
||||
latestRevision:
|
||||
name: myweb-v1
|
||||
revision: 1
|
||||
observedGeneration: 1
|
||||
```
|
||||
|
||||
|
||||
@@ -55,59 +55,62 @@ containers: [{
|
||||
### output
|
||||
Generate a new cr, which is generally associated with workload cr
|
||||
|
||||
## Workload Definition
|
||||
The following workload definition is to generate a deployment
|
||||
## ComponentDefinition
|
||||
The following ComponentDefinition is to generate a deployment
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: worker
|
||||
annotations:
|
||||
definition.oam.dev/description: "Long-running scalable backend worker without network endpoint"
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
extension:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
selector: matchLabels: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
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
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter: {
|
||||
// +usage=Which image would you like to use for your service
|
||||
// +short=i
|
||||
image: string
|
||||
parameter: {
|
||||
// +usage=Which image would you like to use for your service
|
||||
// +short=i
|
||||
image: string
|
||||
|
||||
cmd?: [...string]
|
||||
}
|
||||
cmd?: [...string]
|
||||
}
|
||||
```
|
||||
|
||||
If defined an application as follows
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: application-sample
|
||||
@@ -115,7 +118,7 @@ spec:
|
||||
components:
|
||||
- name: myweb
|
||||
type: worker
|
||||
settings:
|
||||
properties:
|
||||
image: "busybox"
|
||||
cmd:
|
||||
- sleep
|
||||
@@ -145,7 +148,7 @@ spec:
|
||||
|
||||
Define a trait Definition that appends service to workload(worker) , as shown below
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -155,31 +158,32 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {spec: template: metadata: labels: app: context.name}
|
||||
outputs: service: {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
metadata: name: context.name
|
||||
spec: {
|
||||
selector: app: context.name
|
||||
ports: [
|
||||
for k, v in parameter.http {
|
||||
port: v
|
||||
targetPort: v
|
||||
}
|
||||
]
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {spec: template: metadata: labels: app: context.name}
|
||||
outputs: service: {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
metadata: name: context.name
|
||||
spec: {
|
||||
selector: app: context.name
|
||||
ports: [
|
||||
for k, v in parameter.http {
|
||||
port: v
|
||||
targetPort: v
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
http: [string]: int
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
http: [string]: int
|
||||
}
|
||||
```
|
||||
|
||||
If add service capability to the application, as follows
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: application-sample
|
||||
@@ -187,13 +191,13 @@ spec:
|
||||
components:
|
||||
- name: myweb
|
||||
type: worker
|
||||
settings:
|
||||
properties:
|
||||
image: "busybox"
|
||||
cmd:
|
||||
- sleep
|
||||
- "1000"
|
||||
traits:
|
||||
- name: kservice
|
||||
- type: kservice
|
||||
properties:
|
||||
http:
|
||||
server: 80
|
||||
@@ -238,7 +242,7 @@ spec:
|
||||
|
||||
Define a trait Definition that scale workload(worker) replicas
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -248,32 +252,33 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
//+short=r
|
||||
replicas: *1 | int
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
//+short=r
|
||||
replicas: *1 | int
|
||||
}
|
||||
```
|
||||
If add scaler capability to the application, as follows
|
||||
```
|
||||
components:
|
||||
- name: myweb
|
||||
type: worker
|
||||
settings:
|
||||
properties:
|
||||
image: "busybox"
|
||||
cmd:
|
||||
- sleep
|
||||
- "1000"
|
||||
traits:
|
||||
- name: kservice
|
||||
- type: kservice
|
||||
properties:
|
||||
http:
|
||||
server: 80
|
||||
- name: scaler
|
||||
- type: scaler
|
||||
properties:
|
||||
replicas: 10
|
||||
```
|
||||
@@ -307,7 +312,7 @@ spec:
|
||||
|
||||
Define a trait Definition that append containers to workload(worker)
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -317,22 +322,23 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
// +patchKey=name
|
||||
spec: template: spec: containers: [parameter]
|
||||
}
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
// +patchKey=name
|
||||
spec: template: spec: containers: [parameter]
|
||||
}
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
}
|
||||
```
|
||||
|
||||
If add sidercar capability to the application, as follows
|
||||
```
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: application-sample
|
||||
@@ -340,20 +346,20 @@ spec:
|
||||
components:
|
||||
- name: myweb
|
||||
type: worker
|
||||
settings:
|
||||
properties:
|
||||
image: "busybox"
|
||||
cmd:
|
||||
- sleep
|
||||
- "1000"
|
||||
traits:
|
||||
- name: scaler
|
||||
- type: scaler
|
||||
properties:
|
||||
replicas: 10
|
||||
- name: sidercar
|
||||
- type: sidecar
|
||||
properties:
|
||||
name: "sidecar-test"
|
||||
image: "nginx"
|
||||
- name: kservice
|
||||
- type: kservice
|
||||
properties:
|
||||
http:
|
||||
server: 80
|
||||
|
||||
@@ -15,11 +15,11 @@ spec:
|
||||
- type: scaler
|
||||
properties:
|
||||
replicas: 10
|
||||
- kind: sidecar
|
||||
- type: sidecar
|
||||
properties:
|
||||
name: "sidecar-test"
|
||||
image: "nginx"
|
||||
- kind: kservice
|
||||
- type: kservice
|
||||
properties:
|
||||
http:
|
||||
server: 80
|
||||
@@ -1,54 +1,57 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: worker
|
||||
annotations:
|
||||
definition.oam.dev/description: "Long-running scalable backend worker without network endpoint"
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
extension:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
selector: matchLabels: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
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
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
selector:
|
||||
matchLabels:
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
}
|
||||
selector:
|
||||
matchLabels:
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
}
|
||||
|
||||
parameter: {
|
||||
// +usage=Which image would you like to use for your service
|
||||
// +short=i
|
||||
image: string
|
||||
parameter: {
|
||||
// +usage=Which image would you like to use for your service
|
||||
// +short=i
|
||||
image: string
|
||||
|
||||
cmd?: [...string]
|
||||
}
|
||||
cmd?: [...string]
|
||||
}
|
||||
---
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -58,17 +61,18 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
//+short=r
|
||||
replicas: *1 | int
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
//+short=r
|
||||
replicas: *1 | int
|
||||
}
|
||||
---
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -78,19 +82,20 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
// +patchKey=name
|
||||
spec: template: spec: containers: [parameter]
|
||||
}
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
// +patchKey=name
|
||||
spec: template: spec: containers: [parameter]
|
||||
}
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
}
|
||||
---
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -100,28 +105,29 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {spec: template: metadata: labels: app: context.name}
|
||||
outputs: service: {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
metadata: name: context.name
|
||||
spec: {
|
||||
selector: app: context.name
|
||||
ports: [
|
||||
for k, v in parameter.http {
|
||||
port: v
|
||||
targetPort: v
|
||||
}
|
||||
]
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {spec: template: metadata: labels: app: context.name}
|
||||
outputs: service: {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
metadata: name: context.name
|
||||
spec: {
|
||||
selector: app: context.name
|
||||
ports: [
|
||||
for k, v in parameter.http {
|
||||
port: v
|
||||
targetPort: v
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
http: [string]: int
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
http: [string]: int
|
||||
}
|
||||
---
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: services
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: mydeploy
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
extension:
|
||||
template: |
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
}
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
selector: matchLabels: {
|
||||
"app.oam.dev/component": parameter.name
|
||||
}
|
||||
template: {
|
||||
metadata: labels: {
|
||||
"app.oam.dev/component": parameter.name
|
||||
}
|
||||
spec: {
|
||||
containers: [{
|
||||
name: parameter.name
|
||||
image: parameter.image
|
||||
}]
|
||||
}}}
|
||||
}
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
}
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
selector: matchLabels: {
|
||||
"app.oam.dev/component": parameter.name
|
||||
}
|
||||
template: {
|
||||
metadata: labels: {
|
||||
"app.oam.dev/component": parameter.name
|
||||
}
|
||||
spec: {
|
||||
containers: [{
|
||||
name: parameter.name
|
||||
image: parameter.image
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT.
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: webservice
|
||||
annotations:
|
||||
definition.oam.dev/description: "Describes long-running, scalable, containerized services that have a stable network endpoint to receive external network traffic from customers."
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: myingress
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: myworker
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: WorkloadDefinition
|
||||
metadata:
|
||||
name: webapp-chart
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Kubecon 2020 NA Kubevela Tutorial
|
||||
|
||||
> :warning: This is an outdated tutorial only applies to the old version of kubevela.
|
||||
Before you read, you need to know what you are doing.
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
* Kubernetes cluster version >1.16
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT.
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: autoscale
|
||||
namespace: vela-system
|
||||
annotations:
|
||||
definition.oam.dev/description: "Automatically scales workloads by resource utilization metrics or cron triggers."
|
||||
spec:
|
||||
@@ -19,71 +19,68 @@ spec:
|
||||
name: keda
|
||||
url: https://kedacore.github.io/charts
|
||||
version: 2.0.0-rc3
|
||||
template: |
|
||||
import "strconv"
|
||||
|
||||
outputs: autoscaler: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "Autoscaler"
|
||||
spec: {
|
||||
minReplicas: parameter.min
|
||||
maxReplicas: parameter.max
|
||||
if parameter["cpuPercent"] != _|_ && parameter["cron"] != _|_ {
|
||||
triggers: [cpuScaler, cronScaler]
|
||||
}
|
||||
if parameter["cpuPercent"] != _|_ && parameter["cron"] == _|_ {
|
||||
triggers: [cpuScaler]
|
||||
}
|
||||
if parameter["cpuPercent"] == _|_ && parameter["cron"] != _|_ {
|
||||
triggers: [cronScaler]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cpuScaler: {
|
||||
type: "cpu"
|
||||
condition: {
|
||||
type: "Utilization"
|
||||
if parameter["cpuPercent"] != _|_ {
|
||||
// Temporarily use `strconv` for type converting. This bug will be fixed in kubevela#585
|
||||
value: strconv.FormatInt(parameter.cpuPercent, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cronScaler: {
|
||||
type: "cron"
|
||||
if parameter["cron"] != _|_ && parameter.cron["replicas"] != _|_ {
|
||||
condition: {
|
||||
startAt: parameter.cron.startAt
|
||||
duration: parameter.cron.duration
|
||||
days: parameter.cron.days
|
||||
replicas: strconv.FormatInt(parameter.cron.replicas, 10)
|
||||
timezone: parameter.cron.timezone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter: {
|
||||
// +usage=Minimal replicas of the workload
|
||||
min: int
|
||||
// +usage=Maximal replicas of the workload
|
||||
max: int
|
||||
// +usage=Specify the value for CPU utilization, like 80, which means 80%
|
||||
// +alias=cpu-percent
|
||||
cpuPercent?: int
|
||||
// +usage=Cron type auto-scaling. Just for `appfile`, not available for Cli usage
|
||||
cron?: {
|
||||
// +usage=The time to start scaling, like `08:00`
|
||||
startAt: string
|
||||
// +usage=For how long the scaling will last
|
||||
duration: string
|
||||
// +usage=Several workdays or weekends, like "Monday, Tuesday"
|
||||
days: string
|
||||
// +usage=The target replicas to be scaled to
|
||||
replicas: int
|
||||
// +usage=Timezone, like "America/Los_Angeles"
|
||||
timezone: string
|
||||
}
|
||||
}
|
||||
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
import "strconv"
|
||||
outputs: autoscaler: {{
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "Autoscaler"
|
||||
spec: {
|
||||
minReplicas: parameter.min
|
||||
maxReplicas: parameter.max
|
||||
if parameter["cpuPercent"] != _|_ && parameter["cron"] != _|_ {
|
||||
triggers: [cpuScaler, cronScaler]
|
||||
}
|
||||
if parameter["cpuPercent"] != _|_ && parameter["cron"] == _|_ {
|
||||
triggers: [cpuScaler]
|
||||
}
|
||||
if parameter["cpuPercent"] == _|_ && parameter["cron"] != _|_ {
|
||||
triggers: [cronScaler]
|
||||
}
|
||||
}
|
||||
}}
|
||||
cpuScaler: {
|
||||
type: "cpu"
|
||||
condition: {
|
||||
type: "Utilization"
|
||||
if parameter["cpuPercent"] != _|_ {
|
||||
// Temporarily use `strconv` for type converting. This bug will be fixed in kubevela#585
|
||||
value: strconv.FormatInt(parameter.cpuPercent, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
cronScaler: {
|
||||
type: "cron"
|
||||
if parameter["cron"] != _|_ && parameter.cron["replicas"] != _|_ {
|
||||
condition: {
|
||||
startAt: parameter.cron.startAt
|
||||
duration: parameter.cron.duration
|
||||
days: parameter.cron.days
|
||||
replicas: strconv.FormatInt(parameter.cron.replicas, 10)
|
||||
timezone: parameter.cron.timezone
|
||||
}
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
// +usage=Minimal replicas of the workload
|
||||
min: int
|
||||
// +usage=Maximal replicas of the workload
|
||||
max: int
|
||||
// +usage=Specify the value for CPU utilization, like 80, which means 80%
|
||||
// +alias=cpu-percent
|
||||
cpuPercent?: int
|
||||
// +usage=Cron type auto-scaling. Just for `appfile`, not available for Cli usage
|
||||
cron?: {
|
||||
// +usage=The time to start scaling, like `08:00`
|
||||
startAt: string
|
||||
// +usage=For how long the scaling will last
|
||||
duration: string
|
||||
// +usage=Several workdays or weekends, like "Monday, Tuesday"
|
||||
days: string
|
||||
// +usage=The target replicas to be scaled to
|
||||
replicas: int
|
||||
// +usage=Timezone, like "America/Los_Angeles"
|
||||
timezone: string
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -8,27 +8,27 @@ spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
processing: {
|
||||
output: {
|
||||
credentials?: string
|
||||
}
|
||||
http: {
|
||||
method: *"GET" | string
|
||||
url: parameter.serviceURL
|
||||
request: {
|
||||
header: {
|
||||
"authorization.token": parameter.uidtoken
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
patch: {
|
||||
spec: template: spec: serviceAccountName: processing.output.credentials
|
||||
}
|
||||
|
||||
parameter: {
|
||||
uidtoken: string
|
||||
serviceURL: string
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
processing: {
|
||||
output: {
|
||||
credentials?: string
|
||||
}
|
||||
http: {
|
||||
method: *"GET" | string
|
||||
url: parameter.serviceURL
|
||||
request: {
|
||||
header: {
|
||||
"authorization.token": parameter.uidtoken
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
patch: {
|
||||
spec: template: spec: serviceAccountName: processing.output.credentials
|
||||
}
|
||||
parameter: {
|
||||
uidtoken: string
|
||||
serviceURL: string
|
||||
}
|
||||
@@ -1,28 +1,29 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: expose
|
||||
namespace: vela-system
|
||||
spec:
|
||||
extension:
|
||||
template: |
|
||||
parameter: {
|
||||
domain: string
|
||||
http: [string]: int
|
||||
}
|
||||
|
||||
outputs: {
|
||||
for k, v in parameter.http {
|
||||
"\(k)": {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
spec: {
|
||||
selector:
|
||||
app: context.name
|
||||
ports: [{
|
||||
port: v
|
||||
targetPort: v
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
parameter: {
|
||||
domain: string
|
||||
http: [string]: int
|
||||
}
|
||||
outputs: {
|
||||
for k, v in parameter.http {
|
||||
"\(k)": {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
spec: {
|
||||
selector:
|
||||
app: context.name
|
||||
ports: [{
|
||||
port: v
|
||||
targetPort: v
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,50 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "add an init container and use shared volume with pod"
|
||||
name: init-container
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: spec: {
|
||||
// +patchKey=name
|
||||
containers: [{
|
||||
name: context.name
|
||||
// +patchKey=name
|
||||
volumeMounts: [{
|
||||
name: parameter.mountName
|
||||
mountPath: parameter.appMountPath
|
||||
}]
|
||||
}]
|
||||
initContainers: [{
|
||||
name: parameter.name
|
||||
image: parameter.image
|
||||
command: parameter.command
|
||||
// +patchKey=name
|
||||
volumeMounts: [{
|
||||
name: parameter.mountName
|
||||
mountPath: parameter.initMountPath
|
||||
}]
|
||||
}]
|
||||
// +patchKey=name
|
||||
volumes: [{
|
||||
name: parameter.mountName
|
||||
emptyDir: {}
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
mountName: *"workdir" | string
|
||||
appMountPath: string
|
||||
initMountPath: string
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: spec: {
|
||||
// +patchKey=name
|
||||
containers: [{
|
||||
name: context.name
|
||||
// +patchKey=name
|
||||
volumeMounts: [{
|
||||
name: parameter.mountName
|
||||
mountPath: parameter.appMountPath
|
||||
}]
|
||||
}]
|
||||
initContainers: [{
|
||||
name: parameter.name
|
||||
image: parameter.image
|
||||
command: parameter.command
|
||||
// +patchKey=name
|
||||
volumeMounts: [{
|
||||
name: parameter.mountName
|
||||
mountPath: parameter.initMountPath
|
||||
}]
|
||||
}]
|
||||
// +patchKey=name
|
||||
volumes: [{
|
||||
name: parameter.mountName
|
||||
emptyDir: {}
|
||||
}]
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
mountName: *"workdir" | string
|
||||
appMountPath: string
|
||||
initMountPath: string
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "Specify auto scale by annotation"
|
||||
name: kautoscale
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice # this should be some knative like workload
|
||||
extension:
|
||||
template: |-
|
||||
import "encoding/json"
|
||||
patch: {
|
||||
metadata: annotations: {
|
||||
"my.autoscale.ann": json.Marshal({
|
||||
"minReplicas": parameter.min
|
||||
"maxReplicas": parameter.max
|
||||
})
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
min: *1 | int
|
||||
max: *3 | int
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
import "encoding/json"
|
||||
patch: {
|
||||
metadata: annotations: {
|
||||
"my.autoscale.ann": json.Marshal({
|
||||
"minReplicas": parameter.min
|
||||
"maxReplicas": parameter.max
|
||||
})
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
min: *1 | int
|
||||
max: *3 | int
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT.
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: metrics
|
||||
namespace: vela-system
|
||||
annotations:
|
||||
definition.oam.dev/description: "Configures monitoring metrics for your service."
|
||||
spec:
|
||||
@@ -21,26 +21,28 @@ spec:
|
||||
namespace: monitoring
|
||||
url: https://prometheus-community.github.io/helm-charts
|
||||
version: 9.4.4
|
||||
template: |-
|
||||
outputs: metrics: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "MetricsTrait"
|
||||
spec: {
|
||||
scrapeService: parameter
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
// +usage=Format of the metrics, default as prometheus
|
||||
// +short=f
|
||||
format: *"prometheus" | string
|
||||
// +usage=The metrics path of the service
|
||||
path: *"/metrics" | string
|
||||
// +usage=The way to retrieve data which can take the values `http` or `https`
|
||||
scheme: *"http" | string
|
||||
enabled: *true | bool
|
||||
// +usage=The port for metrics, will discovery automatically by default
|
||||
port: *0 | >=1024 & <=65535 & int
|
||||
// +usage=The label selector for the pods, will discovery automatically by default
|
||||
selector?: [string]: string
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
outputs: metrics: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "MetricsTrait"
|
||||
spec: {
|
||||
scrapeService: parameter
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
// +usage=Format of the metrics, default as prometheus
|
||||
// +short=f
|
||||
format: *"prometheus" | string
|
||||
// +usage=The metrics path of the service
|
||||
path: *"/metrics" | string
|
||||
// +usage=The way to retrieve data which can take the values `http` or `https`
|
||||
scheme: *"http" | string
|
||||
enabled: *true | bool
|
||||
// +usage=The port for metrics, will discovery automatically by default
|
||||
port: *0 | >=1024 & <=65535 & int
|
||||
// +usage=The label selector for the pods, will discovery automatically by default
|
||||
selector?: [string]: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "affinity specify node affinity and toleration"
|
||||
name: node-affinity
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: spec: {
|
||||
if parameter.affinity != _|_ {
|
||||
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: [{
|
||||
matchExpressions: [
|
||||
for k, v in parameter.affinity {
|
||||
key: k
|
||||
operator: "In"
|
||||
values: v
|
||||
},
|
||||
]}]
|
||||
}
|
||||
if parameter.tolerations != _|_ {
|
||||
tolerations: [
|
||||
for k, v in parameter.tolerations {
|
||||
effect: "NoSchedule"
|
||||
key: k
|
||||
operator: "Equal"
|
||||
value: v
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter: {
|
||||
affinity?: [string]: [...string]
|
||||
tolerations?: [string]: string
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: spec: {
|
||||
if parameter.affinity != _|_ {
|
||||
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: [{
|
||||
matchExpressions: [
|
||||
for k, v in parameter.affinity {
|
||||
key: k
|
||||
operator: "In"
|
||||
values: v
|
||||
},
|
||||
]}]
|
||||
}
|
||||
if parameter.tolerations != _|_ {
|
||||
tolerations: [
|
||||
for k, v in parameter.tolerations {
|
||||
effect: "NoSchedule"
|
||||
key: k
|
||||
operator: "Equal"
|
||||
value: v
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
affinity?: [string]: [...string]
|
||||
tolerations?: [string]: string
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "Manually scale the app"
|
||||
name: scaler
|
||||
definition.oam.dev/description: "patch replica to the app"
|
||||
name: patch-replica
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
//+short=r
|
||||
replicas: *1 | int
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
//+short=r
|
||||
replicas: *1 | int
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "Manually scale the app"
|
||||
name: patch-scaler
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: replicas: parameter.replicas
|
||||
}
|
||||
parameter: {
|
||||
replicas: *1 | int
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "add env into your pods"
|
||||
name: env
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: spec: {
|
||||
// +patchKey=name
|
||||
containers: [{
|
||||
name: context.name
|
||||
// +patchKey=name
|
||||
env: [
|
||||
for k, v in parameter.env {
|
||||
name: k
|
||||
value: v
|
||||
},
|
||||
]
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
parameter: {
|
||||
env: [string]: string
|
||||
}
|
||||
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: spec: {
|
||||
// +patchKey=name
|
||||
containers: [{
|
||||
name: context.name
|
||||
// +patchKey=name
|
||||
env: [
|
||||
for k, v in parameter.env {
|
||||
name: k
|
||||
value: v
|
||||
},
|
||||
]
|
||||
}]
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
env: [string]: string
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT.
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: rollout
|
||||
namespace: vela-system
|
||||
annotations:
|
||||
definition.oam.dev/description: "Configures Canary deployment strategy for your application."
|
||||
spec:
|
||||
@@ -20,41 +20,43 @@ spec:
|
||||
namespace: vela-system
|
||||
url: https://oam.dev/flagger/archives/
|
||||
version: 1.1.0
|
||||
template: |-
|
||||
outputs: canary: {
|
||||
apiVersion: "flagger.app/v1beta1"
|
||||
kind: "Canary"
|
||||
spec: {
|
||||
provider: "smi"
|
||||
progressDeadlineSeconds: 60
|
||||
service: {
|
||||
// Currently Traffic route is not supported, but this is required field for flagger CRD
|
||||
port: 80
|
||||
// Currently Traffic route is not supported, but this is required field for flagger CRD
|
||||
targetPort: 8080
|
||||
}
|
||||
analysis: {
|
||||
interval: parameter.interval
|
||||
// max number of failed metric checks before rollback
|
||||
threshold: 10
|
||||
// max traffic percentage routed to canary
|
||||
// percentage (0-100)
|
||||
maxWeight: 50
|
||||
// canary increment step
|
||||
// percentage (0-100)
|
||||
stepWeight: parameter.stepWeight
|
||||
// max replicas scale up to canary
|
||||
maxReplicas: parameter.replicas
|
||||
}
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
// +usage=Total replicas of the workload
|
||||
replicas: *2 | int
|
||||
// +alias=step-weight
|
||||
// +usage=Weight percent of every step in rolling update
|
||||
stepWeight: *50 | int
|
||||
// +usage=Schedule interval time
|
||||
interval: *"30s" | string
|
||||
}
|
||||
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
outputs: rollout: {{
|
||||
apiVersion: "flagger.app/v1beta1"
|
||||
kind: "Canary"
|
||||
spec: {
|
||||
provider: "smi"
|
||||
progressDeadlineSeconds: 60
|
||||
service: {
|
||||
// Currently Traffic route is not supported, but this is required field for flagger CRD
|
||||
port: 80
|
||||
// Currently Traffic route is not supported, but this is required field for flagger CRD
|
||||
targetPort: 8080
|
||||
}
|
||||
analysis: {
|
||||
interval: parameter.interval
|
||||
// max number of failed metric checks before rollback
|
||||
threshold: 10
|
||||
// max traffic percentage routed to canary
|
||||
// percentage (0-100)
|
||||
maxWeight: 50
|
||||
// canary increment step
|
||||
// percentage (0-100)
|
||||
stepWeight: parameter.stepWeight
|
||||
// max replicas scale up to canary
|
||||
maxReplicas: parameter.replicas
|
||||
}
|
||||
}
|
||||
}}
|
||||
parameter: {
|
||||
// +usage=Total replicas of the workload
|
||||
replicas: *2 | int
|
||||
// +alias=step-weight
|
||||
// +usage=Weight percent of every step in rolling update
|
||||
stepWeight: *50 | int
|
||||
// +usage=Schedule interval time
|
||||
interval: *"30s" | string
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT.
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: route
|
||||
@@ -18,37 +18,39 @@ spec:
|
||||
name: nginx-ingress
|
||||
url: https://kubernetes-charts.storage.googleapis.com/
|
||||
version: 1.41.2
|
||||
template: |
|
||||
outputs: route: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "Route"
|
||||
spec: {
|
||||
host: parameter.domain
|
||||
|
||||
if parameter.issuer != "" {
|
||||
tls: {
|
||||
issuerName: parameter.issuer
|
||||
}
|
||||
}
|
||||
|
||||
if parameter["rules"] != _|_ {
|
||||
rules: parameter.rules
|
||||
}
|
||||
|
||||
provider: *"nginx" | parameter.provider
|
||||
ingressClass: *"nginx" | parameter.ingressClass
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
// +usage= Domain name
|
||||
domain: *"" | string
|
||||
|
||||
issuer: *"" | string
|
||||
rules?: [...{
|
||||
path: string
|
||||
rewriteTarget: *"" | string
|
||||
}]
|
||||
provider?: string
|
||||
ingressClass?: string
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
outputs: route: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "Route"
|
||||
spec: {
|
||||
host: parameter.domain
|
||||
|
||||
if parameter.issuer != "" {
|
||||
tls: {
|
||||
issuerName: parameter.issuer
|
||||
}
|
||||
}
|
||||
|
||||
if parameter["rules"] != _|_ {
|
||||
rules: parameter.rules
|
||||
}
|
||||
|
||||
provider: *"nginx" | parameter.provider
|
||||
ingressClass: *"nginx" | parameter.ingressClass
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
// +usage= Domain name
|
||||
domain: *"" | string
|
||||
|
||||
issuer: *"" | string
|
||||
rules?: [...{
|
||||
path: string
|
||||
rewriteTarget: *"" | string
|
||||
}]
|
||||
provider?: string
|
||||
ingressClass?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: "Add virtual group labels"
|
||||
name: virtualgroup
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- worker
|
||||
extension:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: {
|
||||
metadata: labels: {
|
||||
if parameter.type == "namespace" {
|
||||
"app.namespace.virtual.group": parameter.group
|
||||
}
|
||||
if parameter.type == "cluster" {
|
||||
"app.cluster.virtual.group": parameter.group
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
group: *"default" | string
|
||||
type: *"namespace" | string
|
||||
}
|
||||
schematic:
|
||||
cue:
|
||||
template: |-
|
||||
patch: {
|
||||
spec: template: {
|
||||
metadata: labels: {
|
||||
if parameter.type == "namespace" {
|
||||
"app.namespace.virtual.group": parameter.group
|
||||
}
|
||||
if parameter.type == "cluster" {
|
||||
"app.cluster.virtual.group": parameter.group
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
group: *"default" | string
|
||||
type: *"namespace" | string
|
||||
}
|
||||
@@ -1,89 +1,92 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: WorkloadDefinition
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: webserver
|
||||
annotations:
|
||||
definition.oam.dev/description: "webserver was composed by deployment and service"
|
||||
spec:
|
||||
definitionRef:
|
||||
name: deployments.apps
|
||||
extension:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
selector: matchLabels: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
template: {
|
||||
metadata: labels: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
spec: {
|
||||
containers: [{
|
||||
name: context.name
|
||||
image: parameter.image
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
spec: {
|
||||
selector: matchLabels: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
template: {
|
||||
metadata: labels: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
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 parameter["env"] != _|_ {
|
||||
env: parameter.env
|
||||
}
|
||||
|
||||
if context["config"] != _|_ {
|
||||
env: context.config
|
||||
}
|
||||
if context["config"] != _|_ {
|
||||
env: context.config
|
||||
}
|
||||
|
||||
ports: [{
|
||||
containerPort: parameter.port
|
||||
}]
|
||||
ports: [{
|
||||
containerPort: parameter.port
|
||||
}]
|
||||
|
||||
if parameter["cpu"] != _|_ {
|
||||
resources: {
|
||||
limits:
|
||||
cpu: parameter.cpu
|
||||
requests:
|
||||
cpu: parameter.cpu
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// workload can have extra object composition by using 'outputs' keyword
|
||||
outputs: service: {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
spec: {
|
||||
selector: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
ports: [
|
||||
{
|
||||
port: parameter.port
|
||||
targetPort: parameter.port
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
image: string
|
||||
cmd?: [...string]
|
||||
port: *80 | int
|
||||
env?: [...{
|
||||
name: string
|
||||
value?: string
|
||||
valueFrom?: {
|
||||
secretKeyRef: {
|
||||
name: string
|
||||
key: string
|
||||
}
|
||||
}
|
||||
}]
|
||||
cpu?: string
|
||||
}
|
||||
if parameter["cpu"] != _|_ {
|
||||
resources: {
|
||||
limits:
|
||||
cpu: parameter.cpu
|
||||
requests:
|
||||
cpu: parameter.cpu
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// workload can have extra object composition by using 'outputs' keyword
|
||||
outputs: service: {
|
||||
apiVersion: "v1"
|
||||
kind: "Service"
|
||||
spec: {
|
||||
selector: {
|
||||
"app.oam.dev/component": context.name
|
||||
}
|
||||
ports: [
|
||||
{
|
||||
port: parameter.port
|
||||
targetPort: parameter.port
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
image: string
|
||||
cmd?: [...string]
|
||||
port: *80 | int
|
||||
env?: [...{
|
||||
name: string
|
||||
value?: string
|
||||
valueFrom?: {
|
||||
secretKeyRef: {
|
||||
name: string
|
||||
key: string
|
||||
}
|
||||
}
|
||||
}]
|
||||
cpu?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
@@ -39,7 +40,12 @@ func ToConfigMap(s Store, name, envName string, configData map[string]string) (*
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cm v1.ConfigMap
|
||||
var cm = v1.ConfigMap{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "v1",
|
||||
Kind: "ConfigMap",
|
||||
},
|
||||
}
|
||||
cm.SetName(name)
|
||||
cm.SetNamespace(namespace)
|
||||
cm.Data = configData
|
||||
|
||||
@@ -330,6 +330,10 @@ outputs: ingress: {
|
||||
}}
|
||||
|
||||
ac3cm := &v12.ConfigMap{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "v1",
|
||||
Kind: "ConfigMap",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"test": "test-value",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user