k3s/pkg/cli/cmds/agent.go

243 lines
7.2 KiB
Go
Raw Normal View History

2019-01-09 16:54:15 +00:00
package cmds
import (
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli"
2019-01-09 16:54:15 +00:00
)
type Agent struct {
2019-03-04 06:29:06 +00:00
Token string
2019-03-04 17:10:01 +00:00
TokenFile string
2019-11-14 19:42:42 +00:00
ClusterSecret string
2019-03-24 19:19:05 +00:00
ServerURL string
2019-07-24 07:22:31 +00:00
DisableLoadBalancer bool
ResolvConf string
2019-03-04 06:29:06 +00:00
DataDir string
NodeIP string
2019-10-15 21:17:26 +00:00
NodeExternalIP string
2019-03-04 06:29:06 +00:00
NodeName string
2019-05-03 17:36:12 +00:00
PauseImage string
Snapshotter string
2019-03-04 06:29:06 +00:00
Docker bool
ContainerRuntimeEndpoint string
NoFlannel bool
FlannelIface string
2019-08-08 05:56:09 +00:00
FlannelConf string
2019-03-04 06:29:06 +00:00
Debug bool
2019-03-08 22:47:44 +00:00
Rootless bool
RootlessAlreadyUnshared bool
2019-11-05 09:45:07 +00:00
WithNodeID bool
EnableSELinux bool
ProtectKernelDefaults bool
2019-01-09 16:54:15 +00:00
AgentShared
ExtraKubeletArgs cli.StringSlice
ExtraKubeProxyArgs cli.StringSlice
Labels cli.StringSlice
Taints cli.StringSlice
PrivateRegistry string
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",
Usage: "(agent/networking) IP address to advertise for node",
2019-01-09 16:54:15 +00:00
Destination: &AgentConfig.NodeIP,
}
2019-10-15 21:17:26 +00:00
NodeExternalIPFlag = cli.StringFlag{
Name: "node-external-ip",
Usage: "(agent/networking) External IP address to advertise for node",
2019-10-15 21:17:26 +00:00
Destination: &AgentConfig.NodeExternalIP,
}
2019-01-09 16:54:15 +00:00
NodeNameFlag = cli.StringFlag{
Name: "node-name",
Usage: "(agent/node) Node name",
EnvVar: version.ProgramUpper + "_NODE_NAME",
2019-01-09 16:54:15 +00:00
Destination: &AgentConfig.NodeName,
}
2019-11-05 09:45:07 +00:00
WithNodeIDFlag = cli.BoolFlag{
Name: "with-node-id",
Usage: "(agent/node) Append id to node name",
Destination: &AgentConfig.WithNodeID,
}
2019-03-02 00:10:18 +00:00
DockerFlag = cli.BoolFlag{
Name: "docker",
Usage: "(agent/runtime) Use docker instead of containerd",
2019-03-02 00:10:18 +00:00
Destination: &AgentConfig.Docker,
}
CRIEndpointFlag = cli.StringFlag{
Name: "container-runtime-endpoint",
Usage: "(agent/runtime) Disable embedded containerd and use alternative CRI implementation",
Destination: &AgentConfig.ContainerRuntimeEndpoint,
}
PrivateRegistryFlag = cli.StringFlag{
Name: "private-registry",
Usage: "(agent/runtime) Private registry configuration file",
Destination: &AgentConfig.PrivateRegistry,
Value: "/etc/rancher/" + version.Program + "/registries.yaml",
}
PauseImageFlag = cli.StringFlag{
Name: "pause-image",
Usage: "(agent/runtime) Customized pause image for containerd or docker sandbox",
Destination: &AgentConfig.PauseImage,
Value: "docker.io/rancher/pause:3.1",
}
SnapshotterFlag = cli.StringFlag{
Name: "snapshotter",
Usage: "(agent/runtime) Override default containerd snapshotter",
Destination: &AgentConfig.Snapshotter,
Value: "overlayfs",
}
2019-03-02 00:10:18 +00:00
FlannelFlag = cli.BoolFlag{
Name: "no-flannel",
Usage: "(deprecated) use --flannel-backend=none",
2019-03-02 00:10:18 +00:00
Destination: &AgentConfig.NoFlannel,
}
FlannelIfaceFlag = cli.StringFlag{
Name: "flannel-iface",
Usage: "(agent/networking) Override default flannel interface",
Destination: &AgentConfig.FlannelIface,
}
2019-08-08 05:56:09 +00:00
FlannelConfFlag = cli.StringFlag{
Name: "flannel-conf",
Usage: "(agent/networking) Override default flannel config file",
2019-08-08 05:56:09 +00:00
Destination: &AgentConfig.FlannelConf,
}
ResolvConfFlag = cli.StringFlag{
Name: "resolv-conf",
Usage: "(agent/networking) Kubelet resolv.conf file",
EnvVar: version.ProgramUpper + "_RESOLV_CONF",
Destination: &AgentConfig.ResolvConf,
}
ExtraKubeletArgs = cli.StringSliceFlag{
Name: "kubelet-arg",
Usage: "(agent/flags) Customized flag for kubelet process",
Value: &AgentConfig.ExtraKubeletArgs,
}
ExtraKubeProxyArgs = cli.StringSliceFlag{
Name: "kube-proxy-arg",
Usage: "(agent/flags) Customized flag for kube-proxy process",
Value: &AgentConfig.ExtraKubeProxyArgs,
}
NodeTaints = cli.StringSliceFlag{
Name: "node-taint",
Usage: "(agent/node) Registering kubelet with set of taints",
Value: &AgentConfig.Taints,
}
NodeLabels = cli.StringSliceFlag{
Name: "node-label",
Usage: "(agent/node) Registering and starting kubelet with set of labels",
Value: &AgentConfig.Labels,
}
DisableSELinuxFlag = cli.BoolTFlag{
Name: "disable-selinux",
Usage: "(deprecated) Use --selinux to explicitly enable SELinux",
Hidden: true,
}
ProtectKernelDefaultsFlag = cli.BoolFlag{
Name: "protect-kernel-defaults",
Usage: "(agent/node) Kernel tuning behavior. If set, error if kernel tunables are different than kubelet defaults.",
Destination: &AgentConfig.ProtectKernelDefaults,
}
SELinuxFlag = cli.BoolFlag{
Name: "selinux",
Usage: "(agent/node) Enable SELinux in containerd",
Hidden: false,
Destination: &AgentConfig.EnableSELinux,
EnvVar: version.ProgramUpper + "_SELINUX",
}
2019-01-09 16:54:15 +00:00
)
func CheckSELinuxFlags(ctx *cli.Context) error {
disable, enable := DisableSELinuxFlag.Name, SELinuxFlag.Name
switch {
case ctx.IsSet(disable) && ctx.IsSet(enable):
return errors.Errorf("--%s is deprecated in favor of --%s to affirmatively enable it in containerd", disable, enable)
case ctx.IsSet(disable):
AgentConfig.EnableSELinux = !ctx.Bool(disable)
}
return nil
}
func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
return cli.Command{
2019-01-09 16:54:15 +00:00
Name: "agent",
Usage: "Run node agent",
UsageText: appName + " agent [OPTIONS]",
Before: CheckSELinuxFlags,
Action: action,
2019-01-09 16:54:15 +00:00
Flags: []cli.Flag{
VLevel,
VModule,
LogFile,
AlsoLogToStderr,
cli.StringFlag{
2019-01-09 16:54:15 +00:00
Name: "token,t",
Usage: "(cluster) Token to use for authentication",
EnvVar: version.ProgramUpper + "_TOKEN",
2019-01-09 16:54:15 +00:00
Destination: &AgentConfig.Token,
},
cli.StringFlag{
2019-03-02 00:07:55 +00:00
Name: "token-file",
Usage: "(cluster) Token file to use for authentication",
EnvVar: version.ProgramUpper + "_TOKEN_FILE",
2019-03-02 00:07:55 +00:00
Destination: &AgentConfig.TokenFile,
},
cli.StringFlag{
2019-01-09 16:54:15 +00:00
Name: "server,s",
Usage: "(cluster) Server to connect to",
EnvVar: version.ProgramUpper + "_URL",
2019-01-09 16:54:15 +00:00
Destination: &AgentConfig.ServerURL,
},
cli.StringFlag{
2019-01-09 16:54:15 +00:00
Name: "data-dir,d",
Usage: "(agent/data) Folder to hold state",
2019-01-09 16:54:15 +00:00
Destination: &AgentConfig.DataDir,
Value: "/var/lib/rancher/" + version.Program + "",
2019-01-09 16:54:15 +00:00
},
NodeNameFlag,
WithNodeIDFlag,
NodeLabels,
NodeTaints,
DockerFlag,
CRIEndpointFlag,
PauseImageFlag,
SnapshotterFlag,
PrivateRegistryFlag,
NodeIPFlag,
NodeExternalIPFlag,
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
ProtectKernelDefaultsFlag,
cli.BoolFlag{
Name: "rootless",
Usage: "(experimental) Run rootless",
Destination: &AgentConfig.Rootless,
},
&SELinuxFlag,
// Deprecated/hidden below
&DisableSELinuxFlag,
FlannelFlag,
cli.StringFlag{
Name: "cluster-secret",
Usage: "(deprecated) use --token",
2019-11-14 19:42:42 +00:00
Destination: &AgentConfig.ClusterSecret,
EnvVar: version.ProgramUpper + "_CLUSTER_SECRET",
},
2019-01-09 16:54:15 +00:00
},
}
}