Skip to content

Commit 2e7d97b

Browse files
fix(iac): Refetch new kubeconfig if controller gets recreated (#115)
1 parent da0c85d commit 2e7d97b

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

terraform-modules/openstack-kubernetes-infra/kubeconfig-extraction.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
resource "null_resource" "copy_kubeconfig" {
22
depends_on = [openstack_compute_instance_v2.kubernetes_server, null_resource.kubernetes_server_provisioner]
33

4+
# Re-fetch kubeconfig whenever the controller is replaced (new cluster CA/certs).
5+
triggers = {
6+
server_id = openstack_compute_instance_v2.kubernetes_server.id
7+
ip_address = local.controller_host_instance.ip_address
8+
}
9+
410
provisioner "local-exec" {
511
# Copy the kubeconfig file from the host to a local file using SCP.
612
# Use ssh-keyscan to prevent interactive prompt on unknown host
7-
# Use sed to replace the localhost address in the KUBECONFIG file with the actual IP adddress of the created VM.
13+
# Use sed to replace the localhost address in the KUBECONFIG file with the actual IP adddress of the created VM.
814
command = <<EOT
915
mkdir -p ${path.root}/.build/ && \
1016
ssh-keyscan -H ${local.controller_host_instance.ip_address} >> ${path.root}/.build/.known_hosts_cogstack && \

terraform-modules/openstack-kubernetes-infra/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ check "controller_floating_ip_required_for_non_default_network" {
9898
assert {
9999
condition = (var.network == null
100100
|| (var.network.name == "external_4003" && var.network.network_id == null)
101-
|| (length([for host in var.host_instances : host if host.is_controller == true && host.floating_ip.use_floating_ip == true]) == 1))
101+
|| (length([for host in var.host_instances : host if host.is_controller == true && host.floating_ip.use_floating_ip == true]) == 1))
102102
error_message = <<-EOT
103103
When using a non-default network, the controller host should have a floating IP in order to be accessible by the terraform agent
104104
EOT

0 commit comments

Comments
 (0)