From 989e9174c2cdf766a004697472280ee9e28c42e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Wed, 31 Jan 2018 09:15:46 +0100 Subject: [PATCH 1/4] Added vSphere cloud provider config update for Kubernetes >= 1.9.2 --- docs/vsphere.md | 5 +-- roles/kubernetes/preinstall/defaults/main.yml | 2 ++ .../templates/vsphere-cloud-config.j2 | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/vsphere.md b/docs/vsphere.md index 5374304c1..9badf6f8d 100644 --- a/docs/vsphere.md +++ b/docs/vsphere.md @@ -34,9 +34,9 @@ Then, in the same file, you need to declare your vCenter credential following th | vsphere_datastore | TRUE | string | | | Datastore name to use | | vsphere_working_dir | TRUE | string | | | Working directory from the view "VMs and template" in the vCenter where VM are placed | | vsphere_scsi_controller_type | TRUE | string | buslogic, pvscsi, parallel | pvscsi | SCSI controller name. Commonly "pvscsi". | -| vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` | +| vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` (only optional for Kubernetes <= 1.9.2) | | vsphere_public_network | FALSE | string | | Blank | Name of the network the VMs are joined to | - +| vsphere_resource_pool | FALSE | string | | Blank | Name of the Resource pool where the VMs are located (optional for Kubernetes >= 1.9.2) | Example configuration ```yml vsphere_vcenter_ip: "myvcenter.domain.com" @@ -48,6 +48,7 @@ vsphere_datacenter: "DATACENTER_name" vsphere_datastore: "DATASTORE_name" vsphere_working_dir: "Docker_hosts" vsphere_scsi_controller_type: "pvscsi" +vsphere_resource_pool: "K8s-Pool" ``` ## Deployment diff --git a/roles/kubernetes/preinstall/defaults/main.yml b/roles/kubernetes/preinstall/defaults/main.yml index e81a2a148..4199d4c7f 100644 --- a/roles/kubernetes/preinstall/defaults/main.yml +++ b/roles/kubernetes/preinstall/defaults/main.yml @@ -47,6 +47,8 @@ vsphere_datacenter: "{{ lookup('env', 'VSPHERE_DATACENTER') }}" vsphere_datastore: "{{ lookup('env', 'VSPHERE_DATASTORE') }}" vsphere_working_dir: "{{ lookup('env', 'VSPHERE_WORKING_DIR') }}" vsphere_insecure: "{{ lookup('env', 'VSPHERE_INSECURE') }}" +vsphere_resource_pool: "{{ lookup('env', 'VSPHERE_RESOURCE_POOL') }}" + vsphere_scsi_controller_type: pvscsi # vsphere_public_network is name of the network the VMs are joined to vsphere_public_network: "{{ lookup('env', 'VSPHERE_PUBLIC_NETWORK')|default('') }}" diff --git a/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 b/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 index ab58f7485..0097e6221 100644 --- a/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 +++ b/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 @@ -1,3 +1,31 @@ +{%- if kube_version | version_compare('v1.9.2', '>=') -%} + +[Global] +datacenters = "{{ vsphere_datacenter }}" +insecure-flag = {{ vsphere_insecure }} +password = "{{ vsphere_password }}" +port = {{ vsphere_vcenter_port }} +user = "{{ vsphere_user }}" + +[VirtualCenter "{{ vsphere_vcenter_ip }}"] + +[Workspace] +server = "{{ vsphere_vcenter_ip }}" +datacenter = "{{ vsphere_datacenter }}" +folder = "{{ vsphere_working_dir }}" +default-datastore = "{{ vsphere_datastore }}" +resourcepool-path = "{{ vsphere_resource_pool }}" + +[Disk] +scsicontrollertype = {{ vsphere_scsi_controller_type }} + +{% if vsphere_public_network is defined and vsphere_public_network != "" %} +[Network] +public-network = {{ vsphere_public_network }} +{% endif %} + +{%- else -%} + [Global] datacenter = "{{ vsphere_datacenter }}" datastore = "{{ vsphere_datastore }}" @@ -18,3 +46,6 @@ scsicontrollertype = {{ vsphere_scsi_controller_type }} [Network] public-network = {{ vsphere_public_network }} {% endif %} + + +{%- endif -%} \ No newline at end of file From fc29764911798b9217da1edaf200c218326831b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Wed, 31 Jan 2018 09:27:45 +0100 Subject: [PATCH 2/4] fixed broken variables table --- docs/vsphere.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/vsphere.md b/docs/vsphere.md index 9badf6f8d..84d4d2ebc 100644 --- a/docs/vsphere.md +++ b/docs/vsphere.md @@ -37,7 +37,9 @@ Then, in the same file, you need to declare your vCenter credential following th | vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` (only optional for Kubernetes <= 1.9.2) | | vsphere_public_network | FALSE | string | | Blank | Name of the network the VMs are joined to | | vsphere_resource_pool | FALSE | string | | Blank | Name of the Resource pool where the VMs are located (optional for Kubernetes >= 1.9.2) | + Example configuration + ```yml vsphere_vcenter_ip: "myvcenter.domain.com" vsphere_vcenter_port: 443 From 9cdd2214f9d9e13834ba7e893feb0872fe36bfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Wed, 31 Jan 2018 09:56:43 +0100 Subject: [PATCH 3/4] render vsphere_resource_pool only if defined --- roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 b/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 index 0097e6221..94258135f 100644 --- a/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 +++ b/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 @@ -14,7 +14,11 @@ server = "{{ vsphere_vcenter_ip }}" datacenter = "{{ vsphere_datacenter }}" folder = "{{ vsphere_working_dir }}" default-datastore = "{{ vsphere_datastore }}" + +{% if vsphere_resource_pool is defined and vsphere_resource_pool != "" %} resourcepool-path = "{{ vsphere_resource_pool }}" +{% endif %} + [Disk] scsicontrollertype = {{ vsphere_scsi_controller_type }} From 7f79210ed197d6328796fb295d8992226ebce057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Wed, 31 Jan 2018 16:51:23 +0100 Subject: [PATCH 4/4] reworked vsphere-cloud-config template --- docs/vsphere.md | 4 +- .../templates/vsphere-cloud-config.j2 | 50 +++++++------------ 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/docs/vsphere.md b/docs/vsphere.md index 84d4d2ebc..8f91cf078 100644 --- a/docs/vsphere.md +++ b/docs/vsphere.md @@ -34,9 +34,9 @@ Then, in the same file, you need to declare your vCenter credential following th | vsphere_datastore | TRUE | string | | | Datastore name to use | | vsphere_working_dir | TRUE | string | | | Working directory from the view "VMs and template" in the vCenter where VM are placed | | vsphere_scsi_controller_type | TRUE | string | buslogic, pvscsi, parallel | pvscsi | SCSI controller name. Commonly "pvscsi". | -| vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` (only optional for Kubernetes <= 1.9.2) | +| vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` (Optional, only used for Kubernetes <= 1.9.2) | | vsphere_public_network | FALSE | string | | Blank | Name of the network the VMs are joined to | -| vsphere_resource_pool | FALSE | string | | Blank | Name of the Resource pool where the VMs are located (optional for Kubernetes >= 1.9.2) | +| vsphere_resource_pool | FALSE | string | | Blank | Name of the Resource pool where the VMs are located (Optional, only used for Kubernetes >= 1.9.2) | Example configuration diff --git a/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 b/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 index 94258135f..d82d72bf8 100644 --- a/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 +++ b/roles/kubernetes/preinstall/templates/vsphere-cloud-config.j2 @@ -1,47 +1,36 @@ -{%- if kube_version | version_compare('v1.9.2', '>=') -%} - [Global] -datacenters = "{{ vsphere_datacenter }}" -insecure-flag = {{ vsphere_insecure }} +user = "{{ vsphere_user }}" password = "{{ vsphere_password }}" port = {{ vsphere_vcenter_port }} -user = "{{ vsphere_user }}" +insecure-flag = {{ vsphere_insecure }} + +{% if kube_version | version_compare('v1.9.2', '>=') %} +datacenters = "{{ vsphere_datacenter }}" +{% else %} +datastore = "{{ vsphere_datastore }}" +datacenter = "{{ vsphere_datacenter }}" +working-dir = "{{ vsphere_working_dir }}" +server = "{{ vsphere_vcenter_ip }}" +{% if vsphere_vm_uuid is defined and vsphere_vm_uuid != "" %} +vm-uuid = "{{ vsphere_vm_uuid }}" +{% endif %} +{% endif %} + +{% if kube_version | version_compare('v1.9.2', '>=') %} [VirtualCenter "{{ vsphere_vcenter_ip }}"] + [Workspace] server = "{{ vsphere_vcenter_ip }}" datacenter = "{{ vsphere_datacenter }}" folder = "{{ vsphere_working_dir }}" default-datastore = "{{ vsphere_datastore }}" - {% if vsphere_resource_pool is defined and vsphere_resource_pool != "" %} resourcepool-path = "{{ vsphere_resource_pool }}" {% endif %} - - -[Disk] -scsicontrollertype = {{ vsphere_scsi_controller_type }} - -{% if vsphere_public_network is defined and vsphere_public_network != "" %} -[Network] -public-network = {{ vsphere_public_network }} {% endif %} -{%- else -%} - -[Global] -datacenter = "{{ vsphere_datacenter }}" -datastore = "{{ vsphere_datastore }}" -insecure-flag = {{ vsphere_insecure }} -password = "{{ vsphere_password }}" -port = {{ vsphere_vcenter_port }} -server = "{{ vsphere_vcenter_ip }}" -user = "{{ vsphere_user }}" -working-dir = "{{ vsphere_working_dir }}" -{% if vsphere_vm_uuid is defined %} -vm-uuid = {{ vsphere_vm_uuid }} -{% endif %} [Disk] scsicontrollertype = {{ vsphere_scsi_controller_type }} @@ -49,7 +38,4 @@ scsicontrollertype = {{ vsphere_scsi_controller_type }} {% if vsphere_public_network is defined and vsphere_public_network != "" %} [Network] public-network = {{ vsphere_public_network }} -{% endif %} - - -{%- endif -%} \ No newline at end of file +{% endif %} \ No newline at end of file