Browse Source

Refactor: simpify cloud_provider is defined condition

For this change, `cloud_provider` change the default value to empty
string.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
pull/11633/head
ChengHao Yang 2 weeks ago
parent
commit
38cd05c503
Failed to extract signature
7 changed files with 9 additions and 12 deletions
  1. 5
      roles/kubernetes-apps/external_cloud_controller/meta/main.yml
  2. 2
      roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2
  3. 2
      roles/kubernetes/node/templates/kubelet.env.v1beta1.j2
  4. 5
      roles/kubernetes/preinstall/tasks/0040-verify-settings.yml
  5. 3
      roles/kubespray-defaults/defaults/main/main.yml
  6. 2
      roles/network_plugin/calico/tasks/pre.yml
  7. 2
      tests/testcases/040_check-network-adv.yml

5
roles/kubernetes-apps/external_cloud_controller/meta/main.yml

@ -2,7 +2,6 @@
dependencies: dependencies:
- role: kubernetes-apps/external_cloud_controller/openstack - role: kubernetes-apps/external_cloud_controller/openstack
when: when:
- cloud_provider is defined
- cloud_provider == "external" - cloud_provider == "external"
- external_cloud_provider is defined - external_cloud_provider is defined
- external_cloud_provider == "openstack" - external_cloud_provider == "openstack"
@ -12,7 +11,6 @@ dependencies:
- external-openstack - external-openstack
- role: kubernetes-apps/external_cloud_controller/vsphere - role: kubernetes-apps/external_cloud_controller/vsphere
when: when:
- cloud_provider is defined
- cloud_provider == "external" - cloud_provider == "external"
- external_cloud_provider is defined - external_cloud_provider is defined
- external_cloud_provider == "vsphere" - external_cloud_provider == "vsphere"
@ -22,7 +20,6 @@ dependencies:
- external-vsphere - external-vsphere
- role: kubernetes-apps/external_cloud_controller/hcloud - role: kubernetes-apps/external_cloud_controller/hcloud
when: when:
- cloud_provider is defined
- cloud_provider == "external" - cloud_provider == "external"
- external_cloud_provider is defined - external_cloud_provider is defined
- external_cloud_provider == "hcloud" - external_cloud_provider == "hcloud"
@ -32,7 +29,6 @@ dependencies:
- external-hcloud - external-hcloud
- role: kubernetes-apps/external_cloud_controller/huaweicloud - role: kubernetes-apps/external_cloud_controller/huaweicloud
when: when:
- cloud_provider is defined
- cloud_provider == "external" - cloud_provider == "external"
- external_cloud_provider is defined - external_cloud_provider is defined
- external_cloud_provider == "huaweicloud" - external_cloud_provider == "huaweicloud"
@ -42,7 +38,6 @@ dependencies:
- external-huaweicloud - external-huaweicloud
- role: kubernetes-apps/external_cloud_controller/oci - role: kubernetes-apps/external_cloud_controller/oci
when: when:
- cloud_provider is defined
- cloud_provider == "external" - cloud_provider == "external"
- external_cloud_provider is defined - external_cloud_provider is defined
- external_cloud_provider == "oci" - external_cloud_provider == "oci"

2
roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2

@ -24,7 +24,7 @@ nodeRegistration:
taints: [] taints: []
{% endif %} {% endif %}
criSocket: {{ cri_socket }} criSocket: {{ cri_socket }}
{% if cloud_provider is defined and cloud_provider in ["external"] %}
{% if cloud_provider == "external" %}
kubeletExtraArgs: kubeletExtraArgs:
cloud-provider: external cloud-provider: external
{% endif %} {% endif %}

2
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" %} {% if kube_network_plugin is defined and kube_network_plugin == "cloud" %}
KUBELET_NETWORK_PLUGIN="--hairpin-mode=promiscuous-bridge --network-plugin=kubenet" KUBELET_NETWORK_PLUGIN="--hairpin-mode=promiscuous-bridge --network-plugin=kubenet"
{% endif %} {% endif %}
{% if cloud_provider is defined and cloud_provider in ["external"] %}
{% if cloud_provider == "external" %}
KUBELET_CLOUDPROVIDER="--cloud-provider={{ cloud_provider }}" KUBELET_CLOUDPROVIDER="--cloud-provider={{ cloud_provider }}"
{% else %} {% else %}
KUBELET_CLOUDPROVIDER="" KUBELET_CLOUDPROVIDER=""

5
roles/kubernetes/preinstall/tasks/0040-verify-settings.yml

@ -166,10 +166,9 @@
- name: Check cloud_provider value - name: Check cloud_provider value
assert: assert:
that: cloud_provider in ['external']
msg: "If set the 'cloud_provider' var must be set either to 'external'"
that: cloud_provider == 'external'
when: when:
- cloud_provider is defined
- cloud_provider
- not ignore_assert_errors - not ignore_assert_errors
tags: tags:
- cloud-provider - cloud-provider

3
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 # to give normal pods time to be gracefully evacuated
kubelet_shutdown_grace_period_critical_pods: 20s 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 # Whether to deploy the container engine
deploy_container_engine: "{{ 'k8s_cluster' in group_names or etcd_deployment_type == 'docker' }}" deploy_container_engine: "{{ 'k8s_cluster' in group_names or etcd_deployment_type == 'docker' }}"

2
roles/network_plugin/calico/tasks/pre.yml

@ -29,7 +29,7 @@
register: calico_kubelet_name register: calico_kubelet_name
delegate_to: "{{ groups['kube_control_plane'][0] }}" delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: when:
- "cloud_provider is defined"
- cloud_provider
- name: Calico | Gather os specific variables - name: Calico | Gather os specific variables
include_vars: "{{ item }}" include_vars: "{{ item }}"

2
tests/testcases/040_check-network-adv.yml

@ -7,7 +7,7 @@
args: args:
executable: /bin/bash executable: /bin/bash
when: 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' - kube_network_plugin | default('calico') == 'calico'
- name: Advanced testcases for network - name: Advanced testcases for network

Loading…
Cancel
Save