Replace traditional append-in-loop patterns with modern Go functions slices.Sorted(), slices.Collect(), and maps.Keys()/maps.Values()
Changes made (5 files):
- cmd/minikube/cmd/config/addons_list.go: Use slices.Sorted(maps.Keys())
- cmd/minikube/cmd/version.go: Use slices.Sorted(maps.Keys())
- hack/changelog/changelog.go: Use slices.Collect(maps.Keys())
- pkg/minikube/node/cache.go: Use slices.Collect(maps.Keys())
- pkg/minikube/registry/registry.go: Use slices.Collect(maps.Values())
Files skipped due to complexity:
- pkg/drivers/kic/oci/oci.go
- pkg/drivers/hyperkit/driver.go
- pkg/drivers/kvm/gpu.go
- pkg/drivers/kvm/numa.go [Unrelated slice optimization possible, can be addressed along with other similar code]
- pkg/minikube/tunnel/kic/*
- cmd/minikube/cmd/service.go
- hack/legacy_fill_db/filldb.go
These cases require more sophisticated transformation logic that might be better addressed in separate issue/PR
Replace 9p mounts with virtiofs for vfkit and krunkit. Testing shows
that virtiofs mount is 23 times faster with krunkit, and 8 times faster
with vfkit.
vfkit and krunkit support multiple virtiofs mounts but minikube
--mount-* flags are not ready for multiple mounts. We have the same
issue with KIC drivers, supporting multiple mounts but using only one.
We hope to improve this in the next release.
Example usage:
minikube start --mount-string ~/models:/mnt/models
The arguments are parsed and validated when configuring the driver, so
invalid arguments fail quickly without starting the driver. The
validated mounts are stored in the machine config:
$ jq '.Driver.VirtiofsMounts' < ~/.minikube/machines/minikube/config.json
[
{
"HostPath": "/Users/joe/models",
"GuestPath": "/mnt/models",
"Tag": "f845b54d-00e3-493d-9541-3b37490b96db"
}
]
Minikube generates a new random UUID for every virtiofs mount to
identify the file system inside the guest. In krunkit and vfkit, every
mount is add as:
--device virtio-fs,sharedDir=/host-path,mountTag=f845b54d-00e3-493d-9541-3b37490b96db
When the guest is started the shared directory is mounted via SSH using:
sudo mkdir -p /mnt/models
sudo mount -t virtiofs f845b54d-00e3-493d-9541-3b37490b96db /mnt/models
Example mount:
$ minikube ssh findmnt /mnt/models
TARGET SOURCE FSTYPE OPTIONS
/mnt/models f845b54d-00e3-493d-9541-3b37490b96db virtiofs rw,relatime
More work is needed to add VirtioFS to qemu. I'm starting with vfkit and
krunkit since they have identical interface (krunkit was designed as
drop-in replacement for vfkit).
* test: Add findmnt package
When testing mounts we can use findmnt --json output to parse the output
cleanly. The package provides only ParseOutput() now, but it can be
extended later to run the findmnt command.
* test: Support virtiofs mounts
Use findmnt command to get the mounted filesystem details cleanly.
We use the actual mount fstype instead of driver name check so we can
switch drivers to virtiofs without changing the test.
For virtiofs mount we skip options validation since we don't support
setting virtiofs options yet, and the options are not the same as 9p
options.
For 9p mounts the uid= and gid= flags were fixed to match the real flags
(dfltuid=,dfltgid=). The issue was hidden by imprecise string matching.
The --mount-string argument defaults to `/Users` on darwin, and
homedir.Homedir() on other platforms (e.g. $HOME on unix).
This is wrong in many ways:
- `/Users` is not HOME on darwin (the right path is `/Users/$USER`).
Using the default mount we cannot access anything inside the guest in
the user home directory. We can access the special `/Users/Shared`
directory, but this should not be a default mount.
- Mounting the user home directory inside the guest in read-write mode
is a horrible default. This exposes the users private keys in .ssh/ to
the guest, any sensitive files in the user home directory, and allows
the guest to change any file on the host.
- Using the `--mount` option mount the default mount directory silently.
This is unexpected, surprising, and not documented in the minikube
handbook[1].
Example access to user private key from the guest with the default
mount:
$ minikube start --mount
$ minikube ssh cat /minikube-host/.ssh/id_ed25519
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----
Fixed by removing the default mount directory and changing mount logic
to check for non-empty mount-string instead of the mount flag.
The mount flag is kept for backward compatibility, but its value is
ignored. In the next release we want to use this flag for supporting
multiple mounts.
Example usage before:
minikube start --mount --mount-string ~/models:/mnt/models
Example usage after:
minikube start --mount-string ~/models:/mnt/models
Breaking changes:
User depending the default mount will have to replace the command:
minikube start --mount
With:
minikube start --mount-string $HOME:/minikube-host
[1] https://minikube.sigs.k8s.io/docs/handbook/mount/
Move all files and packages which are not a driver to the drivers/common
package. This helps to understand the structure of the code.
While moving, move the iso_test.iso into testdata/test.iso to separate
code and test data.
While fixing the test iso path fix few bugs in the tests using wrong iso
path. The test failed because the iso path was wrong instead of issue
with source or destination path.
New directory structure:
% tree -L1 pkg/drivers
pkg/drivers
├── common
├── hyperkit
├── kic
├── krunkit
├── kvm
├── none
├── qemu
├── ssh
└── vfkit
getWindowsVolumeNameCmd uses the deprecated wmic.exe.
See https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic for
details.
Replace the implementation with a call to the Powershell equivalent.
Look in path and system environment vars to locate Powershell.
Improve Powershell discovery
* remove omitnew line
* add new option to hide after spin
* refactor to use new return hideAfterSpin
* add new line by default only when not spinining and delegate spinner newline to spinner code
* add new func for ouptputing with spinner and pass fdwriter directly to the spininer func
* fix unit test
* fix lint for krunkit
* add comment and context
* use different spinning progress bar for sub steps
* make func private
* making more spinning icons
* integration test dont expect sub steps to be visible
* fix unit test and comment why
* change sub step spining icon not to be a progressbar
* pass the filewriter to the spinner library for the spinning steps