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

Add ability to create extra disks on hyperkit vms #11483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ KUBERNETES_VERSION ?= $(shell egrep "DefaultKubernetesVersion =" pkg/minikube/co
KIC_VERSION ?= $(shell egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f2)

# Default to .0 for higher cache hit rates, as build increments typically don't require new ISO versions
ISO_VERSION ?= v1.22.0
ISO_VERSION ?= v1.22.0-1627488369-11483
# Dashes are valid in semver, but not Linux packaging. Use ~ to delimit alpha/beta
DEB_VERSION ?= $(subst -,~,$(RAW_VERSION))
DEB_REVISION ?= 0
Expand Down
27 changes: 27 additions & 0 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const (
defaultSSHUser = "root"
defaultSSHPort = 22
listenAddress = "listen-address"
extraDisks = "extra-disks"
)

var (
Expand Down Expand Up @@ -166,6 +167,7 @@ func initMinikubeFlags() {
startCmd.Flags().StringP(network, "", "", "network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.")
startCmd.Flags().StringVarP(&outputFormat, "output", "o", "text", "Format to print stdout in. Options include: [text,json]")
startCmd.Flags().StringP(trace, "", "", "Send trace events. Options include: [gcp]")
startCmd.Flags().Int(extraDisks, 0, "Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit driver)")
}

// initKubernetesFlags inits the commandline flags for Kubernetes related options
Expand Down Expand Up @@ -407,6 +409,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s

checkNumaCount(k8sVersion)

checkExtraDiskOptions(cmd, drvName)

cc = config.ClusterConfig{
Name: ClusterFlagValue(),
KeepContext: viper.GetBool(keepContext),
Expand Down Expand Up @@ -449,6 +453,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
SSHUser: viper.GetString(sshSSHUser),
SSHKey: viper.GetString(sshSSHKey),
SSHPort: viper.GetInt(sshSSHPort),
ExtraDisks: viper.GetInt(extraDisks),
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: k8sVersion,
ClusterName: ClusterFlagValue(),
Expand Down Expand Up @@ -560,6 +565,11 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
out.WarningT("You cannot change the disk size for an existing minikube cluster. Please first delete the cluster.")
}

checkExtraDiskOptions(cmd, cc.Driver)
if cmd.Flags().Changed(extraDisks) && viper.GetInt(extraDisks) != existing.ExtraDisks {
out.WarningT("You cannot add or remove extra disks for an existing minikube cluster. Please first delete the cluster.")
}

updateStringFromFlag(cmd, &cc.MinikubeISO, isoURL)
updateBoolFromFlag(cmd, &cc.KeepContext, keepContext)
updateBoolFromFlag(cmd, &cc.EmbedCerts, embedCerts)
Expand Down Expand Up @@ -706,3 +716,20 @@ func interpretWaitFlag(cmd cobra.Command) map[string]bool {
klog.Infof("Waiting for components: %+v", waitComponents)
return waitComponents
}

func checkExtraDiskOptions(cmd *cobra.Command, driverName string) {
supportedDrivers := []string{driver.HyperKit}

if cmd.Flags().Changed(extraDisks) {
supported := false
for _, driver := range supportedDrivers {
if driverName == driver {
supported = true
break
}
}
if !supported {
out.WarningT("Specifying extra disks is currently only supported for the following drivers: {{.supported_drivers}}. If you can contribute to add this feature, please create a PR.", out.V{"supported_drivers": supportedDrivers})
}
}
}
16 changes: 11 additions & 5 deletions deploy/iso/minikube-iso/package/automount/minikube-automount
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ MAGIC="boot2docker, please format-me"
# If there is a partition with `boot2docker-data` as its label, use it and be
# very happy. Thus, you can come along if you feel like a room without a roof.
BOOT2DOCKER_DATA=`blkid -o device -l -t LABEL=$LABEL`
UNPARTITIONED_HD="/dev/$(lsblk | grep disk | cut -f1 -d' ')"
DISKS="$(lsblk | grep disk | cut -f1 -d' ')"
echo $BOOT2DOCKER_DATA
if [ ! -n "$BOOT2DOCKER_DATA" ]; then
for DISK in $DISKS; do
if [ -n "$BOOT2DOCKER_DATA" ]; then
# The primary minikube disk has been found or provisioned; stop provisioning other disks
break
fi

UNPARTITIONED_HD="/dev/$DISK"
echo "Is the disk unpartitioned?, test for the 'boot2docker format-me' string"

# Is the disk unpartitioned?, test for the 'boot2docker format-me' string
Expand Down Expand Up @@ -61,18 +67,18 @@ if [ ! -n "$BOOT2DOCKER_DATA" ]; then
BOOT2DOCKER_DATA=`echo "${UNPARTITIONED_HD}1"`
mkfs.ext4 -i 2048 -L $LABEL $BOOT2DOCKER_DATA
else
echo "Disk unpartitioned but something is there... not doing anything"
echo "Disk ($UNPARTITIONED_HD) unpartitioned but something is there... not doing anything"
fi
else
echo "Partition table found on disk, not doing anything"
echo "Partition table found on disk ($UNPARTITIONED_HD), not doing anything"
fi
fi
else
# Pick the first ext4 as a fallback
# TODO: mount all Linux partitions and look for a /var/lib/docker...
BOOT2DOCKER_DATA=`blkid | grep -e 'TYPE="btrfs"' -e 'TYPE="ext4"' | head -n 1 | sed 's/:.*//'`
fi
fi
done

echo $BOOT2DOCKER_DATA

Expand Down
7 changes: 7 additions & 0 deletions pkg/drivers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package drivers

import (
"fmt"
"io"
"io/ioutil"
"os"
Expand All @@ -41,6 +42,12 @@ func GetDiskPath(d *drivers.BaseDriver) string {
return filepath.Join(d.ResolveStorePath("."), d.GetMachineName()+".rawdisk")
}

// ExtraDiskPath returns the path of an additional disk suffixed with an ID.
func ExtraDiskPath(d *drivers.BaseDriver, diskID int) string {
file := fmt.Sprintf("%s-%d.rawdisk", d.GetMachineName(), diskID)
return filepath.Join(d.ResolveStorePath("."), file)
}

// CommonDriver is the common driver base class
type CommonDriver struct{}

Expand Down
8 changes: 8 additions & 0 deletions pkg/drivers/hyperkit/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Driver struct {
UUID string
VpnKitSock string
VSockPorts []string
ExtraDisks int
}

// NewDriver creates a new driver for a host
Expand Down Expand Up @@ -229,6 +230,13 @@ func (d *Driver) createHost() (*hyperkit.HyperKit, error) {
Trim: true,
},
}
for i := 0; i < d.ExtraDisks; i++ {
h.Disks = append(h.Disks, &hyperkit.RawDisk{
Path: pkgdrivers.ExtraDiskPath(d.BaseDriver, i),
Size: d.DiskSize,
Trim: true,
})
}

return h, nil
}
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 @@ -83,6 +83,7 @@ type ClusterConfig struct {
ListenAddress string // Only used by the docker and podman driver
Network string // only used by docker driver
MultiNodeRequested bool
ExtraDisks int // currently only implemented for hyperkit
}

// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/download/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const fileScheme = "file"
// DefaultISOURLs returns a list of ISO URL's to consult by default, in priority order
func DefaultISOURLs() []string {
v := version.GetISOVersion()
isoBucket := "minikube/iso"
isoBucket := "minikube-builds/iso/11483"
return []string{
fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", isoBucket, v),
fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/%s/minikube-%s.iso", v, v),
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/hyperkit/hyperkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func configure(cfg config.ClusterConfig, n config.Node) (interface{}, error) {
VpnKitSock: cfg.HyperkitVpnKitSock,
VSockPorts: cfg.HyperkitVSockPorts,
Cmdline: "loglevel=3 console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 systemd.legacy_systemd_cgroup_controller=yes random.trust_cpu=on hw_rng_model=virtio base host=" + cfg.Name,
ExtraDisks: cfg.ExtraDisks,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion site/content/en/docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ minikube start [flags]
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
Valid kubeadm parameters: ignore-preflight-errors, dry-run, kubeconfig, kubeconfig-dir, node-name, cri-socket, experimental-upload-certs, certificate-key, rootfs, skip-phases, pod-network-cidr
--extra-disks int Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit driver)
--feature-gates string A set of key=value pairs that describe feature gates for alpha/experimental features.
--force Force minikube to perform possibly dangerous operations
--force-systemd If set, force the container runtime to use systemd as cgroup manager. Defaults to false.
Expand All @@ -64,7 +65,7 @@ minikube start [flags]
--insecure-registry strings Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.
--install-addons If set, install addons. Defaults to true. (default true)
--interactive Allow user prompts for more information (default true)
--iso-url strings Locations to fetch the minikube ISO from. (default [https://storage.googleapis.com/minikube/iso/minikube-v1.22.0.iso,https://github.com/kubernetes/minikube/releases/download/v1.22.0/minikube-v1.22.0.iso,https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.22.0.iso])
--iso-url strings Locations to fetch the minikube ISO from. (default [https://storage.googleapis.com/minikube-builds/iso/11483/minikube-v1.22.0-1627488369-11483.iso,https://github.com/kubernetes/minikube/releases/download/v1.22.0-1627488369-11483/minikube-v1.22.0-1627488369-11483.iso,https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.22.0-1627488369-11483.iso])
--keep-context This will keep the existing kubectl context and will create a minikube context.
--kubernetes-version string The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for v1.21.3, 'latest' for v1.22.0-rc.0). Defaults to 'stable'.
--kvm-gpu Enable experimental NVIDIA GPU support in minikube
Expand Down