From cf4fedfe788043ea10c579314e2731b14885cddb Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Thu, 12 May 2022 17:32:17 +0800 Subject: [PATCH 1/2] refactor(argo/workflows): rename argo-workflow to argo-workflows --- .../{argo_workflow_test.yaml => argo_workflows_test.yaml} | 7 ++++--- argo/{workflow => workflows}/README.md | 0 argo/{workflow => workflows}/cron-workflow/cron.yaml | 0 .../workflow-template/00-templates.yaml | 0 .../workflow-template/01-hello-world.yaml | 0 argo/{workflow => workflows}/workflow/hello-world.yaml | 0 6 files changed, 4 insertions(+), 3 deletions(-) rename .github/workflows/{argo_workflow_test.yaml => argo_workflows_test.yaml} (90%) rename argo/{workflow => workflows}/README.md (100%) rename argo/{workflow => workflows}/cron-workflow/cron.yaml (100%) rename argo/{workflow => workflows}/workflow-template/00-templates.yaml (100%) rename argo/{workflow => workflows}/workflow-template/01-hello-world.yaml (100%) rename argo/{workflow => workflows}/workflow/hello-world.yaml (100%) diff --git a/.github/workflows/argo_workflow_test.yaml b/.github/workflows/argo_workflows_test.yaml similarity index 90% rename from .github/workflows/argo_workflow_test.yaml rename to .github/workflows/argo_workflows_test.yaml index d2564a2..e101f50 100644 --- a/.github/workflows/argo_workflow_test.yaml +++ b/.github/workflows/argo_workflows_test.yaml @@ -1,12 +1,12 @@ # verify with local kind k8s cluster. -name: Argo workflow E2E test +name: Argo workflows E2E test on: workflow_dispatch: pull_request: branches: [main] paths: - - "argo/workflow/**" + - "argo/workflows/**" - ".github/workflows/argo_workflow_*" jobs: @@ -32,7 +32,8 @@ jobs: # wait all be ready kubectl -n argo wait deploy --all --for condition=Available --timeout 5m - name: Create ${{ matrix.feature }} feature data - run: kubectl -n argo create -f argo/workflow/${{ matrix.feature }} + working-directory: argo/workflows + run: kubectl -n argo create -f ${{ matrix.feature }} - name: Waitting for verify cron workflows condition. if: matrix.feature == 'cron-workflow' run: | diff --git a/argo/workflow/README.md b/argo/workflows/README.md similarity index 100% rename from argo/workflow/README.md rename to argo/workflows/README.md diff --git a/argo/workflow/cron-workflow/cron.yaml b/argo/workflows/cron-workflow/cron.yaml similarity index 100% rename from argo/workflow/cron-workflow/cron.yaml rename to argo/workflows/cron-workflow/cron.yaml diff --git a/argo/workflow/workflow-template/00-templates.yaml b/argo/workflows/workflow-template/00-templates.yaml similarity index 100% rename from argo/workflow/workflow-template/00-templates.yaml rename to argo/workflows/workflow-template/00-templates.yaml diff --git a/argo/workflow/workflow-template/01-hello-world.yaml b/argo/workflows/workflow-template/01-hello-world.yaml similarity index 100% rename from argo/workflow/workflow-template/01-hello-world.yaml rename to argo/workflows/workflow-template/01-hello-world.yaml diff --git a/argo/workflow/workflow/hello-world.yaml b/argo/workflows/workflow/hello-world.yaml similarity index 100% rename from argo/workflow/workflow/hello-world.yaml rename to argo/workflows/workflow/hello-world.yaml From 49a71de9026abadd43e7b52aab1b447e042d62e4 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Thu, 12 May 2022 21:18:46 +0800 Subject: [PATCH 2/2] feat(argo/events): add simple webhook event pratice file --- .github/workflows/argo_events_test.yaml | 64 +++++++++++++++++++ .github/workflows/argo_workflows_test.yaml | 2 +- argo/events/README.md | 71 ++++++++++++++++++++++ 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/argo_events_test.yaml create mode 100644 argo/events/README.md diff --git a/.github/workflows/argo_events_test.yaml b/.github/workflows/argo_events_test.yaml new file mode 100644 index 0000000..640d743 --- /dev/null +++ b/.github/workflows/argo_events_test.yaml @@ -0,0 +1,64 @@ +# verify with local kind k8s cluster. +name: Argo events E2E test + +on: + workflow_dispatch: + pull_request: + branches: [main] + paths: + - "argo/events/**" + - ".github/workflows/argo_events_*" + +jobs: + kubernetes: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Kubernetes + uses: engineerd/setup-kind@v0.5.0 + with: + # renovate: datasource=go depName=sigs.k8s.io/kind + version: v0.11.0 + - name: Install Argo Workflow in Kubernetes cluster + run: | + kubectl create namespace argo + kubectl -n argo apply -f https://raw.githubusercontent.com/argoproj/argo-workflows/master/manifests/install.yaml + + # wait all be ready + kubectl -n argo wait deploy --all --for condition=Available --timeout 5m + - name: Install Argo Events in Kubernetes cluster + run: | + kubectl create namespace argo-events + kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/master/manifests/install.yaml + kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/eventbus/native.yaml + + # sensor rbac + kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/master/examples/rbac/sensor-rbac.yaml + # workflow rbac + kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/master/examples/rbac/workflow-rbac.yaml + + # webhook event source + kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml + # webhook sensor + kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/webhook.yaml + + # wait all be ready + kubectl -n argo wait deploy --all --for condition=Available --timeout 5m + - name: Trigger webhook event using k8s job. + run: | + kubectl -n default create job sendwebhook --image=curlimages/curl -- curl \ + -X POST \ + -d '{"message":"this is my first webhook"}' \ + -H "Content-Type: application/json" \ + http://webhook-eventsource-svc.argo-events:12000/example + kubectl -n default wait job/sendwebhook --for=condition=completed --timeout=1m + - name: Verify event trigger feature + run: kubectl -n argo-events wait workflows --all --for=condition=Completed --timeout=1m + - name: Debug failure + if: failure() + run: | + kubectl -n argo get all + kubectl -n argo describe all + kubectl -n argo-events get all + kubectl -n argo-events describe all diff --git a/.github/workflows/argo_workflows_test.yaml b/.github/workflows/argo_workflows_test.yaml index e101f50..e8fd747 100644 --- a/.github/workflows/argo_workflows_test.yaml +++ b/.github/workflows/argo_workflows_test.yaml @@ -7,7 +7,7 @@ on: branches: [main] paths: - "argo/workflows/**" - - ".github/workflows/argo_workflow_*" + - ".github/workflows/argo_workflows_*" jobs: kubernetes: diff --git a/argo/events/README.md b/argo/events/README.md new file mode 100644 index 0000000..16dcd7f --- /dev/null +++ b/argo/events/README.md @@ -0,0 +1,71 @@ +Argo events +=== + +accroding to: + +- https://argoproj.github.io/argo-events/quick_start/ + + +## Summary + +[Architecture](https://argoproj.github.io/argo-events/concepts/architecture/) + +![Architecture](https://argoproj.github.io/argo-events/assets/argo-events-architecture.png) + +## Install + +1. setup workflows + - setup workflows namespace: + > `kubectl create namespace argo` + - setup workflows components: + > `kubectl -n argo apply -f https://raw.githubusercontent.com/argoproj/argo-workflows/master/manifests/install.yaml` +2. setup events + - create events namespace + > `kubectl create namespace argo-events` + - create events CRD and role bindings,configmaps, etc... + > `kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/master/manifests/install.yaml` + - setup events components components - event bus: + > `kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/eventbus/native.yaml` + - setup event source components, such as webhook: + > `kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml` + - setup event sensor components: + 1. create service account with role binding: + ```bash + # sensor rbac + kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/master/examples/rbac/sensor-rbac.yaml + # workflow rbac + kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/master/examples/rbac/workflow-rbac.yaml + ``` + 2. create sensor, such as webhook: + > `kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/webhook.yaml` + +## Test + +flow is: + +``` +\ ---> +http request + \ + webhook event source pod + \ + event bus + \ + webhook sensor + \ + k8s + \ + create a argo workflow resource +``` + +1. trigger a webhook request: + ```bash + kubectl -n default create job sendwebhook --image=curlimages/curl -- curl \ + -X POST \ + -d '{"message":"this is my first webhook"}' \ + -H "Content-Type: application/json" \ + http://webhook-eventsource-svc.argo-events:12000/example + kubectl -n default wait job/sendwebhook --for=condition=completed --timeout=1m + ``` +2. wait the workflow + > `kubectl -n argo-events wait workflows --all --for=condition=Completed --timeout=1m`