-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from FogDong/fix-readme
Feat: add example of multiple apps and fix read me
- Loading branch information
Showing
9 changed files
with
266 additions
and
179 deletions.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,87 @@ | ||
# Control the delivery process of multiple applications | ||
|
||
> Note: The example uses following definitions, please use `vela def apply -f <filename>` to install them first. | ||
> - [Definition `read-app`](https://github.com/kubevela/catalog/blob/master/addons/vela-workflow/definitions/read-app.cue) | ||
> - [Definition `apply-app`](https://github.com/kubevela/catalog/blob/master/addons/vela-workflow/definitions/apply-app.cue) | ||
Apply the following workflow to control the delivery process of multiple applications: | ||
|
||
```yaml | ||
apiVersion: core.oam.dev/v1alpha1 | ||
kind: WorkflowRun | ||
metadata: | ||
name: apply-applications | ||
namespace: default | ||
annotations: | ||
workflowrun.oam.dev/debug: "true" | ||
spec: | ||
workflowSpec: | ||
steps: | ||
- name: check-app-exist | ||
type: read-app | ||
properties: | ||
name: webservice-app | ||
- name: apply-app1 | ||
type: apply-app | ||
if: status["check-app-exist"].message == "Application not found" | ||
properties: | ||
data: | ||
apiVersion: core.oam.dev/v1beta1 | ||
kind: Application | ||
metadata: | ||
name: webservice-app | ||
spec: | ||
components: | ||
- name: express-server | ||
type: webservice | ||
properties: | ||
image: crccheck/hello-world | ||
ports: | ||
- port: 8000 | ||
- name: suspend | ||
type: suspend | ||
timeout: 24h | ||
- name: apply-app2 | ||
type: apply-app | ||
properties: | ||
ref: | ||
name: my-app | ||
key: application | ||
type: configMap | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: my-app | ||
namespace: default | ||
data: | ||
application: | | ||
apiVersion: core.oam.dev/v1beta1 | ||
kind: Application | ||
metadata: | ||
name: webservice-app2 | ||
spec: | ||
components: | ||
- name: express-server2 | ||
type: webservice | ||
properties: | ||
image: crccheck/hello-world | ||
ports: | ||
- port: 8000 | ||
``` | ||
Above workflow will first try to read the Application called `webservice-app` from the cluster, if the Application is not found, this step's status message will be `Application not found`. The second step will deploy the `webservice-app` Application if `webservice-app` is not exist in the cluster. After that, the `suspend` step will suspend the delivery process for manual approve. | ||
|
||
``` | ||
$ kubectl get wr | ||
NAME PHASE AGE | ||
apply-applications suspending 2s | ||
``` | ||
You can use `vela workflow resume` to resume this workflow, note that if the workflow has not been resumed in 24 hours, the workflow will failed of timeout: | ||
``` | ||
vela workflow resume apply-applications | ||
``` | ||
After the workflow is resumed, it will deploy an another Application from the data in ConfigMap with key `application`. |
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,56 @@ | ||
# Use Workflow for request and notify | ||
|
||
> Note: The example uses following definitions, please use `vela def apply -f <filename>` to install them first. | ||
> - [Definition `request`](https://github.com/kubevela/catalog/blob/master/addons/vela-workflow/definitions/request.cue) | ||
> - [Definition `notification`](https://github.com/kubevela/kubevela/blob/master/vela-templates/definitions/internal/workflowstep/notification.cue) | ||
Apply the following workflow for request a specified URL first and then use the response as a message to your slack channel. | ||
|
||
```yaml | ||
apiVersion: core.oam.dev/v1alpha1 | ||
kind: WorkflowRun | ||
metadata: | ||
name: request-http | ||
namespace: default | ||
spec: | ||
workflowSpec: | ||
steps: | ||
- name: request | ||
type: request | ||
properties: | ||
url: https://api.github.com/repos/kubevela/workflow | ||
outputs: | ||
- name: stars | ||
valueFrom: | | ||
import "strconv" | ||
"Current star count: " + strconv.FormatInt(response["stargazers_count"], 10) | ||
- name: notification | ||
type: notification | ||
inputs: | ||
- from: stars | ||
parameterKey: slack.message.text | ||
properties: | ||
slack: | ||
url: | ||
value: <your slack url> | ||
- name: failed-notification | ||
type: notification | ||
if: status.request.failed | ||
properties: | ||
slack: | ||
url: | ||
value: <your slack url> | ||
message: | ||
text: "Failed to request github" | ||
|
||
``` | ||
Above workflow will send a request to the GitHub API and get the star count of the workflow repository as an output, then use the output as a message to send a notification to your Slack channel. | ||
Apply the WorkflowRun, you can get a message from Slack like: | ||
![slack-success](./static/slack-success.png) | ||
If you change the `url` to an invalid one, you will get a failed notification: | ||
|
||
![slack-failed](./static/slack-fail.png) |
Oops, something went wrong.