From ecc4cb9d3ea7810f9b168d1dd5b2a833a27a97c2 Mon Sep 17 00:00:00 2001 From: Yang Chiu Date: Fri, 29 Nov 2024 21:13:26 +0800 Subject: [PATCH] ci: refine talos terraform script Signed-off-by: Yang Chiu --- test_framework/scripts/longhorn-setup.sh | 2 ++ test_framework/terraform/aws/talos/main.tf | 29 ++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/test_framework/scripts/longhorn-setup.sh b/test_framework/scripts/longhorn-setup.sh index 56f4937872..c214f90dd2 100755 --- a/test_framework/scripts/longhorn-setup.sh +++ b/test_framework/scripts/longhorn-setup.sh @@ -498,6 +498,8 @@ run_longhorn_tests(){ main(){ set_kubeconfig + sleep 86400 + create_longhorn_namespace if [[ ${DISTRO} == "rhel" ]] || [[ ${DISTRO} == "rockylinux" ]] || [[ ${DISTRO} == "oracle" ]]; then diff --git a/test_framework/terraform/aws/talos/main.tf b/test_framework/terraform/aws/talos/main.tf index b572687ec8..d7d030f16e 100644 --- a/test_framework/terraform/aws/talos/main.tf +++ b/test_framework/terraform/aws/talos/main.tf @@ -189,8 +189,6 @@ data "talos_machine_configuration" "controlplane" { depends_on = [ aws_instance.lh_aws_instance_controlplane ] - count = var.lh_aws_instance_count_controlplane - cluster_name = "lh-tests-cluster" cluster_endpoint = "https://${aws_instance.lh_aws_instance_controlplane[0].public_ip}:6443" machine_type = "controlplane" @@ -208,8 +206,6 @@ data "talos_machine_configuration" "worker" { depends_on = [ aws_instance.lh_aws_instance_controlplane ] - count = var.lh_aws_instance_count_worker - cluster_name = "lh-tests-cluster" cluster_endpoint = "https://${aws_instance.lh_aws_instance_controlplane[0].public_ip}:6443" machine_type = "worker" @@ -219,7 +215,7 @@ data "talos_machine_configuration" "worker" { docs = false examples = false config_patches = [ - file("${path.module}/talos-patch.yaml") + file("${path.module}/talos-patch-worker.yaml") ] } @@ -227,7 +223,7 @@ resource "talos_machine_configuration_apply" "controlplane" { count = var.lh_aws_instance_count_controlplane client_configuration = talos_machine_secrets.machine_secrets.client_configuration - machine_configuration_input = data.talos_machine_configuration.controlplane[count.index].machine_configuration + machine_configuration_input = data.talos_machine_configuration.controlplane.machine_configuration endpoint = aws_instance.lh_aws_instance_controlplane[count.index].public_ip node = aws_instance.lh_aws_instance_controlplane[count.index].private_ip } @@ -236,7 +232,7 @@ resource "talos_machine_configuration_apply" "worker" { count = var.lh_aws_instance_count_worker client_configuration = talos_machine_secrets.machine_secrets.client_configuration - machine_configuration_input = data.talos_machine_configuration.worker[count.index].machine_configuration + machine_configuration_input = data.talos_machine_configuration.worker.machine_configuration endpoint = aws_instance.lh_aws_instance_worker[count.index].public_ip node = aws_instance.lh_aws_instance_worker[count.index].private_ip } @@ -260,15 +256,28 @@ resource "local_file" "talosconfig" { filename = "talos_k8s_config" } -data "talos_cluster_kubeconfig" "this" { +resource "talos_cluster_kubeconfig" "this" { depends_on = [talos_machine_bootstrap.this] client_configuration = talos_machine_secrets.machine_secrets.client_configuration - endpoint = aws_instance.lh_aws_instance_controlplane[0].public_ip + endpoint = aws_instance.lh_aws_instance_controlplane.0.public_ip node = aws_instance.lh_aws_instance_controlplane.0.private_ip } resource "local_file" "kubeconfig" { - content = nonsensitive(data.talos_cluster_kubeconfig.this.kubeconfig_raw) + content = nonsensitive(talos_cluster_kubeconfig.this.kubeconfig_raw) filename = "kubeconfig" } + +data "talos_cluster_health" "this" { + depends_on = [ + talos_machine_configuration_apply.controlplane, + talos_machine_configuration_apply.worker, + talos_cluster_kubeconfig.this + ] + + client_configuration = talos_machine_secrets.machine_secrets.client_configuration + endpoints = aws_instance.lh_aws_instance_controlplane.*.public_ip + control_plane_nodes = aws_instance.lh_aws_instance_controlplane.*.private_ip + worker_nodes = aws_instance.lh_aws_instance_worker.*.private_ip +}