-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add storage deletion workflow with conditional execution #1492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
44 changes: 44 additions & 0 deletions
44
components/site-workflows/eventsources/eventsource-openstack-nova.yaml
This file contains hidden or 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,44 @@ | ||
| apiVersion: argoproj.io/v1alpha1 | ||
| kind: EventSource | ||
| metadata: | ||
| name: openstack-nova | ||
| spec: | ||
| amqp: | ||
| # this is our eventName | ||
| notifications: | ||
| # amqp server url | ||
| url: amqp://rabbitmq-server-0.rabbitmq-nodes.openstack.svc.cluster.local:5672/nova | ||
| # jsonBody specifies that all event body payload coming from this | ||
| # source will be JSON | ||
| jsonBody: true | ||
| # name of the exchange. | ||
| exchangeName: nova | ||
| exchangeType: topic | ||
| exchangeDeclare: | ||
| durable: true | ||
| # routing key for messages within the exchange | ||
| routingKey: 'notifications.info' | ||
| # queue settings, if not provided defaults are used | ||
| queueDeclare: | ||
| name: argo_notifications | ||
| durable: true | ||
| exclusive: false | ||
| autoDelete: false | ||
| noWait: true | ||
|
|
||
| # optional consume settings | ||
| # if not provided, default values will be used | ||
| consume: | ||
| consumerTag: "argo-events" | ||
| autoAck: true | ||
| exclusive: false | ||
| noLocal: false | ||
| # username and password for authentication | ||
| # use secret selectors | ||
| auth: | ||
| username: | ||
| name: argo-nova-user-credentials | ||
| key: username | ||
| password: | ||
| name: argo-nova-user-credentials | ||
| key: password | ||
25 changes: 25 additions & 0 deletions
25
components/site-workflows/eventsources/rabbitmq-user-argo-nova.yaml
This file contains hidden or 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,25 @@ | ||
| --- | ||
| apiVersion: rabbitmq.com/v1beta1 | ||
| kind: User | ||
| metadata: | ||
| name: argo-nova | ||
| spec: | ||
| rabbitmqClusterReference: | ||
| name: rabbitmq # rabbitmqCluster must exist in the same namespace as this resource | ||
| namespace: openstack | ||
| --- | ||
| apiVersion: rabbitmq.com/v1beta1 | ||
| kind: Permission | ||
| metadata: | ||
| name: argo-nova | ||
| spec: | ||
| vhost: "nova" | ||
| userReference: | ||
| name: "argo-nova" # name of a user.rabbitmq.com in the same namespace; must specify either spec.userReference or spec.user | ||
| permissions: | ||
| write: ".*" | ||
| configure: ".*" | ||
| read: ".*" | ||
| rabbitmqClusterReference: | ||
| name: rabbitmq # rabbitmqCluster must exist in the same namespace as this resource | ||
| namespace: openstack |
This file contains hidden or 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
102 changes: 102 additions & 0 deletions
102
components/site-workflows/sensors/sensor-nova-oslo-event.yaml
This file contains hidden or 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,102 @@ | ||
| --- | ||
| apiVersion: argoproj.io/v1alpha1 | ||
| kind: Sensor | ||
| metadata: | ||
| name: nova-oslo-event | ||
| annotations: | ||
| workflows.argoproj.io/title: Process oslo_events for nova compute | ||
| workflows.argoproj.io/description: |+ | ||
| Triggers on the following Nova Events: | ||
|
|
||
| - compute.instance.delete.end which happens when a server is deleted | ||
| AND the server has metadata.storage == "wanted" | ||
|
|
||
| This sensor uses data filters to check the storage metadata and directly | ||
| triggers the ansible playbook without requiring a Python handler. | ||
|
|
||
| The sensor extracts the following parameters from the event: | ||
| - device_id: from payload.node (the Baremetal Node ID) | ||
| - project_id: from payload.tenant_id (UUID without dashes) | ||
|
|
||
| These are passed directly to the storage_on_server_delete.yml ansible playbook. | ||
|
|
||
| Defined in `components/site-workflows/sensors/sensor-nova-oslo-event.yaml` | ||
| spec: | ||
| dependencies: | ||
| - eventName: notifications | ||
| eventSourceName: openstack-nova | ||
| name: nova-dep | ||
| transform: | ||
| # the event is a string-ified JSON so we need to decode it | ||
| # replace the whole event body and add a storage_wanted flag | ||
| jq: | | ||
| .body = (.body["oslo.message"] | fromjson) | | ||
| .body.storage_wanted = (.body.payload.metadata.storage // "none") | ||
| filters: | ||
| # applies each of the items in data with 'and' | ||
| dataLogicalOperator: "and" | ||
| data: | ||
| - path: "body.event_type" | ||
| type: "string" | ||
| value: | ||
| - "compute.instance.delete.end" | ||
| # Only process if storage was wanted | ||
| - path: "body.storage_wanted" | ||
| type: "string" | ||
| value: | ||
| - "wanted" | ||
| template: | ||
| serviceAccountName: sensor-submit-workflow | ||
| triggers: | ||
| - template: | ||
| name: nova-instance-delete | ||
| k8s: | ||
| operation: create | ||
| parameters: | ||
| - dest: spec.arguments.parameters.0.value | ||
| src: | ||
| dataKey: body.payload.node | ||
| dependencyName: nova-dep | ||
| - dest: spec.arguments.parameters.1.value | ||
| src: | ||
| dataKey: body.payload.tenant_id | ||
| dependencyName: nova-dep | ||
| source: | ||
| # create a workflow in argo-events prefixed with nova-delete- | ||
| resource: | ||
| apiVersion: argoproj.io/v1alpha1 | ||
| kind: Workflow | ||
| metadata: | ||
| generateName: nova-delete- | ||
| namespace: argo-events | ||
| spec: | ||
| serviceAccountName: workflow | ||
| entrypoint: main | ||
| # defines the parameters extracted from the event | ||
| arguments: | ||
| parameters: | ||
| - name: device_id | ||
| - name: project_id | ||
| templates: | ||
| - name: main | ||
| steps: | ||
| - - name: ansible-delete-server-storage | ||
| templateRef: | ||
| name: ansible-workflow-template | ||
| template: ansible-run | ||
| arguments: | ||
| parameters: | ||
| - name: playbook | ||
| value: storage_on_server_delete.yml | ||
| - name: extra_vars | ||
| value: device_id={{workflow.parameters.device_id}} project_id={{workflow.parameters.project_id}} | ||
| - - name: ansible-update-switches | ||
| templateRef: | ||
| name: ansible-workflow-template | ||
| template: ansible-run | ||
| arguments: | ||
| parameters: | ||
| - name: playbook | ||
| value: storage_update_switches.yml | ||
| - name: extra_vars | ||
| value: plan_mode=remediation |
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.
Uh oh!
There was an error while loading. Please reload this page.