diff --git a/roles/kubernetes-apps/external_cloud_controller/meta/main.yml b/roles/kubernetes-apps/external_cloud_controller/meta/main.yml index 468fae8eb..f5325a54e 100644 --- a/roles/kubernetes-apps/external_cloud_controller/meta/main.yml +++ b/roles/kubernetes-apps/external_cloud_controller/meta/main.yml @@ -2,7 +2,6 @@ dependencies: - role: kubernetes-apps/external_cloud_controller/openstack when: - - cloud_provider is defined - cloud_provider == "external" - external_cloud_provider is defined - external_cloud_provider == "openstack" @@ -12,7 +11,6 @@ dependencies: - external-openstack - role: kubernetes-apps/external_cloud_controller/vsphere when: - - cloud_provider is defined - cloud_provider == "external" - external_cloud_provider is defined - external_cloud_provider == "vsphere" @@ -22,7 +20,6 @@ dependencies: - external-vsphere - role: kubernetes-apps/external_cloud_controller/hcloud when: - - cloud_provider is defined - cloud_provider == "external" - external_cloud_provider is defined - external_cloud_provider == "hcloud" @@ -32,7 +29,6 @@ dependencies: - external-hcloud - role: kubernetes-apps/external_cloud_controller/huaweicloud when: - - cloud_provider is defined - cloud_provider == "external" - external_cloud_provider is defined - external_cloud_provider == "huaweicloud" @@ -42,7 +38,6 @@ dependencies: - external-huaweicloud - role: kubernetes-apps/external_cloud_controller/oci when: - - cloud_provider is defined - cloud_provider == "external" - external_cloud_provider is defined - external_cloud_provider == "oci" diff --git a/roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2 b/roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2 index dc5cdcb00..123a68ad5 100644 --- a/roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2 +++ b/roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2 @@ -24,7 +24,7 @@ nodeRegistration: taints: [] {% endif %} criSocket: {{ cri_socket }} -{% if cloud_provider is defined and cloud_provider in ["external"] %} +{% if cloud_provider == "external" %} kubeletExtraArgs: cloud-provider: external {% endif %} diff --git a/roles/kubernetes/node/templates/kubelet.env.v1beta1.j2 b/roles/kubernetes/node/templates/kubelet.env.v1beta1.j2 index e3b54d7a3..a5280410a 100644 --- a/roles/kubernetes/node/templates/kubelet.env.v1beta1.j2 +++ b/roles/kubernetes/node/templates/kubelet.env.v1beta1.j2 @@ -21,7 +21,7 @@ KUBELET_VOLUME_PLUGIN="--volume-plugin-dir={{ kubelet_flexvolumes_plugins_dir }} {% if kube_network_plugin is defined and kube_network_plugin == "cloud" %} KUBELET_NETWORK_PLUGIN="--hairpin-mode=promiscuous-bridge --network-plugin=kubenet" {% endif %} -{% if cloud_provider is defined and cloud_provider in ["external"] %} +{% if cloud_provider == "external" %} KUBELET_CLOUDPROVIDER="--cloud-provider={{ cloud_provider }}" {% else %} KUBELET_CLOUDPROVIDER="" diff --git a/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml b/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml index 78d0d9b21..c074526fd 100644 --- a/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml +++ b/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml @@ -166,10 +166,9 @@ - name: Check cloud_provider value assert: - that: cloud_provider in ['external'] - msg: "If set the 'cloud_provider' var must be set either to 'external'" + that: cloud_provider == 'external' when: - - cloud_provider is defined + - cloud_provider - not ignore_assert_errors tags: - cloud-provider diff --git a/roles/kubespray-defaults/defaults/main/main.yml b/roles/kubespray-defaults/defaults/main/main.yml index 3cd59d29b..d9653a66f 100644 --- a/roles/kubespray-defaults/defaults/main/main.yml +++ b/roles/kubespray-defaults/defaults/main/main.yml @@ -271,6 +271,9 @@ kubelet_shutdown_grace_period: 60s # to give normal pods time to be gracefully evacuated kubelet_shutdown_grace_period_critical_pods: 20s +# Cloud Provider +# This variable can only be set to "external" or empty string, otherwise the check will fail. +cloud_provider: "" # Whether to deploy the container engine deploy_container_engine: "{{ 'k8s_cluster' in group_names or etcd_deployment_type == 'docker' }}" diff --git a/roles/network_plugin/calico/tasks/pre.yml b/roles/network_plugin/calico/tasks/pre.yml index 969699f6c..ab236155e 100644 --- a/roles/network_plugin/calico/tasks/pre.yml +++ b/roles/network_plugin/calico/tasks/pre.yml @@ -29,7 +29,7 @@ register: calico_kubelet_name delegate_to: "{{ groups['kube_control_plane'][0] }}" when: - - "cloud_provider is defined" + - cloud_provider - name: Calico | Gather os specific variables include_vars: "{{ item }}" diff --git a/tests/testcases/040_check-network-adv.yml b/tests/testcases/040_check-network-adv.yml index 45cf6db28..504826071 100644 --- a/tests/testcases/040_check-network-adv.yml +++ b/tests/testcases/040_check-network-adv.yml @@ -7,7 +7,7 @@ args: executable: /bin/bash when: - - (calico_ipip_mode is defined and calico_ipip_mode != 'Never' or cloud_provider is defined) + - (calico_ipip_mode is defined and calico_ipip_mode != 'Never') - kube_network_plugin | default('calico') == 'calico' - name: Advanced testcases for network