Unverified Commit 5ff22d0e authored by Hussein Galal's avatar Hussein Galal Committed by GitHub

Reset load balancer state during restoraion (#3879)

Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> Reset load balancer state during restoraion Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com>
parent fedc68f7
......@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net"
"os"
"path/filepath"
"strconv"
"sync"
......@@ -148,3 +149,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
}
......@@ -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"
......@@ -161,6 +162,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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment