Skip to content

Commit

Permalink
Fix create_tidb_cluster_release variable does not work (#1066)
Browse files Browse the repository at this point in the history
Signed-off-by: Aylei <rayingecho@gmail.com>
  • Loading branch information
sre-bot authored and aylei committed Oct 29, 2019
1 parent 951307e commit 987c229
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
21 changes: 11 additions & 10 deletions deploy/modules/aws/tidb-cluster/cluster.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module "tidb-cluster" {
source = "../../share/tidb-cluster-release"

cluster_name = var.cluster_name
cluster_version = var.cluster_version
pd_count = var.pd_count
tikv_count = var.tikv_count
tidb_count = var.tidb_count
tidb_cluster_chart_version = var.tidb_cluster_chart_version
override_values = var.override_values
local_exec_interpreter = var.local_exec_interpreter
base_values = file("${path.module}/values/default.yaml")
kubeconfig_filename = var.eks.kubeconfig_filename
create = var.create_tidb_cluster_release
cluster_name = var.cluster_name
cluster_version = var.cluster_version
pd_count = var.pd_count
tikv_count = var.tikv_count
tidb_count = var.tidb_count
tidb_cluster_chart_version = var.tidb_cluster_chart_version
override_values = var.override_values
local_exec_interpreter = var.local_exec_interpreter
base_values = file("${path.module}/values/default.yaml")
kubeconfig_filename = var.eks.kubeconfig_filename
}
8 changes: 6 additions & 2 deletions deploy/modules/share/tidb-cluster-release/data.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
data "external" "tidb_hostname" {
count = var.create ? 1 : 0
depends_on = [helm_release.tidb-cluster, null_resource.wait-lb-ip]
working_dir = path.cwd
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_filename} get svc -n ${var.cluster_name} ${var.cluster_name}-tidb -o json | jq '.status.loadBalancer.ingress[0]'"]
}

data "external" "monitor_hostname" {
count = var.create ? 1 : 0
depends_on = [helm_release.tidb-cluster, null_resource.wait-mlb-ip]
working_dir = path.cwd
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_filename} get svc -n ${var.cluster_name} ${var.cluster_name}-grafana -o json | jq '.status.loadBalancer.ingress[0]'"]
}

data "external" "tidb_port" {
count = var.create ? 1 : 0
depends_on = [helm_release.tidb-cluster]
working_dir = path.cwd
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_filename} get svc -n ${var.cluster_name} ${var.cluster_name}-tidb -o json | jq '.spec.ports | .[] | select( .name == \"mysql-client\") | {port: .port|tostring}'"]
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_filename} get svc -n ${var.cluster_name} ${var.cluster_name}-tidb -o json | jq '.spec.ports | .[] | select( .name == \"mysql-client\") | {port: .port|tostring}'"]
}

data "external" "monitor_port" {
count = var.create ? 1 : 0
depends_on = [helm_release.tidb-cluster]
working_dir = path.cwd
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_filename} get svc -n ${var.cluster_name} ${var.cluster_name}-grafana -o json | jq '.spec.ports | .[] | select( .name == \"grafana\") | {port: .port|tostring}'"]
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_filename} get svc -n ${var.cluster_name} ${var.cluster_name}-grafana -o json | jq '.spec.ports | .[] | select( .name == \"grafana\") | {port: .port|tostring}'"]
}
7 changes: 6 additions & 1 deletion deploy/modules/share/tidb-cluster-release/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "null_resource" "wait-tiller-ready" {
count = var.create ? 1 : 0
depends_on = [var.kubeconfig_filename, var.wait_on_resource]

provisioner "local-exec" {
Expand All @@ -22,6 +23,7 @@ data "helm_repository" "pingcap" {
}

resource "helm_release" "tidb-cluster" {
count = var.create ? 1 : 0
depends_on = [null_resource.wait-tiller-ready]

repository = data.helm_repository.pingcap.name
Expand Down Expand Up @@ -123,6 +125,7 @@ resource "helm_release" "tidb-cluster" {
}

resource "null_resource" "wait-tidb-ready" {
count = var.create ? 1 : 0
depends_on = [helm_release.tidb-cluster]

provisioner "local-exec" {
Expand All @@ -141,6 +144,7 @@ EOS
}

resource "null_resource" "wait-lb-ip" {
count = var.create ? 1 : 0
depends_on = [
helm_release.tidb-cluster
]
Expand All @@ -163,13 +167,14 @@ EOS
}

resource "null_resource" "wait-mlb-ip" {
count = var.create ? 1 : 0
depends_on = [
helm_release.tidb-cluster
]
provisioner "local-exec" {
interpreter = ["bash", "-c"]
working_dir = path.cwd
command = <<EOS
command = <<EOS
set -euo pipefail
until kubectl get svc -n ${var.cluster_name} ${var.cluster_name}-grafana -o json | jq '.status.loadBalancer.ingress[0]' | grep "${var.service_ingress_key}"; do
Expand Down
8 changes: 4 additions & 4 deletions deploy/modules/share/tidb-cluster-release/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
tidb_hostname = lookup(data.external.tidb_hostname.result, var.service_ingress_key, "empty")
monitor_hostname = lookup(data.external.monitor_hostname.result, var.service_ingress_key, "emtpy")
tidb_hostname = var.create ? lookup(data.external.tidb_hostname[0].result, var.service_ingress_key, "empty") : "not_created"
monitor_hostname = var.create ? lookup(data.external.monitor_hostname[0].result, var.service_ingress_key, "emtpy") : "not_created"
}

output "tidb_hostname" {
Expand All @@ -12,9 +12,9 @@ output "monitor_hostname" {
}

output "tidb_endpoint" {
value = "${local.tidb_hostname}:${data.external.tidb_port.result["port"]}"
value = var.create ? "${local.tidb_hostname}:${data.external.tidb_port[0].result["port"]}" : "not_created"
}

output "monitor_endpoint" {
value = "${local.monitor_hostname}:${data.external.monitor_port.result["port"]}"
value = var.create ? "${local.monitor_hostname}:${data.external.monitor_port[0].result["port"]}" : "not_created"
}
11 changes: 8 additions & 3 deletions deploy/modules/share/tidb-cluster-release/variables.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
variable "kubeconfig_filename" {
description = "The kubeconfig filename, path should be relative to current working dir"
default = ""
default = ""
}

variable "tidb_cluster_chart_version" {
description = "tidb-cluster chart version"
default = "v1.0.1"
}

variable "create" {
description = "whether creating tidb-cluster helm release"
default = true
}

variable "cluster_name" {
type = string
description = "tidb cluster name"
Expand All @@ -34,7 +39,7 @@ variable "tidb_count" {
}

variable "base_values" {
type = string
type = string
default = ""
}

Expand All @@ -56,5 +61,5 @@ variable "local_exec_interpreter" {

variable "wait_on_resource" {
description = "An optional resource to pass in to wait on before running"
default = []
default = []
}

0 comments on commit 987c229

Please sign in to comment.