From cc356e63c4f1d4a0a4cd280d6667270ccdfc7655 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Tue, 3 Apr 2018 16:05:18 -0700 Subject: [PATCH] Miscellaneous none driver fixes. --- hack/jenkins/common.sh | 4 +-- pkg/drivers/none/none.go | 36 +++++++++++-------- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 13 +++++-- .../bootstrapper/kubeadm/templates.go | 3 +- pkg/minikube/constants/constants.go | 10 ++++++ 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/hack/jenkins/common.sh b/hack/jenkins/common.sh index c727b6b2ff2f..3374b009377f 100755 --- a/hack/jenkins/common.sh +++ b/hack/jenkins/common.sh @@ -43,8 +43,8 @@ chmod +x out/docker-machine-driver-* chmod +x out/localkube # Fix permissions in $HOME -sudo chown -R $USER $HOME/.kube -sudo chown -R $USER $HOME/.minikube +sudo chown -R $USER $HOME/.kube || true +sudo chown -R $USER $HOME/.minikube || true export MINIKUBE_WANTREPORTERRORPROMPT=False sudo ./out/minikube-${OS_ARCH} delete || true diff --git a/pkg/drivers/none/none.go b/pkg/drivers/none/none.go index de16670619d8..78063b104a16 100644 --- a/pkg/drivers/none/none.go +++ b/pkg/drivers/none/none.go @@ -22,6 +22,8 @@ import ( "os/exec" "strings" + "github.com/golang/glog" + "github.com/docker/machine/libmachine/drivers" "github.com/docker/machine/libmachine/state" "github.com/pkg/errors" @@ -31,8 +33,9 @@ import ( ) const driverName = "none" -const dockerkillcmd = `docker rm $(docker kill $(docker ps -a --filter="name=k8s_" --format="{{.ID}}"))` -const dockerstopcmd = `docker stop $(docker ps -a --filter="name=k8s_" --format="{{.ID}}")` +const dockerstopcmd = `docker kill $(docker ps -a --filter="name=k8s_" --format="{{.ID}}")` + +var dockerkillcmd = fmt.Sprintf(`docker rm $(%s)`, dockerstopcmd) // none Driver is a driver designed to run localkube w/o a VM type Driver struct { @@ -124,13 +127,14 @@ fi } func (d *Driver) Kill() error { - cmd := exec.Command("sudo", "systemctl", "stop", "localkube.service") - if err := cmd.Start(); err != nil { - return errors.Wrap(err, "stopping the localkube service") - } - cmd = exec.Command("sudo", "rm", "-rf", "/var/lib/localkube") - if err := cmd.Start(); err != nil { - return errors.Wrap(err, "removing localkube") + for _, cmdStr := range [][]string{ + {"systemctl", "stop", "localkube.service"}, + {"rm", "-rf", "/var/lib/localkube"}, + } { + cmd := exec.Command("sudo", cmdStr...) + if out, err := cmd.CombinedOutput(); err != nil { + glog.Warningf("Error %s running command: %s. Output: %s", err, cmdStr, string(out)) + } } return nil } @@ -139,14 +143,16 @@ func (d *Driver) Remove() error { rmCmd := `for svc in "localkube" "kubelet"; do sudo systemctl stop "$svc".service done + sudo rm -rf /data + sudo rm -rf /etc/kubernetes/manifests sudo rm -rf /var/lib/localkube || true` - if _, err := runCommand(rmCmd, true); err != nil { - return errors.Wrap(err, "stopping minikube") + for _, cmdStr := range []string{rmCmd, dockerkillcmd} { + if out, err := runCommand(cmdStr, true); err != nil { + glog.Warningf("Error %s running command: %s, Output: %s", err, cmdStr, out) + } } - runCommand(dockerkillcmd, false) - return nil } @@ -199,7 +205,9 @@ fi break } } - runCommand(dockerstopcmd, false) + if out, err := runCommand(dockerstopcmd, false); err != nil { + glog.Warningf("Error %s running command %s. Output: %s", err, dockerstopcmd, out) + } return nil } diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 407212c936ee..6937c4e21fba 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -112,13 +112,20 @@ func (k *KubeadmBootstrapper) StartCluster(k8s config.KubernetesConfig) error { // We use --ignore-preflight-errors=CRI since /var/run/dockershim.sock is not present. // (because we start kubelet with an invalid config) b := bytes.Buffer{} - if err := kubeadmInitTemplate.Execute(&b, struct{ KubeadmConfigFile string }{constants.KubeadmConfigFile}); err != nil { + templateContext := struct { + KubeadmConfigFile string + Preflights []string + }{ + KubeadmConfigFile: constants.KubeadmConfigFile, + Preflights: constants.Preflights, + } + if err := kubeadmInitTemplate.Execute(&b, templateContext); err != nil { return err } - err := k.c.Run(b.String()) + out, err := k.c.CombinedOutput(b.String()) if err != nil { - return errors.Wrapf(err, "kubeadm init error running command: %s", b.String()) + return errors.Wrapf(err, "kubeadm init error %s running command: %s", b.String(), out) } //TODO(r2d4): get rid of global here diff --git a/pkg/minikube/bootstrapper/kubeadm/templates.go b/pkg/minikube/bootstrapper/kubeadm/templates.go index 395f96a628ce..c88750895038 100644 --- a/pkg/minikube/bootstrapper/kubeadm/templates.go +++ b/pkg/minikube/bootstrapper/kubeadm/templates.go @@ -71,7 +71,8 @@ sudo /usr/bin/kubeadm alpha phase controlplane all --config {{.KubeadmConfigFile sudo /usr/bin/kubeadm alpha phase etcd local --config {{.KubeadmConfigFile}} `)) -var kubeadmInitTemplate = template.Must(template.New("kubeadmInitTemplate").Parse("sudo /usr/bin/kubeadm init --config {{.KubeadmConfigFile}} --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests --ignore-preflight-errors=Swap --ignore-preflight-errors=CRI")) +var kubeadmInitTemplate = template.Must(template.New("kubeadmInitTemplate").Parse( + "sudo /usr/bin/kubeadm init --config {{.KubeadmConfigFile}} {{range .Preflights}}--ignore-preflight-errors={{.}} {{end}}")) // printMapInOrder sorts the keys and prints the map in order, combining key // value pairs with the separator character diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 01ed9fd488d8..9be6436c6d4d 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -150,6 +150,16 @@ const ( KubeadmConfigFile = "/var/lib/kubeadm.yaml" ) +var Preflights = []string{ + "DirAvailable--etc-kubernetes-manifests", + "DirAvailable--data", + "FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml", + "FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml", + "FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml", + "FileAvailable--etc-kubernetes-manifests-etcd.yaml", + "Swap", +} + const ( LocalkubeServicePath = "/etc/systemd/system/localkube.service" LocalkubeRunning = "active"