Skip to content

Commit

Permalink
fixup! fix: do not uninstall k3s during upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
xunleii committed May 31, 2020
1 parent 52b3d80 commit 436a024
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 104 deletions.
54 changes: 1 addition & 53 deletions agent_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,65 +64,13 @@ locals {
}
}

// Remove k3s agent if exists (used on the first run, when an immutable field changes or
// when a server will be reinstalled)
resource null_resource agents_uninstall {
for_each = var.agents

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_uninstall = null_resource.servers_uninstall[local.root_server_name].id
}

connection {
type = try(each.value.connection.type, "ssh")

host = try(each.value.connection.host, each.value.ip)
user = try(each.value.connection.user, null)
password = try(each.value.connection.password, null)
port = try(each.value.connection.port, null)
timeout = try(each.value.connection.timeout, null)

script_path = try(each.value.connection.script_path, null)
private_key = try(each.value.connection.private_key, null)
certificate = try(each.value.connection.certificate, null)
agent = try(each.value.connection.agent, null)
agent_identity = try(each.value.connection.agent_identity, null)
host_key = try(each.value.connection.host_key, null)

https = try(each.value.connection.https, null)
insecure = try(each.value.connection.insecure, null)
use_ntlm = try(each.value.connection.use_ntlm, null)
cacert = try(each.value.connection.cacert, null)

bastion_host = try(each.value.connection.bastion_host, null)
bastion_host_key = try(each.value.connection.bastion_host_key, null)
bastion_port = try(each.value.connection.bastion_port, null)
bastion_user = try(each.value.connection.bastion_user, null)
bastion_password = try(each.value.connection.bastion_password, null)
bastion_private_key = try(each.value.connection.bastion_private_key, null)
bastion_certificate = try(each.value.connection.bastion_certificate, null)
}

// 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 agent
resource null_resource agents_install {
for_each = var.agents

depends_on = [null_resource.servers_install]
triggers = {
on_uninstall = null_resource.agents_uninstall[each.key].id
on_immutable_changes = local.agents_metadata[each.key].immutable_fields_hash
on_new_version = local.k3s_version
}

Expand Down
52 changes: 1 addition & 51 deletions server_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,63 +109,13 @@ locals {
}
}

// Remove k3s server if exists (used on the first run or when an immutable field changes,
// in order to use new settings. It will reinstall the cluster.)
resource null_resource servers_uninstall {
for_each = var.servers

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

connection {
type = try(each.value.connection.type, "ssh")

host = try(each.value.connection.host, each.value.ip)
user = try(each.value.connection.user, null)
password = try(each.value.connection.password, null)
port = try(each.value.connection.port, null)
timeout = try(each.value.connection.timeout, null)

script_path = try(each.value.connection.script_path, null)
private_key = try(each.value.connection.private_key, null)
certificate = try(each.value.connection.certificate, null)
agent = try(each.value.connection.agent, null)
agent_identity = try(each.value.connection.agent_identity, null)
host_key = try(each.value.connection.host_key, null)

https = try(each.value.connection.https, null)
insecure = try(each.value.connection.insecure, null)
use_ntlm = try(each.value.connection.use_ntlm, null)
cacert = try(each.value.connection.cacert, null)

bastion_host = try(each.value.connection.bastion_host, null)
bastion_host_key = try(each.value.connection.bastion_host_key, null)
bastion_port = try(each.value.connection.bastion_port, null)
bastion_user = try(each.value.connection.bastion_user, null)
bastion_password = try(each.value.connection.bastion_password, null)
bastion_private_key = try(each.value.connection.bastion_private_key, null)
bastion_certificate = try(each.value.connection.bastion_certificate, null)
}

// 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
resource null_resource servers_install {
for_each = var.servers

depends_on = [var.depends_on_]
triggers = {
on_uninstall = null_resource.servers_uninstall[each.key].id
on_immutable_changes = local.servers_metadata[each.key].immutable_fields_hash
on_new_version = local.k3s_version
}

Expand Down

0 comments on commit 436a024

Please sign in to comment.