k3s/pkg/daemons/agent/agent.go

73 lines
1.9 KiB
Go
Raw Normal View History

2019-01-01 08:23:01 +00:00
package agent
import (
"math/rand"
2019-01-22 21:14:58 +00:00
"os"
2019-01-01 08:23:01 +00:00
"time"
2019-01-09 16:54:15 +00:00
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/daemons/executor"
2019-01-01 08:23:01 +00:00
"github.com/sirupsen/logrus"
2019-04-08 17:53:52 +00:00
"k8s.io/component-base/logs"
2019-12-12 01:23:55 +00:00
_ "k8s.io/component-base/metrics/prometheus/restclient" // for client metric registration
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
2019-01-01 08:23:01 +00:00
)
const (
unixPrefix = "unix://"
windowsPrefix = "npipe://"
)
2019-01-01 08:23:01 +00:00
func Agent(config *config.Agent) error {
rand.Seed(time.Now().UTC().UnixNano())
2019-11-05 09:45:07 +00:00
logs.InitLogs()
defer logs.FlushLogs()
if err := startKubelet(config); err != nil {
return err
}
2020-04-27 16:31:25 +00:00
if !config.DisableKubeProxy {
return startKubeProxy(config)
}
2019-01-01 08:23:01 +00:00
return nil
}
2020-04-27 16:31:25 +00:00
func startKubeProxy(cfg *config.Agent) error {
argsMap := kubeProxyArgs(cfg)
2019-11-05 09:45:07 +00:00
args := config.GetArgsList(argsMap, cfg.ExtraKubeProxyArgs)
logrus.Infof("Running kube-proxy %s", config.ArgString(args))
return executor.KubeProxy(args)
2019-01-01 08:23:01 +00:00
}
func startKubelet(cfg *config.Agent) error {
argsMap := kubeletArgs(cfg)
2019-03-08 22:47:44 +00:00
args := config.GetArgsList(argsMap, cfg.ExtraKubeletArgs)
logrus.Infof("Running kubelet %s", config.ArgString(args))
2019-01-01 08:23:01 +00:00
return executor.Kubelet(args)
2019-01-01 08:23:01 +00:00
}
2019-01-22 21:14:58 +00:00
func addFeatureGate(current, new string) string {
if current == "" {
return new
}
return current + "," + new
}
// ImageCredProvAvailable checks to see if the kubelet image credential provider bin dir and config
// files exist and are of the correct types. This is exported so that it may be used by downstream projects.
func ImageCredProvAvailable(cfg *config.Agent) bool {
if info, err := os.Stat(cfg.ImageCredProvBinDir); err != nil || !info.IsDir() {
logrus.Debugf("Kubelet image credential provider bin directory check failed: %v", err)
return false
}
if info, err := os.Stat(cfg.ImageCredProvConfig); err != nil || info.IsDir() {
logrus.Debugf("Kubelet image credential provider config file check failed: %v", err)
return false
}
return true
}