Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
1e517559
Commit
1e517559
authored
Feb 16, 2016
by
Phillip Wittrock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix volume secret_test.go on darwin by not checking volume usage metrics
parent
6c638b5f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
15 deletions
+86
-15
metrics_du.go
pkg/volume/metrics_du.go
+2
-11
secret_test.go
pkg/volume/secret/secret_test.go
+9
-3
fs_darwin.go
pkg/volume/util/fs_darwin.go
+47
-0
fs_linux.go
pkg/volume/util/fs_linux.go
+20
-0
fs_unsupported.go
pkg/volume/util/fs_unsupported.go
+8
-1
No files found.
pkg/volume/metrics_du.go
View file @
1e517559
...
@@ -19,8 +19,6 @@ package volume
...
@@ -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) {
...
@@ -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
}
}
...
...
pkg/volume/secret/secret_test.go
View file @
1e517559
...
@@ -21,10 +21,10 @@ import (
...
@@ -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/testing/fake"
"k8s.io/kubernetes/pkg/client/testing/fake"
...
@@ -33,6 +33,8 @@ import (
...
@@ -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) {
...
@@ -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
...
...
pkg/volume/util/fs_darwin.go
0 → 100644
View file @
1e517559
// +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
}
pkg/volume/util/fs_linux.go
View file @
1e517559
...
@@ -19,7 +19,12 @@ limitations under the License.
...
@@ -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) {
...
@@ -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
}
pkg/volume/util/fs_unsupported.go
View file @
1e517559
// +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
...
@@ -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."
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment