Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mounting host volumes on start with docker driver #8159

Merged
merged 7 commits into from
Sep 1, 2020
4 changes: 3 additions & 1 deletion cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
},
}
cc.VerifyComponents = interpretWaitFlag(*cmd)

if viper.GetBool(createMount) && driver.IsKIC(drvName) {
cc.ContainerVolumeMounts = []string{viper.GetString(mountString)}
}
cnm, err := cni.New(cc)
if err != nil {
return cc, config.Node{}, errors.Wrap(err, "cni")
Expand Down
1 change: 1 addition & 0 deletions pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewDriver(c Config) *Driver {
// Create a host using the driver's config
func (d *Driver) Create() error {
params := oci.CreateParams{
Mounts: d.NodeConfig.Mounts,
Name: d.NodeConfig.MachineName,
Image: d.NodeConfig.ImageDigest,
ClusterLabel: oci.ProfileLabelKey + "=" + d.MachineName,
Expand Down
47 changes: 47 additions & 0 deletions pkg/drivers/kic/oci/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ limitations under the License.

package oci

import (
"errors"
"fmt"
"path/filepath"
"strings"
)

const (
// DefaultBindIPV4 is The default IP the container will listen on.
DefaultBindIPV4 = "127.0.0.1"
Expand Down Expand Up @@ -94,6 +101,46 @@ type Mount struct {
Propagation MountPropagation `protobuf:"varint,5,opt,name=propagation,proto3,enum=runtime.v1alpha2.MountPropagation" json:"propagation,omitempty"`
}

// ParseMountString parses a mount string of format:
// '[host-path:]container-path[:<options>]' The comma-delimited 'options' are
// [rw|ro], [Z], [srhared|rslave|rprivate].
func ParseMountString(spec string) (m Mount, err error) {
switch fields := strings.Split(spec, ":"); len(fields) {
case 0:
err = errors.New("invalid empty spec")
case 1:
m.ContainerPath = fields[0]
case 3:
for _, opt := range strings.Split(fields[2], ",") {
switch opt {
case "Z":
m.SelinuxRelabel = true
case "ro":
m.Readonly = true
case "rw":
m.Readonly = false
case "rslave":
m.Propagation = MountPropagationHostToContainer
case "rshared":
m.Propagation = MountPropagationBidirectional
case "private":
m.Propagation = MountPropagationNone
default:
err = fmt.Errorf("unknown mount option: '%s'", opt)
}
}
fallthrough
case 2:
m.HostPath, m.ContainerPath = fields[0], fields[1]
if !filepath.IsAbs(m.ContainerPath) {
err = fmt.Errorf("'%s' container path must be absolute", m.ContainerPath)
}
default:
err = errors.New("spec must be in form: <host path>:<container path>[:<options>]")
}
return m, err
}

// PortMapping specifies a host port mapped into a container port.
// In yaml this looks like:
// containerPort: 80
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ClusterConfig struct {
HyperkitVpnKitSock string // Only used by the Hyperkit driver
HyperkitVSockPorts []string // Only used by the Hyperkit driver
DockerEnv []string // Each entry is formatted as KEY=VALUE.
ContainerVolumeMounts []string // Only used by container drivers: Docker, Podman
InsecureRegistry []string
RegistryMirror []string
HostOnlyCIDR string // Only used by the virtualbox driver
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {
}

var wg sync.WaitGroup
go configureMounts(&wg)
if !driver.IsKIC(starter.Cfg.Driver) {
go configureMounts(&wg)
}

wg.Add(1)
go func() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/registry/drvs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,20 @@ func init() {
}

func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
mounts := make([]oci.Mount, len(cc.ContainerVolumeMounts))
for i, spec := range cc.ContainerVolumeMounts {
var err error
mounts[i], err = oci.ParseMountString(spec)
if err != nil {
return nil, err
}
}

return kic.NewDriver(kic.Config{
MachineName: driver.MachineName(cc, n),
StorePath: localpath.MiniPath(),
ImageDigest: cc.KicBaseImage,
Mounts: mounts,
CPU: cc.CPUs,
Memory: cc.Memory,
OCIBinary: oci.Docker,
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/registry/drvs/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,20 @@ func init() {
}

func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
mounts := make([]oci.Mount, len(cc.ContainerVolumeMounts))
for i, spec := range cc.ContainerVolumeMounts {
var err error
mounts[i], err = oci.ParseMountString(spec)
if err != nil {
return nil, err
}
}

return kic.NewDriver(kic.Config{
MachineName: driver.MachineName(cc, n),
StorePath: localpath.MiniPath(),
ImageDigest: strings.Split(cc.KicBaseImage, "@")[0], // for podman does not support docker images references with both a tag and digest.
Mounts: mounts,
CPU: cc.CPUs,
Memory: cc.Memory,
OCIBinary: oci.Podman,
Expand Down