-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yang Chiu <[email protected]>
- Loading branch information
Showing
3 changed files
with
276 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
terraform { | ||
required_providers { | ||
rancher2 = { | ||
source = "rancher/rancher2" | ||
version = "~> 5.1.0" | ||
} | ||
} | ||
} | ||
|
||
provider "rancher2" { | ||
api_url = var.lab_url | ||
insecure = true | ||
access_key = var.lab_access_key | ||
secret_key = var.lab_secret_key | ||
} | ||
|
||
resource "random_string" "random_suffix" { | ||
length = 8 | ||
special = false | ||
lower = true | ||
upper = false | ||
} | ||
|
||
data "rancher2_cluster_v2" "hal-cluster" { | ||
name = "hal" | ||
} | ||
|
||
resource "rancher2_cloud_credential" "e2e-credential" { | ||
name = "e2e-credential-${random_string.random_suffix.id}" | ||
harvester_credential_config { | ||
cluster_id = data.rancher2_cluster_v2.hal-cluster.cluster_v1_id | ||
cluster_type = "imported" | ||
kubeconfig_content = data.rancher2_cluster_v2.hal-cluster.kube_config | ||
} | ||
} | ||
|
||
resource "rancher2_machine_config_v2" "e2e-machine-config-controlplane" { | ||
|
||
generate_name = "e2e-machine-config-controlplane-${random_string.random_suffix.id}" | ||
|
||
harvester_config { | ||
|
||
vm_namespace = "longhorn-qa" | ||
|
||
cpu_count = "4" | ||
memory_size = "8" | ||
|
||
disk_info = <<EOF | ||
{ | ||
"disks": [{ | ||
"imageName": "longhorn-qa/image-qn4cg", | ||
"size": 100, | ||
"bootOrder": 1 | ||
}] | ||
} | ||
EOF | ||
|
||
network_info = <<EOF | ||
{ | ||
"interfaces": [{ | ||
"networkName": "longhorn-qa/vlan104" | ||
}] | ||
} | ||
EOF | ||
|
||
ssh_user = "sles" | ||
|
||
user_data = <<EOF | ||
#cloud-config | ||
ssh_authorized_keys: | ||
- >- | ||
${file(var.ssh_public_key_file_path)} | ||
runcmd: | ||
- SUSEConnect -r ${var.registration_code} | ||
- zypper install -y qemu-guest-agent iptables | ||
- - systemctl | ||
- enable | ||
- '--now' | ||
- qemu-guest-agent.service | ||
EOF | ||
} | ||
} | ||
|
||
resource "rancher2_machine_config_v2" "e2e-machine-config-worker" { | ||
|
||
generate_name = "e2e-machine-config-worker-${random_string.random_suffix.id}" | ||
|
||
harvester_config { | ||
|
||
vm_namespace = "longhorn-qa" | ||
|
||
cpu_count = "4" | ||
memory_size = "8" | ||
|
||
disk_info = <<EOF | ||
{ | ||
"disks": [{ | ||
"imageName": "longhorn-qa/image-qn4cg", | ||
"size": 100, | ||
"bootOrder": 1 | ||
}, | ||
{ | ||
"storageClassName": "harvester-longhorn", | ||
"size": 100, | ||
"bootOrder": 2 | ||
}] | ||
} | ||
EOF | ||
|
||
network_info = <<EOF | ||
{ | ||
"interfaces": [{ | ||
"networkName": "longhorn-qa/vlan104" | ||
}] | ||
} | ||
EOF | ||
|
||
ssh_user = "sles" | ||
|
||
user_data = <<EOF | ||
#cloud-config | ||
ssh_authorized_keys: | ||
- >- | ||
${file(var.ssh_public_key_file_path)} | ||
runcmd: | ||
- SUSEConnect -r ${var.registration_code} | ||
- zypper install -y qemu-guest-agent iptables open-iscsi nfs-client cryptsetup device-mapper | ||
- zypper -n install --force-resolution kernel-default | ||
- - systemctl | ||
- enable | ||
- '--now' | ||
- qemu-guest-agent.service | ||
- systemctl enable iscsid | ||
- systemctl start iscsid | ||
- touch /etc/modules-load.d/modules.conf | ||
- echo uio >> /etc/modules-load.d/modules.conf | ||
- echo uio_pci_generic >> /etc/modules-load.d/modules.conf | ||
- echo vfio_pci >> /etc/modules-load.d/modules.conf | ||
- echo nvme-tcp >> /etc/modules-load.d/modules.conf | ||
- echo dm_crypt >> /etc/modules-load.d/modules.conf | ||
- echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages | ||
- echo "vm.nr_hugepages=1024" >> /etc/sysctl.conf | ||
- shutdown -r +5 | ||
EOF | ||
} | ||
} | ||
|
||
resource "rancher2_cluster_v2" "e2e-cluster" { | ||
|
||
name = "e2e-cluster-${random_string.random_suffix.id}" | ||
|
||
kubernetes_version = var.k8s_distro_version | ||
|
||
rke_config { | ||
machine_pools { | ||
name = "control-plane-pool" | ||
cloud_credential_secret_name = rancher2_cloud_credential.e2e-credential.id | ||
control_plane_role = true | ||
etcd_role = true | ||
worker_role = false | ||
quantity = 1 | ||
machine_config { | ||
kind = rancher2_machine_config_v2.e2e-machine-config-controlplane.kind | ||
name = rancher2_machine_config_v2.e2e-machine-config-controlplane.name | ||
} | ||
} | ||
machine_pools { | ||
name = "worker-pool" | ||
cloud_credential_secret_name = rancher2_cloud_credential.e2e-credential.id | ||
control_plane_role = false | ||
etcd_role = false | ||
worker_role = true | ||
quantity = 3 | ||
machine_config { | ||
kind = rancher2_machine_config_v2.e2e-machine-config-worker.kind | ||
name = rancher2_machine_config_v2.e2e-machine-config-worker.name | ||
} | ||
} | ||
machine_selector_config { | ||
config = <<EOF | ||
cloud-provider-name: "" | ||
EOF | ||
} | ||
machine_global_config = <<EOF | ||
cni: "calico" | ||
disable-kube-proxy: false | ||
etcd-expose-metrics: false | ||
EOF | ||
upgrade_strategy { | ||
control_plane_concurrency = "10%" | ||
worker_concurrency = "10%" | ||
} | ||
etcd { | ||
snapshot_schedule_cron = "0 */5 * * *" | ||
snapshot_retention = 5 | ||
} | ||
chart_values = "" | ||
} | ||
} | ||
|
||
output "kube_config" { | ||
value = rancher2_cluster_v2.e2e-cluster.kube_config | ||
sensitive = true | ||
} | ||
|
||
output "cluster_id" { | ||
value = data.rancher2_cluster_v2.hal-cluster.cluster_v1_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
variable "lab_url" { | ||
type = string | ||
description = "LAB URL" | ||
sensitive = true | ||
} | ||
|
||
variable "lab_access_key" { | ||
type = string | ||
description = "LAB ACCESS_KEY" | ||
sensitive = true | ||
} | ||
|
||
variable "lab_secret_key" { | ||
type = string | ||
description = "LAB SECRET_KEY" | ||
sensitive = true | ||
} | ||
|
||
variable "ssh_public_key_file_path" { | ||
type = string | ||
default = "~/.ssh/id_rsa.pub" | ||
} | ||
|
||
variable "arch" { | ||
type = string | ||
description = "available values (amd64, arm64)" | ||
default = "amd64" | ||
} | ||
|
||
variable "os_distro_version" { | ||
type = string | ||
default = "15-sp6" | ||
} | ||
|
||
variable "k8s_distro_name" { | ||
type = string | ||
default = "rke2" | ||
description = "kubernetes distro version to install [rke2, k3s] (default: rke2)" | ||
} | ||
|
||
variable "k8s_distro_version" { | ||
type = string | ||
default = "v1.28.14+rke2r1" | ||
description = <<-EOT | ||
kubernetes version that will be deployed | ||
k3s: (default: v1.28.14+k3s1) | ||
rke2: (default: v1.28.14+rke2r1) | ||
EOT | ||
} | ||
|
||
variable "registration_code" { | ||
type = string | ||
sensitive = true | ||
} |