Skip to content

Commit

Permalink
ci: workaround for sle-micro not rebooting via ssh
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Chiu <yang.chiu@suse.com>
  • Loading branch information
yangchiu committed Jul 28, 2024
1 parent dd64dd6 commit 98001e1
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 28 deletions.
72 changes: 59 additions & 13 deletions test_framework/terraform/aws/sle-micro/k3s_instaces.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ resource "null_resource" "registration_controlplane_k3s" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -150,7 +150,7 @@ resource "null_resource" "registration_worker_k3s" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_instance.lh_aws_instance_worker_k3s[count.index].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -168,22 +168,45 @@ resource "null_resource" "package_install_controlplane_k3s" {
provisioner "remote-exec" {

inline = [
"sudo transactional-update pkg install -y open-iscsi nfs-client cryptsetup jq apparmor-parser",
"sudo transactional-update pkg install -y open-iscsi nfs-client cryptsetup jq",
"sudo shutdown -r now",
]

on_failure = continue

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
}

}

resource "time_sleep" "wait_controlplane_1_minute_k3s" {

count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_controlplane : 0

depends_on = [
null_resource.package_install_controlplane_k3s
]

create_duration = "60s"
}

resource "aws_ec2_instance_state" "controlplane_state_k3s" {

count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_controlplane : 0

depends_on = [
time_sleep.wait_controlplane_1_minute_k3s
]

instance_id = aws_instance.lh_aws_instance_controlplane_k3s[count.index].id
state = "running"
}

# node initialization step 2: install required packages after get repos
resource "null_resource" "package_install_worker_k3s" {
count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_worker : 0
Expand All @@ -195,28 +218,51 @@ resource "null_resource" "package_install_worker_k3s" {
provisioner "remote-exec" {

inline = [
"sudo transactional-update pkg install -y open-iscsi nfs-client jq apparmor-parser",
"sudo transactional-update pkg install -y open-iscsi nfs-client jq",
"sudo shutdown -r now",
]

on_failure = continue

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_instance.lh_aws_instance_worker_k3s[count.index].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
}

}

resource "time_sleep" "wait_worker_1_minute_k3s" {

count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_worker : 0

depends_on = [
null_resource.package_install_worker_k3s
]

create_duration = "60s"
}

resource "aws_ec2_instance_state" "worker_state_k3s" {

count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_worker : 0

depends_on = [
time_sleep.wait_worker_1_minute_k3s
]

instance_id = aws_instance.lh_aws_instance_worker_k3s[count.index].id
state = "running"
}

# node initialization step 3: setup k3s cluster for master node
resource "null_resource" "cluster_setup_controlplane_k3s" {
count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_controlplane : 0

depends_on = [
null_resource.package_install_controlplane_k3s
aws_ec2_instance_state.controlplane_state_k3s
]

provisioner "remote-exec" {
Expand All @@ -225,7 +271,7 @@ resource "null_resource" "cluster_setup_controlplane_k3s" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -238,7 +284,7 @@ resource "null_resource" "cluster_setup_worker_k3s" {
count = var.k8s_distro_name == "k3s" ? var.lh_aws_instance_count_worker : 0

depends_on = [
null_resource.package_install_worker_k3s,
aws_ec2_instance_state.worker_state_k3s,
null_resource.cluster_setup_controlplane_k3s
]

Expand All @@ -248,7 +294,7 @@ resource "null_resource" "cluster_setup_worker_k3s" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_instance.lh_aws_instance_worker_k3s[count.index].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -273,7 +319,7 @@ resource "null_resource" "make_sure_k8s_components_running_controlplane_k3s" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -300,13 +346,13 @@ resource "null_resource" "rsync_kubeconfig_file" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
}

provisioner "local-exec" {
command = "rsync -aPvz --rsync-path=\"sudo rsync\" -e \"ssh -o StrictHostKeyChecking=no -l suse -i ${var.aws_ssh_private_key_file_path}\" ${aws_eip.lh_aws_eip_controlplane[0].public_ip}:/etc/rancher/k3s/k3s.yaml . && sed -i 's#https://127.0.0.1:6443#https://${aws_eip.lh_aws_eip_controlplane[0].public_ip}:6443#' k3s.yaml"
command = "rsync -aPvz --rsync-path=\"sudo rsync\" -e \"ssh -o StrictHostKeyChecking=no -l ec2-user -i ${var.aws_ssh_private_key_file_path}\" ${aws_eip.lh_aws_eip_controlplane[0].public_ip}:/etc/rancher/k3s/k3s.yaml . && sed -i 's#https://127.0.0.1:6443#https://${aws_eip.lh_aws_eip_controlplane[0].public_ip}:6443#' k3s.yaml"
}
}
2 changes: 1 addition & 1 deletion test_framework/terraform/aws/sle-micro/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
version = "~> 5.60"
}
}
}
Expand Down
72 changes: 59 additions & 13 deletions test_framework/terraform/aws/sle-micro/rke2_instances.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ resource "null_resource" "registration_controlplane_rke2" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -150,7 +150,7 @@ resource "null_resource" "registration_worker_rke2" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_instance.lh_aws_instance_worker_rke2[count.index].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -168,22 +168,45 @@ resource "null_resource" "package_install_controlplane_rke2" {
provisioner "remote-exec" {

inline = [
"sudo transactional-update pkg install -y open-iscsi nfs-client cryptsetup jq apparmor-parser",
"sudo transactional-update pkg install -y open-iscsi nfs-client cryptsetup jq",
"sudo shutdown -r now",
]

on_failure = continue

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
}

}

