From e32292478107855f6c3046df24c86a2da2b2dc3d Mon Sep 17 00:00:00 2001 From: Hussein Galal Date: Wed, 18 Aug 2021 01:02:30 +0200 Subject: [PATCH] Reset load balancer state during restoraion (#3877) * Reset load balancer state during restoraion Signed-off-by: galal-hussein * Reset load balancer state during restoraion Signed-off-by: galal-hussein --- pkg/agent/loadbalancer/loadbalancer.go | 10 ++++++++++ pkg/cli/server/server.go | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/pkg/agent/loadbalancer/loadbalancer.go b/pkg/agent/loadbalancer/loadbalancer.go index 6e648ffba0..e072bb1b58 100644 --- a/pkg/agent/loadbalancer/loadbalancer.go +++ b/pkg/agent/loadbalancer/loadbalancer.go @@ -4,6 +4,7 @@ import ( "context" "errors" "net" + "os" "path/filepath" "strconv" "sync" @@ -154,3 +155,12 @@ func onDialError(src net.Conn, dstDialErr error) { logrus.Debugf("Incoming conn %v, error dialing load balancer servers: %v", src.RemoteAddr().String(), dstDialErr) src.Close() } + +// ResetLoadBalancer will delete the local state file for the load balacner on disk +func ResetLoadBalancer(dataDir, serviceName string) error { + stateFile := filepath.Join(dataDir, "etc", serviceName+".json") + if err := os.Remove(stateFile); err != nil { + logrus.Warn(err) + } + return nil +} diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 519db288ad..f3fc780eef 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -13,6 +13,7 @@ import ( "github.com/erikdubbelboer/gspt" "github.com/pkg/errors" "github.com/rancher/k3s/pkg/agent" + "github.com/rancher/k3s/pkg/agent/loadbalancer" "github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/clientaccess" "github.com/rancher/k3s/pkg/datadir" @@ -160,6 +161,10 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont serverConfig.ControlConfig.DisableControllerManager = true serverConfig.ControlConfig.DisableScheduler = true serverConfig.ControlConfig.DisableCCM = true + + // delete local loadbalancers state for apiserver and supervisor servers + loadbalancer.ResetLoadBalancer(filepath.Join(cfg.DataDir, "agent"), loadbalancer.SupervisorServiceName) + loadbalancer.ResetLoadBalancer(filepath.Join(cfg.DataDir, "agent"), loadbalancer.APIServerServiceName) } serverConfig.ControlConfig.ClusterReset = cfg.ClusterReset