2019-01-09 16:54:15 +00:00
package cmds
import (
"os"
"path/filepath"
2022-03-02 23:47:27 +00:00
"github.com/k3s-io/k3s/pkg/version"
2020-08-29 19:46:55 +00:00
"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
2022-02-16 22:19:58 +00:00
APIAddressCh chan [ ] string
2019-07-24 07:22:31 +00:00
DisableLoadBalancer bool
2021-11-09 15:44:34 +00:00
DisableServiceLB bool
2021-02-12 15:35:57 +00:00
ETCDAgent bool
LBServerPort int
2019-03-26 22:15:16 +00:00
ResolvConf string
2019-03-04 06:29:06 +00:00
DataDir string
2021-04-21 22:56:20 +00:00
NodeIP cli . StringSlice
NodeExternalIP cli . StringSlice
2019-03-04 06:29:06 +00:00
NodeName string
2019-05-03 17:36:12 +00:00
PauseImage string
2020-07-17 23:16:23 +00:00
Snapshotter string
2019-03-04 06:29:06 +00:00
Docker bool
ContainerRuntimeEndpoint string
2019-03-19 23:28:43 +00:00
FlannelIface string
2019-08-08 05:56:09 +00:00
FlannelConf string
2022-06-08 08:38:07 +00:00
FlannelCniConfFile string
2022-09-01 17:20:32 +00:00
VPNAuth string
VPNAuthFile string
2019-03-04 06:29:06 +00:00
Debug bool
2019-03-08 22:47:44 +00:00
Rootless bool
2019-10-19 10:18:51 +00:00
RootlessAlreadyUnshared bool
2019-11-05 09:45:07 +00:00
WithNodeID bool
2020-08-11 23:17:32 +00:00
EnableSELinux bool
2020-07-14 22:46:10 +00:00
ProtectKernelDefaults bool
2021-05-10 22:58:41 +00:00
ClusterReset bool
2021-02-12 07:37:58 +00:00
PrivateRegistry string
2021-05-10 22:58:41 +00:00
SystemDefaultRegistry string
2021-02-12 07:37:58 +00:00
AirgapExtraRegistry cli . StringSlice
ExtraKubeletArgs cli . StringSlice
ExtraKubeProxyArgs cli . StringSlice
Labels cli . StringSlice
Taints cli . StringSlice
2021-05-10 22:58:41 +00:00
ImageCredProvBinDir string
ImageCredProvConfig string
2021-10-12 06:13:10 +00:00
AgentReady chan <- struct { }
2019-01-09 16:54:15 +00:00
AgentShared
}
type AgentShared struct {
NodeIP string
}
var (
2021-12-07 22:31:32 +00:00
appName = filepath . Base ( os . Args [ 0 ] )
AgentConfig Agent
2023-01-31 20:57:48 +00:00
AgentTokenFlag = & cli . StringFlag {
2021-12-07 22:31:32 +00:00
Name : "token,t" ,
Usage : "(cluster) Token to use for authentication" ,
EnvVar : version . ProgramUpper + "_TOKEN" ,
Destination : & AgentConfig . Token ,
}
2023-01-31 20:57:48 +00:00
NodeIPFlag = & cli . StringSliceFlag {
2021-04-21 22:56:20 +00:00
Name : "node-ip,i" ,
Usage : "(agent/networking) IPv4/IPv6 addresses to advertise for node" ,
Value : & AgentConfig . NodeIP ,
2019-01-09 16:54:15 +00:00
}
2023-01-31 20:57:48 +00:00
NodeExternalIPFlag = & cli . StringSliceFlag {
2021-04-21 22:56:20 +00:00
Name : "node-external-ip" ,
Usage : "(agent/networking) IPv4/IPv6 external IP addresses to advertise for node" ,
Value : & AgentConfig . NodeExternalIP ,
2019-10-15 21:17:26 +00:00
}
2023-01-31 20:57:48 +00:00
NodeNameFlag = & cli . StringFlag {
2019-01-09 16:54:15 +00:00
Name : "node-name" ,
2019-10-27 05:53:25 +00:00
Usage : "(agent/node) Node name" ,
2020-08-29 19:46:55 +00:00
EnvVar : version . ProgramUpper + "_NODE_NAME" ,
2019-01-09 16:54:15 +00:00
Destination : & AgentConfig . NodeName ,
}
2023-01-31 20:57:48 +00:00
WithNodeIDFlag = & cli . BoolFlag {
2019-11-05 09:45:07 +00:00
Name : "with-node-id" ,
Usage : "(agent/node) Append id to node name" ,
Destination : & AgentConfig . WithNodeID ,
}
2023-01-31 20:57:48 +00:00
ProtectKernelDefaultsFlag = & cli . BoolFlag {
2022-08-02 20:51:16 +00:00
Name : "protect-kernel-defaults" ,
Usage : "(agent/node) Kernel tuning behavior. If set, error if kernel tunables are different than kubelet defaults." ,
Destination : & AgentConfig . ProtectKernelDefaults ,
}
2023-01-31 20:57:48 +00:00
SELinuxFlag = & cli . BoolFlag {
2022-08-02 20:51:16 +00:00
Name : "selinux" ,
Usage : "(agent/node) Enable SELinux in containerd" ,
Destination : & AgentConfig . EnableSELinux ,
EnvVar : version . ProgramUpper + "_SELINUX" ,
}
2023-01-31 20:57:48 +00:00
LBServerPortFlag = & cli . IntFlag {
2022-08-02 20:51:16 +00:00
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 ,
EnvVar : version . ProgramUpper + "_LB_SERVER_PORT" ,
Value : 6444 ,
2019-03-02 00:10:18 +00:00
}
2023-01-31 20:57:48 +00:00
DockerFlag = & cli . BoolFlag {
2021-12-16 20:00:40 +00:00
Name : "docker" ,
Usage : "(agent/runtime) (experimental) Use cri-dockerd instead of containerd" ,
Destination : & AgentConfig . Docker ,
}
2023-01-31 20:57:48 +00:00
CRIEndpointFlag = & cli . StringFlag {
2019-10-27 05:53:25 +00:00
Name : "container-runtime-endpoint" ,
2021-12-16 20:00:40 +00:00
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" ,
2019-10-27 05:53:25 +00:00
Destination : & AgentConfig . ContainerRuntimeEndpoint ,
}
2023-01-31 20:57:48 +00:00
PrivateRegistryFlag = & cli . StringFlag {
2019-10-27 05:53:25 +00:00
Name : "private-registry" ,
Usage : "(agent/runtime) Private registry configuration file" ,
Destination : & AgentConfig . PrivateRegistry ,
2020-05-05 22:09:04 +00:00
Value : "/etc/rancher/" + version . Program + "/registries.yaml" ,
2019-10-27 05:53:25 +00:00
}
2023-01-31 20:57:48 +00:00
AirgapExtraRegistryFlag = & cli . StringSliceFlag {
2021-02-26 19:07:15 +00:00
Name : "airgap-extra-registry" ,
Usage : "(agent/runtime) Additional registry to tag airgap images as being sourced from" ,
Value : & AgentConfig . AirgapExtraRegistry ,
Hidden : true ,
2021-02-12 07:37:58 +00:00
}
2023-01-31 20:57:48 +00:00
PauseImageFlag = & cli . StringFlag {
2019-10-27 05:53:25 +00:00
Name : "pause-image" ,
2022-07-28 19:32:15 +00:00
Usage : "(agent/runtime) Customized pause image for containerd or docker sandbox" ,
2019-10-27 05:53:25 +00:00
Destination : & AgentConfig . PauseImage ,
2021-06-10 19:27:00 +00:00
Value : DefaultPauseImage ,
2019-10-27 05:53:25 +00:00
}
2023-01-31 20:57:48 +00:00
SnapshotterFlag = & cli . StringFlag {
2020-07-17 23:16:23 +00:00
Name : "snapshotter" ,
Usage : "(agent/runtime) Override default containerd snapshotter" ,
Destination : & AgentConfig . Snapshotter ,
2021-06-10 19:27:00 +00:00
Value : DefaultSnapshotter ,
2020-07-17 23:16:23 +00:00
}
2023-01-31 20:57:48 +00:00
FlannelIfaceFlag = & cli . StringFlag {
2019-03-19 23:28:43 +00:00
Name : "flannel-iface" ,
2019-10-27 05:53:25 +00:00
Usage : "(agent/networking) Override default flannel interface" ,
2019-03-19 23:28:43 +00:00
Destination : & AgentConfig . FlannelIface ,
}
2023-01-31 20:57:48 +00:00
FlannelConfFlag = & cli . StringFlag {
2019-08-08 05:56:09 +00:00
Name : "flannel-conf" ,
2019-10-27 05:53:25 +00:00
Usage : "(agent/networking) Override default flannel config file" ,
2019-08-08 05:56:09 +00:00
Destination : & AgentConfig . FlannelConf ,
}
2023-01-31 20:57:48 +00:00
FlannelCniConfFileFlag = & cli . StringFlag {
2022-06-08 08:38:07 +00:00
Name : "flannel-cni-conf" ,
Usage : "(agent/networking) Override default flannel cni config file" ,
Destination : & AgentConfig . FlannelCniConfFile ,
}
2022-09-01 17:20:32 +00:00
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>" ,
EnvVar : 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>" ,
EnvVar : version . ProgramUpper + "_VPN_AUTH_FILE" ,
Destination : & AgentConfig . VPNAuthFile ,
}
2023-01-31 20:57:48 +00:00
ResolvConfFlag = & cli . StringFlag {
2019-03-26 22:15:16 +00:00
Name : "resolv-conf" ,
2019-10-27 05:53:25 +00:00
Usage : "(agent/networking) Kubelet resolv.conf file" ,
2020-08-29 19:46:55 +00:00
EnvVar : version . ProgramUpper + "_RESOLV_CONF" ,
2019-03-26 22:15:16 +00:00
Destination : & AgentConfig . ResolvConf ,
}
2023-01-31 20:57:48 +00:00
ExtraKubeletArgs = & cli . StringSliceFlag {
2020-08-29 19:46:55 +00:00
Name : "kubelet-arg" ,
Usage : "(agent/flags) Customized flag for kubelet process" ,
Value : & AgentConfig . ExtraKubeletArgs ,
2019-04-05 00:43:00 +00:00
}
2023-01-31 20:57:48 +00:00
ExtraKubeProxyArgs = & cli . StringSliceFlag {
2020-08-29 19:46:55 +00:00
Name : "kube-proxy-arg" ,
Usage : "(agent/flags) Customized flag for kube-proxy process" ,
Value : & AgentConfig . ExtraKubeProxyArgs ,
2019-04-05 00:43:00 +00:00
}
2023-01-31 20:57:48 +00:00
NodeTaints = & cli . StringSliceFlag {
2020-08-29 19:46:55 +00:00
Name : "node-taint" ,
Usage : "(agent/node) Registering kubelet with set of taints" ,
Value : & AgentConfig . Taints ,
2019-05-07 23:47:07 +00:00
}
2023-01-31 20:57:48 +00:00
NodeLabels = & cli . StringSliceFlag {
2020-08-29 19:46:55 +00:00
Name : "node-label" ,
Usage : "(agent/node) Registering and starting kubelet with set of labels" ,
Value : & AgentConfig . Labels ,
2019-05-07 23:47:07 +00:00
}
2023-01-31 20:57:48 +00:00
ImageCredProvBinDirFlag = & cli . StringFlag {
2021-05-10 22:58:41 +00:00
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" ,
}
2023-01-31 20:57:48 +00:00
ImageCredProvConfigFlag = & cli . StringFlag {
2021-05-10 22:58:41 +00:00
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" ,
}
2019-01-09 16:54:15 +00:00
)
2020-08-29 19:46:55 +00:00
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]" ,
2020-08-29 19:46:55 +00:00
Action : action ,
2019-01-09 16:54:15 +00:00
Flags : [ ] cli . Flag {
2020-08-30 03:30:07 +00:00
ConfigFlag ,
DebugFlag ,
2020-08-29 19:46:55 +00:00
VLevel ,
VModule ,
LogFile ,
AlsoLogToStderr ,
2021-12-07 22:31:32 +00:00
AgentTokenFlag ,
2023-01-31 20:57:48 +00:00
& cli . StringFlag {
2019-03-02 00:07:55 +00:00
Name : "token-file" ,
2019-10-27 05:53:25 +00:00
Usage : "(cluster) Token file to use for authentication" ,
2020-08-29 19:46:55 +00:00
EnvVar : version . ProgramUpper + "_TOKEN_FILE" ,
2019-03-02 00:07:55 +00:00
Destination : & AgentConfig . TokenFile ,
} ,
2023-01-31 20:57:48 +00:00
& cli . StringFlag {
2019-01-09 16:54:15 +00:00
Name : "server,s" ,
2019-10-27 05:53:25 +00:00
Usage : "(cluster) Server to connect to" ,
2020-08-29 19:46:55 +00:00
EnvVar : version . ProgramUpper + "_URL" ,
2019-01-09 16:54:15 +00:00
Destination : & AgentConfig . ServerURL ,
} ,
2023-01-31 20:57:48 +00:00
& cli . StringFlag {
2019-01-09 16:54:15 +00:00
Name : "data-dir,d" ,
2019-10-27 05:53:25 +00:00
Usage : "(agent/data) Folder to hold state" ,
2019-01-09 16:54:15 +00:00
Destination : & AgentConfig . DataDir ,
2020-05-05 22:09:04 +00:00
Value : "/var/lib/rancher/" + version . Program + "" ,
2019-01-09 16:54:15 +00:00
} ,
2020-08-29 19:46:55 +00:00
NodeNameFlag ,
WithNodeIDFlag ,
NodeLabels ,
NodeTaints ,
2021-05-10 22:58:41 +00:00
ImageCredProvBinDirFlag ,
ImageCredProvConfigFlag ,
2023-01-31 20:57:48 +00:00
SELinuxFlag ,
2022-08-02 20:51:16 +00:00
LBServerPortFlag ,
ProtectKernelDefaultsFlag ,
2020-08-29 19:46:55 +00:00
CRIEndpointFlag ,
PauseImageFlag ,
SnapshotterFlag ,
PrivateRegistryFlag ,
2021-02-12 07:37:58 +00:00
AirgapExtraRegistryFlag ,
2020-08-29 19:46:55 +00:00
NodeIPFlag ,
NodeExternalIPFlag ,
ResolvConfFlag ,
FlannelIfaceFlag ,
FlannelConfFlag ,
2022-06-08 08:38:07 +00:00
FlannelCniConfFileFlag ,
2020-08-29 19:46:55 +00:00
ExtraKubeletArgs ,
ExtraKubeProxyArgs ,
2022-11-22 21:43:16 +00:00
// Experimental flags
2023-01-31 20:57:48 +00:00
& cli . BoolFlag {
2019-10-27 05:53:25 +00:00
Name : "rootless" ,
Usage : "(experimental) Run rootless" ,
Destination : & AgentConfig . Rootless ,
} ,
2022-11-22 21:43:16 +00:00
PreferBundledBin ,
2019-10-27 05:53:25 +00:00
// Deprecated/hidden below
2022-08-02 20:51:16 +00:00
DockerFlag ,
2022-09-01 17:20:32 +00:00
VPNAuth ,
VPNAuthFile ,
2019-01-09 16:54:15 +00:00
} ,
}
}