resource "time_sleep" "wait_controlplane_1_minute_rke2" {

count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_controlplane : 0

depends_on = [
null_resource.package_install_controlplane_rke2
]

create_duration = "60s"
}

resource "aws_ec2_instance_state" "controlplane_state_rke2" {

count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_controlplane : 0

depends_on = [
time_sleep.wait_controlplane_1_minute_rke2
]

instance_id = aws_instance.lh_aws_instance_controlplane_rke2[count.index].id
state = "running"
}

# node initialization step 2: install required packages after get repos
resource "null_resource" "package_install_worker_rke2" {
count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_worker : 0
Expand All @@ -195,28 +218,51 @@ resource "null_resource" "package_install_worker_rke2" {
provisioner "remote-exec" {

inline = [
"sudo transactional-update pkg install -y open-iscsi nfs-client jq apparmor-parser",
"sudo transactional-update pkg install -y open-iscsi nfs-client jq",
"sudo shutdown -r now",
]

on_failure = continue

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_instance.lh_aws_instance_worker_rke2[count.index].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
}

}

resource "time_sleep" "wait_worker_1_minute_rke2" {

count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_worker : 0

depends_on = [
null_resource.package_install_worker_rke2
]

create_duration = "60s"
}

resource "aws_ec2_instance_state" "worker_state_rke2" {

count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_worker : 0

depends_on = [
time_sleep.wait_worker_1_minute_rke2
]

instance_id = aws_instance.lh_aws_instance_worker_rke2[count.index].id
state = "running"
}

# node initialization step 3: setup rke2 cluster for master node
resource "null_resource" "cluster_setup_controlplane_rke2" {
count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_controlplane : 0

depends_on = [
null_resource.package_install_controlplane_rke2
aws_ec2_instance_state.controlplane_state_rke2
]

provisioner "remote-exec" {
Expand All @@ -225,7 +271,7 @@ resource "null_resource" "cluster_setup_controlplane_rke2" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -238,7 +284,7 @@ resource "null_resource" "cluster_setup_worker_rke2" {
count = var.k8s_distro_name == "rke2" ? var.lh_aws_instance_count_worker : 0

depends_on = [
null_resource.package_install_worker_rke2,
aws_ec2_instance_state.worker_state_rke2,
null_resource.cluster_setup_controlplane_rke2
]

Expand All @@ -248,7 +294,7 @@ resource "null_resource" "cluster_setup_worker_rke2" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_instance.lh_aws_instance_worker_rke2[count.index].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -273,7 +319,7 @@ resource "null_resource" "make_sure_k8s_components_running_controlplane_rke2" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
Expand All @@ -298,13 +344,13 @@ resource "null_resource" "rsync_kubeconfig_file_rke2" {

connection {
type = "ssh"
user = "suse"
user = "ec2-user"
host = aws_eip.lh_aws_eip_controlplane[0].public_ip
private_key = file(var.aws_ssh_private_key_file_path)
}
}

provisioner "local-exec" {
command = "rsync -aPvz --rsync-path=\"sudo rsync\" -e \"ssh -o StrictHostKeyChecking=no -l suse -i ${var.aws_ssh_private_key_file_path}\" ${aws_eip.lh_aws_eip_controlplane[0].public_ip}:/etc/rancher/rke2/rke2.yaml . && sed -i 's#https://127.0.0.1:6443#https://${aws_eip.lh_aws_eip_controlplane[0].public_ip}:6443#' rke2.yaml"
command = "rsync -aPvz --rsync-path=\"sudo rsync\" -e \"ssh -o StrictHostKeyChecking=no -l ec2-user -i ${var.aws_ssh_private_key_file_path}\" ${aws_eip.lh_aws_eip_controlplane[0].public_ip}:/etc/rancher/rke2/rke2.yaml . && sed -i 's#https://127.0.0.1:6443#https://${aws_eip.lh_aws_eip_controlplane[0].public_ip}:6443#' rke2.yaml"
}
}
2 changes: 1 addition & 1 deletion test_framework/terraform/aws/sle-micro/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ variable "arch" {

variable "os_distro_version" {
type = string
default = "5.5"
default = "6.0"
}

variable "aws_ami_sles_account_number" {
Expand Down

0 comments on commit 98001e1

Please sign in to comment.