Skip to content

Commit

Permalink
Add extra flags for server and agent components
Browse files Browse the repository at this point in the history
  • Loading branch information
galal-hussein committed Apr 9, 2019
1 parent 184f697 commit 7794528
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 96 deletions.
3 changes: 3 additions & 0 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func get(envInfo *cmds.Agent) (*config.Node, error) {
os.Setenv("NODE_NAME", nodeConfig.AgentConfig.NodeName)
v1beta1.KubeletSocket = filepath.Join(envInfo.DataDir, "kubelet/device-plugins/kubelet.sock")

nodeConfig.AgentConfig.ExtraKubeletArgs = envInfo.ExtraKubeletArgs
nodeConfig.AgentConfig.ExtraKubeProxyArgs = envInfo.ExtraKubeProxyArgs

return nodeConfig, nil
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Agent struct {
NoFlannel bool
Debug bool
AgentShared
ExtraKubeletArgs cli.StringSlice
ExtraKubeProxyArgs cli.StringSlice
}

type AgentShared struct {
Expand Down Expand Up @@ -62,6 +64,16 @@ var (
EnvVar: "K3S_RESOLV_CONF",
Destination: &AgentConfig.ResolvConf,
}
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,
}
)

func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
Expand Down Expand Up @@ -107,6 +119,8 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
NodeIPFlag,
CRIEndpointFlag,
ResolvConfFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
},
}
}
46 changes: 33 additions & 13 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import (
)

type Server struct {
Log string
ClusterCIDR string
ClusterSecret string
ServiceCIDR string
ClusterDNS string
HTTPSPort int
HTTPPort int
DataDir string
DisableAgent bool
KubeConfigOutput string
KubeConfigMode string
KnownIPs cli.StringSlice
BindAddress string
Log string
ClusterCIDR string
ClusterSecret string
ServiceCIDR string
ClusterDNS string
HTTPSPort int
HTTPPort int
DataDir string
DisableAgent bool
KubeConfigOutput string
KubeConfigMode string
KnownIPs cli.StringSlice
BindAddress string
ExtraAPIArgs cli.StringSlice
ExtraSchedulerArgs cli.StringSlice
ExtraControllerArgs cli.StringSlice
}

var ServerConfig Server
Expand Down Expand Up @@ -106,12 +109,29 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Usage: "Add additional hostname or IP as a Subject Alternative Name in the TLS cert",
Value: &ServerConfig.KnownIPs,
},
cli.StringSliceFlag{
Name: "kube-apiserver-arg",
Usage: "Customized flag for kube-apiserver process",
Value: &ServerConfig.ExtraAPIArgs,
},
cli.StringSliceFlag{
Name: "kube-scheduler-arg",
Usage: "Customized flag for kube-scheduler process",
Value: &ServerConfig.ExtraSchedulerArgs,
},
cli.StringSliceFlag{
Name: "kube-controller-arg",
Usage: "Customized flag for kube-controller-manager process",
Value: &ServerConfig.ExtraControllerArgs,
},
NodeIPFlag,
NodeNameFlag,
DockerFlag,
FlannelFlag,
CRIEndpointFlag,
ResolvConfFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
},
}
}
3 changes: 3 additions & 0 deletions pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.TLSConfig.HTTPPort = cfg.HTTPPort
serverConfig.TLSConfig.KnownIPs = knownIPs(cfg.KnownIPs)
serverConfig.TLSConfig.BindAddress = cfg.BindAddress
serverConfig.ControlConfig.ExtraAPIArgs = cfg.ExtraAPIArgs
serverConfig.ControlConfig.ExtraControllerArgs = cfg.ExtraControllerArgs
serverConfig.ControlConfig.ExtraSchedulerAPIArgs = cfg.ExtraSchedulerArgs

