Skip to content

Commit

Permalink
Add ability to create extra disks on hyperkit vms
Browse files Browse the repository at this point in the history
Add the ability to create and attach extra disks to hyperkit vms.

Signed-off-by: Blaine Gardner <blaine.gardner@redhat.com>
  • Loading branch information
BlaineEXE committed Jul 28, 2021
1 parent 2b84cb9 commit 8f05ee0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
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
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

0 comments on commit 8f05ee0

Please sign in to comment.