From 95ff805c98fa48ffa8a477649d4e3ac87184fc16 Mon Sep 17 00:00:00 2001 From: Erik Wilson Date: Thu, 14 Nov 2019 12:42:42 -0700 Subject: [PATCH] Fix broken K3S_TOKEN env --- pkg/cli/agent/agent.go | 4 ++++ pkg/cli/cmds/agent.go | 3 ++- pkg/cli/cmds/server.go | 7 ++++--- pkg/cli/server/server.go | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/cli/agent/agent.go b/pkg/cli/agent/agent.go index 40c4636a30..1ce8624333 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 a44a7cc101..0644a1a962 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 edcfdcf5de..19cdecf439 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 ecad127c74..c6f4d577a0 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