From d9f100d3137d13d06a582e4676862d1a714c32e7 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Wed, 9 May 2018 17:04:46 -0500 Subject: [PATCH] Really fix idempotence for Flannel tasks, and get CentOS mostly working. --- README.md | 4 ++-- defaults/main.yml | 2 +- tasks/main.yml | 14 ++++++-------- tasks/setup-RedHat.yml | 3 ++- tests/test.yml | 8 +++++++- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ac13198..d6af6b3 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ Available variables are listed below, along with default values (see `defaults/m TODO. - kubernetes_allow_swap: False + kubernetes_kubelet_extra_args: "" -TODO. +TODO. Example: `"--fail-swap-on=false --cgroup-driver=systemd"`. kubernetes_allow_pods_on_master: True diff --git a/defaults/main.yml b/defaults/main.yml index 1d95a7e..9c3d1da 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,7 +9,7 @@ kubernetes_packages: - name: kubernetes-cni state: present -kubernetes_allow_swap: False +kubernetes_kubelet_extra_args: "" kubernetes_allow_pods_on_master: True kubernetes_enable_web_ui: True diff --git a/tasks/main.yml b/tasks/main.yml index 11e942a..f3f18cb 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,14 +15,14 @@ notify: restart kubelet with_items: "{{ kubernetes_packages }}" -- name: Allow kubelet to run with swap enabled (if configured). +- name: Configure KUBELET_EXTRA_ARGS. lineinfile: path: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf - line: 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"' - regexp: 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on.+' + line: 'Environment="KUBELET_EXTRA_ARGS={{ kubernetes_kubelet_extra_args }}"' + regexp: 'Environment="KUBELET_EXTRA_ARGS=' insertafter: '^Environment=' state: present - when: kubernetes_allow_swap + notify: restart kubelet - name: Ensure kubelet is started and enabled at boot. service: @@ -66,10 +66,8 @@ with_items: - kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml - kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml - register: flannel_networking_result - changed_when: > - ('unchanged' not in flannel_networking_result.stdout) - or ('configured' not in flannel_networking_result.stdout) + register: flannel_result + changed_when: "'created' in flannel_result.stdout" # TODO: Check if taint exists with something like `kubectl describe nodes` # instead of using kubernetes_init_stat.stat.exists check. diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml index 12e976b..09fea09 100644 --- a/tasks/setup-RedHat.yml +++ b/tasks/setup-RedHat.yml @@ -23,4 +23,5 @@ - name: Make cache if Kubernetes GPG key changed. command: "yum -q makecache -y --disablerepo='*' --enablerepo='kubernetes'" when: kubernetes_rpm_key is changed - warn: no + args: + warn: no diff --git a/tests/test.yml b/tests/test.yml index ee92afb..8c3f1d8 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -2,7 +2,8 @@ - hosts: all vars: - kubernetes_allow_swap: True + # Allow swap in test environments (hard to control in some Docker envs). + kubernetes_kubelet_extra_args: "--fail-swap-on=false" pre_tasks: - name: Update apt cache. @@ -14,6 +15,11 @@ - action: setup + - name: Use cgroupfs cgroup driver instead of systemd (Red Hat). + set_fact: + kubernetes_kubelet_extra_args: "--fail-swap-on=false --cgroup-driver=cgroupfs" + when: ansible_os_family == 'RedHat' + roles: - geerlingguy.docker - role_under_test