mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #21364 from pwittrock/macdu
Auto commit by PR queue bot
This commit is contained in:
commit
11cdc919f5
@ -19,8 +19,6 @@ package volume
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/volume/util"
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
@ -64,17 +62,10 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
|
|||||||
|
|
||||||
// runDu executes the "du" command and writes the results to metrics.Used
|
// runDu executes the "du" command and writes the results to metrics.Used
|
||||||
func (md *metricsDu) runDu(metrics *Metrics) error {
|
func (md *metricsDu) runDu(metrics *Metrics) error {
|
||||||
// Uses the same niceness level as cadvisor.fs does when running du
|
used, err := util.Du(md.path)
|
||||||
// Uses -B 1 to always scale to a blocksize of 1 byte
|
|
||||||
out, err := exec.Command("nice", "-n", "19", "du", "-s", "-B", "1", md.path).CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed command 'du' on %s with error %v", md.path, err)
|
return err
|
||||||
}
|
}
|
||||||
used, err := resource.ParseQuantity(strings.Fields(string(out))[0])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to parse 'du' output %s due to error %v", out, err)
|
|
||||||
}
|
|
||||||
used.Format = resource.BinarySI
|
|
||||||
metrics.Used = used
|
metrics.Used = used
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,10 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||||
@ -33,6 +33,8 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/empty_dir"
|
"k8s.io/kubernetes/pkg/volume/empty_dir"
|
||||||
"k8s.io/kubernetes/pkg/volume/util"
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.VolumeHost) {
|
func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.VolumeHost) {
|
||||||
@ -122,12 +124,16 @@ func TestPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
doTestSecretDataInVolume(volumePath, secret, t)
|
doTestSecretDataInVolume(volumePath, secret, t)
|
||||||
|
defer doTestCleanAndTeardown(plugin, testPodUID, testVolumeName, volumePath, t)
|
||||||
|
|
||||||
|
// Metrics only supported on linux
|
||||||
metrics, err := builder.GetMetrics()
|
metrics, err := builder.GetMetrics()
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
assert.NotEmpty(t, metrics)
|
assert.NotEmpty(t, metrics)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
} else {
|
||||||
doTestCleanAndTeardown(plugin, testPodUID, testVolumeName, volumePath, t)
|
t.Skipf("Volume metrics not supported on %s", runtime.GOOS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the case where the 'ready' file has been created and the pod volume dir
|
// Test the case where the 'ready' file has been created and the pod volume dir
|
||||||
|
47
pkg/volume/util/fs_darwin.go
Normal file
47
pkg/volume/util/fs_darwin.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// +build darwin
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2016 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 util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FSInfo linux returns (available bytes, byte capacity, error) for the filesystem that
|
||||||
|
// path resides upon.
|
||||||
|
func FsInfo(path string) (int64, int64, error) {
|
||||||
|
return 0, 0, errors.New("FsInfo not supported for this build.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Du(path string) (*resource.Quantity, error) {
|
||||||
|
out, err := exec.Command("nice", "-n", "19", "du", "-s", path).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed command 'du' ($ nice -n 19 du -s) on path %s with error %v", path, err)
|
||||||
|
}
|
||||||
|
used, err := resource.ParseQuantity(strings.Fields(string(out))[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse 'du' output %s due to error %v", out, err)
|
||||||
|
}
|
||||||
|
used.Format = resource.BinarySI
|
||||||
|
return used, nil
|
||||||
|
}
|
@ -19,7 +19,12 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FSInfo linux returns (available bytes, byte capacity, error) for the filesystem that
|
// FSInfo linux returns (available bytes, byte capacity, error) for the filesystem that
|
||||||
@ -39,3 +44,18 @@ func FsInfo(path string) (int64, int64, error) {
|
|||||||
|
|
||||||
return available, capacity, nil
|
return available, capacity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Du(path string) (*resource.Quantity, error) {
|
||||||
|
// Uses the same niceness level as cadvisor.fs does when running du
|
||||||
|
// Uses -B 1 to always scale to a blocksize of 1 byte
|
||||||
|
out, err := exec.Command("nice", "-n", "19", "du", "-s", "-B", "1", path).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed command 'du' ($ nice -n 19 du -s -B 1) on path %s with error %v", path, err)
|
||||||
|
}
|
||||||
|
used, err := resource.ParseQuantity(strings.Fields(string(out))[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse 'du' output %s due to error %v", out, err)
|
||||||
|
}
|
||||||
|
used.Format = resource.BinarySI
|
||||||
|
return used, nil
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// +build !linux
|
// +build !linux,!darwin
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||||
@ -20,9 +20,16 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FSInfo unsupported returns 0 values for available and capacity and an error.
|
// FSInfo unsupported returns 0 values for available and capacity and an error.
|
||||||
func FsInfo(path string) (int64, int64, error) {
|
func FsInfo(path string) (int64, int64, error) {
|
||||||
return 0, 0, errors.New("FsInfo not supported for this build.")
|
return 0, 0, errors.New("FsInfo not supported for this build.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Du(path string) (*resource.Quantity, error) {
|
||||||
|
return nil, fmt.Errorf("Du not support for this build.")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user