Skip to content

Commit 44f72c9

Browse files
committed
feat(workflows): add sensor and workflow for ironic port events
Added a workflow template that executes the openstack-oslo-event script using the input as the oslo.message body JSON payload. Add a sensor that triggers on the baremetal.port.create.end, baremetal.port.update.end, and baremetal.port.delete.end events and executes the workflowtemplate.
1 parent 5e5fc33 commit 44f72c9

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

workflows/argo-events/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ resources:
2020
- workflowtemplates/keystone-event-project.yaml
2121
- workflowtemplates/enroll-server.yaml
2222
- workflowtemplates/reclean-server.yaml
23+
- workflowtemplates/openstack-oslo-event.yaml
2324
# Alert automation
2425
- sensors/alertmanager-webhook-sensor.yaml
2526
- eventsources/alertmanager-webhook-eventsource.yaml
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
metadata:
3+
name: openstack-oslo-event
4+
annotations:
5+
workflows.argoproj.io/title: OpenStack OSLO event dispatcher
6+
workflows.argoproj.io/description: |
7+
Updates Nautobot with data from an OpenStack OSLO event.
8+
9+
This script takes the JSON parsed body of 'oslo.message' from
10+
an OSLO event. This can be decoded with `jq -r '."oslo.message" | fromjson'`
11+
12+
To test this workflow you can run it with the following:
13+
14+
```
15+
argo -n argo-events submit --from workflowtemplate/openstack-oslo-event \
16+
-p event-json "$(jq -r '."oslo.message" | fromjson')"
17+
```
18+
19+
Defined in `workflows/argo-events/workflowtemplates/openstack-oslo-event.yaml`
20+
kind: WorkflowTemplate
21+
spec:
22+
entrypoint: main
23+
serviceAccountName: workflow
24+
arguments:
25+
parameters:
26+
- name: event-json
27+
value: "{}" # default to empty dict
28+
templates:
29+
- name: main
30+
inputs:
31+
parameters:
32+
- name: event-json
33+
artifacts:
34+
- name: event-data
35+
path: /tmp/event.json
36+
raw:
37+
data: "{{inputs.parameters.event-json}}"
38+
container:
39+
image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest
40+
command:
41+
- openstack-oslo-event
42+
args:
43+
- "--file"
44+
- "/tmp/event.json"
45+
volumeMounts:
46+
- mountPath: /etc/nb-token/
47+
name: nb-token
48+
readOnly: true
49+
- mountPath: /etc/openstack
50+
name: openstack-svc-acct
51+
readOnly: true
52+
volumes:
53+
- name: nb-token
54+
secret:
55+
secretName: nautobot-token
56+
- name: openstack-svc-acct
57+
secret:
58+
secretName: openstack-svc-acct

workflows/openstack/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ resources:
2020
- sensors/sensor-k8s-neutron-deployment.yaml
2121
- sensors/sensor-neutron-event-network-segment-range.yaml
2222
- sensors/sensor-ironic-reclean.yaml
23+
- sensors/sensor-ironic-node-port.yaml
2324
- secrets/nautobot-token.yaml
2425
- secrets/openstack-svc-acct.yaml
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
apiVersion: argoproj.io/v1alpha1
3+
kind: Sensor
4+
metadata:
5+
name: ironic-node-port
6+
annotations:
7+
workflows.argoproj.io/title: Update Nautobot from Ironic Node Port Events
8+
workflows.argoproj.io/description: |+
9+
Triggers on the following Ironic Events:
10+
11+
- baremetal.port.create.end which happens when a baremetal port is created
12+
- baremetal.port.update.end which happens after a port is updated
13+
- baremetal.port.delete.end which happens when a port is deleted
14+
15+
Resulting code should be very similar to:
16+
17+
```
18+
argo -n argo-events submit --from workflowtemplate/openstack-oslo-event \
19+
-p event-json "JSON-payload"
20+
```
21+
22+
Defined in `workflows/argo-events/sensors/ironic-node-port.yaml`
23+
spec:
24+
dependencies:
25+
- eventName: openstack
26+
eventSourceName: openstack-ironic
27+
name: ironic-dep
28+
transform:
29+
# the event is a string-ified JSON so we need to decode it
30+
# replace the whole event body
31+
jq: |
32+
.body = (.body["oslo.message"] | fromjson)
33+
filters:
34+
# applies each of the items in data with 'and' but there's only one
35+
dataLogicalOperator: "and"
36+
data:
37+
- path: "body.event_type"
38+
type: "string"
39+
value:
40+
- "baremetal.port.create.end"
41+
- "baremetal.port.update.end"
42+
- "baremetal.port.delete.end"
43+
template:
44+
serviceAccountName: sensor-submit-workflow
45+
triggers:
46+
- template:
47+
name: ironic-node-port
48+
# uses 'argo' CLI instead of 'kubectl'
49+
argoWorkflow:
50+
# sets the operation to 'argo submit'
51+
operation: submit
52+
# edits source section
53+
parameters:
54+
# first parameter is the parsed oslo.message
55+
- dest: spec.arguments.parameters.0.value
56+
src:
57+
dataKey: body
58+
dependencyName: ironic-dep
59+
source:
60+
# create a workflow in argo-events prefixed with ironic-node-update-
61+
resource:
62+
apiVersion: argoproj.io/v1alpha1
63+
kind: Workflow
64+
metadata:
65+
generateName: ironic-node-port-
66+
namespace: argo-events
67+
spec:
68+
# defines the parameters being replaced above
69+
arguments:
70+
parameters:
71+
- name: event-json
72+
# references the workflow
73+
workflowTemplateRef:
74+
name: openstack-oslo-event

0 commit comments

Comments
 (0)