diff --git a/pkg/cli/agent/agent.go b/pkg/cli/agent/agent.go index 40c4636a302..1ce86243335 100644 --- a/pkg/cli/agent/agent.go +++ b/pkg/cli/agent/agent.go @@ -31,6 +31,10 @@ func Run(ctx *cli.Context) error { cmds.AgentConfig.Token = token } + if cmds.AgentConfig.Token == "" && cmds.AgentConfig.ClusterSecret != "" { + cmds.AgentConfig.Token = cmds.AgentConfig.ClusterSecret + } + if cmds.AgentConfig.Token == "" { return fmt.Errorf("--token is required") } diff --git a/pkg/cli/cmds/agent.go b/pkg/cli/cmds/agent.go index a44a7cc101a..0644a1a962a 100644 --- a/pkg/cli/cmds/agent.go +++ b/pkg/cli/cmds/agent.go @@ -10,6 +10,7 @@ import ( type Agent struct { Token string TokenFile string + ClusterSecret string ServerURL string DisableLoadBalancer bool ResolvConf string @@ -189,7 +190,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command { cli.StringFlag{ Name: "cluster-secret", Usage: "(deprecated) use --token", - Destination: &AgentConfig.Token, + Destination: &AgentConfig.ClusterSecret, EnvVar: "K3S_CLUSTER_SECRET", }, }, diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index edcfdcf5deb..19cdecf439c 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -12,6 +12,7 @@ type Server struct { AgentTokenFile string Token string TokenFile string + ClusterSecret string ServiceCIDR string ClusterDNS string ClusterDomain string @@ -121,7 +122,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { Name: "token,t", Usage: "(cluster) Shared secret used to join a server or agent to a cluster", Destination: &ServerConfig.Token, - EnvVar: "K3S_CLUSTER_SECRET,K3S_TOKEN", + EnvVar: "K3S_TOKEN", }, cli.StringFlag{ Name: "token-file", @@ -231,7 +232,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { }, cli.StringFlag{ Name: "agent-token", - Usage: "(experimental/cluster) Shared secret used to join agents to the cluster, but not agents", + Usage: "(experimental/cluster) Shared secret used to join agents to the cluster, but not servers", Destination: &ServerConfig.AgentToken, EnvVar: "K3S_AGENT_TOKEN", }, @@ -268,7 +269,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { cli.StringFlag{ Name: "cluster-secret", Usage: "(deprecated) use --token", - Destination: &ServerConfig.Token, + Destination: &ServerConfig.ClusterSecret, EnvVar: "K3S_CLUSTER_SECRET", }, cli.BoolFlag{ diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index ecad127c741..c6f4d577a0b 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -55,6 +55,10 @@ func run(app *cli.Context, cfg *cmds.Server) error { } } + if cfg.Token == "" && cfg.ClusterSecret != "" { + cfg.Token = cfg.ClusterSecret + } + serverConfig := server.Config{} serverConfig.DisableAgent = cfg.DisableAgent serverConfig.ControlConfig.Token = cfg.Token