Browse code

Better startup error handling and configurability

Short circuit kubelet initialization if the root volume directory can't be
created, as volume mounts are non-functional in the absence of the directory.
Without this check, volume mounts (including Docker socket mounts for builds)
fail in non-obvious ways.

Make the etcd and volume directories configurable to better facilitate dev
and test environments. Retain the existing defaults for turnkey prod-like
operation.

Dan Mace authored on 2014/09/19 10:59:59
Showing 3 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /_output
2 2
 /third_party
3
-/*.etcd
3
+/openshift.local.*
4 4
 /.project
5 5
 /.vagrant
6 6
 *.swp
... ...
@@ -24,15 +24,15 @@ API_HOST=${API_HOST:-127.0.0.1}
24 24
 KUBELET_PORT=${KUBELET_PORT:-10250}
25 25
 GO_OUT=$(dirname $0)/../_output/go/bin
26 26
 
27
+ETCD_DATA_DIR=$(mktemp -d /tmp/openshift.local.etcd.XXXX)
28
+VOLUME_DIR=$(mktemp -d /tmp/openshift.local.volumes.XXXX)
29
+
27 30
 # Check openshift version
28 31
 out=$(${GO_OUT}/openshift version)
29 32
 echo openshift: $out
30 33
 
31
-# Remove any local data
32
-rm -rf $(dirname $0)/../openshift.local.etcd/
33
-
34 34
 # Start openshift
35
-${GO_OUT}/openshift start 1>&2 &
35
+${GO_OUT}/openshift start --volumeDir=$VOLUME_DIR --etcdDir=$ETCD_DATA_DIR 1>&2 &
36 36
 OS_PID=$!
37 37
 
38 38
 wait_for_url "http://127.0.0.1:${KUBELET_PORT}/healthz" "kubelet: "
... ...
@@ -84,7 +84,9 @@ func NewCommandStartAllInOne(name string) *cobra.Command {
84 84
 	}
85 85
 
86 86
 	flag := cmd.Flags()
87
-	flag.StringVar(&cfg.ListenAddr, "listenAddr", "127.0.0.1:8080", "The OpenShift server listen address.")
87
+	flag.StringVar(&cfg.ListenAddr, "listenAddr", "127.0.0.1:8080", "The server listen address.")
88
+	flag.StringVar(&cfg.VolumeDir, "volumeDir", "openshift.local.volumes", "The volume storage directory.")
89
+	flag.StringVar(&cfg.EtcdDir, "etcdDir", "openshift.local.etcd", "The etcd data directory.")
88 90
 
89 91
 	dockerHelper.InstallFlags(flag)
90 92
 
... ...
@@ -94,6 +96,8 @@ func NewCommandStartAllInOne(name string) *cobra.Command {
94 94
 // config contains all options that apply to a running command
95 95
 type config struct {
96 96
 	ListenAddr string
97
+	VolumeDir  string
98
+	EtcdDir    string
97 99
 	Docker     docker.Helper
98 100
 	masterHost string
99 101
 	nodeHosts  []string
... ...
@@ -235,7 +239,7 @@ func (c *config) runApiserver() {
235 235
 }
236 236
 
237 237
 func (c *config) runKubelet() {
238
-	rootDirectory := path.Clean("/var/lib/openshift")
238
+	rootDirectory := path.Clean(c.VolumeDir)
239 239
 	minionHost := c.bindAddr
240 240
 	minionPort := 10250
241 241
 
... ...
@@ -254,7 +258,12 @@ func (c *config) runKubelet() {
254 254
 	etcdClient, _ := c.getEtcdClient()
255 255
 
256 256
 	// initialize Kubelet
257
-	os.MkdirAll(rootDirectory, 0750)
257
+	if _, err := os.Stat(rootDirectory); os.IsNotExist(err) {
258
+		if mkdirErr := os.MkdirAll(rootDirectory, 0750); mkdirErr != nil {
259
+			glog.Fatalf("Couldn't create kubelet volume root directory '%s': %s", rootDirectory, mkdirErr)
260
+		}
261
+	}
262
+
258 263
 	cfg := kconfig.NewPodConfig(kconfig.PodConfigNotificationSnapshotAndUpdates)
259 264
 	kconfig.NewSourceEtcd(kconfig.EtcdKeyForHost(minionHost), etcdClient, cfg.Channel("etcd"))
260 265
 	k := kubelet.NewMainKubelet(
... ...
@@ -300,7 +309,7 @@ func (c *config) runEtcd() {
300 300
 	etcdConfig := etcdconfig.New()
301 301
 	etcdConfig.Addr = etcdAddr
302 302
 	etcdConfig.BindAddr = etcdAddr
303
-	etcdConfig.DataDir = "openshift.local.etcd"
303
+	etcdConfig.DataDir = c.EtcdDir
304 304
 	etcdConfig.Name = "openshift.local"
305 305
 
306 306
 	// initialize etcd