Skip to content

Commit 055be8b

Browse files
authored
Merge pull request #130 from kbst/integratedevenv
Add new loc env and cluster-local modules
2 parents a957865 + 5b2bc0c commit 055be8b

File tree

29 files changed

+384
-39
lines changed

29 files changed

+384
-39
lines changed

.github/actions/build_artifacts/dist.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
from os import environ, listdir, mkdir
4-
from os.path import isdir
4+
from os.path import isdir, exists, join
55
from shutil import copytree, make_archive, rmtree
66

77
from jinja2 import Environment, FileSystemLoader
@@ -56,10 +56,13 @@ def replace_template(dist_path, file_name, context):
5656
# Replace templated version variable in clusters.tf
5757
replace_template(configuration_dist, 'clusters.tf', {'version': version})
5858

59-
# Replace templated variables in Dockerfile
60-
replace_template(configuration_dist,
61-
'Dockerfile',
62-
{'image_name': image_name, 'image_tag': version})
59+
# Replace templated variables in Dockerfiles
60+
dockerfiles = ['Dockerfile', 'Dockerfile.loc']
61+
for dockerfile in dockerfiles:
62+
if exists(join(configuration_dist, dockerfile)):
63+
replace_template(configuration_dist,
64+
dockerfile,
65+
{'image_name': image_name, 'image_tag': version})
6366

