From f482336b638fca13b7c4b6ec5123072757bb7ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Wed, 31 Jul 2024 18:27:44 +0200 Subject: [PATCH] Properly uninstall traefik configuration When removing the configuration file traefik is not reinstalled. This can be achieved by change the file to an empty one and deleting it once traefik has been reinstalled. --- shared/kubernetes/k3s.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/shared/kubernetes/k3s.go b/shared/kubernetes/k3s.go index 38618e95c..53109e670 100644 --- a/shared/kubernetes/k3s.go +++ b/shared/kubernetes/k3s.go @@ -33,6 +33,10 @@ func InstallK3sTraefikConfig(tcpPorts []types.PortMap, udpPorts []types.PortMap) } // Wait for traefik to be back + waitForTraefik() +} + +func waitForTraefik() { log.Info().Msg(L("Waiting for Traefik to be reloaded")) for i := 0; i < 60; i++ { out, err := utils.RunCmdOutput(zerolog.TraceLevel, "kubectl", "get", "job", "-n", "kube-system", @@ -50,6 +54,21 @@ func InstallK3sTraefikConfig(tcpPorts []types.PortMap, udpPorts []types.PortMap) // UninstallK3sTraefikConfig uninstall K3s Traefik configuration. func UninstallK3sTraefikConfig(dryRun bool) { + // Write a blank file first to get traefik to be reinstalled + if !dryRun { + log.Info().Msg(L("Reinstalling Traefik without additionnal configuration")) + err := os.WriteFile(k3sTraefikConfigPath, []byte{}, 0600) + if err != nil { + log.Error().Err(err).Msg(L("failed to write empty traefik configuration")) + } else { + // Wait for traefik to be back + waitForTraefik() + } + } else { + log.Info().Msg(L("Would reinstall Traefik without additionnal configuration")) + } + + // Now that it's reinstalled, remove the file utils.UninstallFile(k3sTraefikConfigPath, dryRun) }