k3s/pkg/cli/cmds/agent.go

344 lines
12 KiB
Go
Raw Permalink Normal View History

2019-01-09 11:54:15 -05:00
package cmds
import (
"os"
"path/filepath"
"github.com/k3s-io/k3s/pkg/version"
"github.com/urfave/cli/v2"
2019-01-09 11:54:15 -05:00
)
type Agent struct {
2019-03-04 01:29:06 -05:00
Token string
2019-03-04 12:10:01 -05:00
TokenFile string
2019-11-14 14:42:42 -05:00
ClusterSecret string
2019-03-24 15:19:05 -04:00
ServerURL string
APIAddressCh chan []string
2019-07-24 03:22:31 -04:00
DisableLoadBalancer bool
DisableServiceLB bool
ETCDAgent bool
LBServerPort int
ResolvConf string
2019-03-04 01:29:06 -05:00
DataDir string
BindAddress string
NodeIP cli.StringSlice
NodeExternalIP cli.StringSlice
NodeInternalDNS cli.StringSlice
NodeExternalDNS cli.StringSlice
2019-03-04 01:29:06 -05:00
NodeName string
2019-05-03 13:36:12 -04:00
PauseImage string
Snapshotter string
2019-03-04 01:29:06 -05:00
Docker bool
ContainerdNoDefault bool
ContainerdNonrootDevices bool
2019-03-04 01:29:06 -05:00
ContainerRuntimeEndpoint string
DefaultRuntime string
ImageServiceEndpoint string
FlannelIface string
2019-08-08 01:56:09 -04:00
FlannelConf string
FlannelCniConfFile string
VPNAuth string
VPNAuthFile string
2019-03-04 01:29:06 -05:00
Debug bool
EnablePProf bool
2019-03-08 17:47:44 -05:00
Rootless bool
RootlessAlreadyUnshared bool
2019-11-05 04:45:07 -05:00
WithNodeID bool
EnableSELinux bool
ProtectKernelDefaults bool
ClusterReset bool
PrivateRegistry string
SystemDefaultRegistry string
AirgapExtraRegistry cli.StringSlice
ExtraKubeletArgs cli.StringSlice
ExtraKubeProxyArgs cli.StringSlice
Labels cli.StringSlice
Taints cli.StringSlice
ImageCredProvBinDir string
ImageCredProvConfig string
2019-01-09 11:54:15 -05:00
AgentShared
}
type AgentShared struct {
NodeIP string
}
var (
appName = filepath.Base(os.Args[0])
AgentConfig Agent
AgentTokenFlag = &cli.StringFlag{
Name: "token",
Aliases: []string{"t"},
Usage: "(cluster) Token to use for authentication",
EnvVars: []string{version.ProgramUpper + "_TOKEN"},
Destination: &AgentConfig.Token,
}
NodeIPFlag = &cli.StringSliceFlag{
Name: "node-ip",
Aliases: []string{"i"},
Usage: "(agent/networking) IPv4/IPv6 addresses to advertise for node",
Destination: &AgentConfig.NodeIP,
2019-01-09 11:54:15 -05:00
}
NodeExternalIPFlag = &cli.StringSliceFlag{
Name: "node-external-ip",
Usage: "(agent/networking) IPv4/IPv6 external IP addresses to advertise for node",
Destination: &AgentConfig.NodeExternalIP,
2019-10-15 17:17:26 -04:00
}
NodeInternalDNSFlag = &cli.StringSliceFlag{
Name: "node-internal-dns",
Usage: "(agent/networking) internal DNS addresses to advertise for node",
Destination: &AgentConfig.NodeInternalDNS,
}
NodeExternalDNSFlag = &cli.StringSliceFlag{
Name: "node-external-dns",
Usage: "(agent/networking) external DNS addresses to advertise for node",
Destination: &AgentConfig.NodeExternalDNS,
}
NodeNameFlag = &cli.StringFlag{
2019-01-09 11:54:15 -05:00
Name: "node-name",
Usage: "(agent/node) Node name",
EnvVars: []string{version.ProgramUpper + "_NODE_NAME"},
2019-01-09 11:54:15 -05:00
Destination: &AgentConfig.NodeName,
}
WithNodeIDFlag = &cli.BoolFlag{
2019-11-05 04:45:07 -05:00
Name: "with-node-id",
Usage: "(agent/node) Append id to node name",
Destination: &AgentConfig.WithNodeID,
}
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",
Destination: &AgentConfig.EnableSELinux,
EnvVars: []string{version.ProgramUpper + "_SELINUX"},
}
LBServerPortFlag = &cli.IntFlag{
Name: "lb-server-port",
Usage: "(agent/node) Local port for supervisor client load-balancer. If the supervisor and apiserver are not colocated an additional port 1 less than this port will also be used for the apiserver client load-balancer.",
Destination: &AgentConfig.LBServerPort,
EnvVars: []string{version.ProgramUpper + "_LB_SERVER_PORT"},
Value: 6444,
2019-03-01 19:10:18 -05:00
}
DockerFlag = &cli.BoolFlag{
Name: "docker",
Usage: "(agent/runtime) (experimental) Use cri-dockerd instead of containerd",
Destination: &AgentConfig.Docker,
}
CRIEndpointFlag = &cli.StringFlag{
Name: "container-runtime-endpoint",
Usage: "(agent/runtime) Disable embedded containerd and use the CRI socket at the given path; when used with --docker this sets the docker socket path",
Destination: &AgentConfig.ContainerRuntimeEndpoint,
}
DefaultRuntimeFlag = &cli.StringFlag{
Name: "default-runtime",
Usage: "(agent/runtime) Set the default runtime in containerd",
Destination: &AgentConfig.DefaultRuntime,
}
ImageServiceEndpointFlag = &cli.StringFlag{
Name: "image-service-endpoint",
Usage: "(agent/runtime) Disable embedded containerd image service and use remote image service socket at the given path. If not specified, defaults to --container-runtime-endpoint.",
Destination: &AgentConfig.ImageServiceEndpoint,
}
PrivateRegistryFlag = &cli.StringFlag{
Name: "private-registry",
Usage: "(agent/runtime) Private registry configuration file",
Destination: &AgentConfig.PrivateRegistry,
Value: "/etc/rancher/" + version.Program + "/registries.yaml",
}
AirgapExtraRegistryFlag = &cli.StringSliceFlag{
Name: "airgap-extra-registry",
Usage: "(agent/runtime) Additional registry to tag airgap images as being sourced from",
Value: &AgentConfig.AirgapExtraRegistry,
Hidden: true,
}
PauseImageFlag = &cli.StringFlag{
Name: "pause-image",
Usage: "(agent/runtime) Customized pause image for containerd or docker sandbox",
Destination: &AgentConfig.PauseImage,
Value: "rancher/mirrored-pause:3.6",
}
SnapshotterFlag = &cli.StringFlag{
Name: "snapshotter",
Usage: "(agent/runtime) Override default containerd snapshotter",
Destination: &AgentConfig.Snapshotter,
Value: DefaultSnapshotter,
}
FlannelIfaceFlag = &cli.StringFlag{
Name: "flannel-iface",
Usage: "(agent/networking) Override default flannel interface",
Destination: &AgentConfig.FlannelIface,
}
FlannelConfFlag = &cli.StringFlag{
2019-08-08 01:56:09 -04:00
Name: "flannel-conf",
Usage: "(agent/networking) Override default flannel config file",
2019-08-08 01:56:09 -04:00
Destination: &AgentConfig.FlannelConf,
}
FlannelCniConfFileFlag = &cli.StringFlag{
Name: "flannel-cni-conf",
Usage: "(agent/networking) Override default flannel cni config file",
Destination: &AgentConfig.FlannelCniConfFile,
}
VPNAuth = &cli.StringFlag{
Name: "vpn-auth",
Usage: "(agent/networking) (experimental) Credentials for the VPN provider. It must include the provider name and join key in the format name=<vpn-provider>,joinKey=<key>[,controlServerURL=<url>][,extraArgs=<args>]",
EnvVars: []string{version.ProgramUpper + "_VPN_AUTH"},
Destination: &AgentConfig.VPNAuth,
}
VPNAuthFile = &cli.StringFlag{
Name: "vpn-auth-file",
Usage: "(agent/networking) (experimental) File containing credentials for the VPN provider. It must include the provider name and join key in the format name=<vpn-provider>,joinKey=<key>[,controlServerURL=<url>][,extraArgs=<args>]",
EnvVars: []string{version.ProgramUpper + "_VPN_AUTH_FILE"},
Destination: &AgentConfig.VPNAuthFile,
}
ResolvConfFlag = &cli.StringFlag{
Name: "resolv-conf",
Usage: "(agent/networking) Kubelet resolv.conf file",
EnvVars: []string{version.ProgramUpper + "_RESOLV_CONF"},
Destination: &AgentConfig.ResolvConf,
}
ExtraKubeletArgs = &cli.StringSliceFlag{
Name: "kubelet-arg",
Usage: "(agent/flags) Customized flag for kubelet process",
Destination: &AgentConfig.ExtraKubeletArgs,
}
ExtraKubeProxyArgs = &cli.StringSliceFlag{
Name: "kube-proxy-arg",
Usage: "(agent/flags) Customized flag for kube-proxy process",
Destination: &AgentConfig.ExtraKubeProxyArgs,
}
NodeTaints = &cli.StringSliceFlag{
Name: "node-taint",
Usage: "(agent/node) Registering kubelet with set of taints",
Destination: &AgentConfig.Taints,
}
NodeLabels = &cli.StringSliceFlag{
Name: "node-label",
Usage: "(agent/node) Registering and starting kubelet with set of labels",
Destination: &AgentConfig.Labels,
}
ImageCredProvBinDirFlag = &cli.StringFlag{
Name: "image-credential-provider-bin-dir",
Usage: "(agent/node) The path to the directory where credential provider plugin binaries are located",
Destination: &AgentConfig.ImageCredProvBinDir,
Value: "/var/lib/rancher/credentialprovider/bin",
}
ImageCredProvConfigFlag = &cli.StringFlag{
Name: "image-credential-provider-config",
Usage: "(agent/node) The path to the credential provider plugin config file",
Destination: &AgentConfig.ImageCredProvConfig,
Value: "/var/lib/rancher/credentialprovider/config.yaml",
}
DisableAgentLBFlag = &cli.BoolFlag{
Name: "disable-apiserver-lb",
Usage: "(agent/networking) (experimental) Disable the agent's client-side load-balancer and connect directly to the configured server address",
Destination: &AgentConfig.DisableLoadBalancer,
}
DisableDefaultRegistryEndpointFlag = &cli.BoolFlag{
Name: "disable-default-registry-endpoint",
Usage: "(agent/containerd) Disables containerd's fallback default registry endpoint when a mirror is configured for that registry",
Destination: &AgentConfig.ContainerdNoDefault,
}
NonrootDevicesFlag = &cli.BoolFlag{
Name: "nonroot-devices",
Usage: "(agent/containerd) Allows non-root pods to access devices by setting device_ownership_from_security_context=true in the containerd CRI config",
Destination: &AgentConfig.ContainerdNonrootDevices,
}
EnablePProfFlag = &cli.BoolFlag{
Name: "enable-pprof",
Usage: "(experimental) Enable pprof endpoint on supervisor port",
Destination: &AgentConfig.EnablePProf,
}
BindAddressFlag = &cli.StringFlag{
Name: "bind-address",
Usage: "(listener) " + version.Program + " bind address (default: 0.0.0.0)",
Destination: &AgentConfig.BindAddress,
}
2019-01-09 11:54:15 -05:00
)
func NewAgentCommand(action func(ctx *cli.Context) error) *cli.Command {
return &cli.Command{
2019-01-09 11:54:15 -05:00
Name: "agent",
Usage: "Run node agent",
UsageText: appName + " agent [OPTIONS]",
Action: action,
2019-01-09 11:54:15 -05:00
Flags: []cli.Flag{
ConfigFlag,
DebugFlag,
VLevel,
VModule,
LogFile,
AlsoLogToStderr,
AgentTokenFlag,
&cli.StringFlag{
2019-03-01 19:07:55 -05:00
Name: "token-file",
Usage: "(cluster) Token file to use for authentication",
EnvVars: []string{version.ProgramUpper + "_TOKEN_FILE"},
2019-03-01 19:07:55 -05:00
Destination: &AgentConfig.TokenFile,
},
&cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Usage: "(cluster) Server to connect to",
EnvVars: []string{version.ProgramUpper + "_URL"},
2019-01-09 11:54:15 -05:00
Destination: &AgentConfig.ServerURL,
},
// Note that this is different from DataDirFlag used elswhere in the CLI,
// as this is bound to AgentConfig instead of ServerConfig.
&cli.StringFlag{
Name: "data-dir",
Aliases: []string{"d"},
Usage: "(agent/data) Folder to hold state",
2019-01-09 11:54:15 -05:00
Destination: &AgentConfig.DataDir,
Value: "/var/lib/rancher/" + version.Program + "",
EnvVars: []string{version.ProgramUpper + "_DATA_DIR"},
2019-01-09 11:54:15 -05:00
},
NodeNameFlag,
WithNodeIDFlag,
NodeLabels,
NodeTaints,
ImageCredProvBinDirFlag,
ImageCredProvConfigFlag,
SELinuxFlag,
LBServerPortFlag,
ProtectKernelDefaultsFlag,
CRIEndpointFlag,
DefaultRuntimeFlag,
ImageServiceEndpointFlag,
PauseImageFlag,
SnapshotterFlag,
PrivateRegistryFlag,
DisableDefaultRegistryEndpointFlag,
NonrootDevicesFlag,
AirgapExtraRegistryFlag,
NodeIPFlag,
BindAddressFlag,
NodeExternalIPFlag,
NodeInternalDNSFlag,
NodeExternalDNSFlag,
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
FlannelCniConfFileFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
// Experimental flags
EnablePProfFlag,
&cli.BoolFlag{
Name: "rootless",
Usage: "(experimental) Run rootless",
Destination: &AgentConfig.Rootless,
},
PreferBundledBin,
// Deprecated/hidden below
DockerFlag,
VPNAuth,
VPNAuthFile,
DisableAgentLBFlag,
2019-01-09 11:54:15 -05:00
},
}
}