Skip to content

Commit

Permalink
fix: kube-dns service deletion (#8565)
Browse files Browse the repository at this point in the history
Signed-off-by: Cyril Corbon <[email protected]>
  • Loading branch information
cyril-corbon authored Feb 21, 2022
1 parent 2537177 commit 418fc00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions roles/kubernetes-apps/ansible/tasks/cleanup_dns.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
---
- name: Kubernetes Apps | Register coredns deployment annotation `createdby`
command: "{{ kubectl }} get deploy -n kube-system coredns -o jsonpath='{ .spec.template.metadata.annotations.createdby }'"
register: createdby_annotation
register: createdby_annotation_deploy
changed_when: false
ignore_errors: true # noqa ignore-errors
when:
- dns_mode in ['coredns', 'coredns_dual']
- inventory_hostname == groups['kube_control_plane'][0]

- name: Kubernetes Apps | Register coredns service annotation `createdby`
command: "{{ kubectl }} get svc -n kube-system kube-dns -o jsonpath='{ .metadata.annotations.createdby }'"
register: createdby_annotation_svc
changed_when: false
ignore_errors: true # noqa ignore-errors
when:
Expand All @@ -18,7 +27,7 @@
when:
- dns_mode in ['coredns', 'coredns_dual']
- inventory_hostname == groups['kube_control_plane'][0]
- createdby_annotation.stdout != 'kubespray'
- createdby_annotation_deploy.stdout != 'kubespray'

- name: Kubernetes Apps | Delete kubeadm Kube-DNS service
kube:
Expand All @@ -30,3 +39,4 @@
when:
- dns_mode in ['coredns', 'coredns_dual']
- inventory_hostname == groups['kube_control_plane'][0]
- createdby_annotation_svc.stdout != 'kubespray'
1 change: 1 addition & 0 deletions roles/kubernetes-apps/ansible/templates/coredns-svc.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ metadata:
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
createdby: 'kubespray'
spec:
selector:
k8s-app: kube-dns{{ coredns_ordinal_suffix }}
Expand Down

0 comments on commit 418fc00

Please sign in to comment.