Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #142 from leopoldxx/fix_examples
Browse files Browse the repository at this point in the history
fix examples with the new code
  • Loading branch information
wonderflow authored Jul 29, 2020
2 parents 76fc1eb + e51d72c commit bd60d02
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 33 deletions.
21 changes: 12 additions & 9 deletions examples/component-versioning/component-mutable.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

## Prerequisite

1. Make sure [`addon-oam-kubernetes-local`](https://github.com/crossplane/addon-oam-kubernetes-local) was installed.
2. Before component versioning mechanism released in Crossplane, you can run `go run examples/containerized-workload/main.go`
instead of using crossplane. After this feature was released in crossplane, install crossplane will work.
Make sure [`OAM runtime`](../../README.md#install-oam-runtime) was installed and started.

## ApplicationConfiguration always using the latest component

Expand All @@ -14,7 +12,7 @@ Step 1. Create OAM component
$ kubectl apply -f examples/containerized-workload/sample_workload_definition.yaml
$ kubectl apply -f examples/containerized-workload/sample_trait_definition.yaml
$ kubectl apply -f examples/containerized-workload/sample_scope_definition.yaml
$ kubectl apply -f examples/containerized-workload/sample_component.yaml
$ kubectl apply -f examples/component-versioning/sample_component.yaml
component.core.oam.dev/example-component created
```

Expand All @@ -32,6 +30,8 @@ Snapshot of current component stored in this ControllerRevision
$ kubectl get controllerrevisions.apps example-component-brk71rbipt3d60vfo4t0 -o yaml
apiVersion: apps/v1
data:
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
name: example-component
namespace: default
Expand All @@ -51,7 +51,9 @@ data:
- containerPort: 80
name: wordpress
status:
latestRevision: ""
latestRevision:
name: example-component-bsemlvvoceaedeu80kfg
revision: 1
kind: ControllerRevision
metadata:
name: example-component-brk71rbipt3d60vfo4t0
Expand All @@ -68,7 +70,7 @@ revision: 1
Step 2. Create AppConfig

```shell script
$ kubectl apply -f examples/containerized-workload/sample_application_config.yaml
$ kubectl apply -f examples/component-versioning/sample_application_config.yaml
applicationconfiguration.core.oam.dev/example-appconfig created
```

Expand Down Expand Up @@ -188,7 +190,7 @@ component.core.oam.dev "example-component" deleted
Step 1. The first step is the same. Create OAM component, and check the ControllerRevision.

```shell script
$ kubectl apply -f examples/containerized-workload/sample_component.yaml
$ kubectl apply -f examples/component-versioning/sample_component.yaml
component.core.oam.dev/example-component created
```

Expand Down Expand Up @@ -219,10 +221,10 @@ spec:
replicaCount: 3
```
Assume we name it as `component-mutable-app.yaml` and apply this AppConfig.
Assume we name it as `examples/component-versioning/component-mutable-app.yaml` and apply this AppConfig.

```shell script
$ kubectl apply -f component-mutable-app.yaml
$ kubectl apply -f examples/component-versioning/component-mutable-app.yaml
applicationconfiguration.core.oam.dev/example-appconfig created
```

Expand Down Expand Up @@ -270,6 +272,7 @@ component.core.oam.dev/example-component edited
The controllerRevision was created.

```shell script
$ kubectl get controllerrevisions.apps
NAME CONTROLLER REVISION AGE
example-component-brk71b3ipt3d60vfo4sg component.core.oam.dev/example-component 1 29m
example-component-brke6rbipt3d60vfo4ug component.core.oam.dev/example-component 2 73s
Expand Down
13 changes: 13 additions & 0 deletions examples/component-versioning/sample_application_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
name: example-appconfig
spec:
components:
- componentName: example-component
traits:
- trait:
apiVersion: core.oam.dev/v1alpha2
kind: ManualScalerTrait
spec:
replicaCount: 3
18 changes: 18 additions & 0 deletions examples/component-versioning/sample_component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
name: example-component
spec:
workload:
apiVersion: core.oam.dev/v1alpha2
kind: ContainerizedWorkload
spec:
containers:
- name: wordpress
image: wordpress:4.6.1-apache
ports:
- containerPort: 80
name: wordpress
env:
- name: TEST_ENV
value: test
13 changes: 8 additions & 5 deletions examples/component-versioning/versioning-mechanism.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

## Prerequisite

1. Make sure [`addon-oam-kubernetes-local`](https://github.com/crossplane/addon-oam-kubernetes-local) was installed.
2. Before component versioning mechanism released in Crossplane, you can run `go run examples/containerized-workload/main.go`
instead of using crossplane. After this feature was released in crossplane, install crossplane will work.
3. Make sure [`Simple Rollout`](https://github.com/oam-dev/catalog/tree/master/traits/simplerollouttrait) was installed for this demo.
1. Make sure [`Simple Rollout`](https://github.com/oam-dev/catalog/tree/master/traits/simplerollouttrait) was installed for this demo.
2. Make sure [`OAM runtime`](../../README.md#install-oam-runtime) was installed and started.


## Containing Trait with revisionEnabled and ApplicationConfiguration always using the latest component

Expand All @@ -26,6 +25,10 @@ metadata:
name: simplerollouttraits.extend.oam.dev
spec:
revisionEnabled: true
workloadRefPath: spec.workloadRef
appliesToWorkloads:
- core.oam.dev/v1alpha2.ContainerizedWorkload
- deployments.apps
definitionRef:
name: simplerollouttraits.extend.oam.dev
```
Expand Down Expand Up @@ -83,7 +86,7 @@ And the trait works on stable at:
```shell script
$ kubectl get simplerollouttraits.extend.oam.dev
NAME AGE
example-component 3m16s
example-component-trait-bbc946f94 3m16s
$ kubectl get simplerollouttraits.extend.oam.dev example-component -o yaml
apiVersion: extend.oam.dev/v1alpha2
kind: SimpleRolloutTrait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ spec:
components:
- componentName: example-component
parameterValues:
- name: instance-name
value: example-appconfig-workload
- name: image
value: wordpress:php7.2
traits:
Expand Down
1 change: 0 additions & 1 deletion examples/containerized-workload/sample_component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ spec:
value: test
parameters:
- name: instance-name
required: true
fieldPaths:
- metadata.name
- name: image
Expand Down
4 changes: 3 additions & 1 deletion examples/containerized-workload/sample_scope_definition.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: core.oam.dev/v1alpha2
kind: ScopeDefinition
metadata:
name: healthscope.core.oam.dev
name: healthscopes.core.oam.dev
spec:
workloadRefsPath: spec.workloadRefs
allowComponentOverlap: true
Expand All @@ -12,3 +12,5 @@ apiVersion: core.oam.dev/v1alpha2
kind: HealthScope
metadata:
name: example-health-scope
spec:
workloadRefs: []
23 changes: 19 additions & 4 deletions examples/dependency/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ Prepare CRD and Definitions:
kubectl apply -f examples/dependency/definition.yaml
```

Start OAM runtime:
Make sure [`OAM runtime`](../../README.md#install-oam-runtime) was installed and started.

```shell script
go run ./cmd/oam-runtime/main.go
```

# Case 1: Use status as output and pass through to another workload

Expand Down Expand Up @@ -151,6 +148,13 @@ can pass `spec.key` to `sink` component. So we specify a matcher for it.
fieldPath: "status.state"
```

And now `sink` workload is not created because its dataInputs is not ready.

```shell script
$ kubectl get foo.example.com sink -o yaml
Error from server (NotFound): foo.example.com "sink" not found
```

After a while, assuming the controller of this CRD will reconcile and make the `status.state` to be running.
Let's update it manually.

Expand All @@ -170,6 +174,17 @@ status:

Then the dependency will meet the requirement. You should see that the field "spec.key" of `sink` workload has been filled.

```shell
$ kubectl get foo.example.com sink -o yaml
apiVersion: example.com/v1
kind: Foo
metadata:
name: sink
namespace: default
spec:
key: test-value
```

clean resource for next case:

```shell script
Expand Down
12 changes: 1 addition & 11 deletions examples/dependency/demo-with-conditions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,4 @@ spec:
- valueFrom:
dataOutputName: example-key
toFieldPaths:
- "spec.key"
traits:
- trait:
apiVersion: serving.knative.dev/v1
kind: Route
metadata:
name: trait-test
spec:
traffic:
- configurationName: webapp
percent: 100
- "spec.key"

0 comments on commit bd60d02

Please sign in to comment.