2019-01-09 16:54:15 +00:00
|
|
|
package cmds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Agent struct {
|
2019-03-04 06:29:06 +00:00
|
|
|
Token string
|
2019-03-04 17:10:01 +00:00
|
|
|
TokenFile string
|
2019-03-24 19:19:05 +00:00
|
|
|
ServerURL string
|
2019-03-26 22:15:16 +00:00
|
|
|
ResolvConf string
|
2019-03-04 06:29:06 +00:00
|
|
|
DataDir string
|
|
|
|
NodeIP string
|
|
|
|
NodeName string
|
|
|
|
ClusterSecret string
|
|
|
|
Docker bool
|
|
|
|
ContainerRuntimeEndpoint string
|
|
|
|
NoFlannel bool
|
|
|
|
Debug bool
|
2019-03-08 22:47:44 +00:00
|
|
|
Rootless bool
|
2019-01-09 16:54:15 +00:00
|
|
|
AgentShared
|
2019-04-05 00:43:00 +00:00
|
|
|
ExtraKubeletArgs cli.StringSlice
|
|
|
|
ExtraKubeProxyArgs cli.StringSlice
|
2019-01-09 16:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AgentShared struct {
|
|
|
|
NodeIP string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
appName = filepath.Base(os.Args[0])
|
|
|
|
AgentConfig Agent
|
|
|
|
NodeIPFlag = cli.StringFlag{
|
|
|
|
Name: "node-ip,i",
|
2019-03-02 00:10:18 +00:00
|
|
|
Usage: "(agent) IP address to advertise for node",
|
2019-01-09 16:54:15 +00:00
|
|
|
Destination: &AgentConfig.NodeIP,
|
|
|
|
}
|
|
|
|
NodeNameFlag = cli.StringFlag{
|
|
|
|
Name: "node-name",
|
2019-03-02 00:10:18 +00:00
|
|
|
Usage: "(agent) Node name",
|
2019-01-09 16:54:15 +00:00
|
|
|
EnvVar: "K3S_NODE_NAME",
|
|
|
|
Destination: &AgentConfig.NodeName,
|
|
|
|
}
|
2019-03-02 00:10:18 +00:00
|
|
|
DockerFlag = cli.BoolFlag{
|
|
|
|
Name: "docker",
|
|
|
|
Usage: "(agent) Use docker instead of containerd",
|
|
|
|
Destination: &AgentConfig.Docker,
|
|
|
|
}
|
|
|
|
FlannelFlag = cli.BoolFlag{
|
|
|
|
Name: "no-flannel",
|
|
|
|
Usage: "(agent) Disable embedded flannel",
|
|
|
|
Destination: &AgentConfig.NoFlannel,
|
|
|
|
}
|
2019-03-04 06:29:06 +00:00
|
|
|
CRIEndpointFlag = cli.StringFlag{
|
|
|
|
Name: "container-runtime-endpoint",
|
|
|
|
Usage: "(agent) Disable embedded containerd and use alternative CRI implementation",
|
|
|
|
Destination: &AgentConfig.ContainerRuntimeEndpoint,
|
|
|
|
}
|
2019-03-26 22:15:16 +00:00
|
|
|
ResolvConfFlag = cli.StringFlag{
|
|
|
|
Name: "resolv-conf",
|
|
|
|
Usage: "Kubelet resolv.conf file",
|
|
|
|
EnvVar: "K3S_RESOLV_CONF",
|
|
|
|
Destination: &AgentConfig.ResolvConf,
|
|
|
|
}
|
2019-04-05 00:43:00 +00:00
|
|
|
ExtraKubeletArgs = cli.StringSliceFlag{
|
|
|
|
Name: "kubelet-arg",
|
|
|
|
Usage: "(agent) Customized flag for kubelet process",
|
|
|
|
Value: &AgentConfig.ExtraKubeletArgs,
|
|
|
|
}
|
|
|
|
ExtraKubeProxyArgs = cli.StringSliceFlag{
|
|
|
|
Name: "kube-proxy-arg",
|
|
|
|
Usage: "(agent) Customized flag for kube-proxy process",
|
|
|
|
Value: &AgentConfig.ExtraKubeProxyArgs,
|
|
|
|
}
|
2019-01-09 16:54:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
Name: "agent",
|
|
|
|
Usage: "Run node agent",
|
|
|
|
UsageText: appName + " agent [OPTIONS]",
|
|
|
|
Action: action,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "token,t",
|
|
|
|
Usage: "Token to use for authentication",
|
|
|
|
EnvVar: "K3S_TOKEN",
|
|
|
|
Destination: &AgentConfig.Token,
|
|
|
|
},
|
2019-03-02 00:07:55 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "token-file",
|
|
|
|
Usage: "Token file to use for authentication",
|
|
|
|
EnvVar: "K3S_TOKEN_FILE",
|
|
|
|
Destination: &AgentConfig.TokenFile,
|
|
|
|
},
|
2019-01-09 16:54:15 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "server,s",
|
|
|
|
Usage: "Server to connect to",
|
|
|
|
EnvVar: "K3S_URL",
|
|
|
|
Destination: &AgentConfig.ServerURL,
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "data-dir,d",
|
|
|
|
Usage: "Folder to hold state",
|
|
|
|
Destination: &AgentConfig.DataDir,
|
|
|
|
Value: "/var/lib/rancher/k3s",
|
|
|
|
},
|
2019-01-22 21:14:58 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "cluster-secret",
|
|
|
|
Usage: "Shared secret used to bootstrap a cluster",
|
|
|
|
Destination: &AgentConfig.ClusterSecret,
|
|
|
|
EnvVar: "K3S_CLUSTER_SECRET",
|
|
|
|
},
|
2019-03-08 22:47:44 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "rootless",
|
|
|
|
Usage: "(experimental) Run rootless",
|
|
|
|
Destination: &AgentConfig.Rootless,
|
|
|
|
},
|
2019-03-02 00:10:18 +00:00
|
|
|
DockerFlag,
|
|
|
|
FlannelFlag,
|
2019-01-09 16:54:15 +00:00
|
|
|
NodeNameFlag,
|
|
|
|
NodeIPFlag,
|
2019-03-04 06:29:06 +00:00
|
|
|
CRIEndpointFlag,
|
2019-03-26 22:15:16 +00:00
|
|
|
ResolvConfFlag,
|
2019-04-05 00:43:00 +00:00
|
|
|
ExtraKubeletArgs,
|
|
|
|
ExtraKubeProxyArgs,
|
2019-01-09 16:54:15 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|