Skip to content

Commit

Permalink
Use kubernetes.core.k8s for coredns and nodelocaldns manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
VannTen committed Dec 7, 2023
1 parent 4b2cce8 commit 0191d66
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 96 deletions.
23 changes: 0 additions & 23 deletions roles/kubernetes-apps/ansible/tasks/coredns.yml

This file was deleted.

56 changes: 16 additions & 40 deletions roles/kubernetes-apps/ansible/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,24 @@
delay: 1
when: inventory_hostname == groups['kube_control_plane'][0]

- name: Kubernetes Apps | CoreDNS
import_tasks: "coredns.yml"
when:
- dns_mode in ['coredns', 'coredns_dual']
- inventory_hostname == groups['kube_control_plane'][0]
tags:
- coredns

- name: Kubernetes Apps | nodelocalDNS
import_tasks: "nodelocaldns.yml"
when:
- enable_nodelocaldns
- inventory_hostname == groups['kube_control_plane'] | first
tags:
- nodelocaldns

- name: Kubernetes Apps | Start Resources
kube:
name: "{{ item.item.name }}"
namespace: "kube-system"
kubectl: "{{ bin_dir }}/kubectl"
resource: "{{ item.item.type }}"
filename: "{{ kube_config_dir }}/{{ item.item.file }}"
state: "latest"
with_items:
- "{{ coredns_manifests.results | default({}) }}"
- "{{ coredns_secondary_manifests.results | default({}) }}"
- "{{ nodelocaldns_manifests.results | default({}) }}"
- "{{ nodelocaldns_second_manifests.results | default({}) }}"
when:
- dns_mode != 'none'
- inventory_hostname == groups['kube_control_plane'][0]
- not item is skipped
register: resource_result
until: resource_result is succeeded
retries: 4
- name: Kubernetes Apps | DNS
kubernetes.core.k8s:
state: present
apply: true
server_side_apply:
field_manager: kubespray+version # TODO add version variable
force_conflicts: true
validate:
fail_on_error: true
strict: true
template: "{{ all_manifests_lists | flatten }}"
register: result
until: result is succeeded
retries: 10
delay: 5
tags:
- coredns
- nodelocaldns
loop_control:
label: "{{ item.item.file }}"
- coredns
- nodelocaldns

- name: Kubernetes Apps | Etcd metrics endpoints
import_tasks: etcd_metrics.yml
Expand Down
33 changes: 0 additions & 33 deletions roles/kubernetes-apps/ansible/tasks/nodelocaldns.yml

This file was deleted.

23 changes: 23 additions & 0 deletions roles/kubernetes-apps/ansible/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,26 @@ primary_dns_by_mode:

nodelocaldns_forward_target: "{{ ([primary_dns_by_mode[dns_mode]] + (dns_mode == 'coredns_dual') | ternary([skydns_server_secondary], [])) | join(' ') }}"
nodelocaldns_upstream_forward_target: "{{ upstream_dns_servers | d([]) | join(' ') | d('/etc/resolv.conf', true) }}"

coredns_manifests:
- coredns-clusterrole.yml.j2
- coredns-clusterrolebinding.yml.j2
- coredns-config.yml.j2
- coredns-deployment.yml.j2
- coredns-sa.yml.j2
- coredns-svc.yml.j2
- dns-autoscaler.yml.j2
- dns-autoscaler-clusterrole.yml.j2
- dns-autoscaler-clusterrolebinding.yml.j2
- dns-autoscaler-sa.yml.j2

nodelocaldns_manifests:
- nodelocaldns-config.yml.j2
- nodelocaldns-sa.yml.j2
- nodelocaldns-daemonset.yml.j2

all_apps:
- coredns
all_manifests_lists:
- "{{ (dns_mode in ['coredns', 'coredns_dual'] and ansible_run_tags | intersect(['all', 'coredns']) | length > 0 and 'coredns' not in ansible_skip_tags) | ternary(coredns_manifests, []) }}"
- "{{ (enable_nodelocaldns and ansible_run_tags | intersect(['all', 'coredns', 'nodelocaldns']) | length > 0 and ansible_skip_tags | intersect(['coredns', 'nodelocaldns']) | length == 0) | ternary(nodelocaldns_manifests, []) }}"

0 comments on commit 0191d66

Please sign in to comment.