From b0e7dc581d199dd27d0c2e859b2d424191348335 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:12:19 +0200 Subject: [PATCH 1/9] print_kubeconfig_path(): add some debug messages If script is run right after 'git clone', it will wait for more than a minute without any output, which would definitely be confusing for users. This commit adds some debug messages, which indicates, that we are trying to determine usable kubeconfig file. Signed-off-by: Mateusz Gozdek --- scripts/common.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 0b0bdcf..915b17d 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -9,11 +9,12 @@ function stderr() { #--- function print_kubeconfig_path() { + stderr "Checking available kubeconfig file..." local asset_dir="$1" # check for kubeconfig already in use [ -f "${KUBECONFIG:-}" ] && { - for i in {1..6}; do kubectl cluster-info >/dev/null 2>&1 && { + for i in {1..6}; do stderr "Running 'KUBECONFIG=$KUBECONFIG kubectl cluster-info'... ($i/6)"; kubectl cluster-info >/dev/null 2>&1 && { stderr "Will use existing cluster with kubeconfig at '$KUBECONFIG'" echo "$(readlink -f $KUBECONFIG)" exit 0 @@ -21,7 +22,7 @@ function print_kubeconfig_path() { } export KUBECONFIG="$(readlink -f ${asset_dir}/auth/kubeconfig)" - for i in {1..6}; do kubectl cluster-info >/dev/null 2>&1 && { + for i in {1..6}; do stderr "Running 'KUBECONFIG=$KUBECONFIG kubectl cluster-info'... ($i/6)"; kubectl cluster-info >/dev/null 2>&1 && { stderr "Will use existing cluster with kubeconfig at '$KUBECONFIG'" echo "$(readlink -f $KUBECONFIG)" exit 0 From ebe741990db65385fc6baea13e1946dd9889cfcf Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:15:46 +0200 Subject: [PATCH 2/9] print_kubeconfig_path(): run cluster-info only if any KUBECONFIG file exists If no kubeconfig file is found, it should be OK to immediately abort. Signed-off-by: Mateusz Gozdek --- scripts/common.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 915b17d..55192c7 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -22,11 +22,13 @@ function print_kubeconfig_path() { } export KUBECONFIG="$(readlink -f ${asset_dir}/auth/kubeconfig)" - for i in {1..6}; do stderr "Running 'KUBECONFIG=$KUBECONFIG kubectl cluster-info'... ($i/6)"; kubectl cluster-info >/dev/null 2>&1 && { - stderr "Will use existing cluster with kubeconfig at '$KUBECONFIG'" - echo "$(readlink -f $KUBECONFIG)" - exit 0 - } || sleep 5; done + [ -f "${KUBECONFIG:-}" ] && { + for i in {1..6}; do stderr "Running 'KUBECONFIG=$KUBECONFIG kubectl cluster-info'... ($i/6)"; kubectl cluster-info >/dev/null 2>&1 && { + stderr "Will use existing cluster with kubeconfig at '$KUBECONFIG'" + echo "$(readlink -f $KUBECONFIG)" + exit 0 + } || sleep 5; done + } stderr "No existing cluster / kubeconfg found." } From 34cdefe81743daaf302aa295fbd697a30d42d9c4 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:19:08 +0200 Subject: [PATCH 3/9] benchmark.sh/benchmark-multi.sh: suggest running setup-cluster.sh If no working cluster is found, suggest running relevant setup-cluster.sh script, to give user a hint what he may forgot to do. Signed-off-by: Mateusz Gozdek --- scripts/istio/benchmark-multi.sh | 2 +- scripts/istio/benchmark.sh | 2 +- scripts/linkerd/benchmark-multi.sh | 2 +- scripts/linkerd/benchmark.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/istio/benchmark-multi.sh b/scripts/istio/benchmark-multi.sh index 0c8cd10..bb0f88c 100755 --- a/scripts/istio/benchmark-multi.sh +++ b/scripts/istio/benchmark-multi.sh @@ -13,7 +13,7 @@ source "$script_dir/../common.sh" asset_dir="${script_dir}/../../assets" KUBECONFIG=$(print_kubeconfig_path "$asset_dir") [ ! -f "$KUBECONFIG" ] && { - echo "No working cluster config found, aborting." + echo "No working cluster config found, aborting. Did you run '$script_dir/setup-cluster.sh' ?" exit 1; } export KUBECONFIG diff --git a/scripts/istio/benchmark.sh b/scripts/istio/benchmark.sh index fa82aeb..537a56f 100755 --- a/scripts/istio/benchmark.sh +++ b/scripts/istio/benchmark.sh @@ -23,7 +23,7 @@ istio_type="tuned" asset_dir="${script_dir}/../../assets" KUBECONFIG=$(print_kubeconfig_path "$asset_dir") [ ! -f "$KUBECONFIG" ] && { - echo "No working cluster config found, aborting." + echo "No working cluster config found, aborting. Did you run '$script_dir/setup-cluster.sh' ?" exit 1; } export KUBECONFIG diff --git a/scripts/linkerd/benchmark-multi.sh b/scripts/linkerd/benchmark-multi.sh index c0ec633..560fe60 100755 --- a/scripts/linkerd/benchmark-multi.sh +++ b/scripts/linkerd/benchmark-multi.sh @@ -13,7 +13,7 @@ source "$script_dir/../common.sh" asset_dir="${script_dir}/../../assets" KUBECONFIG=$(print_kubeconfig_path "$asset_dir") [ ! -f "$KUBECONFIG" ] && { - echo "No working cluster config found, aborting." + echo "No working cluster config found, aborting. Did you run '$script_dir/setup-cluster.sh' ?" exit 1; } export KUBECONFIG diff --git a/scripts/linkerd/benchmark.sh b/scripts/linkerd/benchmark.sh index c9ee736..1c04664 100755 --- a/scripts/linkerd/benchmark.sh +++ b/scripts/linkerd/benchmark.sh @@ -20,7 +20,7 @@ linkerd=$(grok_cmd 4 "linkerd2-cli-edge-19.5.3-linux" $@) asset_dir="${script_dir}/../../assets" KUBECONFIG=$(print_kubeconfig_path "$asset_dir") [ ! -f "$KUBECONFIG" ] && { - echo "No working cluster config found, aborting." + echo "No working cluster config found, aborting. Did you run '$script_dir/setup-cluster.sh' ?" exit 1; } export KUBECONFIG From 5401b805fd36412645008cc075be12b80c5ac8f6 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:20:43 +0200 Subject: [PATCH 4/9] ask_create_cluster(): always run 'terraform init' It's a good practice to always run 'terraform init' before other terraform operations to make sure the environment is correctly initialized (plugins etc). Signed-off-by: Mateusz Gozdek --- scripts/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/common.sh b/scripts/common.sh index 55192c7..eb0f622 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -68,6 +68,7 @@ function ask_create_cluster() { rm -rf "$asset_dir" pushd "${terraform_dir}" + terraform init (terraform destroy || true) && terraform apply || { echo "Failed to set up test cluster." exit 1; } From d80ef3b010d892976a564e25612b626329853c04 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:30:50 +0200 Subject: [PATCH 5/9] terraform/README.md: remove whitespace Signed-off-by: Mateusz Gozdek --- terraform/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/README.md b/terraform/README.md index 002b56c..f096230 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -3,7 +3,7 @@ This directory contains Terraform code, which spawns a Kubernetes cluster in a Packet datacenter to perform the benchmark on. -To configure your cluster, please copy the file `variables.auto.tfvars.template` +To configure your cluster, please copy the file `variables.auto.tfvars.template` to `variables.auto.tfvars`, then edit `variables.auto.tfvars` and set the variables as discussed below. @@ -17,7 +17,7 @@ packet_project_id = "" Optionally, you may also set: ``` -cluster_name="my-lokomotive-benchmarkcluster" +cluster_name="my-lokomotive-benchmarkcluster" facility="" ssh_keys=["list of keys to grant ssh access to nodes"] controller_node_type = "t1.small" From 58e97209671db334873767e4de279b497244b3b6 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:37:42 +0200 Subject: [PATCH 6/9] README.md: add a note about cleaning up infrastructure So users knows how to do it. Signed-off-by: Mateusz Gozdek --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 757c924..aeb4320 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,8 @@ tuned, and bare, simply issue: Please note that you must always use scripts from the directory of your respective cluster service mesh. If your cluster currently has istio installed, please only use scripts from `scripts/istio/`. + +## Cleaning up + +After you finish running benchmarks, you can tear down infrastructure by going to `terraform` directory and running `terraform destroy`. +Once it's complete, it should be fine to remove `assets` directory. From 42d841b7283e2f5a4e1916901c55b018688b88af Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 14:47:25 +0200 Subject: [PATCH 7/9] terraform: fix default SSH public key file path By default 'ssh-keygen' writes it to ~/.ssh/id_rsa.pub, not ~/.ssh/.id_rsa.pub, so we should follow it, so users don't have to change it. Signed-off-by: Mateusz Gozdek --- terraform/cluster.tf | 2 +- terraform/variables.auto.tfvars.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/cluster.tf b/terraform/cluster.tf index 33406e2..53a7164 100644 --- a/terraform/cluster.tf +++ b/terraform/cluster.tf @@ -31,7 +31,7 @@ variable "ssh_keys" { type = "list" description = "List of SSH public key files or SSH public keys." default = [ - "~/.ssh/.id_rsa.pub" + "~/.ssh/id_rsa.pub" ] } variable "controller_node_type" { diff --git a/terraform/variables.auto.tfvars.template b/terraform/variables.auto.tfvars.template index 7191007..9c45b6c 100644 --- a/terraform/variables.auto.tfvars.template +++ b/terraform/variables.auto.tfvars.template @@ -15,7 +15,7 @@ packet_project_id = "" facility="ams1" cluster_name="lokomotive-benchmark" -ssh_keys=["~/.ssh/.id_rsa.pub"] +ssh_keys=["~/.ssh/id_rsa.pub"] controller_node_type = "t1.small" worker_node_type = "t1.small" From a5e3b408f3436e2a949ab1b8ef9df45411ad5d9d Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 15:05:11 +0200 Subject: [PATCH 8/9] terraform/cluster.tf: remove rogue dollar sign in ssh_keys Signed-off-by: Mateusz Gozdek --- terraform/cluster.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/cluster.tf b/terraform/cluster.tf index 53a7164..c5828bc 100644 --- a/terraform/cluster.tf +++ b/terraform/cluster.tf @@ -80,7 +80,7 @@ module "packet-svc-mesh-benchmark" { dns_zone = "${var.dns_zone}" dns_zone_id = "${data.aws_route53_zone.cluster.zone_id}" - ssh_keys = ["$${var.ssh_keys}"] + ssh_keys = ["${var.ssh_keys}"] asset_dir = "../assets" cluster_name = "${var.cluster_name}" @@ -110,7 +110,7 @@ module "worker-pool-0" { packet = "packet.default" } - ssh_keys = ["$${var.ssh_keys}"] + ssh_keys = ["${var.ssh_keys}"] cluster_name = "${var.cluster_name}" project_id = "${var.packet_project_id}" From bd47fbc1fb9468354d9afba19fe0730676428400 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 27 May 2019 17:00:40 +0200 Subject: [PATCH 9/9] terraform/cluster.tf: allow to use both SSH public key files and text public keys Currently, default value for ssh_keys variable is incorrect, as code underneath expects it to be content of id_rsa.pub file and not the path to this file. This commit adds new variable 'ssh_key_files', which expects array of SSH public key file paths, which is later expanded to the correct content and merged with old 'ssh_keys' variable. This gives user flexibility to specify either SSH key or SSH key file or both if needed. Signed-off-by: Mateusz Gozdek --- terraform/cluster.tf | 17 ++++++++++++++--- terraform/variables.auto.tfvars.template | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/terraform/cluster.tf b/terraform/cluster.tf index c5828bc..1634e34 100644 --- a/terraform/cluster.tf +++ b/terraform/cluster.tf @@ -29,7 +29,12 @@ variable "facility" { } variable "ssh_keys" { type = "list" - description = "List of SSH public key files or SSH public keys." + description = "List of SSH public keys." + default = [] +} +variable "ssh_key_files" { + type = "list" + description = "List of SSH public key files." default = [ "~/.ssh/id_rsa.pub" ] @@ -49,7 +54,13 @@ variable "worker_node_count" { description = "Number of worker nodes in the cluster. Must be 2 or higher." default = "2" } +resource "null_resource" "ssh_keys" { + count = "${length("${var.ssh_key_files}")}" + triggers = { + ssh_key = "${file("${var.ssh_key_files[count.index]}")}" + } +} data "aws_route53_zone" "cluster" { name = "${var.dns_zone}." @@ -80,7 +91,7 @@ module "packet-svc-mesh-benchmark" { dns_zone = "${var.dns_zone}" dns_zone_id = "${data.aws_route53_zone.cluster.zone_id}" - ssh_keys = ["${var.ssh_keys}"] + ssh_keys = ["${var.ssh_keys}", "${null_resource.ssh_keys.*.triggers.ssh_key}"] asset_dir = "../assets" cluster_name = "${var.cluster_name}" @@ -110,7 +121,7 @@ module "worker-pool-0" { packet = "packet.default" } - ssh_keys = ["${var.ssh_keys}"] + ssh_keys = ["${var.ssh_keys}", "${null_resource.ssh_keys.*.triggers.ssh_key}"] cluster_name = "${var.cluster_name}" project_id = "${var.packet_project_id}" diff --git a/terraform/variables.auto.tfvars.template b/terraform/variables.auto.tfvars.template index 9c45b6c..03cf31b 100644 --- a/terraform/variables.auto.tfvars.template +++ b/terraform/variables.auto.tfvars.template @@ -15,7 +15,8 @@ packet_project_id = "" facility="ams1" cluster_name="lokomotive-benchmark" -ssh_keys=["~/.ssh/id_rsa.pub"] +ssh_keys=["ssh-rsa AAAAB3NzaC1..."] +ssh_key_files=["~/.ssh/id_rsa.pub"] controller_node_type = "t1.small" worker_node_type = "t1.small"