Fixes #16: CentOS 7 configuration of KUBELET_EXTRA_ARGS was broken.

This commit is contained in:
Jeff Geerling 2018-09-07 22:46:11 -05:00
parent dcea1bfe57
commit 8fb27abcc8
6 changed files with 44 additions and 16 deletions

View File

@ -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

34
tasks/kubelet-setup.yml Normal file
View File

@ -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

View File

@ -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:

View File

@ -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:

2
vars/Debian.yml Normal file
View File

@ -0,0 +1,2 @@
---
kubelet_environment_file_path: /etc/default/kubelet

2
vars/RedHat.yml Normal file
View File

@ -0,0 +1,2 @@
---
kubelet_environment_file_path: /etc/sysconfig/kubelet