Skip to content

Commit 05d18a5

Browse files
sets ContainerVolumeMounts when a container driver is selected
1 parent d266331 commit 05d18a5

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

minikube/service/minikube_client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import (
2121
_ "k8s.io/minikube/pkg/minikube/registry/drvs"
2222
)
2323

24+
const (
25+
Podman = "podman"
26+
Docker = "docker"
27+
)
28+
2429
type ClusterClient interface {
2530
SetConfig(args MinikubeClientConfig)
2631
GetConfig() MinikubeClientConfig
@@ -144,6 +149,9 @@ func (e *MinikubeClient) Start() (*kubeconfig.Settings, error) {
144149
}
145150

146151
e.clusterConfig.MinikubeISO = url
152+
if e.clusterConfig.Driver == Podman || e.clusterConfig.Driver == Docker { // use volume mounts for container runtimes
153+
e.clusterConfig.ContainerVolumeMounts = []string{e.clusterConfig.MountString}
154+
}
147155

148156
if e.nativeSsh {
149157
ssh.SetDefaultClient(ssh.Native)

minikube/service/minikube_client_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,66 @@ func TestMinikubeClient_GetAddons(t *testing.T) {
625625
}
626626
}
627627

628+
func TestMinikubeClient_ContainerMounts(t *testing.T) {
629+
630+
type fields struct {
631+
mount bool
632+
mountString string
633+
driver string
634+
}
635+
tests := []struct {
636+
name string
637+
fields fields
638+
want []string
639+
}{
640+
{
641+
name: "Should set container mounts when provided mount string",
642+
fields: fields{
643+
mount: true,
644+
mountString: "/test:/data",
645+
driver: "docker",
646+
},
647+
want: []string{"/test:/data"},
648+
},
649+
{
650+
name: "Should not set container mounts for non container drivers",
651+
fields: fields{
652+
mount: true,
653+
mountString: "/test:/data",
654+
driver: "other",
655+
},
656+
want: nil,
657+
},
658+
}
659+
for _, tt := range tests {
660+
ctrl := gomock.NewController(t)
661+
662+
t.Run(tt.name, func(t *testing.T) {
663+
e := &MinikubeClient{
664+
clusterConfig: config.ClusterConfig{
665+
Driver: tt.fields.driver,
666+
Mount: tt.fields.mount,
667+
MountString: tt.fields.mountString,
668+
Nodes: []config.Node{
669+
{},
670+
},
671+
},
672+
clusterName: "sut",
673+
addons: []string{},
674+
isoUrls: []string{},
675+
deleteOnFailure: false,
676+
nRunner: getNodeSuccess(ctrl),
677+
dLoader: getDownloadSuccess(ctrl),
678+
}
679+
e.Start()
680+
got := e.clusterConfig.ContainerVolumeMounts
681+
if !reflect.DeepEqual(got, tt.want) {
682+
t.Errorf("clusterConfig.ContainerVolumeMounts = %v, want %v", got, tt.want)
683+
}
684+
})
685+
}
686+
}
687+
628688
func getProvisionerFailure(ctrl *gomock.Controller) Cluster {
629689
nRunnerProvisionFailure := NewMockCluster(ctrl)
630690

0 commit comments

Comments
 (0)