Skip to content

Commit

Permalink
Update mount implementation, add mount integration tests, and check t…
Browse files Browse the repository at this point in the history
…hat path exists.
  • Loading branch information
aaron-prindle committed Apr 6, 2017
1 parent 12e41ae commit 8e801e3
Show file tree
Hide file tree
Showing 60 changed files with 1,596 additions and 2,604 deletions.
11 changes: 10 additions & 1 deletion cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/third_party/go9p/p/srv/examples/ufs"
"k8s.io/minikube/third_party/go9p/ufs"
)

// mountCmd represents the mount command
Expand All @@ -42,6 +42,15 @@ var mountCmd = &cobra.Command{
fmt.Fprintln(os.Stderr, errText)
os.Exit(1)
}
if _, err := os.Stat(args[0]); err != nil {
if os.IsNotExist(err) {
errText := fmt.Sprintf("Cannot find directory %s for mount", args[0])
fmt.Fprintln(os.Stderr, errText)
} else {
errText := fmt.Sprintf("Error accesssing directory %s for mount", args[0])
fmt.Fprintln(os.Stderr, errText)
}
}
var debugVal int
if glog.V(1) {
debugVal = 1 // ufs.StartServer takes int debug param
Expand Down
3 changes: 2 additions & 1 deletion hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/minikube-${OS_ARCH} out/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/e2e-${OS_ARCH} out/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/pvc.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox-mount-test.yaml testdata/

# Set the executable bit on the e2e binary and out binary
chmod +x out/e2e-${OS_ARCH}
Expand Down Expand Up @@ -63,4 +64,4 @@ curl "https://api.github.com/repos/kubernetes/minikube/statuses/${COMMIT}?access
-d "{\"state\": \"$status\", \"description\": \"Jenkins\", \"target_url\": \"$target_url\", \"context\": \"${JOB_NAME}\"}"
set -x

exit $result
exit $result
1 change: 1 addition & 0 deletions pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func Mount9pHost(api libmachine.API) error {
if err != nil {
return errors.Wrap(err, "Error getting the host IP address to use from within the VM")
}
host.RunSSHCommand(GetMount9pCleanupCommand())
_, err = host.RunSSHCommand(GetMount9pCommand(ip))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/cluster/cluster_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func getVMHostIP(host *host.Host) (net.IP, error) {
case "virtualbox":
return net.ParseIP("10.0.2.2"), nil
case "xhyve":
return net.ParseIP("10.0.2.2"), nil
return net.ParseIP("192.168.64.1"), nil
default:
return []byte{}, errors.New("Error, attempted to get host ip address for unsupported driver")
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/minikube/cluster/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func GenLocalkubeStartCmd(kubernetesConfig KubernetesConfig) (string, error) {
flagVals = append(flagVals, "--feature-gates="+kubernetesConfig.FeatureGates)
}

if kubernetesConfig.APIServerName != "" {
if kubernetesConfig.APIServerName != constants.APIServerName {
flagVals = append(flagVals, "--apiserver-name="+kubernetesConfig.APIServerName)
}

Expand Down Expand Up @@ -226,9 +226,16 @@ else
fi
`, constants.LocalkubePIDPath)

func GetMount9pCleanupCommand() string {
return `
sudo umount /mount-9p;
sudo rm -rf /mount-9p;
`
}

func GetMount9pCommand(ip net.IP) string {
return fmt.Sprintf(`
sudo mkdir /mount-9p;
sudo mount -t 9p -o trans=tcp -o port=5640 %s /mount-9p;
sudo mount -t 9p -o trans=tcp -o port=5640 -o uid=1001 -o gid=1001 %s /mount-9p;
sudo chmod 775 /mount-9p;`, ip)
}
1 change: 1 addition & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ func TestFunctional(t *testing.T) {
t.Run("Dashboard", testDashboard)
t.Run("ServicesList", testServicesList)
t.Run("Provisioning", testProvisioning)
t.Run("Mounting", testMounting)
}
112 changes: 112 additions & 0 deletions test/integration/mount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// +build integration

/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"

"k8s.io/kubernetes/pkg/api"
commonutil "k8s.io/minikube/pkg/util"
"k8s.io/minikube/test/integration/util"
)

func testMounting(t *testing.T) {
t.Parallel()
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}

tempDir, err := ioutil.TempDir("", "mounttest")
if err != nil {
t.Fatalf("Unexpected error while creating tempDir: %s", err)
}
defer os.RemoveAll(tempDir)

mountCmd := fmt.Sprintf("mount %s", tempDir)
cmd := minikubeRunner.RunDaemon(mountCmd)
defer cmd.Process.Kill()

kubectlRunner := util.NewKubectlRunner(t)
podName := "busybox"
podPath, _ := filepath.Abs("testdata/busybox-mount-test.yaml")

// Write file in mounted dir from host
expected := "test\n"
files := []string{"fromhost", "fromhostremove"}
for _, file := range files {
path := filepath.Join(tempDir, file)
err = ioutil.WriteFile(path, []byte(expected), 0644)
if err != nil {
t.Fatalf("Unexpected error while writing file %s: %s.", path, err)
}
}
mountTest := func() error {
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
return err
}
defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath})

p := &api.Pod{}
for p.Status.Phase != "Running" {
p = kubectlRunner.GetPod(podName, "default")
}

path := filepath.Join(tempDir, "frompod")
out, err := ioutil.ReadFile(path)
if err != nil {
return &commonutil.RetriableError{Err: err}
}
// test that file written from pod can be read from host echo test > /mount-9p/frompod; in pod
if string(out) != expected {
t.Fatalf("Expected file %s to contain text %s, was %s.", path, expected, out)
}

// test that file written from host was read in by the pod via cat /mount-9p/fromhost;
if out, err = kubectlRunner.RunCommand([]string{"logs", podName}); err != nil {
return &commonutil.RetriableError{Err: err}
}
if string(out) != expected {
t.Fatalf("Expected file %s to contain text %s, was %s.", path, expected, out)
}

// test that fromhostremove was deleted by the pod from the mount via rm /mount-9p/fromhostremove
path = filepath.Join(tempDir, "fromhostremove")
if _, err := os.Stat(path); err == nil {
t.Fatalf("Expected file %s to be removed", path, expected, out)
}

// test that frompodremove can be deleted on the host
path = filepath.Join(tempDir, "frompodremove")
if err := os.Remove(path); err != nil {
t.Fatalf("Unexpected error removing file %s: %s", path, err)
}

return nil
}
if err := commonutil.RetryAfter(40, mountTest, 5*time.Second); err != nil {
t.Fatal("mountTest failed with error:", err)
}

}
19 changes: 19 additions & 0 deletions test/integration/testdata/busybox-mount-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
containers:
- image: busybox:glibc
command: [ "/bin/sh", "-c", "--" ]
args: [ "cat /mount-9p/fromhost; echo test > /mount-9p/frompod; rm /mount-9p/fromhostremove; echo test > /mount-9p/frompodremove;" ]
name: busybox
volumeMounts:
- mountPath: /mount-9p
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /mount-9p

11 changes: 11 additions & 0 deletions test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ func (m *MinikubeRunner) RunCommand(command string, checkError bool) string {
return string(stdout)
}

func (m *MinikubeRunner) RunDaemon(command string) *exec.Cmd {
commandArr := strings.Split(command, " ")
path, _ := filepath.Abs(m.BinaryPath)
cmd := exec.Command(path, commandArr...)
err := cmd.Start()
if err != nil {
m.T.Fatalf("Error running command: %s %s", command, err)
}
return cmd
}

func (m *MinikubeRunner) SSH(command string) (string, error) {
path, _ := filepath.Abs(m.BinaryPath)
cmd := exec.Command(path, "ssh", command)
Expand Down
2 changes: 2 additions & 0 deletions third_party/go9p/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.orig
*.rej
13 changes: 0 additions & 13 deletions third_party/go9p/AUTHORS

This file was deleted.

18 changes: 0 additions & 18 deletions third_party/go9p/CONTRIBUTORS

This file was deleted.

11 changes: 11 additions & 0 deletions third_party/go9p/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This is go9p done in a way that I can understand.

To install:
export GOPATH=~rminnich/go
go get -a /k8s.io/minikube/third_party/go9p
go get -a /k8s.io/minikube/third_party/go9p/ufs
go install -a /k8s.io/minikube/third_party/go9p/ufs

~/go/bin/ufs


Loading

0 comments on commit 8e801e3

Please sign in to comment.