This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
implement Trait patch back before workload emitted #134
Open
ifree613
wants to merge
4
commits into
crossplane:master
Choose a base branch
from
ifree613:traitpatch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
## How do I add trait with patch fragments | ||
|
||
### Prerequisites | ||
* [Install OAM Runtime](https://github.com/crossplane/oam-kubernetes-runtime#install-oam-runtime) | ||
|
||
|
||
### Install traits with patch fragments | ||
|
||
* Install the Trait Definition | ||
|
||
``` | ||
apiVersion: core.oam.dev/v1alpha2 | ||
kind: TraitDefinition | ||
metadata: | ||
name: nodeselectors.extended.oam.dev | ||
spec: | ||
patch: true | ||
appliesToWorkloads: | ||
- core.oam.dev/v1alpha2.ContainerizedWorkload | ||
definitionRef: | ||
name: nodeselectors.extended.oam.dev | ||
``` | ||
* Install NodeSelector Controller | ||
|
||
|
||
* Add traits with patch fragments to the ApplicationConfiguration | ||
|
||
`sample_application_config.yaml` | ||
|
||
``` | ||
apiVersion: core.oam.dev/v1alpha2 | ||
kind: ApplicationConfiguration | ||
metadata: | ||
name: example-appconfig | ||
spec: | ||
components: | ||
- componentName: example-component | ||
parameterValues: | ||
- name: instance-name | ||
value: example-appconfig-workload | ||
- name: image | ||
value: wordpress:php7.2 | ||
traits: | ||
- trait: | ||
apiVersion: core.oam.dev/v1alpha2 | ||
kind: ManualScalerTrait | ||
metadata: | ||
name: example-appconfig-trait | ||
spec: | ||
replicaCount: 3 | ||
- trait: | ||
apiVersion: extended.oam.dev/v1alpha2 | ||
kind: NodeSelector | ||
metadata: | ||
name: example-appconfig-nodeselector | ||
spec: | ||
disktype: ssd | ||
scopes: | ||
- scopeRef: | ||
apiVersion: core.oam.dev/v1alpha2 | ||
kind: HealthScope | ||
name: example-health-scope | ||
``` | ||
|
||
|
||
* Apply a sample application configuration | ||
|
||
``` | ||
# kubectl apply -f sample_application_config.yaml | ||
|
||
``` | ||
* Check the status of the Trait and confirm whether the value of patchConfig is set successfully | ||
|
||
``` | ||
# kubectl get NodeSelector example-appconfig-nodeselector | ||
``` | ||
|
||
``` | ||
apiVersion: extended.oam.dev/v1alpha2 | ||
kind: NodeSelector | ||
metadata: | ||
name: example-component-trait-6db9578cfd | ||
spec: | ||
disktype: ssd | ||
status: | ||
patchConfig: nodeselector-cm | ||
phase: Ready | ||
``` | ||
|
||
|
||
### Query ConfigMap content to confirm whether the Patch data is correct | ||
|
||
``` | ||
# kubectl get cm nodeselector-cm -o yaml | ||
``` | ||
|
||
``` | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: nodeselector-cm | ||
data: | ||
patch: | | ||
{ | ||
"spec": { | ||
"template": { | ||
"spec": { | ||
"nodeSelector": { | ||
"disktype": "ssd" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
||
### Check the Spec content of the Workload | ||
|
||
``` | ||
# kubectl get deployment example-appconfig-workload -o yaml | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this one have a unit test? I would also suggest to break this function into multiple pieces (the patch itself can be a function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll add a unit test