forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_kubelet.go
83 lines (70 loc) · 2.19 KB
/
run_kubelet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package kubelet
import (
"fmt"
"strings"
"github.com/golang/glog"
"github.com/openshift/origin/pkg/oc/clusterup/docker/dockerhelper"
"github.com/openshift/origin/pkg/oc/clusterup/docker/openshift"
"github.com/openshift/origin/pkg/oc/clusterup/docker/run"
"github.com/openshift/origin/pkg/oc/lib/errors"
)
type KubeletRunConfig struct {
// ContainerBinds is a list of local/path:image/path pairs
ContainerBinds []string
// NodeImage is the docker image for openshift start node
NodeImage string
Environment []string
HTTPProxy string
HTTPSProxy string
NoProxy []string
Args []string
}
func NewKubeletRunConfig() *KubeletRunConfig {
return &KubeletRunConfig{
ContainerBinds: []string{
"/var/lib/kubelet/device-plugins:/var/lib/kubelet/device-plugins:rw",
"/var/log:/var/log:rw",
"/var/run:/var/run:rw",
"/sys:/sys:rw",
"/sys/fs/cgroup:/sys/fs/cgroup:rw",
"/dev:/dev",
},
}
}
// Start starts the OpenShift master as a Docker container
// and returns a directory in the local file system where
// the OpenShift configuration has been copied
func (opt KubeletRunConfig) StartKubelet(dockerClient dockerhelper.Interface, logdir string) (string, error) {
componentName := "start-kubelet"
imageRunHelper := run.NewRunHelper(dockerhelper.NewHelper(dockerClient)).New()
glog.Infof("Running %q", componentName)
env := []string{}
if len(opt.HTTPProxy) > 0 {
env = append(env, fmt.Sprintf("HTTP_PROXY=%s", opt.HTTPProxy))
}
if len(opt.HTTPSProxy) > 0 {
env = append(env, fmt.Sprintf("HTTPS_PROXY=%s", opt.HTTPSProxy))
}
if len(opt.NoProxy) > 0 {
env = append(env, fmt.Sprintf("NO_PROXY=%s", strings.Join(opt.NoProxy, ",")))
}
env = append(env, opt.Environment...)
createConfigCmd := []string{
"kubelet",
}
createConfigCmd = append(createConfigCmd, opt.Args...)
containerID, err := imageRunHelper.Image(opt.NodeImage).
Name(openshift.ContainerName).
Privileged().
DiscardContainer().
HostNetwork().
HostPid().
Bind(opt.ContainerBinds...).
Env(env...).
Entrypoint("hyperkube").
Command(createConfigCmd...).Start()
if err != nil {
return "", errors.NewError("could not create OpenShift configuration: %v", err).WithCause(err)
}
return containerID, nil
}