Skip to content

Commit

Permalink
Merge pull request #2149 from aojea/dockerbtrfs
Browse files Browse the repository at this point in the history
detect docker btrfs backend filesystem
  • Loading branch information
k8s-ci-robot authored Mar 23, 2021
2 parents 487ced1 + 69b84ab commit 91ef7a3
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions pkg/cluster/internal/providers/docker/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package docker

import (
"encoding/json"
"strings"

"sigs.k8s.io/kind/pkg/exec"
Expand Down Expand Up @@ -48,15 +49,39 @@ func usernsRemap() bool {
}

// mountDevMapper checks if the Docker storage driver is Btrfs or ZFS
// or if the backing filesystem is Btrfs
func mountDevMapper() bool {
storage := ""
// check the docker storage driver
cmd := exec.Command("docker", "info", "-f", "{{.Driver}}")
lines, err := exec.OutputLines(cmd)
if err != nil {
if err != nil || len(lines) != 1 {
return false
}
if len(lines) > 0 {
storage = strings.ToLower(strings.TrimSpace(lines[0]))

storage = strings.ToLower(strings.TrimSpace(lines[0]))
if storage == "btrfs" || storage == "zfs" || storage == "devicemapper" {
return true
}
return storage == "btrfs" || storage == "zfs"

// check the backing file system
// docker info -f '{{json .DriverStatus }}'
// [["Backing Filesystem","extfs"],["Supports d_type","true"],["Native Overlay Diff","true"]]
cmd = exec.Command("docker", "info", "-f", "{{json .DriverStatus }}")
lines, err = exec.OutputLines(cmd)
if err != nil || len(lines) != 1 {
return false
}
var dat [][]string
if err := json.Unmarshal([]byte(lines[0]), &dat); err != nil {
return false
}
for _, item := range dat {
if item[0] == "Backing Filesystem" {
storage = strings.ToLower(item[1])
break
}
}

return storage == "btrfs" || storage == "zfs" || storage == "xfs"
}

0 comments on commit 91ef7a3

Please sign in to comment.