Skip to content

Commit f818568

Browse files
authored
feat!: talos multinode initial support (#72)
* Update * Fix instance type * Fix name * F
1 parent e56a220 commit f818568

File tree

11 files changed

+100
-60
lines changed

11 files changed

+100
-60
lines changed

ephemeral/instance.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ data "digitalocean_image" "talos" {
1515
name = "talos-v1.9.1"
1616
}
1717

18-
resource "digitalocean_droplet" "talos" {
19-
name = "rnd-${local.prefix}-spectrum-cp"
18+
resource "digitalocean_droplet" "cp" {
19+
count = 1
20+
name = "rnd-${local.prefix}-spectrum-cp-${count.index}"
2021
size = "s-8vcpu-16gb"
2122
image = data.digitalocean_image.talos.id
2223
region = "fra1"
@@ -32,6 +33,6 @@ resource "digitalocean_droplet" "talos" {
3233
}
3334

3435
resource "digitalocean_reserved_ip" "l2" {
35-
droplet_id = digitalocean_droplet.talos.id
36-
region = digitalocean_droplet.talos.region
36+
droplet_id = digitalocean_droplet.cp[0].id
37+
region = digitalocean_droplet.cp[0].region
3738
}

ephemeral/main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ data "vault_generic_secret" "docker" {
1313
module "talos" {
1414
source = "../terraform-modules/talos"
1515
cluster_name = local.prefix
16-
server_ip = digitalocean_droplet.talos.ipv4_address
1716

18-
config_patches = [
19-
file("${path.root}/config_patch.yml"),
17+
control_planes = [
18+
{
19+
name = "cp-0"
20+
server_ip = digitalocean_droplet.cp[0].ipv4_address
21+
config_patches = [
22+
file("${path.root}/patches/registry.yml"),
23+
]
24+
},
2025
]
2126
}
2227

@@ -36,7 +41,7 @@ module "spectrum" {
3641
DOTOKEN = base64encode(data.vault_generic_secret.spectrum.data.token)
3742
DOMAIN = "${local.prefix}.fluence.dev"
3843
PREFIX = local.prefix
39-
LOADBALANCER_IP = digitalocean_droplet.talos.ipv4_address
44+
LOADBALANCER_IP = digitalocean_droplet.cp[0].ipv4_address
4045
L2_IP = digitalocean_reserved_ip.l2.ip_address
4146
}
4247
}
File renamed without changes.

examples/talos/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Server customization
44

5-
In talos machine is configured from a single configuration file in yaml format. Talos terraform module allows to specify overlays of the main configuration file maintained by cloudless labs [here](https://github.com/fluencelabs/spectrum/blob/main/terraform-modules/talos/templates/controlplane_patch.yml) with `config_pathes` option.
5+
In talos machine is configured from a single configuration file in yaml format. Talos terraform module allows to specify overlays of the main configuration file maintained by cloudless labs [here](https://github.com/fluencelabs/spectrum/blob/main/terraform-modules/talos/base_config.yml) with `config_pathes` option.
66

7-
You can configure server specific things like layout of disks or network configuration. Checkout [talos documentation](https://www.talos.dev/v1.9/reference/configuration/v1alpha1/config/) and see `config_patch.yml` for an example of a `bond` interface configuration.
7+
You can configure server specific things like layout of disks or network configuration. Checkout [talos documentation](https://www.talos.dev/v1.9/reference/configuration/v1alpha1/config/) and see [`cp-0.yml`](https://github.com/fluencelabs/blob/main/examples/talos/patches/cp-0.yml) for an example of a `bond` interface configuration.
88

99
## Terraform state
1010

examples/talos/main.tf

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@ provider "helm" {
2222

2323
module "talos" {
2424
source = "git::https://github.com/fluencelabs/spectrum.git//terraform-modules/talos?ref=terraform-module-talos-v0.1.0" # x-release-please-version
25-
cluster_name = var.cluster_name
26-
server_ip = var.server_ip
27-
# config_patches = [
28-
# file("${path.root}/config_patch.yml"),
29-
# ]
30-
}
31-
32-
variable "server_ip" {
33-
type = string
34-
description = "IP at which server is accessible"
35-
}
25+
cluster_name = "my-cluster"
3626

37-
variable "cluster_name" {
38-
type = string
39-
description = "Name used in k8s and talos to distinguish between clusters"
27+
control_planes = [
28+
{
29+
name = "cp-0"
30+
server_ip = "1.2.3.4"
31+
config_patches = [
32+
file("${path.root}/patches/base.yml"),
33+
file("${path.root}/patches/cp-0.yml"),
34+
]
35+
},
36+
]
4037
}

examples/talos/patches/base.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
machine:
2+
time:
3+
servers:
4+
- time.cloudflare.com

examples/talos/config_patch.yml renamed to examples/talos/patches/cp-0.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ machine:
3030
serial: Y0L0A031T5N8
3131

3232
network:
33-
hostname: foobar
3433
interfaces:
3534
- interface: bond0
3635
dhcp: false

examples/talos/variables.auto.tfvars

Lines changed: 0 additions & 2 deletions
This file was deleted.

terraform-modules/talos/templates/controlplane_patch.yml renamed to terraform-modules/talos/base_config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
machine:
2-
time:
3-
servers:
4-
- time.cloudflare.com
2+
network:
3+
hostname: ${hostname}
54
install:
65
diskSelector:
76
size: '>= 100GB'

terraform-modules/talos/talos.tf

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,79 @@
11
resource "talos_machine_secrets" "this" {
2-
talos_version = "v1.9"
2+
talos_version = var.talos_version
33
}
44

5-
data "talos_machine_configuration" "this" {
5+
locals {
6+
virtual_ip = var.virtual_ip != "" ? var.virtual_ip : var.control_planes[0].server_ip
7+
cluster_endpoint = "https://${local.virtual_ip}:6443"
8+
}
9+
10+
data "talos_machine_configuration" "control_plane" {
11+
for_each = { for control_plane in var.control_planes : control_plane.name => control_plane }
12+
talos_version = var.talos_version
613
cluster_name = var.cluster_name
714
machine_type = "controlplane"
8-
cluster_endpoint = "https://${var.server_ip}:6443"
15+
cluster_endpoint = local.cluster_endpoint
916
machine_secrets = talos_machine_secrets.this.machine_secrets
10-
talos_version = "v1.9"
1117
config_patches = [
12-
templatefile("${path.module}/templates/controlplane_patch.yml", {})
18+
templatefile("${path.module}/base_config.yml", { hostname = each.value.name })
1319
]
1420
}
1521

16-
resource "talos_machine_configuration_apply" "this" {
22+
data "talos_machine_configuration" "worker" {
23+
for_each = { for worker in var.workers : worker.name => worker }
24+
talos_version = var.talos_version
25+
cluster_name = var.cluster_name
26+
cluster_endpoint = local.cluster_endpoint
27+
machine_type = "worker"
28+
machine_secrets = talos_machine_secrets.this.machine_secrets
29+
config_patches = [
30+
templatefile("${path.module}/base_config.yml", { hostname = each.value.name })
31+
]
32+
}
33+
34+
resource "talos_machine_configuration_apply" "control_plane" {
35+
for_each = { for control_plane in var.control_planes : control_plane.name => control_plane }
36+
client_configuration = talos_machine_secrets.this.client_configuration
37+
machine_configuration_input = data.talos_machine_configuration.control_plane[each.key].machine_configuration
38+
node = each.value.server_ip
39+
config_patches = each.value.config_patches
40+
}
41+
42+
resource "talos_machine_configuration_apply" "worker" {
43+
for_each = { for worker in var.workers : worker.name => worker }
1744
client_configuration = talos_machine_secrets.this.client_configuration
18-
machine_configuration_input = data.talos_machine_configuration.this.machine_configuration
19-
node = var.server_ip
20-
config_patches = var.config_patches
45+
machine_configuration_input = data.talos_machine_configuration.worker[each.key].machine_configuration
46+
node = each.value.server_ip
47+
config_patches = each.value.config_patches
2148
}
2249

2350
data "talos_client_configuration" "this" {
2451
cluster_name = var.cluster_name
2552
client_configuration = talos_machine_secrets.this.client_configuration
2653
endpoints = [
27-
var.server_ip
54+
for control_plane in var.control_planes : control_plane.server_ip
2855
]
2956
}
3057

3158
resource "talos_machine_bootstrap" "this" {
32-
depends_on = [talos_machine_configuration_apply.this]
59+
depends_on = [talos_machine_configuration_apply.control_plane]
3360
client_configuration = talos_machine_secrets.this.client_configuration
34-
endpoint = var.server_ip
35-
node = var.server_ip
61+
endpoint = var.control_planes[0].server_ip
62+
node = var.control_planes[0].server_ip
3663
}
3764

3865
resource "talos_cluster_kubeconfig" "this" {
3966
client_configuration = talos_machine_secrets.this.client_configuration
40-
node = var.server_ip
67+
node = var.control_planes[0].server_ip
4168
}
4269

43-
# data "talos_cluster_health" "this" {
44-
# client_configuration = data.talos_client_configuration.this.client_configuration
45-
# control_plane_nodes = [var.server_ip]
46-
# endpoints = data.talos_client_configuration.this.endpoints
47-
# skip_kubernetes_checks = true
48-
# }
49-
5070
data "http" "talos_health" {
51-
url = "https://${var.server_ip}:6443/version"
71+
url = "${local.cluster_endpoint}/version"
5272
insecure = true
5373
retry {
54-
attempts = 20
74+
attempts = 60
5575
min_delay_ms = 5000
5676
max_delay_ms = 5000
5777
}
58-
depends_on = [
59-
talos_machine_bootstrap.this,
60-
]
78+
depends_on = [talos_machine_bootstrap.this]
6179
}

0 commit comments

Comments
 (0)