Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not uninstall k3s during upgrade #25

Merged
merged 1 commit into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions agent_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ resource null_resource agents_install {

depends_on = [null_resource.servers_install]
triggers = {
// Reinstall k3s only when specific fields changes (name or flags)
on_immutable_fields_changes = local.agents_metadata[each.key].immutable_fields_hash
on_immutable_changes = local.agents_metadata[each.key].immutable_fields_hash
on_new_version = local.k3s_version
}

connection {
Expand Down Expand Up @@ -110,15 +110,6 @@ resource null_resource agents_install {
destination = "/tmp/k3s-installer"
}

// Remove old k3s installation
provisioner remote-exec {
inline = [
"if ! command -V k3s-agent-uninstall.sh > /dev/null; then exit; fi",
"echo >&2 [WARN] K3s seems already installed on this node and will be uninstalled.",
"k3s-agent-uninstall.sh",
]
}

// Install k3s
provisioner remote-exec {
inline = [
Expand All @@ -129,7 +120,7 @@ resource null_resource agents_install {
}

// Drain k3s node on destruction in order to safely move all workflows to another node.
resource null_resource agent_drain {
resource null_resource agents_drain {
for_each = var.agents

depends_on = [null_resource.agents_install]
Expand Down Expand Up @@ -187,7 +178,6 @@ resource null_resource agents_annotation {
triggers = {
agent_name = local.agents_metadata[split(var.separator, each.key)[0]].name
annotation_name = split(var.separator, each.key)[1]
on_install = null_resource.agents_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value

// Because some fields must be used on destruction, we need to store them into the current
Expand Down Expand Up @@ -247,7 +237,6 @@ resource null_resource agents_label {
triggers = {
agent_name = local.agents_metadata[split(var.separator, each.key)[0]].name
label_name = split(var.separator, each.key)[1]
on_install = null_resource.agents_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value

// Because some fields must be used on destruction, we need to store them into the current
Expand Down Expand Up @@ -307,7 +296,6 @@ resource null_resource agents_taint {
triggers = {
agent_name = local.agents_metadata[split(var.separator, each.key)[0]].name
taint_name = split(var.separator, each.key)[1]
on_install = null_resource.agents_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value

// Because some fields must be used on destruction, we need to store them into the current
Expand Down
19 changes: 4 additions & 15 deletions server_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ locals {
)))

immutable_fields_hash = sha1(join("", concat(
[var.name, var.cidr.pods, var.cidr.services, local.k3s_version],
[var.name, var.cidr.pods, var.cidr.services],
var.global_flags,
try(server.flags, []),
)))
Expand All @@ -115,7 +115,8 @@ resource null_resource servers_install {

depends_on = [var.depends_on_]
triggers = {
on_immutable_fields_changes = local.servers_metadata[each.key].immutable_fields_hash
on_immutable_changes = local.servers_metadata[each.key].immutable_fields_hash
on_new_version = local.k3s_version
}

connection {
Expand Down Expand Up @@ -154,15 +155,6 @@ resource null_resource servers_install {
destination = "/tmp/k3s-installer"
}

// Remove old k3s installation
provisioner remote-exec {
inline = [
"if ! command -V k3s-uninstall.sh > /dev/null; then exit; fi",
"echo >&2 [WARN] K3s seems already installed on this node and will be uninstalled.",
"k3s-uninstall.sh",
]
}

// Install k3s server
provisioner "remote-exec" {
inline = [
Expand All @@ -173,7 +165,7 @@ resource null_resource servers_install {
}

// Drain k3s node on destruction in order to safely move all workflows to another node.
resource null_resource server_drain {
resource null_resource servers_drain {
for_each = var.servers

depends_on = [null_resource.servers_install]
Expand Down Expand Up @@ -228,7 +220,6 @@ resource null_resource servers_annotation {
triggers = {
server_name = local.servers_metadata[split(var.separator, each.key)[0]].name
annotation_name = split(var.separator, each.key)[1]
on_install = null_resource.servers_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value

connection_json = base64encode(jsonencode(local.root_server_connection))
Expand Down Expand Up @@ -285,7 +276,6 @@ resource null_resource servers_label {
triggers = {
server_name = local.servers_metadata[split(var.separator, each.key)[0]].name
label_name = split(var.separator, each.key)[1]
on_install = null_resource.servers_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value

connection_json = base64encode(jsonencode(local.root_server_connection))
Expand Down Expand Up @@ -343,7 +333,6 @@ resource null_resource servers_taint {
server_name = local.servers_metadata[split(var.separator, each.key)[0]].name
taint_name = split(var.separator, each.key)[1]
connection_json = base64encode(jsonencode(local.root_server_connection))
on_install = null_resource.servers_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value

connection_json = base64encode(jsonencode(local.root_server_connection))
Expand Down