Skip to content

Commit db1a260

Browse files
authored
Merge pull request #1436 from gmautner/master
Allows specifying k3s version
2 parents e171efc + 92a25b1 commit db1a260

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

init.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ resource "null_resource" "kustomization" {
128128
# Redeploy when versions of addons need to be updated
129129
versions = join("\n", [
130130
coalesce(var.initial_k3s_channel, "N/A"),
131+
coalesce(var.install_k3s_version, "N/A"),
131132
coalesce(var.cluster_autoscaler_version, "N/A"),
132133
coalesce(var.hetzner_ccm_version, "N/A"),
133134
coalesce(var.hetzner_csi_version, "N/A"),
@@ -233,6 +234,7 @@ resource "null_resource" "kustomization" {
233234
"${path.module}/templates/plans.yaml.tpl",
234235
{
235236
channel = var.initial_k3s_channel
237+
version = var.install_k3s_version
236238
disable_eviction = !var.system_upgrade_enable_eviction
237239
})
238240
destination = "/var/post_install/plans.yaml"

kube.tf.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ module "kube-hetzner" {
590590
# The default is "v1.29".
591591
# initial_k3s_channel = "stable"
592592

593+
# Allows you to specify the k3s version. If defined, supersedes initial_k3s_channel.
594+
# See https://github.com/k3s-io/k3s/releases
595+
# install_k3s_version = "v1.30.2+k3s2"
596+
593597
# The cluster name, by default "k3s"
594598
# cluster_name = ""
595599

locals.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,18 @@ locals {
125125
swap_node_label = ["node.kubernetes.io/server-swap=enabled"]
126126

127127
install_k3s_server = concat(local.common_pre_install_k3s_commands, [
128-
"curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_CHANNEL=${var.initial_k3s_channel} INSTALL_K3S_EXEC='server ${var.k3s_exec_server_args}' sh -"
128+
var.install_k3s_version == "" ? (
129+
"curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_CHANNEL=${var.initial_k3s_channel} INSTALL_K3S_EXEC='server ${var.k3s_exec_server_args}' sh -"
130+
) : (
131+
"curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_VERSION=${var.install_k3s_version} INSTALL_K3S_EXEC='server ${var.k3s_exec_server_args}' sh -"
132+
)
129133
], (var.disable_selinux ? [] : local.apply_k3s_selinux), local.common_post_install_k3s_commands)
130134
install_k3s_agent = concat(local.common_pre_install_k3s_commands, [
131-
"curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_CHANNEL=${var.initial_k3s_channel} INSTALL_K3S_EXEC='agent ${var.k3s_exec_agent_args}' sh -"
135+
var.install_k3s_version == "" ? (
136+
"curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_CHANNEL=${var.initial_k3s_channel} INSTALL_K3S_EXEC='agent ${var.k3s_exec_agent_args}' sh -"
137+
) : (
138+
"curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_VERSION=${var.install_k3s_version} INSTALL_K3S_EXEC='agent ${var.k3s_exec_agent_args}' sh -"
139+
)
132140
], (var.disable_selinux ? [] : local.apply_k3s_selinux), local.common_post_install_k3s_commands)
133141

134142
control_plane_nodes = merge([

templates/plans.yaml.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ metadata:
1010
k3s_upgrade: agent
1111
spec:
1212
concurrency: 1
13+
%{~ if version == "" ~}
1314
channel: https://update.k3s.io/v1-release/channels/${channel}
15+
%{~ else ~}
16+
version: ${version}
17+
%{~ endif ~}
1418
serviceAccountName: system-upgrade
1519
nodeSelector:
1620
matchExpressions:
@@ -41,7 +45,11 @@ metadata:
4145
k3s_upgrade: server
4246
spec:
4347
concurrency: 1
48+
%{~ if version == "" ~}
4449
channel: https://update.k3s.io/v1-release/channels/${channel}
50+
%{~ else ~}
51+
version: ${version}
52+
%{~ endif ~}
4553
serviceAccountName: system-upgrade
4654
nodeSelector:
4755
matchExpressions:

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ variable "initial_k3s_channel" {
545545
}
546546
}
547547

548+
variable "install_k3s_version" {
549+
type = string
550+
default = ""
551+
description = "Allows you to specify the k3s version (Example: v1.29.6+k3s2). Supersedes initial_k3s_channel."
552+
}
553+
548554
variable "system_upgrade_enable_eviction" {
549555
type = bool
550556
default = true

0 commit comments

Comments
 (0)