Skip to content

Commit

Permalink
Move handling of secondary coredns into jinja
Browse files Browse the repository at this point in the history
Loops inside the template rather than doing a separate task.
  • Loading branch information
VannTen committed Dec 7, 2023
1 parent 2c3ea84 commit bc1026d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
21 changes: 0 additions & 21 deletions roles/kubernetes-apps/ansible/tasks/coredns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,8 @@
- { name: dns-autoscaler, file: dns-autoscaler-clusterrolebinding.yml, type: clusterrolebinding }
- { name: dns-autoscaler, file: dns-autoscaler-sa.yml, type: sa }
register: coredns_manifests
vars:
clusterIP: "{{ skydns_server }}"
when:
- dns_mode in ['coredns', 'coredns_dual']
- inventory_hostname == groups['kube_control_plane'][0]
tags:
- coredns

- name: Kubernetes Apps | Lay Down Secondary CoreDNS Template
template:
src: "{{ item.src }}.j2"
dest: "{{ kube_config_dir }}/{{ item.file }}"
mode: 0644
with_items:
- { name: coredns, src: coredns-deployment.yml, file: coredns-deployment-secondary.yml, type: deployment }
- { name: coredns, src: coredns-svc.yml, file: coredns-svc-secondary.yml, type: svc }
- { name: dns-autoscaler, src: dns-autoscaler.yml, file: coredns-autoscaler-secondary.yml, type: deployment }
register: coredns_secondary_manifests
vars:
clusterIP: "{{ skydns_server_secondary }}"
coredns_ordinal_suffix: "-secondary"
when:
- dns_mode == 'coredns_dual'
- inventory_hostname == groups['kube_control_plane'][0]
tags:
- coredns
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% for coredns_ordinal_suffix in coredns_ordinal_suffixes %}
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -121,3 +122,4 @@ spec:
- key: hosts
path: hosts
{% endif %}
{% endfor %}
4 changes: 3 additions & 1 deletion roles/kubernetes-apps/ansible/templates/coredns-svc.yml.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% for coredns_ordinal_suffix in coredns_ordinal_suffixes %}
---
apiVersion: v1
kind: Service
Expand All @@ -15,7 +16,7 @@ metadata:
spec:
selector:
k8s-app: kube-dns{{ coredns_ordinal_suffix }}
clusterIP: {{ clusterIP }}
clusterIP: {{ lookup('vars', 'skydns_server' + (coredns_ordinal_suffix | replace('-', '_'))) }}
ports:
- name: dns
port: 53
Expand All @@ -28,3 +29,4 @@ spec:
- name: metrics
port: 9153
protocol: TCP
{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

{% for coredns_ordinal_suffix in coredns_ordinal_suffixes %}
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -84,3 +85,4 @@ spec:
- --configmap=dns-autoscaler{{ coredns_ordinal_suffix }}
- --target=Deployment/coredns{{ coredns_ordinal_suffix }}
serviceAccountName: dns-autoscaler
{% endfor %}
1 change: 1 addition & 0 deletions roles/kubernetes-apps/ansible/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coredns_ordinal_suffixes: "{{ [''] + (dns_mode == 'coredns_dual' | ternary(['-secondary'], [])) }}"

0 comments on commit bc1026d

Please sign in to comment.