6467
# Replace default ingress reference
6568
replace_template(manifests_dist,

aws/cluster-local/configuration.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module "configuration" {
2+
source = "../../common/configuration"
3+
4+
configuration = var.configuration
5+
base_key = var.configuration_base_key
6+
}
7+
8+
locals {
9+
# current workspace config
10+
cfg = module.configuration.merged[terraform.workspace]
11+
12+
name_prefix = local.cfg["name_prefix"]
13+
14+
base_domain = local.cfg["base_domain"]
15+
16+
http_port_default = terraform.workspace == "apps" ? 80 : 8080
17+
http_port = lookup(local.cfg, "http_port", local.http_port_default)
18+
19+
https_port_default = terraform.workspace == "apps" ? 443 : 8443
20+
https_port = lookup(local.cfg, "https_port", local.https_port_default)
21+
22+
manifest_path_default = "manifests/overlays/${terraform.workspace}"
23+
manifest_path = var.manifest_path != null ? var.manifest_path : local.manifest_path_default
24+
25+
disable_default_ingress = lookup(local.cfg, "disable_default_ingress", false)
26+
27+
node_image = lookup(local.cfg, "node_image", null)
28+
29+
node_count = lookup(local.cfg, "cluster_min_size", 1)
30+
nodes = [
31+
for node, _ in range(local.node_count) :
32+
"worker"
33+
]
34+
extra_nodes = join(",", local.nodes)
35+
36+
# on AWS the region is determined by the provider configuration
37+
# in the local implementation we don't have access to that
38+
# to still support multi-region setups locally, we hash the availability zones
39+
# and use that as the region part of the cluster name prefixed with eks-
40+
cluster_availability_zones_lookup = lookup(local.cfg, "cluster_availability_zones", "")
41+
fake_region_hash = substr(sha256(local.cluster_availability_zones_lookup), 0, 7)
42+
fake_region = "eks-${local.fake_region_hash}"
43+
}

aws/cluster-local/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module "cluster_metadata" {
2+
source = "../../common/metadata"
3+
4+
name_prefix = local.name_prefix
5+
base_domain = local.base_domain
6+
7+
provider_name = "aws"
8+
provider_region = local.fake_region
9+
}
10+
11+
module "cluster" {
12+
source = "../../kind/_modules/kind"
13+
14+
metadata_name = module.cluster_metadata.name
15+
metadata_fqdn = module.cluster_metadata.fqdn
16+
metadata_tags = module.cluster_metadata.tags
17+
metadata_labels = module.cluster_metadata.labels
18+
19+
node_image = local.node_image
20+
extra_nodes = local.extra_nodes
21+
22+
http_port = local.http_port
23+
https_port = local.https_port
24+
25+
manifest_path = local.manifest_path
26+
27+
disable_default_ingress = local.disable_default_ingress
28+
}

aws/cluster-local/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "configuration" {
2+
type = map(map(string))
3+
description = "Map with per workspace cluster configuration."
4+
}
5+
6+
variable "configuration_base_key" {
7+
type = string
8+
description = "The key in the configuration map all other keys inherit from."
9+
default = "apps"
10+
}
11+
12+
variable "manifest_path" {
13+
type = string
14+
description = "Path to Kustomize overlay to build."
15+
default = null
16+
}

aws/cluster-local/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module "configuration" {
2+
source = "../../common/configuration"
3+
4+
configuration = var.configuration
5+
base_key = var.configuration_base_key
6+
}
7+
8+
locals {
9+
# current workspace config
10+
cfg = module.configuration.merged[terraform.workspace]
11+
12+
name_prefix = local.cfg["name_prefix"]
13+
14+
base_domain = local.cfg["base_domain"]
15+
16+
# on Azure the region is determined by resource group
17+
# in the local implementation we don't have access to that
18+
# to still support multi-region setups locally, we hash the resource group name
19+
# and use that as the region part of the cluster name prefixed with aks-
20+
resource_group = local.cfg["resource_group"]
21+
fake_region_hash = substr(sha256(local.resource_group), 0, 7)
22+
fake_region = "aks-${local.fake_region_hash}"
23+
24+
http_port_default = terraform.workspace == "apps" ? 80 : 8080
25+
http_port = lookup(local.cfg, "http_port", local.http_port_default)
26+
27+
https_port_default = terraform.workspace == "apps" ? 443 : 8443
28+
https_port = lookup(local.cfg, "https_port", local.https_port_default)
29+
30+
manifest_path_default = "manifests/overlays/${terraform.workspace}"
31+
manifest_path = var.manifest_path != null ? var.manifest_path : local.manifest_path_default
32+
33+
disable_default_ingress = lookup(local.cfg, "disable_default_ingress", false)
34+
35+
node_image = lookup(local.cfg, "node_image", null)
36+
37+
node_count = lookup(local.cfg, "default_node_pool_min_count", "1")
38+
nodes = [
39+
for node, _ in range(local.node_count) :
40+
"worker"
41+
]
42+
extra_nodes = join(",", local.nodes)
43+
44+
}

azurerm/cluster-local/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module "cluster_metadata" {
2+
source = "../../common/metadata"
3+
4+
name_prefix = local.name_prefix
5+
base_domain = local.base_domain
6+
7+
provider_name = "azure"
8+
provider_region = local.fake_region
9+
10+
# Azure does not allow / character in labels
11+
label_namespace = "kubestack.com-"
12+
}
13+
14+
module "cluster" {
15+
source = "../../kind/_modules/kind"
16+
17+
metadata_name = module.cluster_metadata.name
18+
metadata_fqdn = module.cluster_metadata.fqdn
19+
metadata_tags = module.cluster_metadata.tags
20+
metadata_labels = module.cluster_metadata.labels
21+
22+
node_image = local.node_image
23+
extra_nodes = local.extra_nodes
24+
25+
http_port = local.http_port
26+
https_port = local.https_port
27+
28+
manifest_path = local.manifest_path
29+
30+
disable_default_ingress = local.disable_default_ingress
31+
}

azurerm/cluster-local/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "configuration" {
2+
type = map(map(string))
3+
description = "Map with per workspace cluster configuration."
4+
}
5+
6+
variable "configuration_base_key" {
7+
type = string
8+
description = "The key in the configuration map all other keys inherit from."
9+
default = "apps"
10+
}
11+
12+
variable "manifest_path" {
13+
type = string
14+
description = "Path to Kustomize overlay to build."
15+
default = null
16+
}

azurerm/cluster-local/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

google/cluster-local/configuration.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module "configuration" {
2+
source = "../../common/configuration"
3+
4+
configuration = var.configuration
5+
base_key = var.configuration_base_key
6+
}
7+
8+
locals {
9+
# current workspace config
10+
cfg = module.configuration.merged[terraform.workspace]
11+
12+
name_prefix = local.cfg["name_prefix"]
13+
14+
base_domain = local.cfg["base_domain"]
15+
16+
# while we have the real region for GKE
17+
# we still hash and prefix it with gke-
18+
# to align with the local implementations
19+
# for AKS end EKS
20+
fake_region_hash = substr(sha256(local.cfg["region"]), 0, 7)
21+
fake_region = "gke-${local.fake_region_hash}"
22+
23+
http_port_default = terraform.workspace == "apps" ? 80 : 8080
24+
http_port = lookup(local.cfg, "http_port", local.http_port_default)
25+
26+
https_port_default = terraform.workspace == "apps" ? 443 : 8443
27+
https_port = lookup(local.cfg, "https_port", local.https_port_default)
28+
29+
manifest_path_default = "manifests/overlays/${terraform.workspace}"
30+
manifest_path = var.manifest_path != null ? var.manifest_path : local.manifest_path_default
31+
32+
disable_default_ingress = lookup(local.cfg, "disable_default_ingress", false)
33+
34+
node_image = lookup(local.cfg, "node_image", null)
35+
36+
# technically it should be min_node_count times number of AZs
37+
# but it seems better to keep node count low in the dev env
38+
node_count = lookup(local.cfg, "cluster_min_node_count", 1)
39+
nodes = [
40+
for node, _ in range(local.node_count) :
41+
"worker"
42+
]
43+
extra_nodes = join(",", local.nodes)
44+
45+
}

0 commit comments

Comments
 (0)