forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
235 lines (191 loc) · 6.2 KB
/
start.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package server
import (
"fmt"
"net"
"net/http"
_ "net/http/pprof"
"net/url"
"os"
"strconv"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/golang/glog"
"github.com/openshift/origin/pkg/cmd/server/etcd"
"github.com/openshift/origin/pkg/cmd/server/kubernetes"
"github.com/openshift/origin/pkg/cmd/server/origin"
// Admission control plugins from upstream Kubernetes
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/limitranger"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/namespace/exists"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/resourcedefaults"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/resourcequota"
)
const (
unauthenticatedUsername = "system:anonymous"
authenticatedGroup = "system:authenticated"
unauthenticatedGroup = "system:unauthenticated"
)
func (cfg Config) startMaster() error {
// Allow privileged containers
// TODO: make this configurable and not the default https://github.com/openshift/origin/issues/662
capabilities.Initialize(capabilities.Capabilities{
AllowPrivileged: true,
})
cfg.MintNodeCerts()
cfg.MintSystemClientCert("admin", "system:cluster-admins")
cfg.MintSystemClientCert("openshift-deployer", "system:deployers")
cfg.MintSystemClientCert("openshift-client")
if cfg.StartKube {
cfg.MintSystemClientCert("kube-client")
}
glog.Infof(" Client certificates and .kubeconfig files generated in %v", cfg.CertDir)
openshiftConfig, err := cfg.BuildOriginMasterConfig()
if err != nil {
return err
}
// must start policy caching immediately
openshiftConfig.RunPolicyCache()
authConfig, err := cfg.BuildAuthConfig()
if err != nil {
return err
}
glog.Infof(" Nodes: %v", cfg.GetNodeList())
if cfg.StartKube {
kubeConfig, err := cfg.BuildKubernetesMasterConfig(openshiftConfig.RequestContextMapper, openshiftConfig.KubeClient())
if err != nil {
return err
}
kubeConfig.EnsurePortalFlags()
openshiftConfig.Run([]origin.APIInstaller{kubeConfig}, []origin.APIInstaller{authConfig})
kubeConfig.RunScheduler()
kubeConfig.RunReplicationController()
kubeConfig.RunEndpointController()
kubeConfig.RunMinionController()
kubeConfig.RunResourceQuotaManager()
} else {
kubeAddr, err := cfg.GetKubernetesAddress()
if err != nil {
return err
}
proxy := &kubernetes.ProxyConfig{
KubernetesAddr: kubeAddr,
ClientConfig: &openshiftConfig.KubeClientConfig,
}
openshiftConfig.Run([]origin.APIInstaller{proxy}, []origin.APIInstaller{authConfig})
}
// TODO: recording should occur in individual components
record.StartRecording(openshiftConfig.KubeClient().Events(""), kapi.EventSource{Component: "master"})
glog.Infof("Using images from %q", openshiftConfig.ImageFor("<component>"))
openshiftConfig.RunAssetServer()
openshiftConfig.RunBuildController()
openshiftConfig.RunBuildImageChangeTriggerController()
openshiftConfig.RunDeploymentController()
openshiftConfig.RunDeployerPodController()
openshiftConfig.RunDeploymentConfigController()
openshiftConfig.RunDeploymentConfigChangeController()
openshiftConfig.RunDeploymentImageChangeTriggerController()
openshiftConfig.RunProjectAuthorizationCache()
return nil
}
// run launches the appropriate startup modes or returns an error.
func (cfg Config) Start(args []string) error {
if cfg.WriteConfigOnly {
return nil
}
switch {
case cfg.StartMaster && cfg.StartNode:
glog.Infof("Starting an OpenShift all-in-one, reachable at %s (etcd: %s)", cfg.MasterAddr.String(), cfg.EtcdAddr.String())
if cfg.MasterPublicAddr.Provided {
glog.Infof("OpenShift master public address is %s", cfg.MasterPublicAddr.String())
}
case cfg.StartMaster:
glog.Infof("Starting an OpenShift master, reachable at %s (etcd: %s)", cfg.MasterAddr.String(), cfg.EtcdAddr.String())
if cfg.MasterPublicAddr.Provided {
glog.Infof("OpenShift master public address is %s", cfg.MasterPublicAddr.String())
}
case cfg.StartNode:
glog.Infof("Starting an OpenShift node, connecting to %s", cfg.MasterAddr.String())
}
if cfg.StartEtcd {
if err := cfg.RunEtcd(); err != nil {
return err
}
}
if env("OPENSHIFT_PROFILE", "") == "web" {
go func() {
glog.Infof("Starting profiling endpoint at http://127.0.0.1:6060/debug/pprof/")
glog.Fatal(http.ListenAndServe("127.0.0.1:6060", nil))
}()
}
if cfg.StartMaster {
if err := cfg.startMaster(); err != nil {
return err
}
}
if cfg.StartNode {
kubeClient, _, err := cfg.GetKubeClient()
if err != nil {
return err
}
if !cfg.StartMaster {
// TODO: recording should occur in individual components
record.StartRecording(kubeClient.Events(""), kapi.EventSource{Component: "node"})
}
nodeConfig, err := cfg.BuildKubernetesNodeConfig()
if err != nil {
return err
}
nodeConfig.EnsureVolumeDir()
nodeConfig.EnsureDocker(cfg.Docker)
nodeConfig.RunProxy()
nodeConfig.RunKubelet()
}
select {}
return nil
}
func envInt(key string, defaultValue int32, minValue int32) int32 {
value, err := strconv.ParseInt(env(key, fmt.Sprintf("%d", defaultValue)), 10, 32)
if err != nil || int32(value) < minValue {
glog.Warningf("Invalid %s. Defaulting to %d.", key, defaultValue)
return defaultValue
}
return int32(value)
}
// env returns an environment variable or a default value if not specified.
func env(key string, defaultValue string) string {
val := os.Getenv(key)
if len(val) == 0 {
return defaultValue
}
return val
}
func (cfg Config) RunEtcd() error {
etcdAddr, err := cfg.GetEtcdAddress()
if err != nil {
return err
}
etcdConfig := &etcd.Config{
BindAddr: cfg.GetEtcdBindAddress(),
PeerBindAddr: cfg.GetEtcdPeerBindAddress(),
MasterAddr: etcdAddr.Host,
EtcdDir: cfg.EtcdDir,
}
etcdConfig.Run()
return nil
}
func getHost(theURL url.URL) string {
host, _, err := net.SplitHostPort(theURL.Host)
if err != nil {
return theURL.Host
}
return host
}
func getPort(theURL url.URL) int {
_, port, err := net.SplitHostPort(theURL.Host)
if err != nil {
return 0
}
intport, _ := strconv.Atoi(port)
return intport
}