Skip to content

Commit

Permalink
Invoke cluster reset function when only reset flag is passed (k3s-io#…
Browse files Browse the repository at this point in the history
…3276)

Signed-off-by: galal-hussein <[email protected]>
  • Loading branch information
galal-hussein authored May 5, 2021
1 parent e1b9067 commit f410fc7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Agent struct {
Labels cli.StringSlice
Taints cli.StringSlice
AgentShared
ClusterReset bool
}

type AgentShared struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions pkg/cluster/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f410fc7

Please sign in to comment.