|
| 1 | +--- |
| 2 | +apiVersion: argoproj.io/v1alpha1 |
| 3 | +kind: Sensor |
| 4 | +metadata: |
| 5 | + name: nova-oslo-event |
| 6 | + annotations: |
| 7 | + workflows.argoproj.io/title: Process oslo_events for nova compute |
| 8 | + workflows.argoproj.io/description: |+ |
| 9 | + Triggers on the following Nova Events: |
| 10 | +
|
| 11 | + - compute.instance.delete.end which happens when a server is deleted |
| 12 | + AND the server has metadata.storage == "wanted" |
| 13 | +
|
| 14 | + This sensor uses data filters to check the storage metadata and directly |
| 15 | + triggers the ansible playbook without requiring a Python handler. |
| 16 | +
|
| 17 | + The sensor extracts the following parameters from the event: |
| 18 | + - device_id: from payload.node (the Baremetal Node ID) |
| 19 | + - project_id: from payload.tenant_id (UUID without dashes) |
| 20 | +
|
| 21 | + These are passed directly to the storage_on_server_delete.yml ansible playbook. |
| 22 | +
|
| 23 | + Defined in `components/site-workflows/sensors/sensor-nova-oslo-event.yaml` |
| 24 | +spec: |
| 25 | + dependencies: |
| 26 | + - eventName: notifications |
| 27 | + eventSourceName: openstack-nova |
| 28 | + name: nova-dep |
| 29 | + transform: |
| 30 | + # the event is a string-ified JSON so we need to decode it |
| 31 | + # replace the whole event body and add a storage_wanted flag |
| 32 | + jq: | |
| 33 | + .body = (.body["oslo.message"] | fromjson) | |
| 34 | + .body.storage_wanted = (.body.payload.metadata.storage // "none") |
| 35 | + filters: |
| 36 | + # applies each of the items in data with 'and' |
| 37 | + dataLogicalOperator: "and" |
| 38 | + data: |
| 39 | + - path: "body.event_type" |
| 40 | + type: "string" |
| 41 | + value: |
| 42 | + - "compute.instance.delete.end" |
| 43 | + # Only process if storage was wanted |
| 44 | + - path: "body.storage_wanted" |
| 45 | + type: "string" |
| 46 | + value: |
| 47 | + - "wanted" |
| 48 | + template: |
| 49 | + serviceAccountName: sensor-submit-workflow |
| 50 | + triggers: |
| 51 | + - template: |
| 52 | + name: nova-instance-delete |
| 53 | + k8s: |
| 54 | + operation: create |
| 55 | + parameters: |
| 56 | + - dest: spec.arguments.parameters.0.value |
| 57 | + src: |
| 58 | + dataKey: body.payload.node |
| 59 | + dependencyName: nova-dep |
| 60 | + - dest: spec.arguments.parameters.1.value |
| 61 | + src: |
| 62 | + dataKey: body.payload.tenant_id |
| 63 | + dependencyName: nova-dep |
| 64 | + source: |
| 65 | + # create a workflow in argo-events prefixed with nova-delete- |
| 66 | + resource: |
| 67 | + apiVersion: argoproj.io/v1alpha1 |
| 68 | + kind: Workflow |
| 69 | + metadata: |
| 70 | + generateName: nova-delete- |
| 71 | + namespace: argo-events |
| 72 | + spec: |
| 73 | + serviceAccountName: workflow |
| 74 | + entrypoint: main |
| 75 | + # defines the parameters extracted from the event |
| 76 | + arguments: |
| 77 | + parameters: |
| 78 | + - name: device_id |
| 79 | + - name: project_id |
| 80 | + templates: |
| 81 | + - name: main |
| 82 | + steps: |
| 83 | + - - name: ansible-delete-server-storage |
| 84 | + templateRef: |
| 85 | + name: ansible-workflow-template |
| 86 | + template: ansible-run |
| 87 | + arguments: |
| 88 | + parameters: |
| 89 | + - name: playbook |
| 90 | + value: storage_on_server_delete.yml |
| 91 | + - name: extra_vars |
| 92 | + value: device_id={{workflow.parameters.device_id}} project_id={{workflow.parameters.project_id}} |
| 93 | + - - name: ansible-update-switches |
| 94 | + templateRef: |
| 95 | + name: ansible-workflow-template |
| 96 | + template: ansible-run |
| 97 | + arguments: |
| 98 | + parameters: |
| 99 | + - name: playbook |
| 100 | + value: storage_update_switches.yml |
| 101 | + - name: extra_vars |
| 102 | + value: plan_mode=remediation |
0 commit comments