Skip to content
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
5 changes: 5 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ const (
// MountUIDFlag is the flag used to set the mount UID
MountUIDFlag = "uid"

// FSType9p is 9p filesystem type
FSType9p = "9p"
// FSTypeVirtiofs is virtiofs filesystem type
FSTypeVirtiofs = "virtiofs"

// Mirror CN
AliyunMirror = "registry.cn-hangzhou.aliyuncs.com/google_containers"
)
Expand Down
88 changes: 88 additions & 0 deletions test/integration/findmnt/findmnt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//go:build integration

/*
Copyright 2025 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// package parse findmnt command results.
package findmnt

import (
"encoding/json"
"slices"
)

// Filesystem is a findmnt --json filesystem node. It may include children
// filesystems.
type Filesystem struct {
Target string `json:"target"`
Source string `json:"source"`
FSType string `json:"fstype"`
Options string `json:"options"`
Children []Filesystem `json:"children,omitempty"`
}

// Result if findmnt --json result.
type Result struct {
Filesystems []Filesystem `json:"filesystems"`
}

// ParseOutput parse findmnt --json output.
func ParseOutput(output []byte) (*Result, error) {
r := &Result{}
if err := json.Unmarshal(output, r); err != nil {
return nil, err
}
return r, nil
}

func (r *Result) Equal(other *Result) bool {
if r == other {
return true
}
if other == nil {
return false
}
if !slices.EqualFunc(r.Filesystems, other.Filesystems, func(a, b Filesystem) bool {
return a.Equal(&b)
}) {
return false
}
return true
}

func (f *Filesystem) Equal(other *Filesystem) bool {
if f == other {
return true
}
if other == nil {
return false
}
if f.Target != other.Target {
return false
}
if f.Source != other.Source {
return false
}
if f.FSType != other.FSType {
return false
}
if !slices.EqualFunc(f.Children, other.Children, func(a, b Filesystem) bool {
return a.Equal(&b)
}) {
return false
}
return true
}
91 changes: 91 additions & 0 deletions test/integration/findmnt/findmnt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//go:build integration

/*
Copyright 2025 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package findmnt_test

import (
"os"
"testing"

"k8s.io/minikube/test/integration/findmnt"
)

func TestParseAllMounts(t *testing.T) {
// Output from `findmnt --json` command.
output, err := os.ReadFile("testdata/findmnt.json")
if err != nil {
t.Fatal(err)
}
result, err := findmnt.ParseOutput(output)
if err != nil {
t.Fatal(err)
}

assert(t, len(result.Filesystems), 1)

root := result.Filesystems[0]
assert(t, root.Target, "/")
assert(t, root.Source, "tmpfs")
assert(t, root.FSType, "tmpfs")
assert(t, root.Options, "rw,relatime,size=5469192k")
assert(t, len(root.Children), 20)

dev := root.Children[0]
assert(t, dev.Target, "/dev")
assert(t, dev.Source, "devtmpfs")
assert(t, dev.FSType, "devtmpfs")
assert(t, dev.Options, "rw,relatime,size=2838500k,nr_inodes=709625,mode=755")
assert(t, len(dev.Children), 4)

devShm := dev.Children[0]
assert(t, devShm.Target, "/dev/shm")
assert(t, devShm.Source, "tmpfs")
assert(t, devShm.FSType, "tmpfs")
assert(t, devShm.Options, "rw,nosuid,nodev")
}

func TestParseSingle(t *testing.T) {
// Output from `findmnt --json /proc` command.
output, err := os.ReadFile("testdata/findmnt-proc.json")
if err != nil {
t.Fatal(err)
}
result, err := findmnt.ParseOutput(output)
if err != nil {
t.Fatal(err)
}
expected := &findmnt.Result{
Filesystems: []findmnt.Filesystem{
{
Target: "/proc",
Source: "proc",
FSType: "proc",
Options: "rw,relatime",
},
},
}
if !result.Equal(expected) {
t.Fatalf("expected %+v, got %+v", expected, result)
}
}

func assert[T comparable](t *testing.T, a, b T) {
if a != b {
t.Fatalf("expected \"%v\", got \"%v\"", b, a)
}
}
10 changes: 10 additions & 0 deletions test/integration/findmnt/testdata/findmnt-proc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"filesystems": [
{
"target": "/proc",
"source": "proc",
"fstype": "proc",
"options": "rw,relatime"
}
]
}
Loading
Loading