From 5eb11f510493bdcfac83ae530552a4f144fbd0b1 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Tue, 8 May 2018 22:38:05 -0700 Subject: [PATCH] Allow Flatcar Linux os_image on AWS, rename os_channel * Replace os_channel variable with os_image to align naming across clouds. Users who set this option to stable, beta, or alpha should now set os_image to coreos-stable, coreos-beta, or coreos-alpha. * Default os_image to coreos-stable. This continues to use the most recent image from the stable channel as always. * Allow Container Linux derivative Flatcar Linux by setting os_image to `flatcar-stable`, `flatcar-beta`, `flatcar-alpha` --- CHANGES.md | 8 +++-- aws/container-linux/kubernetes/ami.tf | 32 ++++++++++++++++++- aws/container-linux/kubernetes/controllers.tf | 2 +- aws/container-linux/kubernetes/variables.tf | 6 ++-- aws/container-linux/kubernetes/workers.tf | 2 +- aws/container-linux/kubernetes/workers/ami.tf | 32 ++++++++++++++++++- .../kubernetes/workers/variables.tf | 6 ++-- .../kubernetes/workers/workers.tf | 2 +- docs/advanced/worker-pools.md | 4 +-- docs/cl/aws.md | 2 +- 10 files changed, 79 insertions(+), 17 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d0fabd3e..72099b8d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,10 +9,12 @@ Notable changes between versions. #### AWS -* Allow "preemptible" workers via spot instances ([#202](https://github.com/poseidon/typhoon/pull/202)) - * Add `worker_price` to allow worker spot instances. Defaults to empty string for the worker autoscaling group to use regular on-demand instances. +* Allow preemptible workers via spot instances ([#202](https://github.com/poseidon/typhoon/pull/202)) + * Add `worker_price` to allow worker spot instances. Default to empty string for the worker autoscaling group to use regular on-demand instances. * Add `spot_price` to internal `workers` module for spot [worker pools](https://typhoon.psdn.io/advanced/worker-pools/) - * Note: Unlike GCP `preemptible` workers, spot instances require you to pick a bid price. +* Allow Container Linux derivative [Flatcar Linux](https://docs.flatcar-linux.org/) by setting `os_image` to `flatcar-stable`, `flatcar-beta`, `flatcar-alpha`. +* Replace `os_channel` variable with `os_image` to align naming across clouds + * Please change values `stable`, `beta`, or `alpha` to `coreos-stable` (default), `coreos-beta`, `coreos-alpha` (action required!) #### Addons diff --git a/aws/container-linux/kubernetes/ami.tf b/aws/container-linux/kubernetes/ami.tf index 03c6c0f6..d995a4fa 100644 --- a/aws/container-linux/kubernetes/ami.tf +++ b/aws/container-linux/kubernetes/ami.tf @@ -1,3 +1,12 @@ +locals { + # Pick a CoreOS Container Linux derivative + # coreos-stable -> Container Linux AMI + # flatcar-stable -> Flatcar Linux AMI + ami_id = "${local.flavor == "flatcar" ? data.aws_ami.flatcar.image_id : data.aws_ami.coreos.image_id}" + flavor = "${element(split("-", var.os_image), 0)}" + channel = "${element(split("-", var.os_image), 1)}" +} + data "aws_ami" "coreos" { most_recent = true owners = ["595879546273"] @@ -14,6 +23,27 @@ data "aws_ami" "coreos" { filter { name = "name" - values = ["CoreOS-${var.os_channel}-*"] + values = ["CoreOS-${local.channel}-*"] } } + +data "aws_ami" "flatcar" { + most_recent = true + owners = ["075585003325"] + + filter { + name = "architecture" + values = ["x86_64"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "name" + values = ["Flatcar-${local.channel}-*"] + } +} + diff --git a/aws/container-linux/kubernetes/controllers.tf b/aws/container-linux/kubernetes/controllers.tf index 039dcfae..c08be944 100644 --- a/aws/container-linux/kubernetes/controllers.tf +++ b/aws/container-linux/kubernetes/controllers.tf @@ -23,7 +23,7 @@ resource "aws_instance" "controllers" { instance_type = "${var.controller_type}" - ami = "${data.aws_ami.coreos.image_id}" + ami = "${local.ami_id}" user_data = "${element(data.ct_config.controller_ign.*.rendered, count.index)}" # storage diff --git a/aws/container-linux/kubernetes/variables.tf b/aws/container-linux/kubernetes/variables.tf index a3eb2952..d24c7b6b 100644 --- a/aws/container-linux/kubernetes/variables.tf +++ b/aws/container-linux/kubernetes/variables.tf @@ -41,10 +41,10 @@ variable "worker_type" { description = "EC2 instance type for workers" } -variable "os_channel" { +variable "os_image" { type = "string" - default = "stable" - description = "Container Linux AMI channel (stable, beta, alpha)" + default = "coreos-stable" + description = "AMI channel for a Container Linux derivative (coreos-stable, coreos-beta, coreos-alpha, flatcar-stable, flatcar-beta, flatcar-alpha)" } variable "disk_size" { diff --git a/aws/container-linux/kubernetes/workers.tf b/aws/container-linux/kubernetes/workers.tf index 39091c32..8547402b 100644 --- a/aws/container-linux/kubernetes/workers.tf +++ b/aws/container-linux/kubernetes/workers.tf @@ -8,7 +8,7 @@ module "workers" { security_groups = ["${aws_security_group.worker.id}"] count = "${var.worker_count}" instance_type = "${var.worker_type}" - os_channel = "${var.os_channel}" + os_image = "${var.os_image}" disk_size = "${var.disk_size}" spot_price = "${var.worker_price}" diff --git a/aws/container-linux/kubernetes/workers/ami.tf b/aws/container-linux/kubernetes/workers/ami.tf index 03c6c0f6..d995a4fa 100644 --- a/aws/container-linux/kubernetes/workers/ami.tf +++ b/aws/container-linux/kubernetes/workers/ami.tf @@ -1,3 +1,12 @@ +locals { + # Pick a CoreOS Container Linux derivative + # coreos-stable -> Container Linux AMI + # flatcar-stable -> Flatcar Linux AMI + ami_id = "${local.flavor == "flatcar" ? data.aws_ami.flatcar.image_id : data.aws_ami.coreos.image_id}" + flavor = "${element(split("-", var.os_image), 0)}" + channel = "${element(split("-", var.os_image), 1)}" +} + data "aws_ami" "coreos" { most_recent = true owners = ["595879546273"] @@ -14,6 +23,27 @@ data "aws_ami" "coreos" { filter { name = "name" - values = ["CoreOS-${var.os_channel}-*"] + values = ["CoreOS-${local.channel}-*"] } } + +data "aws_ami" "flatcar" { + most_recent = true + owners = ["075585003325"] + + filter { + name = "architecture" + values = ["x86_64"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "name" + values = ["Flatcar-${local.channel}-*"] + } +} + diff --git a/aws/container-linux/kubernetes/workers/variables.tf b/aws/container-linux/kubernetes/workers/variables.tf index 0208b464..9b34a18a 100644 --- a/aws/container-linux/kubernetes/workers/variables.tf +++ b/aws/container-linux/kubernetes/workers/variables.tf @@ -34,10 +34,10 @@ variable "instance_type" { description = "EC2 instance type" } -variable "os_channel" { +variable "os_image" { type = "string" - default = "stable" - description = "Container Linux AMI channel (stable, beta, alpha)" + default = "coreos-stable" + description = "AMI channel for a Container Linux derivative (coreos-stable, coreos-beta, coreos-alpha, flatcar-stable, flatcar-beta, flatcar-alpha)" } variable "disk_size" { diff --git a/aws/container-linux/kubernetes/workers/workers.tf b/aws/container-linux/kubernetes/workers/workers.tf index fc6a6f7d..a7aea21e 100644 --- a/aws/container-linux/kubernetes/workers/workers.tf +++ b/aws/container-linux/kubernetes/workers/workers.tf @@ -41,7 +41,7 @@ resource "aws_autoscaling_group" "workers" { # Worker template resource "aws_launch_configuration" "worker" { - image_id = "${data.aws_ami.coreos.image_id}" + image_id = "${local.ami_id}" instance_type = "${var.instance_type}" spot_price = "${var.spot_price}" diff --git a/docs/advanced/worker-pools.md b/docs/advanced/worker-pools.md index 081c18f2..6c77df16 100644 --- a/docs/advanced/worker-pools.md +++ b/docs/advanced/worker-pools.md @@ -33,7 +33,7 @@ module "tempest-worker-pool" { count = 2 instance_type = "m5.large" - os_channel = "beta" + os_image = "coreos-beta" } ``` @@ -66,7 +66,7 @@ The AWS internal `workers` module supports a number of [variables](https://githu |:-----|:------------|:--------|:--------| | count | Number of instances | 1 | 3 | | instance_type | EC2 instance type | "t2.small" | "t2.medium" | -| os_channel | Container Linux AMI channel | stable| "beta", "alpha" | +| os_image | AMI channel for a Container Linux derivative | coreos-stable | coreos-stable, coreos-beta, coreos-alpha, flatcar-stable, flatcar-beta, flatcar-alpha | | disk_size | Size of the disk in GB | 40 | 100 | | spot_price | Spot price in USD for workers. Leave as default empty string for regular on-demand instances | "" | "0.10" | | service_cidr | Must match `service_cidr` of cluster | "10.3.0.0/16" | "10.3.0.0/24" | diff --git a/docs/cl/aws.md b/docs/cl/aws.md index 447daaa6..83a93c83 100644 --- a/docs/cl/aws.md +++ b/docs/cl/aws.md @@ -241,7 +241,7 @@ Reference the DNS zone id with `"${aws_route53_zone.zone-for-clusters.zone_id}"` | worker_count | Number of workers | 1 | 3 | | controller_type | EC2 instance type for controllers | "t2.small" | See below | | worker_type | EC2 instance type for workers | "t2.small" | See below | -| os_channel | Container Linux AMI channel | stable | stable, beta, alpha | +| os_image | AMI channel for a Container Linux derivative | coreos-stable | coreos-stable, coreos-beta, coreos-alpha, flatcar-stable, flatcar-beta, flatcar-alpha | | disk_size | Size of the EBS volume in GB | "40" | "100" | | disk_type | Type of the EBS volume | "gp2" | standard, gp2, io1 | | worker_price | Spot price in USD for workers. Leave as default empty string for regular on-demand instances | "" | "0.10" |