From 440d28e41eb7a6efd68706e0cdda47430a085bbd Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Wed, 13 Dec 2023 11:05:05 +0200 Subject: [PATCH] Error out in ValidateHosts if all controllers are marked to be reset Signed-off-by: Kimmo Lehto --- phase/validate_hosts.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/phase/validate_hosts.go b/phase/validate_hosts.go index eca1c8a5..653267c4 100644 --- a/phase/validate_hosts.go +++ b/phase/validate_hosts.go @@ -25,12 +25,21 @@ func (p *ValidateHosts) Run() error { p.machineidcount = make(map[string]int, len(p.Config.Spec.Hosts)) p.privateaddrcount = make(map[string]int, len(p.Config.Spec.Hosts)) + controllerCount := len(p.Config.Spec.Hosts.Controllers()) + var resetControllerCount int for _, h := range p.Config.Spec.Hosts { p.hncount[h.Metadata.Hostname]++ p.machineidcount[h.Metadata.MachineID]++ if h.PrivateAddress != "" { p.privateaddrcount[h.PrivateAddress]++ } + if h.IsController() && h.Reset { + resetControllerCount++ + } + } + + if resetControllerCount >= controllerCount { + return fmt.Errorf("all controllers are marked to be reset - this will break the cluster. use `k0sctl reset` instead if that is intentional") } return p.parallelDo(