From f410fc7d1e956b54acbea96cb404941cdc79e8bd Mon Sep 17 00:00:00 2001 From: Hussein Galal Date: Wed, 5 May 2021 17:40:04 +0200 Subject: [PATCH] Invoke cluster reset function when only reset flag is passed (#3276) Signed-off-by: galal-hussein --- pkg/agent/run.go | 5 +++++ pkg/cli/cmds/agent.go | 1 + pkg/cli/server/server.go | 1 + pkg/cluster/managed.go | 7 +++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/agent/run.go b/pkg/agent/run.go index 4ac3e2e15b..21de502cc4 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -361,6 +361,11 @@ func setupTunnelAndRunAgent(ctx context.Context, nodeConfig *daemonconfig.Node, case <-ctx.Done(): return ctx.Err() } + } else if cfg.ClusterReset && proxy.IsAPIServerLBEnabled() { + if err := agent.Agent(&nodeConfig.AgentConfig); err != nil { + return err + } + agentRan = true } if err := tunnel.Setup(ctx, nodeConfig, proxy); err != nil { diff --git a/pkg/cli/cmds/agent.go b/pkg/cli/cmds/agent.go index 2cbf9f28ef..8181694ac7 100644 --- a/pkg/cli/cmds/agent.go +++ b/pkg/cli/cmds/agent.go @@ -43,6 +43,7 @@ type Agent struct { Labels cli.StringSlice Taints cli.StringSlice AgentShared + ClusterReset bool } type AgentShared struct { diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 6d551843b5..7b0935238e 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -404,6 +404,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont agentConfig.Token = token agentConfig.DisableLoadBalancer = !serverConfig.ControlConfig.DisableAPIServer agentConfig.ETCDAgent = serverConfig.ControlConfig.DisableAPIServer + agentConfig.ClusterReset = serverConfig.ControlConfig.ClusterReset agentConfig.Rootless = cfg.Rootless diff --git a/pkg/cluster/managed.go b/pkg/cluster/managed.go index d9d896d286..0057f8c42e 100644 --- a/pkg/cluster/managed.go +++ b/pkg/cluster/managed.go @@ -70,9 +70,12 @@ func (c *Cluster) start(ctx context.Context) error { if !os.IsNotExist(err) { return err } - } else { - return fmt.Errorf("cluster-reset was successfully performed, please remove the cluster-reset flag and start %s normally, if you need to perform another cluster reset, you must first manually delete the %s file", version.Program, resetFile) + rebootstrap := func() error { + return c.storageBootstrap(ctx) + } + return c.managedDB.Reset(ctx, rebootstrap) } + return fmt.Errorf("cluster-reset was successfully performed, please remove the cluster-reset flag and start %s normally, if you need to perform another cluster reset, you must first manually delete the %s file", version.Program, resetFile) } // removing the reset file and ignore error if the file doesn't exist