Skip to content

Commit

Permalink
Properly uninstall traefik configuration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbosdo committed Jul 31, 2024
1 parent 864cb7f commit f482336
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions shared/kubernetes/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
}

Expand Down

0 comments on commit f482336

Please sign in to comment.