Skip to content

Commit

Permalink
Merge pull request #28536 from kubernetes/revert-28176-inode-check-dep
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Revert "Declare out of disk when there is no free inodes"

Reverts #28176

Fixes #28481
  • Loading branch information
k8s-merge-robot authored Jul 7, 2016
2 parents 6de30e6 + 5d05fba commit 52e8d4f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 102 deletions.
15 changes: 5 additions & 10 deletions pkg/kubelet/disk_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ type DiskSpacePolicy struct {
}

type fsInfo struct {
Usage int64
Capacity int64
Available int64
Timestamp time.Time
InodesFree int64
Usage int64
Capacity int64
Available int64
Timestamp time.Time
}

type realDiskSpaceManager struct {
Expand Down Expand Up @@ -79,7 +78,6 @@ func (dm *realDiskSpaceManager) getFsInfo(fsType string, f func() (cadvisorapi.F
fsi.Usage = int64(fs.Usage)
fsi.Capacity = int64(fs.Capacity)
fsi.Available = int64(fs.Available)
fsi.InodesFree = int64(fs.InodesFree)
dm.cachedInfo[fsType] = fsi
}
return fsi, nil
Expand All @@ -104,14 +102,11 @@ func (dm *realDiskSpaceManager) isSpaceAvailable(fsType string, threshold int, f
if fsInfo.Available < 0 {
return true, fmt.Errorf("wrong available space for %q: %+v", fsType, fsInfo)
}

if fsInfo.Available < int64(threshold)*mb {
glog.Infof("Running out of space on disk for %q: available %d MB, threshold %d MB", fsType, fsInfo.Available/mb, threshold)
return false, nil
}
if fsInfo.InodesFree == 0 {
glog.Infof("Running out of inodes for %q", fsType)
return false, nil
}
return true, nil
}

Expand Down
127 changes: 37 additions & 90 deletions pkg/kubelet/disk_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ func TestSpaceAvailable(t *testing.T) {
assert.NoError(err)

mockCadvisor.On("ImagesFsInfo").Return(cadvisorapi.FsInfo{
Usage: 400 * mb,
Capacity: 1000 * mb,
Available: 600 * mb,
InodesFree: 5,
Usage: 400 * mb,
Capacity: 1000 * mb,
Available: 600 * mb,
}, nil)
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 9 * mb,
Capacity: 10 * mb,
InodesFree: 5,
Usage: 9 * mb,
Capacity: 10 * mb,
}, nil)

ok, err := dm.IsRuntimeDiskSpaceAvailable()
Expand All @@ -83,18 +81,17 @@ func TestSpaceAvailable(t *testing.T) {
}

// TestIsRuntimeDiskSpaceAvailableWithSpace verifies IsRuntimeDiskSpaceAvailable results when
// space and inodes are available.
// space is available.
func TestIsRuntimeDiskSpaceAvailableWithSpace(t *testing.T) {
assert, policy, mockCadvisor := setUp(t)
dm, err := newDiskSpaceManager(mockCadvisor, policy)
require.NoError(t, err)

// 500MB available
mockCadvisor.On("ImagesFsInfo").Return(cadvisorapi.FsInfo{
Usage: 9500 * mb,
Capacity: 10000 * mb,
Available: 500 * mb,
InodesFree: 10,
Usage: 9500 * mb,
Capacity: 10000 * mb,
Available: 500 * mb,
}, nil)

ok, err := dm.IsRuntimeDiskSpaceAvailable()
Expand All @@ -108,30 +105,9 @@ func TestIsRuntimeDiskSpaceAvailableWithoutSpace(t *testing.T) {
// 1MB available
assert, policy, mockCadvisor := setUp(t)
mockCadvisor.On("ImagesFsInfo").Return(cadvisorapi.FsInfo{
Usage: 999 * mb,
Capacity: 1000 * mb,
Available: 1 * mb,
InodesFree: 10,
}, nil)

dm, err := newDiskSpaceManager(mockCadvisor, policy)
require.NoError(t, err)

ok, err := dm.IsRuntimeDiskSpaceAvailable()
assert.NoError(err)
assert.False(ok)
}

// TestIsRuntimeDiskSpaceAvailableWithoutInode verifies IsRuntimeDiskSpaceAvailable results when
// inode is not available.
func TestIsRuntimeDiskSpaceAvailableWithoutInode(t *testing.T) {
// 1MB available
assert, policy, mockCadvisor := setUp(t)
mockCadvisor.On("ImagesFsInfo").Return(cadvisorapi.FsInfo{
Usage: 999 * mb,
Capacity: 1000 * mb,
Available: 500 * mb,
InodesFree: 0,
Usage: 999 * mb,
Capacity: 1000 * mb,
Available: 1 * mb,
}, nil)

dm, err := newDiskSpaceManager(mockCadvisor, policy)
Expand All @@ -143,7 +119,7 @@ func TestIsRuntimeDiskSpaceAvailableWithoutInode(t *testing.T) {
}

// TestIsRootDiskSpaceAvailableWithSpace verifies IsRootDiskSpaceAvailable results when
// space and inodes are available.
// space is available.
func TestIsRootDiskSpaceAvailableWithSpace(t *testing.T) {
assert, policy, mockCadvisor := setUp(t)
policy.RootFreeDiskMB = 10
Expand All @@ -152,10 +128,9 @@ func TestIsRootDiskSpaceAvailableWithSpace(t *testing.T) {

// 999MB available
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 1 * mb,
Capacity: 1000 * mb,
Available: 999 * mb,
InodesFree: 10,
Usage: 1 * mb,
Capacity: 1000 * mb,
Available: 999 * mb,
}, nil)

ok, err := dm.IsRootDiskSpaceAvailable()
Expand All @@ -173,31 +148,9 @@ func TestIsRootDiskSpaceAvailableWithoutSpace(t *testing.T) {

// 9MB available
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 990 * mb,
Capacity: 1000 * mb,
Available: 9 * mb,
InodesFree: 10,
}, nil)

ok, err := dm.IsRootDiskSpaceAvailable()
assert.NoError(err)
assert.False(ok)
}

// TestIsRootDiskSpaceAvailableWithoutInode verifies IsRootDiskSpaceAvailable results when
// inode is not available.
func TestIsRootDiskSpaceAvailableWithoutInode(t *testing.T) {
assert, policy, mockCadvisor := setUp(t)
policy.RootFreeDiskMB = 10
dm, err := newDiskSpaceManager(mockCadvisor, policy)
assert.NoError(err)

// 9MB available
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 990 * mb,
Capacity: 1000 * mb,
Available: 500 * mb,
InodesFree: 0,
Usage: 990 * mb,
Capacity: 1000 * mb,
Available: 9 * mb,
}, nil)

