diff --git a/roles/win_nodes/kubernetes_patch/defaults/main.yml b/roles/win_nodes/kubernetes_patch/defaults/main.yml index 2dd8721b9..ab979d4c8 100644 --- a/roles/win_nodes/kubernetes_patch/defaults/main.yml +++ b/roles/win_nodes/kubernetes_patch/defaults/main.yml @@ -3,3 +3,5 @@ kubernetes_user_manifests_path: "{{ ansible_env.HOME }}/kube-manifests" # Optionally remove kube_proxy installed by kubeadm kube_proxy_remove: false +# nodeselector for kube-proxy ds is beta until 1.18 +kube_proxy_nodeselector: "{{ 'kubernetes.io/os' if kube_version is version('v1.18.0', '>=') else 'beta.kubernetes.io/os' }}" diff --git a/roles/win_nodes/kubernetes_patch/files/nodeselector-os-linux-patch.json b/roles/win_nodes/kubernetes_patch/files/nodeselector-os-linux-patch.json deleted file mode 100644 index d6a7761da..000000000 --- a/roles/win_nodes/kubernetes_patch/files/nodeselector-os-linux-patch.json +++ /dev/null @@ -1 +0,0 @@ -{"spec":{"template":{"spec":{"nodeSelector":{"kubernetes.io/os":"linux"}}}}} \ No newline at end of file diff --git a/roles/win_nodes/kubernetes_patch/tasks/main.yml b/roles/win_nodes/kubernetes_patch/tasks/main.yml index 8d838686f..ada163451 100644 --- a/roles/win_nodes/kubernetes_patch/tasks/main.yml +++ b/roles/win_nodes/kubernetes_patch/tasks/main.yml @@ -9,17 +9,12 @@ - name: Apply kube-proxy nodeselector block: - - name: Copy kube-proxy daemonset nodeselector patch - copy: - src: nodeselector-os-linux-patch.json - dest: "{{ kubernetes_user_manifests_path }}/nodeselector-os-linux-patch.json" - # Due to https://github.com/kubernetes/kubernetes/issues/58212 we cannot rely on exit code for "kubectl patch" - name: Check current nodeselector for kube-proxy daemonset command: >- {{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf get ds kube-proxy --namespace=kube-system - -o jsonpath='{.spec.template.spec.nodeSelector.kubernetes\.io/os}' + -o jsonpath='{.spec.template.spec.nodeSelector.{{ kube_proxy_nodeselector | regex_replace('\.', '\\.') }}}' register: current_kube_proxy_state retries: 60 delay: 5 @@ -30,9 +25,7 @@ shell: >- {{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf patch ds kube-proxy --namespace=kube-system --type=strategic -p - "$(cat nodeselector-os-linux-patch.json)" - args: - chdir: "{{ kubernetes_user_manifests_path }}" + '{"spec":{"template":{"spec":{"nodeSelector":{"{{ kube_proxy_nodeselector }}":"linux"} }}}}' register: patch_kube_proxy_state when: current_kube_proxy_state.stdout | trim | lower != "linux"