Skip to content

Commit

Permalink
Merge pull request #1436 from gmautner/master
Browse files Browse the repository at this point in the history
Allows specifying k3s version
  • Loading branch information
mysticaltech authored Aug 9, 2024
2 parents e171efc + 92a25b1 commit db1a260
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ resource "null_resource" "kustomization" {
# Redeploy when versions of addons need to be updated
versions = join("\n", [
coalesce(var.initial_k3s_channel, "N/A"),
coalesce(var.install_k3s_version, "N/A"),
coalesce(var.cluster_autoscaler_version, "N/A"),
coalesce(var.hetzner_ccm_version, "N/A"),
coalesce(var.hetzner_csi_version, "N/A"),
Expand Down Expand Up @@ -233,6 +234,7 @@ resource "null_resource" "kustomization" {
"${path.module}/templates/plans.yaml.tpl",
{
channel = var.initial_k3s_channel
version = var.install_k3s_version
disable_eviction = !var.system_upgrade_enable_eviction
})
destination = "/var/post_install/plans.yaml"
Expand Down
4 changes: 4 additions & 0 deletions kube.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ module "kube-hetzner" {
# The default is "v1.29".
# initial_k3s_channel = "stable"

# Allows you to specify the k3s version. If defined, supersedes initial_k3s_channel.
# See https://github.com/k3s-io/k3s/releases
# install_k3s_version = "v1.30.2+k3s2"

# The cluster name, by default "k3s"
# cluster_name = ""

Expand Down
12 changes: 10 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,18 @@ locals {
swap_node_label = ["node.kubernetes.io/server-swap=enabled"]

install_k3s_server = concat(local.common_pre_install_k3s_commands, [
"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 -"
var.install_k3s_version == "" ? (
"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 -"
) : (
"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 -"
)
], (var.disable_selinux ? [] : local.apply_k3s_selinux), local.common_post_install_k3s_commands)
install_k3s_agent = concat(local.common_pre_install_k3s_commands, [
"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 -"
var.install_k3s_version == "" ? (
"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 -"
) : (
"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 -"
)
], (var.disable_selinux ? [] : local.apply_k3s_selinux), local.common_post_install_k3s_commands)

control_plane_nodes = merge([
Expand Down
8 changes: 8 additions & 0 deletions templates/plans.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ metadata:
k3s_upgrade: agent
spec:
concurrency: 1
%{~ if version == "" ~}
channel: https://update.k3s.io/v1-release/channels/${channel}
%{~ else ~}
version: ${version}
%{~ endif ~}
serviceAccountName: system-upgrade
nodeSelector:
matchExpressions:
Expand Down Expand Up @@ -41,7 +45,11 @@ metadata:
k3s_upgrade: server
spec:
concurrency: 1
%{~ if version == "" ~}
channel: https://update.k3s.io/v1-release/channels/${channel}
%{~ else ~}
version: ${version}
%{~ endif ~}
serviceAccountName: system-upgrade
nodeSelector:
matchExpressions:
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ variable "initial_k3s_channel" {
}
}

variable "install_k3s_version" {
type = string
default = ""
description = "Allows you to specify the k3s version (Example: v1.29.6+k3s2). Supersedes initial_k3s_channel."
}

variable "system_upgrade_enable_eviction" {
type = bool
default = true
Expand Down

0 comments on commit db1a260

Please sign in to comment.