Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend application's capabilities by trait definition #742

Merged
merged 8 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/core.oam.dev/v1alpha2/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type WorkloadDefinitionList struct {
// A TraitDefinitionSpec defines the desired state of a TraitDefinition.
type TraitDefinitionSpec struct {
// Reference to the CustomResourceDefinition that defines this trait kind.
Reference DefinitionReference `json:"definitionRef"`
Reference DefinitionReference `json:"definitionRef,omitempty"`

// Revision indicates whether a trait is aware of component revision
// +optional
Expand Down
2 changes: 0 additions & 2 deletions charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ spec:
workloadRefPath:
description: WorkloadRefPath indicates where/if a trait accepts a workloadRef object
type: string
required:
- definitionRef
type: object
type: object
served: true
Expand Down
144 changes: 144 additions & 0 deletions config/samples/vela-server/Demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Application Example

In this Demo, Application application-sample will be converted to appconfig 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
```
kubectl apply -f template.yaml
```
Step 2: Create a sample application in the cluster
```
kubectl apply -f application-sample.yaml
```
Step 3: View the application status
```
kubectl get -f application-sample.yaml -oyaml

// You can see the following
apiVersion: core.oam.dev/v1alpha2
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
spec:
services:
myweb:
cmd:
- sleep
- "1000"
image: busybox
scaler:
replicas: 10
service:
http:
server: 80
sidecar:
command:
- sleep
- "1000"
image: busybox
name: test-sidecar
type: worker
status:
conditions:
- lastTransitionTime: "2020-12-02T12:12:52Z"
reason: Available
status: "True"
type: Parsed
- lastTransitionTime: "2020-12-02T12:12:52Z"
reason: Available
status: "True"
type: Built
- lastTransitionTime: "2020-12-02T12:12:52Z"
reason: Available
status: "True"
type: Applied
status: running

```

Step 4: View the oam CR generated by application

```
kubectl get appconfig/application-sample -oyaml

// appconfig is as follows
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
labels:
application.oam.dev: application-sample
name: application-sample
namespace: oam-test
ownerReferences:
- apiVersion: core.oam.dev/v1alpha2
controller: true
kind: Application
name: application-sample
uid: dca7acc3-664c-422b-aa52-4fe012e37974
spec:
components:
- componentName: myweb
traits:
- trait:
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
ports:
- port: 80
targetPort: 80
selector:
app: myweb

kubectl get component/myweb -oyaml

// component is as follows
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
labels:
application.oam.dev: application-sample
name: myweb
namespace: oam-test
ownerReferences:
- apiVersion: core.oam.dev/v1alpha2
controller: true
kind: Application
name: application-sample
uid: dca7acc3-664c-422b-aa52-4fe012e37974
spec:
workload:
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 10
selector:
matchLabels:
app.oam.dev/component: myweb
template:
metadata:
labels:
app: myweb
app.oam.dev/component: myweb
spec:
containers:
- command:
- sleep
- "1000"
image: busybox
name: myweb
- command:
- sleep
- "1000"
image: busybox
name: test-sidecar
```

Loading