Skip to content

Commit

Permalink
Set ownerRef to null for SA, Role and RoleBinding to avoid conflicts
Browse files Browse the repository at this point in the history
 - Without this, if an AnsibleJob is deleted while another is running,
   it's service account, role and rolebinding will be cascade deleted,
   making the running job fail.
  • Loading branch information
rooftopcellist committed Nov 9, 2023
1 parent 1cd9230 commit 71939c2
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
15 changes: 15 additions & 0 deletions roles/common/tasks/unset-ownerref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Remove ownerReferences on persistent resources
k8s:
definition:
apiVersion: "{{ item.apiVersion }}"
kind: "{{ item.kind }}"
metadata:
name: "resource-operator-controller-manager-job"
namespace: '{{ ansible_operator_meta.namespace }}'
ownerReferences: null
loop:
- { kind: 'ServiceAccount', apiVersion: 'v1' }
- { kind: 'Role', apiVersion: 'rbac.authorization.k8s.io/v1' }
- { kind: 'RoleBinding', apiVersion: 'rbac.authorization.k8s.io/v1' }
no_log: "{{ no_log }}"
3 changes: 3 additions & 0 deletions roles/credential/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
state: present
definition: "{{ lookup('template', 'service_account.yml.j2') }}"

- name: Unset ownerReference on ServiceAccount, Role, and RoleBinding
include_tasks: ../common/tasks/unset-ownerref.yml

- name: Start K8s Runner Job
kubernetes.core.k8s:
state: present
Expand Down
3 changes: 3 additions & 0 deletions roles/instancegroup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
state: present
definition: "{{ lookup('template', 'service_account.yml.j2') }}"

- name: Unset ownerReference on ServiceAccount, Role, and RoleBinding
include_tasks: ../common/tasks/unset-ownerref.yml

- name: Start K8s Runner Job
kubernetes.core.k8s:
state: present
Expand Down
1 change: 0 additions & 1 deletion roles/inventory/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
# defaults file for Inventory
job_ttl: 3600
backoff_limit: 1

1 change: 0 additions & 1 deletion roles/inventory/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@
message: "There was an error when creating the inventory"
when:
- inventory.failed

3 changes: 3 additions & 0 deletions roles/job/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
state: present
definition: "{{ lookup('template', 'service_account.yml.j2') }}"

- name: Unset ownerReference on ServiceAccount, Role, and RoleBinding
include_tasks: ../common/tasks/unset-ownerref.yml

- name: Start K8s Runner Job
kubernetes.core.k8s:
state: present
Expand Down
1 change: 0 additions & 1 deletion roles/jobtemplate/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,3 @@
message: "There was an error in the job template"
when:
- job_template.failed

3 changes: 3 additions & 0 deletions roles/project/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
state: present
definition: "{{ lookup('template', 'service_account.yml.j2') }}"

- name: Unset ownerReference on ServiceAccount, Role, and RoleBinding
include_tasks: ../common/tasks/unset-ownerref.yml

- name: Start K8s Runner Job
kubernetes.core.k8s:
state: present
Expand Down
3 changes: 3 additions & 0 deletions roles/schedule/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
state: present
definition: "{{ lookup('template', 'service_account.yml.j2') }}"

- name: Unset ownerReference on ServiceAccount, Role, and RoleBinding
include_tasks: ../common/tasks/unset-ownerref.yml

- name: Start K8s Runner Job
kubernetes.core.k8s:
state: present
Expand Down
3 changes: 3 additions & 0 deletions roles/workflow/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
state: present
definition: "{{ lookup('template', 'service_account.yml.j2') }}"

- name: Unset ownerReference on ServiceAccount, Role, and RoleBinding
include_tasks: ../common/tasks/unset-ownerref.yml

- name: Start K8s Runner Job
kubernetes.core.k8s:
state: present
Expand Down
1 change: 0 additions & 1 deletion test-e2e/tests/job-deprecated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ spec:
tower_auth_secret: awxaccess
job_template_name: Demo Job Template
runner_pull_policy: IfNotPresent

0 comments on commit 71939c2

Please sign in to comment.