diff --git a/CHANGES.md b/CHANGES.md index 8446396c..13c6e33d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,10 @@ Notable changes between versions. * To SSH during a disk install for debugging, SSH as user "core" with port 2222 * Remove the old trick of using a user "debug" during disk install +#### Google Cloud + +* Refactor out the `controller` internal module + #### Addons * Add Prometheus discovery for etcd peers on controller nodes ([#175](https://github.com/poseidon/typhoon/pull/175)) diff --git a/google-cloud/container-linux/kubernetes/controllers/network.tf b/google-cloud/container-linux/kubernetes/apiserver.tf similarity index 97% rename from google-cloud/container-linux/kubernetes/controllers/network.tf rename to google-cloud/container-linux/kubernetes/apiserver.tf index 97fb3ac5..f7f41dba 100644 --- a/google-cloud/container-linux/kubernetes/controllers/network.tf +++ b/google-cloud/container-linux/kubernetes/apiserver.tf @@ -17,7 +17,7 @@ resource "google_dns_record_set" "controllers" { rrdatas = ["${google_compute_address.controllers-ip.address}"] } -# Network Load Balancer (i.e. forwarding rule) +# Network Load Balancer for controllers resource "google_compute_forwarding_rule" "controller-https-rule" { name = "${var.cluster_name}-controller-https-rule" ip_address = "${google_compute_address.controllers-ip.address}" diff --git a/google-cloud/container-linux/kubernetes/bootkube.tf b/google-cloud/container-linux/kubernetes/bootkube.tf index eed49493..221c9432 100644 --- a/google-cloud/container-linux/kubernetes/bootkube.tf +++ b/google-cloud/container-linux/kubernetes/bootkube.tf @@ -4,7 +4,7 @@ module "bootkube" { cluster_name = "${var.cluster_name}" api_servers = ["${format("%s.%s", var.cluster_name, var.dns_zone)}"] - etcd_servers = "${module.controllers.etcd_fqdns}" + etcd_servers = ["${null_resource.repeat.*.triggers.domain}"] asset_dir = "${var.asset_dir}" networking = "${var.networking}" network_mtu = 1440 diff --git a/google-cloud/container-linux/kubernetes/controllers/cl/controller.yaml.tmpl b/google-cloud/container-linux/kubernetes/cl/controller.yaml.tmpl similarity index 100% rename from google-cloud/container-linux/kubernetes/controllers/cl/controller.yaml.tmpl rename to google-cloud/container-linux/kubernetes/cl/controller.yaml.tmpl diff --git a/google-cloud/container-linux/kubernetes/cluster.tf b/google-cloud/container-linux/kubernetes/cluster.tf deleted file mode 100644 index f1031d1e..00000000 --- a/google-cloud/container-linux/kubernetes/cluster.tf +++ /dev/null @@ -1,44 +0,0 @@ -module "controllers" { - source = "controllers" - cluster_name = "${var.cluster_name}" - - # GCE - region = "${var.region}" - network = "${google_compute_network.network.name}" - dns_zone = "${var.dns_zone}" - dns_zone_name = "${var.dns_zone_name}" - count = "${var.controller_count}" - machine_type = "${var.controller_type}" - os_image = "${var.os_image}" - disk_size = "${var.disk_size}" - - # configuration - networking = "${var.networking}" - kubeconfig = "${module.bootkube.kubeconfig}" - ssh_authorized_key = "${var.ssh_authorized_key}" - service_cidr = "${var.service_cidr}" - cluster_domain_suffix = "${var.cluster_domain_suffix}" - clc_snippets = "${var.controller_clc_snippets}" -} - -module "workers" { - source = "workers" - name = "${var.cluster_name}" - cluster_name = "${var.cluster_name}" - - # GCE - region = "${var.region}" - network = "${google_compute_network.network.name}" - count = "${var.worker_count}" - machine_type = "${var.worker_type}" - os_image = "${var.os_image}" - disk_size = "${var.disk_size}" - preemptible = "${var.worker_preemptible}" - - # configuration - kubeconfig = "${module.bootkube.kubeconfig}" - ssh_authorized_key = "${var.ssh_authorized_key}" - service_cidr = "${var.service_cidr}" - cluster_domain_suffix = "${var.cluster_domain_suffix}" - clc_snippets = "${var.worker_clc_snippets}" -} diff --git a/google-cloud/container-linux/kubernetes/controllers/controllers.tf b/google-cloud/container-linux/kubernetes/controllers.tf similarity index 81% rename from google-cloud/container-linux/kubernetes/controllers/controllers.tf rename to google-cloud/container-linux/kubernetes/controllers.tf index d1821d76..9acce2dc 100644 --- a/google-cloud/container-linux/kubernetes/controllers/controllers.tf +++ b/google-cloud/container-linux/kubernetes/controllers.tf @@ -1,6 +1,6 @@ # Discrete DNS records for each controller's private IPv4 for etcd usage resource "google_dns_record_set" "etcds" { - count = "${var.count}" + count = "${var.controller_count}" # DNS Zone name where record should be created managed_zone = "${var.dns_zone_name}" @@ -21,11 +21,11 @@ data "google_compute_zones" "all" { # Controller instances resource "google_compute_instance" "controllers" { - count = "${var.count}" + count = "${var.controller_count}" name = "${var.cluster_name}-controller-${count.index}" zone = "${element(data.google_compute_zones.all.names, count.index)}" - machine_type = "${var.machine_type}" + machine_type = "${var.controller_type}" metadata { user-data = "${element(data.ct_config.controller_ign.*.rendered, count.index)}" @@ -41,7 +41,7 @@ resource "google_compute_instance" "controllers" { } network_interface { - network = "${var.network}" + network = "${google_compute_network.network.name}" # Ephemeral external IP access_config = {} @@ -51,9 +51,13 @@ resource "google_compute_instance" "controllers" { tags = ["${var.cluster_name}-controller"] } +locals { + controllers_ipv4_public = ["${google_compute_instance.controllers.*.network_interface.0.access_config.0.assigned_nat_ip}"] +} + # Controller Container Linux Config data "template_file" "controller_config" { - count = "${var.count}" + count = "${var.controller_count}" template = "${file("${path.module}/cl/controller.yaml.tmpl")}" @@ -65,7 +69,7 @@ data "template_file" "controller_config" { # etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,... etcd_initial_cluster = "${join(",", formatlist("%s=https://%s:2380", null_resource.repeat.*.triggers.name, null_resource.repeat.*.triggers.domain))}" - kubeconfig = "${indent(10, var.kubeconfig)}" + kubeconfig = "${indent(10, module.bootkube.kubeconfig)}" ssh_authorized_key = "${var.ssh_authorized_key}" k8s_dns_service_ip = "${cidrhost(var.service_cidr, 10)}" cluster_domain_suffix = "${var.cluster_domain_suffix}" @@ -75,7 +79,7 @@ data "template_file" "controller_config" { # Horrible hack to generate a Terraform list of a desired length without dependencies. # Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]} resource null_resource "repeat" { - count = "${var.count}" + count = "${var.controller_count}" triggers { name = "etcd${count.index}" @@ -84,8 +88,8 @@ resource null_resource "repeat" { } data "ct_config" "controller_ign" { - count = "${var.count}" + count = "${var.controller_count}" content = "${element(data.template_file.controller_config.*.rendered, count.index)}" pretty_print = false - snippets = ["${var.clc_snippets}"] + snippets = ["${var.controller_clc_snippets}"] } diff --git a/google-cloud/container-linux/kubernetes/controllers/outputs.tf b/google-cloud/container-linux/kubernetes/controllers/outputs.tf deleted file mode 100644 index 97bbf957..00000000 --- a/google-cloud/container-linux/kubernetes/controllers/outputs.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "etcd_fqdns" { - value = ["${null_resource.repeat.*.triggers.domain}"] -} - -output "ipv4_public" { - value = ["${google_compute_instance.controllers.*.network_interface.0.access_config.0.assigned_nat_ip}"] -} diff --git a/google-cloud/container-linux/kubernetes/controllers/variables.tf b/google-cloud/container-linux/kubernetes/controllers/variables.tf deleted file mode 100644 index b42bab52..00000000 --- a/google-cloud/container-linux/kubernetes/controllers/variables.tf +++ /dev/null @@ -1,87 +0,0 @@ -variable "cluster_name" { - type = "string" - description = "Unique cluster name" -} - -variable "region" { - type = "string" - description = "Google Cloud region (e.g. us-central1, see `gcloud compute regions list`)." -} - -variable "network" { - type = "string" - description = "Name of the network to attach to the compute instance interfaces" -} - -variable "dns_zone" { - type = "string" - description = "Google Cloud DNS Zone value to create etcd/k8s subdomains (e.g. dghubble.io)" -} - -variable "dns_zone_name" { - type = "string" - description = "Google Cloud DNS Zone name to create etcd/k8s subdomains (e.g. dghubble-io)" -} - -# instances - -variable "count" { - type = "string" - description = "Number of controller compute instances the instance group should manage" -} - -variable "machine_type" { - type = "string" - description = "Machine type for compute instances (e.g. gcloud compute machine-types list)" -} - -variable "os_image" { - type = "string" - description = "OS image from which to initialize the disk (e.g. gcloud compute images list)" -} - -variable "disk_size" { - type = "string" - default = "40" - description = "Size of the disk in GB" -} - -# configuration - -variable "networking" { - description = "Choice of networking provider (flannel or calico)" - type = "string" - default = "calico" -} - -variable "kubeconfig" { - type = "string" - description = "Generated Kubelet kubeconfig" -} - -variable "ssh_authorized_key" { - type = "string" - description = "SSH public key for logging in as user 'core'" -} - -variable "service_cidr" { - description = <