ok, err := dm.IsRootDiskSpaceAvailable()
Expand All @@ -212,16 +165,14 @@ func TestCache(t *testing.T) {
assert.NoError(err)

mockCadvisor.On("ImagesFsInfo").Return(cadvisorapi.FsInfo{
Usage: 400 * mb,
Capacity: 1000 * mb,
Available: 300 * mb,
InodesFree: 10,
Usage: 400 * mb,
Capacity: 1000 * mb,
Available: 300 * mb,
}, nil).Once()
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 500 * mb,
Capacity: 1000 * mb,
Available: 500 * mb,
InodesFree: 5,
Usage: 500 * mb,
Capacity: 1000 * mb,
Available: 500 * mb,
}, nil).Once()

// Initial calls which should be recorded in mockCadvisor
Expand Down Expand Up @@ -273,10 +224,9 @@ func Test_getFsInfo(t *testing.T) {

// Sunny day case
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 10 * mb,
Capacity: 100 * mb,
Available: 90 * mb,
InodesFree: 5,
Usage: 10 * mb,
Capacity: 100 * mb,
Available: 90 * mb,
}, nil).Once()

dm := &realDiskSpaceManager{
Expand All @@ -292,10 +242,9 @@ func Test_getFsInfo(t *testing.T) {
// Threshold case
mockCadvisor = new(cadvisortest.Mock)
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 9 * mb,
Capacity: 100 * mb,
Available: 9 * mb,
InodesFree: 5,
Usage: 9 * mb,
Capacity: 100 * mb,
Available: 9 * mb,
}, nil).Once()

dm = &realDiskSpaceManager{
Expand All @@ -309,10 +258,9 @@ func Test_getFsInfo(t *testing.T) {

// Frozen case
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 9 * mb,
Capacity: 10 * mb,
Available: 500 * mb,
InodesFree: 5,
Usage: 9 * mb,
Capacity: 10 * mb,
Available: 500 * mb,
}, nil).Once()

dm = &realDiskSpaceManager{
Expand All @@ -327,10 +275,9 @@ func Test_getFsInfo(t *testing.T) {
// Capacity error case
mockCadvisor = new(cadvisortest.Mock)
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
Usage: 9 * mb,
Capacity: 0,
Available: 500 * mb,
InodesFree: 5,
Usage: 9 * mb,
Capacity: 0,
Available: 500 * mb,
}, nil).Once()

dm = &realDiskSpaceManager{
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2695,8 +2695,8 @@ func TestValidateContainerLogStatus(t *testing.T) {
// sufficient disk space or it is out of disk, depending on the capacity, availability and
// threshold values.
func updateDiskSpacePolicy(kubelet *Kubelet, mockCadvisor *cadvisortest.Mock, rootCap, dockerCap, rootAvail, dockerAvail uint64, rootThreshold, dockerThreshold int) error {
dockerimagesFsInfo := cadvisorapiv2.FsInfo{Capacity: rootCap * mb, Available: rootAvail * mb, InodesFree: 5}
rootFsInfo := cadvisorapiv2.FsInfo{Capacity: dockerCap * mb, Available: dockerAvail * mb, InodesFree: 5}
dockerimagesFsInfo := cadvisorapiv2.FsInfo{Capacity: rootCap * mb, Available: rootAvail * mb}
rootFsInfo := cadvisorapiv2.FsInfo{Capacity: dockerCap * mb, Available: dockerAvail * mb}
mockCadvisor.On("ImagesFsInfo").Return(dockerimagesFsInfo, nil)
mockCadvisor.On("RootFsInfo").Return(rootFsInfo, nil)

Expand Down

0 comments on commit 52e8d4f

Please sign in to comment.