Skip to content

Commit

Permalink
Miscellaneous none driver fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorenc authored and dlorenc committed Apr 4, 2018
1 parent 125eede commit cc356e6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
4 changes: 2 additions & 2 deletions hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions pkg/drivers/none/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 10 additions & 3 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cc356e6

Please sign in to comment.