Skip to content

Commit

Permalink
Use a finalizer to make sure web hooks are removed when operator is u…
Browse files Browse the repository at this point in the history
…ninstalled

When uninstalling the forklift operator, not all resources
are removed from the cluster. In particular, there are
at least 3 validatingwebhookconfiguration objects and 3
mutatingwebhookconfiguration objects that are left behind. By using a
finalizer on the operator, we can ensure that these objects are removed
from the cluster.

Fixes: https://issues.redhat.com/browse/MTV-1076

Signed-off-by: Jonathon Jongsma <[email protected]>
  • Loading branch information
jonner committed Oct 8, 2024
1 parent 8a8c742 commit d7999c6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
42 changes: 12 additions & 30 deletions operator/roles/forkliftcontroller/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,15 @@
state: absent
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-forklift-api.yml.j2') }}"

- name: "Setup secrets validating webhook configuration"
k8s:
state: present
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-secrets.yml.j2') }}"

- name: "Setup plans validating webhook configuration"
k8s:
state: present
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-plans.yml.j2') }}"

- name: "Setup providers validating webhook configuration"
k8s:
state: present
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-providers.yml.j2') }}"

- name: "Delete aggregated mutating webhook configurations"
k8s:
state: absent
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-forklift-api.yml.j2') }}"

- name: "Setup secrets mutating webhook configuration"
k8s:
state: present
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-secrets.yml.j2') }}"

- name: "Setup plans mutating webhook configuration"
k8s:
state: present
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-plans.yml.j2') }}"


- name: "Setup providers mutating webhook configuration"
k8s:
state: present
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-providers.yml.j2') }}"
- name: "Setup webhook configuration"
include_tasks: webhooks.yml
vars:
webhook_state: "present"

- name: "Setup default provider"
k8s:
Expand Down Expand Up @@ -276,3 +250,11 @@
namespace: "{{ app_namespace }}"
name: forklift-must-gather-api
state: absent
when: finalize is not defined

- block:
- name: "Remove webhook configuration"
include_tasks: webhooks.yml
vars:
webhook_state: "absent"
when: finalize
32 changes: 32 additions & 0 deletions operator/roles/forkliftcontroller/tasks/webhooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- block:
- name: "Setup secrets validating webhook configuration"
k8s:
state: "{{ webhook_state }}"
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-secrets.yml.j2') }}"

- name: "Setup plans validating webhook configuration"
k8s:
state: "{{ webhook_state }}"
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-plans.yml.j2') }}"

- name: "Setup providers validating webhook configuration"
k8s:
state: "{{ webhook_state }}"
definition: "{{ lookup('template', 'api/validatingwebhookconfiguration-providers.yml.j2') }}"

- name: "Setup secrets mutating webhook configuration"
k8s:
state: "{{ webhook_state }}"
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-secrets.yml.j2') }}"

- name: "Setup plans mutating webhook configuration"
k8s:
state: "{{ webhook_state }}"
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-plans.yml.j2') }}"

- name: "Setup providers mutating webhook configuration"
k8s:
state: "{{ webhook_state }}"
definition: "{{ lookup('template', 'api/mutatingwebhookconfiguration-providers.yml.j2') }}"

4 changes: 4 additions & 0 deletions operator/watches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
kind: ForkliftController
role: forkliftcontroller
#+kubebuilder:scaffold:watch
finalizer:
name: forklift.konveyor.io/finalizer
vars:
finalize: true

0 comments on commit d7999c6

Please sign in to comment.