From 8fb27abcc88384aa07b58e9ae2c16abc1ab5b748 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 7 Sep 2018 22:46:11 -0500 Subject: [PATCH] Fixes #16: CentOS 7 configuration of KUBELET_EXTRA_ARGS was broken. --- defaults/main.yml | 1 - tasks/kubelet-setup.yml | 34 ++++++++++++++++++++++++++++++++++ tasks/main.yml | 18 ++++-------------- tests/test.yml | 3 ++- vars/Debian.yml | 2 ++ vars/RedHat.yml | 2 ++ 6 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 tasks/kubelet-setup.yml create mode 100644 vars/Debian.yml create mode 100644 vars/RedHat.yml diff --git a/defaults/main.yml b/defaults/main.yml index 20426b8..7804c12 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -11,7 +11,6 @@ kubernetes_packages: kubernetes_role: master -kubernetes_kubelet_extra_args_config_file: /etc/default/kubelet kubernetes_kubelet_extra_args: "" kubernetes_allow_pods_on_master: True diff --git a/tasks/kubelet-setup.yml b/tasks/kubelet-setup.yml new file mode 100644 index 0000000..b016bd7 --- /dev/null +++ b/tasks/kubelet-setup.yml @@ -0,0 +1,34 @@ +--- +- name: Check for existence of kubelet environment file. + stat: + path: '{{ kubelet_environment_file_path }}' + register: kubelet_environment_file + +- name: Set facts for KUBELET_EXTRA_ARGS task if environment file exists. + set_fact: + kubelet_args_path: '{{ kubelet_environment_file_path }}' + kubelet_args_line: "{{ 'KUBELET_EXTRA_ARGS=' + kubernetes_kubelet_extra_args }}" + kubelet_args_regexp: '^KUBELET_EXTRA_ARGS=' + when: kubelet_environment_file.stat.exists + +- name: Set facts for KUBELET_EXTRA_ARGS task if environment file doesn't exist. + set_fact: + kubelet_args_path: '/etc/systemd/system/kubelet.service.d/10-kubeadm.conf' + kubelet_args_line: "{{ 'Environment=\"KUBELET_EXTRA_ARGS=' + kubernetes_kubelet_extra_args + '\"' }}" + kubelet_args_regexp: '^Environment=' + when: kubelet_environment_file.stat.exists == False + +- name: Configure KUBELET_EXTRA_ARGS. + lineinfile: + path: '{{ kubelet_args_path }}' + line: '{{ kubelet_args_line }}' + regexp: '{{ kubelet_args_regexp }}' + state: present + register: kubelet_config_file + +- name: Reload systemd unit if args were changed. + systemd: + state: restarted + daemon_reload: yes + name: kubelet + when: kubelet_config_file is changed diff --git a/tasks/main.yml b/tasks/main.yml index 8025acd..5d709e2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,7 @@ --- +- name: Include OS-specific variables. + include_vars: "{{ ansible_os_family }}.yml" + - include_tasks: setup-RedHat.yml when: ansible_os_family == 'RedHat' @@ -15,20 +18,7 @@ notify: restart kubelet with_items: "{{ kubernetes_packages }}" -- name: Configure KUBELET_EXTRA_ARGS. - lineinfile: - path: '{{ kubernetes_kubelet_extra_args_config_file }}' - line: 'KUBELET_EXTRA_ARGS={{ kubernetes_kubelet_extra_args }}' - regexp: 'KUBELET_EXTRA_ARGS=' - state: present - register: kubelet_unit_file - -- name: Reload systemd unit if args were changed. - systemd: - state: restarted - daemon_reload: yes - name: kubelet - when: kubelet_unit_file is changed +- include_tasks: kubelet-setup.yml - name: Ensure kubelet is started and enabled at boot. service: diff --git a/tests/test.yml b/tests/test.yml index 8c3f1d8..4b51872 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -4,6 +4,7 @@ vars: # Allow swap in test environments (hard to control in some Docker envs). kubernetes_kubelet_extra_args: "--fail-swap-on=false" + docker_install_compose: False pre_tasks: - name: Update apt cache. @@ -17,7 +18,7 @@ - name: Use cgroupfs cgroup driver instead of systemd (Red Hat). set_fact: - kubernetes_kubelet_extra_args: "--fail-swap-on=false --cgroup-driver=cgroupfs" + kubernetes_kubelet_extra_args: '"--fail-swap-on=false --cgroup-driver=cgroupfs"' when: ansible_os_family == 'RedHat' roles: diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..67f5eae --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,2 @@ +--- +kubelet_environment_file_path: /etc/default/kubelet diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..04919de --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,2 @@ +--- +kubelet_environment_file_path: /etc/sysconfig/kubelet