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) {
cc.VolumeMounts = []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.
VolumeMounts []string
Asarew marked this conversation as resolved.
Show resolved Hide resolved
InsecureRegistry []string
RegistryMirror []string
HostOnlyCIDR string // Only used by the virtualbox driver
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.VolumeMounts))
Asarew marked this conversation as resolved.
Show resolved Hide resolved
for i, spec := range cc.VolumeMounts {
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