From a070c72214a14e3c3557b8c09db563aca2e3d831 Mon Sep 17 00:00:00 2001 From: ChengHao Yang <17496418+tico88612@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:45:00 +0800 Subject: [PATCH] Refactor: simpify external_cloud_provider is defined For this change, `external_cloud_provider` set default value to empty string. Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com> --- .../external_cloud_controller/meta/main.yml | 5 ----- .../preinstall/tasks/0040-verify-settings.yml | 10 ++++++++++ roles/kubespray-defaults/defaults/main/main.yml | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/roles/kubernetes-apps/external_cloud_controller/meta/main.yml b/roles/kubernetes-apps/external_cloud_controller/meta/main.yml index f5325a54e..fffd57a32 100644 --- a/roles/kubernetes-apps/external_cloud_controller/meta/main.yml +++ b/roles/kubernetes-apps/external_cloud_controller/meta/main.yml @@ -3,7 +3,6 @@ dependencies: - role: kubernetes-apps/external_cloud_controller/openstack when: - cloud_provider == "external" - - external_cloud_provider is defined - external_cloud_provider == "openstack" - inventory_hostname == groups['kube_control_plane'][0] tags: @@ -12,7 +11,6 @@ dependencies: - role: kubernetes-apps/external_cloud_controller/vsphere when: - cloud_provider == "external" - - external_cloud_provider is defined - external_cloud_provider == "vsphere" - inventory_hostname == groups['kube_control_plane'][0] tags: @@ -21,7 +19,6 @@ dependencies: - role: kubernetes-apps/external_cloud_controller/hcloud when: - cloud_provider == "external" - - external_cloud_provider is defined - external_cloud_provider == "hcloud" - inventory_hostname == groups['kube_control_plane'][0] tags: @@ -30,7 +27,6 @@ dependencies: - role: kubernetes-apps/external_cloud_controller/huaweicloud when: - cloud_provider == "external" - - external_cloud_provider is defined - external_cloud_provider == "huaweicloud" - inventory_hostname == groups['kube_control_plane'][0] tags: @@ -39,7 +35,6 @@ dependencies: - role: kubernetes-apps/external_cloud_controller/oci when: - cloud_provider == "external" - - external_cloud_provider is defined - external_cloud_provider == "oci" - inventory_hostname == groups['kube_control_plane'][0] tags: diff --git a/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml b/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml index c074526fd..2e57b1a1c 100644 --- a/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml +++ b/roles/kubernetes/preinstall/tasks/0040-verify-settings.yml @@ -174,6 +174,16 @@ - cloud-provider - facts +- name: Check external_cloud_provider value + assert: + that: external_cloud_provider in ['hcloud', 'huaweicloud', 'oci', 'openstack', 'vsphere'] + when: + - cloud_provider == 'external' + - not ignore_assert_errors + tags: + - cloud-provider + - facts + - name: "Check that kube_service_addresses is a network range" assert: that: diff --git a/roles/kubespray-defaults/defaults/main/main.yml b/roles/kubespray-defaults/defaults/main/main.yml index d9653a66f..939027f87 100644 --- a/roles/kubespray-defaults/defaults/main/main.yml +++ b/roles/kubespray-defaults/defaults/main/main.yml @@ -274,6 +274,12 @@ 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: "" +# External Cloud Controller Manager (Formerly known as cloud provider) +# cloud_provider must be "external", otherwise this setting is invalid. +# Supported external cloud controllers are: 'openstack', 'vsphere', 'oci', 'huaweicloud' and 'hcloud' +# If you fill in a value other than the above, the check will fail. +external_cloud_provider: "" + # Whether to deploy the container engine deploy_container_engine: "{{ 'k8s_cluster' in group_names or etcd_deployment_type == 'docker' }}"