mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 01:23:48 +00:00
Fix an issue when rotated logs of dead containers are not removed.
This commit is contained in:
@@ -38,6 +38,9 @@ type OSInterface interface {
|
||||
Pipe() (r *os.File, w *os.File, err error)
|
||||
ReadDir(dirname string) ([]os.FileInfo, error)
|
||||
Glob(pattern string) ([]string, error)
|
||||
Open(name string) (*os.File, error)
|
||||
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
|
||||
Rename(oldpath, newpath string) error
|
||||
}
|
||||
|
||||
// RealOS is used to dispatch the real system level operations.
|
||||
@@ -105,3 +108,18 @@ func (RealOS) ReadDir(dirname string) ([]os.FileInfo, error) {
|
||||
func (RealOS) Glob(pattern string) ([]string, error) {
|
||||
return filepath.Glob(pattern)
|
||||
}
|
||||
|
||||
// Open will call os.Open to return the file.
|
||||
func (RealOS) Open(name string) (*os.File, error) {
|
||||
return os.Open(name)
|
||||
}
|
||||
|
||||
// OpenFile will call os.OpenFile to return the file.
|
||||
func (RealOS) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
|
||||
return os.OpenFile(name, flag, perm)
|
||||
}
|
||||
|
||||
// Rename will call os.Rename to rename a file.
|
||||
func (RealOS) Rename(oldpath, newpath string) error {
|
||||
return os.Rename(oldpath, newpath)
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ type FakeOS struct {
|
||||
ReadDirFn func(string) ([]os.FileInfo, error)
|
||||
MkdirAllFn func(string, os.FileMode) error
|
||||
SymlinkFn func(string, string) error
|
||||
GlobFn func(string, string) bool
|
||||
HostName string
|
||||
Removes []string
|
||||
Files map[string][]*os.FileInfo
|
||||
@@ -78,8 +79,12 @@ func (f *FakeOS) RemoveAll(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create is a fake call that returns nil.
|
||||
func (FakeOS) Create(path string) (*os.File, error) {
|
||||
// Create is a fake call that creates a virtual file and returns nil.
|
||||
func (f *FakeOS) Create(path string) (*os.File, error) {
|
||||
if f.Files == nil {
|
||||
f.Files = make(map[string][]*os.FileInfo)
|
||||
}
|
||||
f.Files[path] = []*os.FileInfo{}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -111,7 +116,31 @@ func (f *FakeOS) ReadDir(dirname string) ([]os.FileInfo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Glob is a fake call that returns nil.
|
||||
// Glob is a fake call that returns list of virtual files matching a pattern.
|
||||
func (f *FakeOS) Glob(pattern string) ([]string, error) {
|
||||
if f.GlobFn != nil {
|
||||
var res []string
|
||||
for k := range f.Files {
|
||||
if f.GlobFn(pattern, k) {
|
||||
res = append(res, k)
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Open is a fake call that returns nil.
|
||||
func (FakeOS) Open(name string) (*os.File, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// OpenFile is a fake call that return nil.
|
||||
func (FakeOS) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Rename is a fake call that return nil.
|
||||
func (FakeOS) Rename(oldpath, newpath string) error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user