diff --git a/pkg/volume/metrics_du_test.go b/pkg/volume/metrics_du_test.go index c78dad1c7fd..72ba784e4ae 100644 --- a/pkg/volume/metrics_du_test.go +++ b/pkg/volume/metrics_du_test.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "os" "path/filepath" + "syscall" "testing" utiltesting "k8s.io/client-go/util/testing" @@ -29,7 +30,15 @@ import ( volumetest "k8s.io/kubernetes/pkg/volume/testing" ) -const expectedBlockSize = 4096 +func getExpectedBlockSize(path string) int64 { + statfs := &syscall.Statfs_t{} + err := syscall.Statfs(path, statfs) + if err != nil { + return 0 + } + + return int64(statfs.Bsize) +} // TestMetricsDuGetCapacity tests that MetricsDu can read disk usage // for path @@ -69,7 +78,7 @@ func TestMetricsDuGetCapacity(t *testing.T) { if err != nil { t.Errorf("Unexpected error when calling GetMetrics %v", err) } - if e, a := (expectedEmptyDirUsage.Value() + expectedBlockSize), actual.Used.Value(); e != a { + if e, a := (expectedEmptyDirUsage.Value() + getExpectedBlockSize(filepath.Join(tmpDir, "f1"))), actual.Used.Value(); e != a { t.Errorf("Unexpected Used for directory with file. Expected %v, got %d.", e, a) } }