Skip to content

Commit

Permalink
Refactor tests to use cluster service modules for ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
pst committed Jun 1, 2021
1 parent c78d624 commit 2f00fcd
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 82 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ validate: .init
entrypoint terraform validate

test: validate
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform apply --target module.aks_zero --target module.eks_zero --target module.gke_zero --input=false --auto-approve
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform apply --input=false --auto-approve
Expand Down
4 changes: 4 additions & 0 deletions google/_modules/gke/kubeconfig.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ data "template_file" "kubeconfig" {
cluster_ca = google_container_cluster.current.master_auth[0].cluster_ca_certificate
path_cwd = path.cwd
}

# when the node pool is destroyed before the k8s namespaces
# the namespaces get stuck in terminating
depends_on = [module.node_pool]
}
21 changes: 21 additions & 0 deletions tests/aks_zero_cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module "aks_zero" {
source = "../azurerm/cluster"

configuration = {
# Settings for Apps-cluster
apps = {
resource_group = "terraform-kubestack-testing"
name_prefix = "kbstacctest"
base_domain = "infra.serverwolken.de"

default_node_pool_vm_size = "Standard_B2s"
default_node_pool_min_count = 1
default_node_pool_max_count = 1

network_plugin = "azure"
}

# Settings for Ops-cluster
ops = {}
}
}
32 changes: 32 additions & 0 deletions tests/aks_zero_ingress.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module "aks_zero_nginx" {
providers = {
kustomization = kustomization.aks_zero
}
source = "test.kbst.xyz/catalog/nginx/kustomization"
version = "0.46.0-kbst.1"

configuration = {
apps = {
patches = [{
patch = <<-EOF
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
loadBalancerIP: ${module.aks_zero.default_ingress_ip}
EOF
}]

replicas = [{
name = "ingress-nginx-controller"
count = 1
}]
}

ops = {}

loc = {}
}
}
4 changes: 4 additions & 0 deletions tests/aks_zero_providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "kustomization" {
alias = "aks_zero"
kubeconfig_raw = module.aks_zero.kubeconfig
}
21 changes: 0 additions & 21 deletions tests/clusters.tf

This file was deleted.

53 changes: 0 additions & 53 deletions tests/config.auto.tfvars

This file was deleted.

33 changes: 33 additions & 0 deletions tests/eks_zero_cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module "eks_zero" {
providers = {
aws = aws.eks_zero
}

source = "../aws/cluster"

configuration = {
# Settings for Apps-cluster
apps = {
name_prefix = "kbstacctest"
base_domain = "infra.serverwolken.de"
cluster_instance_type = "t3a.medium"
cluster_desired_capacity = "1"
cluster_min_size = "1"
cluster_max_size = "1"
cluster_availability_zones = "eu-west-1a,eu-west-1b,eu-west-1c"

cluster_aws_auth_map_users = <<MAPUSERS
- userarn: arn:aws:iam::694714331404:user/pst
username: pst
groups:
- system:masters
MAPUSERS
}

# Settings for Ops-cluster
ops = {
cluster_max_size = "1"
cluster_availability_zones = "eu-west-1a,eu-west-1b"
}
}
}
36 changes: 36 additions & 0 deletions tests/eks_zero_ingress.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module "eks_zero_nginx" {
providers = {
kustomization = kustomization.eks_zero
}
source = "test.kbst.xyz/catalog/nginx/kustomization"
version = "0.46.0-kbst.1"

configuration = {
apps = {
replicas = [{
name = "ingress-nginx-controller"
count = 1
}]
}

ops = {}

loc = {}
}
}

module "eks_zero_dns_zone" {
providers = {
aws = aws.eks_zero
kubernetes = kubernetes.eks_zero
}

source = "../aws/cluster/elb-dns"

ingress_service_name = "ingress-nginx-controller"
ingress_service_namespace = "ingress-nginx"

metadata_fqdn = module.eks_zero.current_metadata["fqdn"]

depends_on = [module.eks_zero, module.eks_zero_nginx]
}
27 changes: 27 additions & 0 deletions tests/eks_zero_providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
provider "aws" {
alias = "eks_zero"
region = "eu-west-1"
}


provider "kustomization" {
alias = "eks_zero"
kubeconfig_raw = module.eks_zero.kubeconfig
}

locals {
eks_zero_kubeconfig = yamldecode(module.eks_zero.kubeconfig)
}

provider "kubernetes" {
alias = "eks_zero"

host = local.eks_zero_kubeconfig["clusters"][0]["cluster"]["server"]
cluster_ca_certificate = base64decode(local.eks_zero_kubeconfig["clusters"][0]["cluster"]["certificate-authority-data"])

exec {
api_version = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["apiVersion"]
args = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["args"]
command = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["command"]
}
}
24 changes: 24 additions & 0 deletions tests/gke_zero_cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "gke_zero" {
source = "../google/cluster"

configuration = {
# Settings for Apps-cluster
apps = {
project_id = "terraform-kubestack-testing"
name_prefix = "kbstacctest"
base_domain = "infra.serverwolken.de"

cluster_min_master_version = "1.19"

cluster_machine_type = "e2-medium"
cluster_min_node_count = 1
cluster_max_node_count = 1

region = "europe-west1"
cluster_node_locations = "europe-west1-b,europe-west1-c,europe-west1-d"
}

# Settings for Ops-cluster
ops = {}
}
}
32 changes: 32 additions & 0 deletions tests/gke_zero_ingress.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module "gke_zero_nginx" {
providers = {
kustomization = kustomization.gke_zero
}
source = "test.kbst.xyz/catalog/nginx/kustomization"
version = "0.46.0-kbst.1"

configuration = {
apps = {
patches = [{
patch = <<-EOF
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
loadBalancerIP: ${module.gke_zero.default_ingress_ip}
EOF
}]

replicas = [{
name = "ingress-nginx-controller"
count = 1
}]
}

ops = {}

loc = {}
}
}
4 changes: 4 additions & 0 deletions tests/gke_zero_providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "kustomization" {
alias = "gke_zero"
kubeconfig_raw = module.gke_zero.kubeconfig
}
4 changes: 0 additions & 4 deletions tests/providers.tf

This file was deleted.

4 changes: 0 additions & 4 deletions tests/variables.tf

This file was deleted.

13 changes: 13 additions & 0 deletions tests/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
}

kustomization = {
source = "kbst/kustomization"
}
}

required_version = ">= 0.15"
}

0 comments on commit 2f00fcd

Please sign in to comment.