Chore: organize appliesToWorkloads field of trait defs, add doc example (#4483)

* Chore: organize appliesToWorkloads field of trait defs, add doc example

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* fix gen

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* add deprecate label

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* fix

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* fix script to read all definition in directory

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* add comment

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* go.mod

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* update some usage, better trait doc gen

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* minor fix

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* minor fix

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* postpone markdown escape pipe char

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
This commit is contained in:
qiaozp
2022-07-28 22:20:55 -05:00
committed by GitHub
parent 20877f7946
commit 7cdaa09660
93 changed files with 753 additions and 94 deletions

View File

@@ -120,7 +120,7 @@ type TraitDefinitionSpec struct {
PodDisruptive bool `json:"podDisruptive,omitempty"`
// AppliesToWorkloads specifies the list of workload kinds this trait
// applies to. Workload kinds are specified in kind.group/version format,
// applies to. Workload kinds are specified in resource.group/version format,
// e.g. server.core.oam.dev/v1alpha2. Traits that omit this field apply to
// all workload kinds.
// +optional

View File

@@ -3650,7 +3650,7 @@ spec:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload
kinds this trait applies to. Workload kinds are specified
in kind.group/version format, e.g. server.core.oam.dev/v1alpha2.
in resource.group/version format, e.g. server.core.oam.dev/v1alpha2.
Traits that omit this field apply to all workload kinds.
items:
type: string

View File

@@ -708,7 +708,7 @@ spec:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload
kinds this trait applies to. Workload kinds are specified
in kind.group/version format, e.g. server.core.oam.dev/v1alpha2.
in resource.group/version format, e.g. server.core.oam.dev/v1alpha2.
Traits that omit this field apply to all workload kinds.
items:
type: string

View File

@@ -356,7 +356,7 @@ spec:
properties:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload kinds
this trait applies to. Workload kinds are specified in kind.group/version
this trait applies to. Workload kinds are specified in resource.group/version
format, e.g. server.core.oam.dev/v1alpha2. Traits that omit this
field apply to all workload kinds.
items:

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -4,7 +4,7 @@ apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: Add annotations on K8s pod for your workload which follows the pod spec in path 'spec.template'.
definition.oam.dev/description: Add annotations on your workload. if it generates pod, add same annotations for generated pods.
labels:
custom.definition.oam.dev/ui-hidden: "true"
name: annotations

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
schematic:
cue:
template: |

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -12,6 +12,7 @@ metadata:
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
schematic:
cue:
template: |

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
schematic:
cue:
template: |

View File

@@ -10,6 +10,9 @@ metadata:
name: expose
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
podDisruptive: false
schematic:
cue:

View File

@@ -9,7 +9,8 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
podDisruptive: false
schematic:
cue:
@@ -85,7 +86,7 @@ spec:
// +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation.
classInSpec: *false | bool
// +usage=Specify the secret name you want to quote.
// +usage=Specify the secret name you want to quote to use tls.
secretName?: string
// +usage=Specify the host of the ingress gateway, which is used to generate the endpoints when the host is empty.

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: false
schematic:
cue:

View File

@@ -12,6 +12,9 @@ metadata:
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -4,7 +4,7 @@ apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: Add labels on K8s pod for your workload which follows the pod spec in path 'spec.template'.
definition.oam.dev/description: Add labels on your workload. if it generates pod, add same label for generated pods.
labels:
custom.definition.oam.dev/ui-hidden: "true"
name: labels

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -6,11 +6,13 @@ metadata:
annotations:
definition.oam.dev/description: Enable public web traffic for the component without creating a Service.
labels:
custom.definition.oam.dev/deprecated: "true"
custom.definition.oam.dev/ui-hidden: "true"
name: pure-ingress
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads: []
appliesToWorkloads:
- '*'
conflictsWith: []
podDisruptive: false
schematic:

View File

@@ -6,6 +6,7 @@ metadata:
annotations:
definition.oam.dev/description: Add a datasource to Grafana
labels:
custom.definition.oam.dev/deprecated: "true"
custom.definition.oam.dev/ui-hidden: "true"
name: register-grafana-datasource
namespace: {{ include "systemDefinitionNamespace" . }}

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -9,7 +9,8 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
podDisruptive: false
schematic:
cue:

View File

@@ -9,7 +9,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: false
schematic:
cue:

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
schematic:
cue:
template: |

View File

@@ -10,8 +10,12 @@ metadata:
name: sidecar
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
attributes:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -10,6 +10,9 @@ metadata:
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -3650,7 +3650,7 @@ spec:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload
kinds this trait applies to. Workload kinds are specified
in kind.group/version format, e.g. server.core.oam.dev/v1alpha2.
in resource.group/version format, e.g. server.core.oam.dev/v1alpha2.
Traits that omit this field apply to all workload kinds.
items:
type: string

View File

@@ -708,7 +708,7 @@ spec:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload
kinds this trait applies to. Workload kinds are specified
in kind.group/version format, e.g. server.core.oam.dev/v1alpha2.
in resource.group/version format, e.g. server.core.oam.dev/v1alpha2.
Traits that omit this field apply to all workload kinds.
items:
type: string

View File

@@ -356,7 +356,7 @@ spec:
properties:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload kinds
this trait applies to. Workload kinds are specified in kind.group/version
this trait applies to. Workload kinds are specified in resource.group/version
format, e.g. server.core.oam.dev/v1alpha2. Traits that omit this
field apply to all workload kinds.
items:

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -4,7 +4,7 @@ apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: Add annotations on K8s pod for your workload which follows the pod spec in path 'spec.template'.
definition.oam.dev/description: Add annotations on your workload. if it generates pod, add same annotations for generated pods.
labels:
custom.definition.oam.dev/ui-hidden: "true"
name: annotations

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
schematic:
cue:
template: |

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -12,6 +12,7 @@ metadata:
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
schematic:
cue:
template: |

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
schematic:
cue:
template: |

View File

@@ -10,6 +10,9 @@ metadata:
name: expose
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
podDisruptive: false
schematic:
cue:

View File

@@ -9,7 +9,8 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
podDisruptive: false
schematic:
cue:
@@ -85,7 +86,7 @@ spec:
// +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation.
classInSpec: *false | bool
// +usage=Specify the secret name you want to quote.
// +usage=Specify the secret name you want to quote to use tls.
secretName?: string
// +usage=Specify the host of the ingress gateway, which is used to generate the endpoints when the host is empty.

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: false
schematic:
cue:

View File

@@ -12,6 +12,9 @@ metadata:
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -4,7 +4,7 @@ apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: Add labels on K8s pod for your workload which follows the pod spec in path 'spec.template'.
definition.oam.dev/description: Add labels on your workload. if it generates pod, add same label for generated pods.
labels:
custom.definition.oam.dev/ui-hidden: "true"
name: labels

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -6,11 +6,13 @@ metadata:
annotations:
definition.oam.dev/description: Enable public web traffic for the component without creating a Service.
labels:
custom.definition.oam.dev/deprecated: "true"
custom.definition.oam.dev/ui-hidden: "true"
name: pure-ingress
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads: []
appliesToWorkloads:
- '*'
conflictsWith: []
podDisruptive: false
schematic:

View File

@@ -6,6 +6,7 @@ metadata:
annotations:
definition.oam.dev/description: Add a datasource to Grafana
labels:
custom.definition.oam.dev/deprecated: "true"
custom.definition.oam.dev/ui-hidden: "true"
name: register-grafana-datasource
namespace: {{ include "systemDefinitionNamespace" . }}

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -9,7 +9,8 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
podDisruptive: false
schematic:
cue:

View File

@@ -9,7 +9,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: false
schematic:
cue:

View File

@@ -11,7 +11,10 @@ metadata:
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
schematic:
cue:
template: |

View File

@@ -10,8 +10,12 @@ metadata:
name: sidecar
namespace: {{ include "systemDefinitionNamespace" . }}
spec:
appliesToWorkloads:
- '*'
attributes:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

View File

@@ -10,6 +10,9 @@ metadata:
spec:
appliesToWorkloads:
- deployments.apps
- statefulsets.apps
- daemonsets.apps
- jobs.batch
podDisruptive: true
schematic:
cue:

3
go.mod
View File

@@ -124,6 +124,8 @@ require (
sigs.k8s.io/gateway-api v0.4.3
)
require github.com/rogpeppe/go-internal v1.8.0
require (
cloud.google.com/go/compute v1.7.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
@@ -256,7 +258,6 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/rubenv/sql-migrate v0.0.0-20210614095031-55d5740dbbcc // indirect
github.com/russross/blackfriday v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect

View File

@@ -86,7 +86,9 @@ func TraitDef(ctx context.Context, c common.Args, path, location *string, defdir
},
CustomDocHeader: CustomTraitHeaderEN,
}
ref.Remote = &docgen.FromCluster{Namespace: types.DefaultKubeVelaNS}
ref.Local = &docgen.FromLocal{
Path: TraitDefDir,
}
if *path != "" {
ref.I18N = &docgen.En
@@ -99,22 +101,24 @@ func TraitDef(ctx context.Context, c common.Args, path, location *string, defdir
os.Exit(1)
}
fmt.Printf("trait reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), *path)
}
if *location == "" || *location == "en" {
ref.I18N = &docgen.En
if err := ref.GenerateReferenceDocs(ctx, c, TraitDefRefPath); err != nil {
fmt.Println(err)
os.Exit(1)
} else {
// Generate to default path depends on language
if *location == "" || *location == "en" {
ref.I18N = &docgen.En
if err := ref.GenerateReferenceDocs(ctx, c, TraitDefRefPath); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("trait reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), TraitDefRefPath)
}
fmt.Printf("trait reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), TraitDefRefPath)
}
if *location == "" || *location == "zh" {
ref.I18N = &docgen.Zh
ref.CustomDocHeader = CustomTraitHeaderZH
if err := ref.GenerateReferenceDocs(ctx, c, TraitDefRefPathZh); err != nil {
fmt.Println(err)
os.Exit(1)
if *location == "" || *location == "zh" {
ref.I18N = &docgen.Zh
ref.CustomDocHeader = CustomTraitHeaderZH
if err := ref.GenerateReferenceDocs(ctx, c, TraitDefRefPathZh); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("trait reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), TraitDefRefPathZh)
}
fmt.Printf("trait reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), TraitDefRefPathZh)
}
}

View File

@@ -3650,7 +3650,7 @@ spec:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload
kinds this trait applies to. Workload kinds are specified
in kind.group/version format, e.g. server.core.oam.dev/v1alpha2.
in resource.group/version format, e.g. server.core.oam.dev/v1alpha2.
Traits that omit this field apply to all workload kinds.
items:
type: string

View File

@@ -708,7 +708,7 @@ spec:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload
kinds this trait applies to. Workload kinds are specified
in kind.group/version format, e.g. server.core.oam.dev/v1alpha2.
in resource.group/version format, e.g. server.core.oam.dev/v1alpha2.
Traits that omit this field apply to all workload kinds.
items:
type: string

View File

@@ -356,7 +356,7 @@ spec:
properties:
appliesToWorkloads:
description: AppliesToWorkloads specifies the list of workload kinds
this trait applies to. Workload kinds are specified in kind.group/version
this trait applies to. Workload kinds are specified in resource.group/version
format, e.g. server.core.oam.dev/v1alpha2. Traits that omit this
field apply to all workload kinds.
items:

View File

@@ -0,0 +1,27 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: busybox
spec:
components:
- name: busybox
type: webservice
properties:
image: busybox
cmd: ["sleep", "86400"]
traits:
- type: sidecar
properties:
name: sidecar-nginx
image: nginx
- type: command
properties:
# you can use command to control multiple containers by filling `containers`
# NOTE: in containers, you must set the container name for each container
containers:
- containerName: busybox
command: ["sleep", "8640000"]
- containerName: sidecar-nginx
args: ["-q"]
```

View File

@@ -0,0 +1,28 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: busybox
spec:
components:
- name: busybox
type: webservice
properties:
image: busybox
cmd: ["sleep", "86400"]
traits:
- type: sidecar
properties:
name: sidecar-nginx
image: nginx
- type: container-image
properties:
# you can use container-image to control multiple containers by filling `containers`
# NOTE: in containers, you must set the container name for each container
containers:
- containerName: busybox
image: busybox-1.34.0
imagePullPolicy: IfNotPresent
- containerName: sidecar-nginx
image: nginx-1.20
```

View File

@@ -0,0 +1,18 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: website
spec:
components:
- name: frontend
type: webservice
properties:
image: nginx
traits:
- type: cpuscaler
properties:
min: 1
max: 10
cpuPercent: 60
```

View File

@@ -0,0 +1,31 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: busybox
spec:
components:
- name: busybox
type: webservice
properties:
image: busybox
cmd: ["sleep", "86400"]
traits:
- type: sidecar
properties:
name: sidecar-nginx
image: nginx
- type: env
properties:
# you can use env to control multiple containers by filling `containers`
# NOTE: in containers, you must set the container name for each container
containers:
- containerName: busybox
env:
key_for_busybox_first: value_first
key_for_busybox_second: value_second
- containerName: sidecar-nginx
env:
key_for_nginx_first: value_first
key_for_nginx_second: value_second
```

View File

@@ -0,0 +1,16 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: test-app
spec:
components:
- name: hello-world
type: webservice
properties:
image: crccheck/hello-world
traits:
- type: expose
properties:
port: [8000]
```

View File

@@ -0,0 +1,20 @@
```yaml
# vela-app.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: first-vela-app
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
port: 8000
traits:
- type: gateway
properties:
domain: testsvc.example.com
http:
"/": 8000
```

View File

@@ -0,0 +1,23 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: application-with-hostalias
spec:
components:
- name: busybox-runner
type: worker
properties:
image: busybox
cmd:
- sleep
- '1000'
traits:
- type: hostalias
properties:
hostAliases:
- ip: 127.0.0.1
hostnames:
- localname
- locals
```

View File

@@ -0,0 +1,21 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: busybox
spec:
components:
- name: busybox
type: webservice
properties:
image: busybox
cmd: ["sleep", "86400"]
traits:
- type: init-container
properties:
name: init-busybox
image: busybox
cmd: ["echo", "hello"]
initMountPath: /data
appMountPath: /data-initialized
```

View File

@@ -0,0 +1,23 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bucket-app
spec:
components:
- name: bucket-comp
type: kustomize
# ... omitted for brevity
traits:
- type: kustomize-json-patch
properties:
patchesJson:
- target:
version: v1
kind: Deployment
name: podinfo
patch:
- op: add
path: /metadata/annotations/key
value: value
```

View File

@@ -0,0 +1,24 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bucket-app
spec:
components:
- name: bucket-comp
type: kustomize
# ... omitted for brevity
traits:
- type: kustomize-patch
properties:
patches:
- patch: |-
apiVersion: v1
kind: Pod
metadata:
name: not-used
labels:
app.kubernetes.io/part-of: test-app
target:
labelSelector: "app=podinfo"
```

View File

@@ -0,0 +1,23 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bucket-app
spec:
components:
- name: bucket-comp
type: kustomize
# ... omitted for brevity
traits:
- type: kustomize-strategy-merge
properties:
patchesStrategicMerge:
- apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
spec:
template:
spec:
serviceAccount: custom-service-account
```

View File

@@ -0,0 +1,28 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: application-with-lifecycle
spec:
components:
- name: busybox-runner
type: worker
properties:
image: busybox
cmd:
- sleep
- '1000'
traits:
- type: lifecycle
properties:
postStart:
exec:
command:
- echo
- 'hello world'
preStop:
httpGet:
host: "www.aliyun.com"
scheme: "HTTPS"
port: 443
```

View File

@@ -0,0 +1,50 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bookinfo
spec:
components:
- name: productpage
type: webservice
properties:
image: nocalhost-docker.pkg.coding.net/nocalhost/bookinfo/productpage:latest
port: 9080
traits:
- type: nocalhost
properties:
port: 9080
gitUrl: https://github.com/nocalhost/bookinfo-productpage.git
image: nocalhost-docker.pkg.coding.net/nocalhost/dev-images/python:3.7.7-slim-productpage-with-pydevd
shell: "bash"
workDir: "/opt/work"
resources:
limits:
memory: 1Gi
cpu: "1"
requests:
memory: 512Mi
cpu: "0.5"
debug:
remoteDebugPort: 9009
hotReload: true
sync:
type: send
filePattern:
- ./
ignoreFilePattern:
- .git
- .idea
command:
run:
- sh
- run.sh
debug:
- sh
- debug.sh
env:
- name: "foo"
value: "bar"
portForward:
- 39080:9080
```

View File

@@ -0,0 +1,25 @@
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: resource-app
spec:
components:
- name: express-server
type: webservice
properties:
image: crccheck/hello-world
ports:
- port: 8000
traits:
- type: resource
properties:
cpu: 2
memory: 2Gi
requests:
cpu: 2
memory: 2Gi
limits:
cpu: 4
memory: 4Gi
```

View File

@@ -0,0 +1,85 @@
1. Prepare a Kubernetes Secret
The secret can be manually created, or generated by other component or external system.
For example, we have a secret `db-conn-example` whose data is as below:
```yaml
endpoint: https://xxx.com
password: 123
username: myname
```
2. Bind the Secret into your component by `service-binding` trait
For example, we have a webservice component who needs to consume a database. The database connection string should be set
to Pod environments: `endpoint`, `username` and `DB_PASSWORD`.
We can set the properties for envMappings as below. For each environment, `secret` represents the secret name, and `key`
represents the key of the secret.
Here is the complete properties for the trait.
```yaml
traits:
- type: service-binding
properties:
envMappings:
DB_PASSWORD:
secret: db-conn-example
key: password
endpoint:
secret: db-conn-example
key: endpoint
username:
secret: db-conn-example
key: username
```
In particular, if the environment name, like `endpoint`, is same to the `key` of the secret, we can omit the `key`.
So we can simplify the properties as below.
```yaml
traits:
- type: service-binding
properties:
envMappings:
DB_PASSWORD:
secret: db-conn-example
key: password
endpoint:
secret: db-conn-example
username:
secret: db-conn-example
```
We can finally prepare an Application for the business component `binding-test-comp` to consume the secret, which is a
representative of a database cloud resource.
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: webapp
spec:
components:
- name: binding-test-comp
type: webservice
properties:
image: zzxwill/flask-web-application:v0.3.1-crossplane
ports: 80
traits:
- type: service-binding
properties:
envMappings:
# environments refer to db-conn secret
DB_PASSWORD:
secret: db-conn-example
key: password
endpoint:
secret: db-conn-example
username:
secret: db-conn-example
```
Deploy this YAML and the Secret `db-conn-example` will be binding into environment of workload.

View File

@@ -0,0 +1,48 @@
```yaml
# sample.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: storage-app
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
traits:
- type: storage
properties:
# PVC type storage
pvc:
- name: test1
mountPath: /test/mount/pvc
# EmptyDir type storage
emptyDir:
- name: test1
mountPath: /test/mount/emptydir
# ConfigMap type storage
configMap:
- name: test1
mountPath: /test/mount/cm
# Mount ConfigMap to Env
mountToEnv:
envName: TEST_ENV
configMapKey: key1
data:
key1: value1
key2: value2
# Secret type storage
secret:
- name: test1
mountPath: /test/mount/secret
# Mount Secret to Env
mountToEnv:
envName: TEST_SECRET
secretKey: key1
data:
key1: dmFsdWUx
key2: dmFsdWUy
```

View File

@@ -35,6 +35,9 @@ import (
"github.com/oam-dev/kubevela/pkg/utils/common"
)
// AllComponentTypes means trait can be applied to all component types
const AllComponentTypes = "*"
// MarkdownReference is the struct for capability information in
type MarkdownReference struct {
Filter func(types.Capability) bool
@@ -213,13 +216,21 @@ func (ref *MarkdownReference) GenerateMarkdownForCap(ctx context.Context, c type
if c.Type == types.TypeTrait {
if c.Labels[types.LabelDefinitionHidden] == "true" {
description += "\n\n> " + lang.Get("For now this trait is hidden from the VelaUX. Available when using CLI.")
}
description += "\n\n### " + lang.Get("Apply To Component Types") + "\n\n"
var applyto string
for _, ap := range c.AppliesTo {
applyto += "- " + ap + "\n"
if len(c.AppliesTo) == 1 && c.AppliesTo[0] == AllComponentTypes {
applyto += lang.Get("All Component Types.")
} else {
applyto += lang.Get("Component based on the following kinds of resources:") + "\n"
for _, ap := range c.AppliesTo {
applyto += "- " + ap + "\n"
}
}
if applyto == "" {
applyto = "- All/*"
applyto = lang.Get("All Component Types.")
}
description += applyto + "\n"
}

View File

@@ -20,7 +20,9 @@ import (
"context"
"encoding/json"
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
@@ -30,6 +32,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"github.com/rogpeppe/go-internal/modfile"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog/v2"
@@ -65,11 +68,13 @@ func (ref *ParseReference) getCapabilities(ctx context.Context, c common.Args) (
)
switch {
case ref.Local != nil:
lcap, err := ParseLocalFile(ref.Local.Path, c)
lcaps, err := ParseLocalFiles(ref.Local.Path, c)
if err != nil {
return nil, fmt.Errorf("failed to get capability from local file %s: %w", ref.DefinitionName, err)
}
caps = append(caps, *lcap)
for _, lcap := range lcaps {
caps = append(caps, *lcap)
}
case ref.Remote != nil:
config, err := c.GetConfig()
if err != nil {
@@ -113,7 +118,7 @@ func (ref *ParseReference) prettySentence(s string) string {
return ref.I18N.Get(s) + ref.I18N.Get(".")
}
func (ref *ParseReference) formatTableString(s string) string {
return strings.ReplaceAll(s, "|", `\|`)
return strings.ReplaceAll(s, "|", `&#124;`)
}
// prepareConsoleParameter prepares the table content for each property
@@ -263,7 +268,8 @@ func (ref *ParseReference) parseParameters(capName string, paraValue cue.Value,
}
default:
var param ReferenceParameter
param.Name = "-"
// TODO better composition type handling, see command trait.
param.Name = "--"
param.Usage = "Composition type"
param.PrintableType = extractTypeFromError(paraValue)
params = append(params, param)
@@ -306,7 +312,7 @@ func extractTypeFromError(paraValue cue.Value) string {
return str
}
str = sll[1]
sll = strings.Split(str, ") (type")
sll = strings.Split(str, " (type")
return sll[0]
}
@@ -485,6 +491,41 @@ func (ref *ParseReference) parseTerraformCapabilityParameters(capability types.C
return tables, outputsTables, nil
}
// ParseLocalFiles parse the local files in directory and get name, configuration from local ComponentDefinition file
func ParseLocalFiles(localFilePath string, c common.Args) ([]*types.Capability, error) {
lcaps := make([]*types.Capability, 0)
if modfile.IsDirectoryPath(localFilePath) {
// walk the dir and get files
err := filepath.WalkDir(localFilePath, func(path string, info fs.DirEntry, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if !strings.HasSuffix(info.Name(), ".yaml") && !strings.HasSuffix(info.Name(), ".cue") {
return nil
}
lcap, err := ParseLocalFile(path, c)
if err != nil {
return err
}
lcaps = append(lcaps, lcap)
return nil
})
if err != nil {
return nil, err
}
} else {
lcap, err := ParseLocalFile(localFilePath, c)
if err != nil {
return nil, err
}
lcaps = append(lcaps, lcap)
}
return lcaps, nil
}
// ParseLocalFile parse the local file and get name, configuration from local ComponentDefinition file
func ParseLocalFile(localFilePath string, c common.Args) (*types.Capability, error) {
data, err := pkgUtils.ReadRemoteOrLocalPath(localFilePath, false)
@@ -537,6 +578,7 @@ func ParseLocalFile(localFilePath string, c common.Args) (*types.Capability, err
return nil, errors.Wrapf(err, "fail to parse definition to capability")
}
return &lcap, nil
}
// WalkParameterSchema will extract properties from *openapi3.Schema

View File

@@ -6,7 +6,7 @@
}
description: "Affinity specifies affinity and toleration K8s pod for your workload which follows the pod spec in path 'spec.template'."
attributes: {
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
podDisruptive: true
}
}

View File

@@ -4,7 +4,7 @@ annotations: {
labels: {
"ui-hidden": "true"
}
description: "Add annotations on K8s pod for your workload which follows the pod spec in path 'spec.template'."
description: "Add annotations on your workload. if it generates pod, add same annotations for generated pods."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]

View File

@@ -5,7 +5,9 @@ command: {
"ui-hidden": "true"
}
description: "Add command on K8s pod for your workload which follows the pod spec in path 'spec.template'"
attributes: appliesToWorkloads: ["*"]
attributes: {
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {
#PatchParams: {

View File

@@ -7,7 +7,7 @@
description: "Set the image of the container."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {

View File

@@ -5,7 +5,9 @@ cpuscaler: {
"ui-hidden": "true"
}
description: "Automatically scale the component based on CPU usage."
attributes: appliesToWorkloads: ["deployments.apps"]
attributes: {
appliesToWorkloads: ["deployments.apps", "statefulsets.apps"]
}
}
template: {

View File

@@ -5,7 +5,9 @@ env: {
"ui-hidden": "true"
}
description: "Add env on K8s pod for your workload which follows the pod spec in path 'spec.template'"
attributes: appliesToWorkloads: ["*"]
attributes: {
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {
#PatchParams: {

View File

@@ -11,6 +11,7 @@ expose: {
description: "Expose port to enable web traffic for your component."
attributes: {
podDisruptive: false
appliesToWorkloads: ["deployments.apps", "statefulsets.apps"]
status: {
customStatus: #"""
message: *"" | string

View File

@@ -5,7 +5,8 @@ gateway: {
description: "Enable public web traffic for the component, the ingress API matches K8s v1.20+."
attributes: {
podDisruptive: false
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps"]
status: {
customStatus: #"""
let igs = context.outputs.ingress.status.loadBalancer.ingress
@@ -111,7 +112,7 @@ template: {
// +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation.
classInSpec: *false | bool
// +usage=Specify the secret name you want to quote.
// +usage=Specify the secret name you want to quote to use tls.
secretName?: string
// +usage=Specify the host of the ingress gateway, which is used to generate the endpoints when the host is empty.

View File

@@ -7,7 +7,7 @@ hostalias: {
description: "Add host aliases on K8s pod for your workload which follows the pod spec in path 'spec.template'."
attributes: {
podDisruptive: false
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {

View File

@@ -7,7 +7,7 @@
description: "add an init container and use shared volume with pod"
attributes: {
podDisruptive: true
appliesToWorkloads: ["deployments.apps"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {

View File

@@ -4,7 +4,7 @@ labels: {
labels: {
"ui-hidden": "true"
}
description: "Add labels on K8s pod for your workload which follows the pod spec in path 'spec.template'."
description: "Add labels on your workload. if it generates pod, add same label for generated pods."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]

View File

@@ -7,7 +7,7 @@ lifecycle: {
description: "Add lifecycle hooks for every container of K8s pod for your workload which follows the pod spec in path 'spec.template'."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {

View File

@@ -11,7 +11,7 @@ nocalhost: {
description: "nocalhost develop configuration."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}

View File

@@ -1,7 +1,6 @@
"pure-ingress": {
annotations: {}
attributes: {
appliesToWorkloads: []
appliesToWorkloads: ["*"]
conflictsWith: []
podDisruptive: false
status: {
@@ -24,7 +23,8 @@
}
description: "Enable public web traffic for the component without creating a Service."
labels: {
"ui-hidden": "true"
"ui-hidden": "true"
"deprecated": "true"
}
type: "trait"
}

View File

@@ -8,7 +8,8 @@
}
description: "Add a datasource to Grafana"
labels: {
"ui-hidden": "true"
"ui-hidden": "true"
"deprecated": "true"
}
type: "trait"
}

View File

@@ -7,7 +7,7 @@ resource: {
description: "Add resource requests and limits on K8s pod for your workload which follows the pod spec in path 'spec.template.'"
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {

View File

@@ -5,7 +5,7 @@ scaler: {
description: "Manually scale K8s pod for your workload which follows the pod spec in path 'spec.template'."
attributes: {
podDisruptive: false
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps"]
}
}
template: {

View File

@@ -5,7 +5,7 @@
description: "Specify serviceAccount for your workload which follows the pod spec in path 'spec.template'."
attributes: {
podDisruptive: false
appliesToWorkloads: ["*"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {

View File

@@ -5,7 +5,9 @@
"ui-hidden": "true"
}
description: "Binding secrets of cloud resources to component env. This definition is DEPRECATED, please use 'storage' instead."
attributes: appliesToWorkloads: ["*"]
attributes: {
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
template: {
patch: spec: template: spec: {

View File

@@ -7,7 +7,9 @@ sidecar: {
description: "Inject a sidecar container to K8s pod for your workload which follows the pod spec in path 'spec.template'."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]
attributes: {
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
}
}
}
template: {

View File

@@ -4,7 +4,7 @@ storage: {
labels: {}
description: "Add storages on K8s pod for your workload which follows the pod spec in path 'spec.template'."
attributes: {
appliesToWorkloads: ["deployments.apps"]
appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"]
podDisruptive: true
}
}