From 5c16358d0cc26ce79882af71fce2fb0a4cf66046 Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Tue, 3 Apr 2018 11:25:07 -0700 Subject: [PATCH] optionally use ip as node name --- docs/input-variables.md | 1 + instances/k8smaster/datasources.tf | 1 + instances/k8smaster/scripts/setup.template.sh | 8 +++++++- instances/k8smaster/variables.tf | 4 ++++ instances/k8sworker/datasources.tf | 1 + instances/k8sworker/scripts/setup.template.sh | 8 +++++++- instances/k8sworker/variables.tf | 4 ++++ k8s-oci.tf | 6 ++++++ variables.tf | 4 ++++ 9 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/input-variables.md b/docs/input-variables.md index cf6f81e..a84c8ef 100644 --- a/docs/input-variables.md +++ b/docs/input-variables.md @@ -39,6 +39,7 @@ worker_iscsi_volume_size | unset | optional size of worker_iscsi_volume_mount | /var/lib/docker | optional mount path of iSCSI volume when worker_iscsi_volume_size is set etcd_iscsi_volume_create | false | boolean flag indicating whether or not to attach an iSCSI volume to attach to each etcd node etcd_iscsi_volume_size | 50 | size in GBs of volume when etcd_iscsi_volume_create is set +use_hostname_as_nodename | true | use the hostname for the node name, otherwise use just the ip ### TLS Certificates & SSH key pair name | default | description diff --git a/instances/k8smaster/datasources.tf b/instances/k8smaster/datasources.tf index 0f4d93d..5a39e39 100644 --- a/instances/k8smaster/datasources.tf +++ b/instances/k8smaster/datasources.tf @@ -25,6 +25,7 @@ data "template_file" "setup-template" { cloud_controller_version = "${var.cloud_controller_version}" flexvolume_driver_version = "${var.flexvolume_driver_version}" volume_provisioner_version = "${var.volume_provisioner_version}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename ? "true" : "false"}" } } diff --git a/instances/k8smaster/scripts/setup.template.sh b/instances/k8smaster/scripts/setup.template.sh index 1fd50f7..91c43bf 100644 --- a/instances/k8smaster/scripts/setup.template.sh +++ b/instances/k8smaster/scripts/setup.template.sh @@ -2,7 +2,13 @@ EXTERNAL_IP=$(curl -s -m 10 http://whatismyip.akamai.com/) NAMESPACE=$(echo -n "${domain_name}" | sed "s/\.oraclevcn\.com//g") -FQDN_HOSTNAME=$(getent hosts $(ip route get 1 | awk '{print $NF;exit}') | awk '{print $2}') +FQDN_HOSTNAME=$(ip route get 1 | awk '{print $NF;exit}') + +## Should we even use Terraform anymore? +if [[ "${use_hostname_as_nodename}" = "true" ]]; +then + FQDN_HOSTNAME=$(getent hosts $FQDN_HOSTNAME | awk '{print $2}') +fi # Pull instance metadata curl -sL --retry 3 http://169.254.169.254/opc/v1/instance/ | tee /tmp/instance_meta.json diff --git a/instances/k8smaster/variables.tf b/instances/k8smaster/variables.tf index ca475a8..d32f845 100644 --- a/instances/k8smaster/variables.tf +++ b/instances/k8smaster/variables.tf @@ -95,3 +95,7 @@ variable "assign_private_ip" { description = "Assign a static private ip based on CIDR block for that AD" default = false } + +variable "use_hostname_as_nodename" { + default = true +} diff --git a/instances/k8sworker/datasources.tf b/instances/k8sworker/datasources.tf index d4a67a7..1a3d498 100644 --- a/instances/k8sworker/datasources.tf +++ b/instances/k8sworker/datasources.tf @@ -26,6 +26,7 @@ data "template_file" "setup-template" { worker_iscsi_volume_mount = "${var.worker_iscsi_volume_mount}" flexvolume_driver_version = "${var.flexvolume_driver_version}" reverse_proxy_setup = "${var.reverse_proxy_setup}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename ? "true" : "false"}" } } diff --git a/instances/k8sworker/scripts/setup.template.sh b/instances/k8sworker/scripts/setup.template.sh index ee4029e..a59c79f 100644 --- a/instances/k8sworker/scripts/setup.template.sh +++ b/instances/k8sworker/scripts/setup.template.sh @@ -2,7 +2,13 @@ EXTERNAL_IP=$(curl -s -m 10 http://whatismyip.akamai.com/) NAMESPACE=$(echo -n "${domain_name}" | sed "s/\.oraclevcn\.com//g") -FQDN_HOSTNAME=$(getent hosts $(ip route get 1 | awk '{print $NF;exit}') | awk '{print $2}') +FQDN_HOSTNAME=$(ip route get 1 | awk '{print $NF;exit}') + +## Should we even use Terraform anymore? +if [[ "${use_hostname_as_nodename}" = "true" ]]; +then + FQDN_HOSTNAME=$(getent hosts $FQDN_HOSTNAME | awk '{print $2}') +fi # Pull instance metadata curl -sL --retry 3 http://169.254.169.254/opc/v1/instance/ | tee /tmp/instance_meta.json diff --git a/instances/k8sworker/variables.tf b/instances/k8sworker/variables.tf index 975338f..87af15a 100644 --- a/instances/k8sworker/variables.tf +++ b/instances/k8sworker/variables.tf @@ -87,3 +87,7 @@ variable "flexvolume_driver_version" {} variable "reverse_proxy_setup" {} variable "reverse_proxy_clount_init" {} + +variable "use_hostname_as_nodename" { + default = true +} diff --git a/k8s-oci.tf b/k8s-oci.tf index da4e63a..e98bd7b 100644 --- a/k8s-oci.tf +++ b/k8s-oci.tf @@ -237,6 +237,7 @@ module "instances-k8smaster-ad1" { volume_provisioner_secret = "${module.oci-volume-provisioner.volume-provisioner-yaml}" assign_private_ip = "${var.master_maintain_private_ip}" etcd_endpoints = "${local.etcd_endpoints}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename}" } module "instances-k8smaster-ad2" { @@ -280,6 +281,7 @@ module "instances-k8smaster-ad2" { volume_provisioner_secret = "${module.oci-volume-provisioner.volume-provisioner-yaml}" assign_private_ip = "${var.master_maintain_private_ip}" etcd_endpoints = "${local.etcd_endpoints}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename}" } module "instances-k8smaster-ad3" { @@ -323,6 +325,7 @@ module "instances-k8smaster-ad3" { volume_provisioner_secret = "${module.oci-volume-provisioner.volume-provisioner-yaml}" assign_private_ip = "${var.master_maintain_private_ip}" etcd_endpoints = "${local.etcd_endpoints}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename}" } module "instances-k8sworker-ad1" { @@ -360,6 +363,7 @@ module "instances-k8sworker-ad1" { worker_iscsi_volume_create = "${var.worker_iscsi_volume_create}" worker_iscsi_volume_size = "${var.worker_iscsi_volume_size}" worker_iscsi_volume_mount = "${var.worker_iscsi_volume_mount}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename}" } module "instances-k8sworker-ad2" { @@ -397,6 +401,7 @@ module "instances-k8sworker-ad2" { worker_iscsi_volume_create = "${var.worker_iscsi_volume_create}" worker_iscsi_volume_size = "${var.worker_iscsi_volume_size}" worker_iscsi_volume_mount = "${var.worker_iscsi_volume_mount}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename}" } module "instances-k8sworker-ad3" { @@ -434,6 +439,7 @@ module "instances-k8sworker-ad3" { worker_iscsi_volume_create = "${var.worker_iscsi_volume_create}" worker_iscsi_volume_size = "${var.worker_iscsi_volume_size}" worker_iscsi_volume_mount = "${var.worker_iscsi_volume_mount}" + use_hostname_as_nodename = "${var.use_hostname_as_nodename}" } ### Load Balancers diff --git a/variables.tf b/variables.tf index 39c91f5..4dca9c5 100644 --- a/variables.tf +++ b/variables.tf @@ -480,3 +480,7 @@ variable "volume_provisioner_user_private_key_path" { variable "volume_provisioner_user_private_key_password" { default = "" } + +variable "use_hostname_as_nodename" { + default = true +}