Skip to content

Commit 842a561

Browse files
committed
[installer-tests] Add tests for k8s versions and ubuntu version
1 parent 29a2405 commit 842a561

File tree

12 files changed

+203
-112
lines changed

12 files changed

+203
-112
lines changed

.werft/installer-tests.ts

+48-10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
9595

9696
const config: TestConfig = TEST_CONFIGURATIONS[testConfig];
9797
const cloud: string = config.CLOUD;
98+
const k8s_version: string = randK8sVersion(testConfig)
9899

99100
// `INFRA_PHASES` describe the phases that can be mixed
100101
// and matched to form a test configuration
@@ -103,22 +104,22 @@ const cloud: string = config.CLOUD;
103104
const INFRA_PHASES: { [name: string]: InfraConfig } = {
104105
STANDARD_GKE_CLUSTER: {
105106
phase: "create-std-gke-cluster",
106-
makeTarget: "gke-standard-cluster",
107+
makeTarget: `gke-standard-cluster`,
107108
description: "Creating a GKE cluster with 1 nodepool each for workspace and server",
108109
},
109110
STANDARD_K3S_CLUSTER_ON_GCP: {
110111
phase: "create-std-k3s-cluster",
111-
makeTarget: "k3s-standard-cluster",
112+
makeTarget: `k3s-standard-cluster os_version=${randOsVersion()}`,
112113
description: "Creating a k3s cluster on GCP with 1 node",
113114
},
114115
STANDARD_AKS_CLUSTER: {
115116
phase: "create-std-aks-cluster",
116-
makeTarget: "aks-standard-cluster",
117+
makeTarget: `aks-standard-cluster`,
117118
description: "Creating an aks cluster(azure)",
118119
},
119120
STANDARD_EKS_CLUSTER: {
120121
phase: "create-std-eks-cluster",
121-
makeTarget: "eks-standard-cluster",
122+
makeTarget: `eks-standard-cluster`,
122123
description: "Creating a EKS cluster with 1 nodepool each for workspace and server",
123124
},
124125
CERT_MANAGER: {
@@ -133,7 +134,7 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
133134
},
134135
GENERATE_KOTS_CONFIG: {
135136
phase: "generate-kots-config",
136-
makeTarget: `generate-kots-config storage=${randomize()} registry=${randomize()} db=${randomize()}`,
137+
makeTarget: `generate-kots-config storage=${randDeps()} registry=${randDeps()} db=${randDeps()}`,
137138
description: `Generate KOTS Config file`,
138139
},
139140
CLUSTER_ISSUER: {
@@ -318,7 +319,7 @@ function callMakeTargets(phase: string, description: string, makeTarget: string,
318319
werft.log(phase, `Calling ${makeTarget}`);
319320

320321
// exporting cloud env var is important for the make targets
321-
const response = exec(`export cloud=${cloud} && make -C ${makefilePath} ${makeTarget}`, {
322+
const response = exec(`export TF_VAR_cluster_version=${k8s_version} cloud=${cloud} && make -C ${makefilePath} ${makeTarget}`, {
322323
slice: phase,
323324
dontCheckRc: true,
324325
});
@@ -339,15 +340,52 @@ function callMakeTargets(phase: string, description: string, makeTarget: string,
339340
return response.code;
340341
}
341342

342-
function randomize(): string {
343-
// in the follow-up PR we will add `${platform}-${resource}` as an option here to
344-
// test against resource dependencies(storage, db, registry) for each cloud platform
343+
function randomize(options: string[]): string {
344+
return options[Math.floor(Math.random() * options.length)];
345+
}
346+
347+
function randDeps(): string {
345348
var depOptions: string[] = ["incluster", "external"]
349+
346350
if(deps && depOptions.includes(deps)) {
347351
return deps
348352
}
349353

350-
return depOptions[Math.floor(Math.random() * depOptions.length)];
354+
return randomize(depOptions)
355+
}
356+
357+
function randK8sVersion(config: string): string {
358+
var options: string[] = []
359+
switch(cloud) {
360+
case "STANDARD_GKE_TEST": {
361+
options = ["1.21", "1.22", "1.23"]
362+
break;
363+
}
364+
case "STANDARD_AKS_TEST": {
365+
options = ["1.21", "1.22", "1.23"]
366+
break;
367+
}
368+
case "STANDARD_EKS_TEST": {
369+
options = ["1.20", "1.21", "1.22"]
370+
break;
371+
}
372+
case "STANDARD_K3S_TEST": {
373+
options = ["1.22.12+k3s1", "v1.23.9+k3s1", "1.24.3+k3s1"]
374+
break;
375+
}
376+
}
377+
// in the follow-up PR we will add `${platform}-${resource}` as an option here to
378+
// test against resource dependencies(storage, db, registry) for each cloud platform
379+
380+
return randomize(options)
381+
}
382+
383+
function randOsVersion(): string {
384+
// in the follow-up PR we will add `${platform}-${resource}` as an option here to
385+
// test against resource dependencies(storage, db, registry) for each cloud platform
386+
var options: string[] = ["2204", "2004", "1804"]
387+
388+
return randomize(options)
351389
}
352390

353391
function cleanup() {

install/infra/terraform/aks/kubernetes.tf

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
data "azurerm_kubernetes_service_versions" "k8s" {
2-
location = azurerm_resource_group.gitpod.location
3-
include_preview = false
4-
}
5-
61
resource "azurerm_role_assignment" "k8s" {
72
count = var.dns_enabled ? 1 : 0
83

@@ -20,37 +15,37 @@ resource "azurerm_role_assignment" "k8s_reader" {
2015
}
2116

2217
resource "azurerm_kubernetes_cluster" "k8s" {
23-
name = format(local.name_format, local.location, "primary")
24-
location = azurerm_resource_group.gitpod.location
25-
resource_group_name = azurerm_resource_group.gitpod.name
26-
dns_prefix = "gitpod"
27-
tags = {}
28-
api_server_authorized_ip_ranges = []
29-
30-
kubernetes_version = data.azurerm_kubernetes_service_versions.k8s.latest_version
18+
name = format(local.name_format, local.location, "primary")
19+
location = azurerm_resource_group.gitpod.location
20+
resource_group_name = azurerm_resource_group.gitpod.name
21+
dns_prefix = "gitpod"
22+
tags = {}
23+
api_server_authorized_ip_ranges = []
24+
25+
kubernetes_version = var.cluster_version
3126
http_application_routing_enabled = false
3227

3328
default_node_pool {
3429
name = local.nodes.0.name
3530
vm_size = local.machine
3631

3732

38-
node_taints = []
39-
tags = {}
40-
zones = []
33+
node_taints = []
34+
tags = {}
35+
zones = []
4136

4237
enable_auto_scaling = true
4338
min_count = 1
4439
max_count = 10
45-
orchestrator_version = data.azurerm_kubernetes_service_versions.k8s.latest_version
40+
orchestrator_version = var.cluster_version
4641
node_labels = local.nodes.0.labels
4742

4843
type = "VirtualMachineScaleSets"
4944
vnet_subnet_id = azurerm_subnet.network.id
5045
}
5146

5247
identity {
53-
type = "SystemAssigned"
48+
type = "SystemAssigned"
5449
identity_ids = []
5550
}
5651

@@ -74,7 +69,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "pools" {
7469
enable_auto_scaling = true
7570
min_count = 1
7671
max_count = 10
77-
orchestrator_version = data.azurerm_kubernetes_service_versions.k8s.latest_version
72+
orchestrator_version = var.cluster_version
7873
node_labels = local.nodes[count.index + 1].labels
7974
vnet_subnet_id = azurerm_subnet.network.id
8075
}

install/infra/terraform/aks/variables.tf

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Common variables
22
variable "kubeconfig" {
3-
default = "./kubeconfig"
3+
default = "./kubeconfig"
4+
}
45

6+
variable "cluster_version" {
7+
description = "kubernetes version of to create the cluster with"
58
}
9+
610
variable "dns_enabled" {}
711
variable "domain_name" {}
812
variable "enable_airgapped" {}
@@ -14,6 +18,5 @@ variable "workspace_name" {
1418

1519
// Azure-specific variables
1620
variable "location" {
17-
default = "northeurope"
18-
21+
default = "northeurope"
1922
}

install/infra/terraform/eks/kubernetes.tf

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ module "vpc" {
22
source = "terraform-aws-modules/vpc/aws"
33
version = "3.12.0"
44

5-
name = "vpc-${var.cluster_name}"
6-
cidr = var.vpc_cidr
7-
azs = var.vpc_availability_zones
8-
private_subnets = [var.private_primary_subnet_cidr, var.private_secondary_subnet_cidr]
9-
public_subnets = [var.public_primary_subnet_cidr, var.public_secondary_subnet_cidr, var.public_db_subnet_cidr_1, var.public_db_subnet_cidr_2]
10-
enable_nat_gateway = true
5+
name = "vpc-${var.cluster_name}"
6+
cidr = var.vpc_cidr
7+
azs = var.vpc_availability_zones
8+
private_subnets = [var.private_primary_subnet_cidr, var.private_secondary_subnet_cidr]
9+
public_subnets = [var.public_primary_subnet_cidr, var.public_secondary_subnet_cidr, var.public_db_subnet_cidr_1, var.public_db_subnet_cidr_2]
10+
enable_nat_gateway = true
1111
enable_dns_hostnames = true
1212
}
1313

1414
resource "aws_security_group" "nodes" {
15-
name = "nodes-sg-${var.cluster_name}"
15+
name = "nodes-sg-${var.cluster_name}"
1616
vpc_id = module.vpc.vpc_id
1717

1818
ingress {
19-
from_port = 0
20-
to_port = 0
21-
protocol = "-1"
19+
from_port = 0
20+
to_port = 0
21+
protocol = "-1"
2222
cidr_blocks = ["0.0.0.0/0"]
2323
}
2424

2525
egress {
26-
from_port = 0
27-
to_port = 0
28-
protocol = "-1"
26+
from_port = 0
27+
to_port = 0
28+
protocol = "-1"
2929
cidr_blocks = ["0.0.0.0/0"]
3030
}
3131
}
@@ -34,10 +34,10 @@ module "eks" {
3434
source = "terraform-aws-modules/eks/aws"
3535
version = "18.8.1"
3636

37-
cluster_name = var.cluster_name
38-
cluster_version = "1.22"
37+
cluster_name = var.cluster_name
38+
cluster_version = var.cluster_version
3939

40-
cluster_endpoint_public_access = true
40+
cluster_endpoint_public_access = true
4141

4242
vpc_id = module.vpc.vpc_id
4343
subnet_ids = module.vpc.public_subnets
@@ -58,7 +58,7 @@ module "eks" {
5858
iam_role_attach_cni_policy = true
5959
ami_id = var.image_id
6060
enable_bootstrap_user_data = true
61-
vpc_security_group_ids = [aws_security_group.nodes.id]
61+
vpc_security_group_ids = [aws_security_group.nodes.id]
6262
}
6363

6464
eks_managed_node_groups = {
@@ -144,7 +144,7 @@ module "vpc_cni_irsa" {
144144
}
145145

146146
resource "null_resource" "kubeconfig" {
147-
depends_on = [ module.eks ]
147+
depends_on = [module.eks]
148148
provisioner "local-exec" {
149149
command = "aws eks update-kubeconfig --region ${var.region} --name ${var.cluster_name} --kubeconfig ${var.kubeconfig}"
150150
}

install/infra/terraform/eks/variables.tf

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,45 @@ variable "cluster_name" {
22
type = string
33
description = "EKS cluster name."
44
}
5+
6+
variable "cluster_version" {
7+
type = string
8+
description = "Kubernetes version to create the cluster with"
9+
default = "1.22"
10+
}
11+
512
variable "kubeconfig" {
613
type = string
714
description = "Path to the kubeconfig file"
815
default = "kubeconfig"
916
}
1017

1118
variable "image_id" {
12-
type = string
19+
type = string
1320
description = "AMI Image ID specific to the region"
1421
// latest ubuntu image for 1.22 k8s for eu-west-1 region, refer https://cloud-images.ubuntu.com/docs/aws/eks/
1522
default = "ami-0793b4124359a6ad7"
1623
}
1724

1825
variable "service_machine_type" {
19-
type = string
26+
type = string
2027
description = "Machine type for service workload node pool"
21-
default = "m6i.xlarge"
28+
default = "m6i.xlarge"
2229
}
2330

2431
variable "workspace_machine_type" {
25-
type = string
32+
type = string
2633
description = "Machine type for workspace workload node pool"
27-
default = "m6i.2xlarge"
34+
default = "m6i.2xlarge"
2835
}
2936

3037
variable "region" {
31-
type = string
38+
type = string
3239
default = "eu-west-1"
3340
}
3441

3542
variable "vpc_availability_zones" {
36-
type = list(string)
43+
type = list(string)
3744
default = ["eu-west-1c", "eu-west-1b"]
3845
}
3946

0 commit comments

Comments
 (0)