_, serverConfig.ControlConfig.ClusterIPRange, err = net2.ParseCIDR(cfg.ClusterCIDR)
if err != nil {
Expand Down
75 changes: 38 additions & 37 deletions pkg/daemons/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func Agent(config *config.Agent) error {
return nil
}

func kubeProxy(config *config.Agent) {
args := []string{
"--proxy-mode", "iptables",
"--healthz-bind-address", "127.0.0.1",
"--kubeconfig", config.KubeConfig,
"--cluster-cidr", config.ClusterCIDR.String(),
}
args = append(args, config.ExtraKubeletArgs...)
func kubeProxy(cfg *config.Agent) {
argsMap := map[string]string{
"proxy-mode": "iptables",
"healthz-bind-address": "127.0.0.1",
"kubeconfig": cfg.KubeConfig,
"cluster-cidr": cfg.ClusterCIDR.String(),
}
args := config.GetArgsList(argsMap, cfg.ExtraKubeProxyArgs)

command := app2.NewProxyCommand()
command.SetArgs(args)
Expand All @@ -50,63 +50,64 @@ func kubelet(cfg *config.Agent) {
logs.InitLogs()
defer logs.FlushLogs()

args := []string{
"--healthz-bind-address", "127.0.0.1",
"--read-only-port", "0",
"--allow-privileged=true",
"--cluster-domain", "cluster.local",
"--kubeconfig", cfg.KubeConfig,
"--eviction-hard", "imagefs.available<5%,nodefs.available<5%",
"--eviction-minimum-reclaim", "imagefs.available=10%,nodefs.available=10%",
"--fail-swap-on=false",
//"--cgroup-root", "/k3s",
"--cgroup-driver", "cgroupfs",
argsMap := map[string]string{
"healthz-bind-address": "127.0.0.1",
"read-only-port": "0",
"allow-privileged": "true",
"cluster-domain": "cluster.local",
"kubeconfig": cfg.KubeConfig,
"eviction-hard": "imagefs.available<5%,nodefs.available<5%",
"eviction-minimum-reclaim": "imagefs.available=10%,nodefs.available=10%",
"fail-swap-on": "false",
//"cgroup-root": "/k3s",
"cgroup-driver": "cgroupfs",
}
if cfg.RootDir != "" {
args = append(args, "--root-dir", cfg.RootDir)
args = append(args, "--cert-dir", filepath.Join(cfg.RootDir, "pki"))
args = append(args, "--seccomp-profile-root", filepath.Join(cfg.RootDir, "seccomp"))
argsMap["root-dir"] = cfg.RootDir
argsMap["cert-dir"] = filepath.Join(cfg.RootDir, "pki")
argsMap["seccomp-profile-root"] = filepath.Join(cfg.RootDir, "seccomp")
}
if cfg.CNIConfDir != "" {
args = append(args, "--cni-conf-dir", cfg.CNIConfDir)
argsMap["cni-conf-dir"] = cfg.CNIConfDir
}
if cfg.CNIBinDir != "" {
args = append(args, "--cni-bin-dir", cfg.CNIBinDir)
argsMap["cni-bin-dir"] = cfg.CNIBinDir
}
if len(cfg.ClusterDNS) > 0 {
args = append(args, "--cluster-dns", cfg.ClusterDNS.String())
argsMap["cluster-dns"] = cfg.ClusterDNS.String()
}
if cfg.ResolvConf != "" {
args = append(args, "--resolv-conf", cfg.ResolvConf)
argsMap["resolv-conf"] = cfg.ResolvConf
}
if cfg.RuntimeSocket != "" {
args = append(args, "--container-runtime", "remote")
args = append(args, "--container-runtime-endpoint", cfg.RuntimeSocket)
args = append(args, "--serialize-image-pulls=false")
argsMap["container-runtime"] = "remote"
argsMap["container-runtime-endpoint"] = cfg.RuntimeSocket
argsMap["serialize-image-pulls"] = "false"
}
if cfg.ListenAddress != "" {
args = append(args, "--address", cfg.ListenAddress)
argsMap["address"] = cfg.ListenAddress
}
if cfg.CACertPath != "" {
args = append(args, "--anonymous-auth=false", "--client-ca-file", cfg.CACertPath)
argsMap["anonymous-auth"] = "false"
argsMap["client-ca-file"] = cfg.CACertPath
}
if cfg.NodeName != "" {
args = append(args, "--hostname-override", cfg.NodeName)
argsMap["hostname-override"] = cfg.NodeName
}
defaultIP, err := net.ChooseHostInterface()
if err != nil || defaultIP.String() != cfg.NodeIP {
args = append(args, "--node-ip", cfg.NodeIP)
argsMap["node-ip"] = cfg.NodeIP
}
root, hasCFS := checkCgroups()
if !hasCFS {
logrus.Warn("Disabling CPU quotas due to missing cpu.cfs_period_us")
args = append(args, "--cpu-cfs-quota=false")
argsMap["cpu-cfs-quota"] = "false"
}
if root != "" {
args = append(args, "--runtime-cgroups", root)
args = append(args, "--kubelet-cgroups", root)
argsMap["runtime-cgroups"] = root
argsMap["kubelet-cgroups"] = root
}
args = append(args, cfg.ExtraKubeletArgs...)
args := config.GetArgsList(argsMap, cfg.ExtraKubeletArgs)

command.SetArgs(args)

Expand Down
19 changes: 19 additions & 0 deletions pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"crypto/tls"
"fmt"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -106,3 +107,21 @@ func (a ArgString) String() string {
}
return b.String()
}

func GetArgsList(argsMap map[string]string, extraArgs []string) []string {
// add extra args to args map to override any default option
for _, arg := range extraArgs {
splitArg := strings.Split(arg, "=")
if len(splitArg) < 2 {
argsMap[splitArg[0]] = "true"
continue
}
argsMap[splitArg[0]] = splitArg[1]
}
var args []string
for arg, value := range argsMap {
cmd := fmt.Sprintf("--%s=%s", arg, value)
args = append(args, cmd)
}
return args
}
Loading

0 comments on commit 7794528

Please sign in to comment.