Merge pull request #1080 from erikwilson/fix-agent-token-env

Fix broken K3S_TOKEN env
This commit is contained in:
Erik Wilson 2019-11-14 16:32:48 -07:00 committed by GitHub
commit 39c0224f0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -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")
}

View File

@ -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",
},
},

View File

@ -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{

View File

@ -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