Skip to content

Commit 7efa21e

Browse files
Refactored submodule to return liqo helm chart values only
1 parent f3daa9f commit 7efa21e

File tree

6 files changed

+88
-429
lines changed

6 files changed

+88
-429
lines changed

main.tf

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
locals {
2+
liqo_chart_repo = "https://castai.github.io/liqo"
3+
liqo_chart_name = "liqo"
4+
liqo_release_name = "omni"
5+
liqo_image_tag = var.liqo_chart_version
6+
27
omni_namespace = "castai-omni"
38
omni_agent_release = "omni-agent"
49
omni_agent_chart = "omni-agent"
510
castai_helm_repository = "https://castai.github.io/helm-charts"
611
}
712

8-
# OCI Cloud Resources (created first to provide attributes to edge location)
9-
module "liqo" {
13+
# Compute Liqo Helm chart configuration
14+
module "liqo_helm_values" {
1015
source = "./modules/gke"
1116

12-
namespace = local.omni_namespace
13-
liqo_chart_version = var.liqo_chart_version
17+
image_tag = local.liqo_image_tag
1418
cluster_name = var.cluster_name
1519
cluster_region = var.cluster_region
1620
cluster_zone = var.cluster_zone
@@ -20,6 +24,20 @@ module "liqo" {
2024
reserved_subnet_cidrs = var.reserved_subnet_cidrs
2125
}
2226

27+
# Liqo Helm Release
28+
resource "helm_release" "liqo" {
29+
name = local.liqo_release_name
30+
repository = local.liqo_chart_repo
31+
chart = local.liqo_chart_name
32+
version = var.liqo_chart_version
33+
namespace = local.omni_namespace
34+
create_namespace = true
35+
cleanup_on_fail = true
36+
wait = true
37+
38+
set = module.liqo_helm_values.set_values
39+
}
40+
2341
# Wait for Liqo network resources to be ready before proceeding
2442
resource "null_resource" "wait_for_liqo_network" {
2543
provisioner "local-exec" {
@@ -54,7 +72,7 @@ resource "null_resource" "wait_for_liqo_network" {
5472
EOT
5573
}
5674

57-
depends_on = [module.liqo]
75+
depends_on = [helm_release.liqo]
5876
}
5977

6078
# Extract the external CIDR value from Liqo network resource

modules/gke/main.tf

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,67 @@
11
locals {
2-
liqo_release_name = "omni"
3-
liqo_chart_repo = "https://castai.github.io/liqo"
4-
liqo_chart_name = "liqo"
2+
pools_cidrs = ["10.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12", var.service_cidr]
53

6-
# Format reserved subnet CIDRs as YAML array with proper indentation
7-
pools_cidrs = ["10.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12", var.service_cidr]
8-
pools_cidrs_yaml = length(local.pools_cidrs) > 0 ? join("\n ", [
9-
for cidr in local.pools_cidrs : "- ${cidr}"
10-
]) : "[]"
11-
12-
reserved_subnets_yaml = length(var.reserved_subnet_cidrs) > 0 ? join("\n ", [
13-
for cidr in var.reserved_subnet_cidrs : "- ${cidr}"
14-
]) : "[]"
4+
basic_set_values = [
5+
{
6+
name = "tag"
7+
value = var.image_tag
8+
},
9+
{
10+
name = "apiServer.address"
11+
value = var.api_server_address
12+
},
13+
{
14+
name = "discovery.config.clusterID"
15+
value = var.cluster_name
16+
},
17+
{
18+
name = "discovery.config.clusterLabels.liqo\\.io/provider"
19+
value = "gke"
20+
},
21+
{
22+
name = "discovery.config.clusterLabels.topology\\.kubernetes\\.io/region"
23+
value = var.cluster_region
24+
},
25+
{
26+
name = "ipam.podCIDR"
27+
value = var.pod_cidr
28+
},
29+
{
30+
name = "ipam.serviceCIDR"
31+
value = var.service_cidr
32+
},
33+
{
34+
name = "telemetry.enabled"
35+
value = "false"
36+
}
37+
]
1538

16-
# Render the values file with variable substitutions
17-
liqo_helm_values = templatefile("${path.module}/templates/values.yaml", {
18-
cluster_name = var.cluster_name
19-
liqo_version = var.liqo_chart_version
20-
api_server_address = var.api_server_address
21-
cluster_region = var.cluster_region
22-
cluster_zone = var.cluster_zone
23-
pod_cidr = var.pod_cidr
24-
service_cidr = var.service_cidr
25-
pools_cidrs = local.pools_cidrs_yaml
26-
reserved_subnets_cidrs = local.reserved_subnets_yaml
27-
})
28-
}
39+
# Conditional zone label
40+
zone_set_values = var.cluster_zone != "" ? [
41+
{
42+
name = "discovery.config.clusterLabels.topology\\.kubernetes\\.io/zone"
43+
value = var.cluster_zone
44+
}
45+
] : []
2946

30-
# Liqo Helm Release
31-
resource "helm_release" "liqo" {
32-
name = local.liqo_release_name
33-
repository = local.liqo_chart_repo
34-
chart = local.liqo_chart_name
35-
version = var.liqo_chart_version
36-
namespace = var.namespace
37-
create_namespace = true
38-
cleanup_on_fail = true
39-
wait = true
47+
pools_set_values = [
48+
for idx, cidr in local.pools_cidrs : {
49+
name = "ipam.pools[${idx}]"
50+
value = cidr
51+
}
52+
]
4053

41-
values = [
42-
local.liqo_helm_values
54+
reserved_subnets_set_values = [
55+
for idx, cidr in var.reserved_subnet_cidrs : {
56+
name = "ipam.reservedSubnets[${idx}]"
57+
value = cidr
58+
}
4359
]
60+
61+
all_set_values = concat(
62+
local.basic_set_values,
63+
local.zone_set_values,
64+
local.pools_set_values,
65+
local.reserved_subnets_set_values
66+
)
4467
}

modules/gke/outputs.tf

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
output "liqo_release_name" {
2-
description = "Name of the liqo Helm release"
3-
value = helm_release.liqo.name
1+
output "set_values" {
2+
description = "All Helm set values for liqo configuration"
3+
value = local.all_set_values
44
}
5-
6-
output "liqo_namespace" {
7-
description = "Namespace where liqo is installed"
8-
value = helm_release.liqo.namespace
9-
}
10-
11-
output "liqo_version" {
12-
description = "Version of the liqo Helm chart installed"
13-
value = helm_release.liqo.version
14-
}
15-
16-
output "liqo_status" {
17-
description = "Status of the liqo Helm release"
18-
value = helm_release.liqo.status
19-
}

0 commit comments

Comments
 (0)