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
af0e2fd5
Commit
af0e2fd5
authored
Jan 12, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3403 from thockin/klet-dirs-structure
Apply more structure to pod data dirs
parents
b3d827e3
523a80be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
9 deletions
+139
-9
kubelet.go
pkg/kubelet/kubelet.go
+43
-5
kubelet_test.go
pkg/kubelet/kubelet_test.go
+96
-4
No files found.
pkg/kubelet/kubelet.go
View file @
af0e2fd5
...
...
@@ -170,16 +170,30 @@ func (kl *Kubelet) GetRootDir() string {
// GetPodsDir returns the full path to the directory under which pod
// directories are created.
// TODO(thockin): For now, this is the same as the root because that is assumed
// in other code. Will fix.
func
(
kl
*
Kubelet
)
GetPodsDir
()
string
{
return
kl
.
GetRootDir
(
)
return
path
.
Join
(
kl
.
GetRootDir
(),
"pods"
)
}
// GetPodDir returns the full path to the per-pod data directory for the
// specified pod. This directory may not exist if the pod does not exist.
func
(
kl
*
Kubelet
)
GetPodDir
(
podUID
string
)
string
{
return
path
.
Join
(
kl
.
GetRootDir
(),
podUID
)
// Backwards compat. The "old" stuff should be removed before 1.0
// release. The thinking here is this:
// !old && !new = use new
// !old && new = use new
// old && !new = use old
// old && new = use new (but warn)
oldPath
:=
path
.
Join
(
kl
.
GetRootDir
(),
podUID
)
oldExists
:=
dirExists
(
oldPath
)
newPath
:=
path
.
Join
(
kl
.
GetPodsDir
(),
podUID
)
newExists
:=
dirExists
(
newPath
)
if
oldExists
&&
!
newExists
{
return
oldPath
}
if
oldExists
{
glog
.
Warningf
(
"Data dir for pod %q exists in both old and new form, using new"
,
podUID
)
}
return
newPath
}
// GetPodVolumesDir returns the full path to the per-pod data directory under
...
...
@@ -193,7 +207,31 @@ func (kl *Kubelet) GetPodVolumesDir(podUID string) string {
// which container data is held for the specified pod. This directory may not
// exist if the pod or container does not exist.
func
(
kl
*
Kubelet
)
GetPodContainerDir
(
podUID
,
ctrName
string
)
string
{
return
path
.
Join
(
kl
.
GetPodDir
(
podUID
),
ctrName
)
// Backwards compat. The "old" stuff should be removed before 1.0
// release. The thinking here is this:
// !old && !new = use new
// !old && new = use new
// old && !new = use old
// old && new = use new (but warn)
oldPath
:=
path
.
Join
(
kl
.
GetPodDir
(
podUID
),
ctrName
)
oldExists
:=
dirExists
(
oldPath
)
newPath
:=
path
.
Join
(
kl
.
GetPodDir
(
podUID
),
"containers"
,
ctrName
)
newExists
:=
dirExists
(
newPath
)
if
oldExists
&&
!
newExists
{
return
oldPath
}
if
oldExists
{
glog
.
Warningf
(
"Data dir for pod %q, container %q exists in both old and new form, using new"
,
podUID
,
ctrName
)
}
return
newPath
}
func
dirExists
(
path
string
)
bool
{
s
,
err
:=
os
.
Stat
(
path
)
if
err
!=
nil
{
return
false
}
return
s
.
IsDir
()
}
type
ByCreated
[]
*
docker
.
Container
...
...
pkg/kubelet/kubelet_test.go
View file @
af0e2fd5
...
...
@@ -98,25 +98,117 @@ func TestKubeletDirs(t *testing.T) {
var
exp
,
got
string
got
=
kubelet
.
GetPodsDir
()
exp
=
root
exp
=
path
.
Join
(
root
,
"pods"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodDir
(
"abc123"
)
exp
=
path
.
Join
(
root
,
"abc123"
)
exp
=
path
.
Join
(
root
,
"
pods/
abc123"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodVolumesDir
(
"abc123"
)
exp
=
path
.
Join
(
root
,
"abc123/volumes"
)
exp
=
path
.
Join
(
root
,
"
pods/
abc123/volumes"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodContainerDir
(
"abc123"
,
"def456"
)
exp
=
path
.
Join
(
root
,
"abc123/def456"
)
exp
=
path
.
Join
(
root
,
"pods/abc123/containers/def456"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
}
func
TestKubeletDirsCompat
(
t
*
testing
.
T
)
{
kubelet
,
_
,
_
:=
newTestKubelet
(
t
)
root
:=
kubelet
.
rootDirectory
if
err
:=
os
.
MkdirAll
(
root
,
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
var
exp
,
got
string
// Old-style pod dir.
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/oldpod"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
// New-style pod dir.
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/pods/newpod"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
// Both-style pod dir.
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/bothpod"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/pods/bothpod"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
got
=
kubelet
.
GetPodDir
(
"oldpod"
)
exp
=
path
.
Join
(
root
,
"oldpod"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodDir
(
"newpod"
)
exp
=
path
.
Join
(
root
,
"pods/newpod"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodDir
(
"bothpod"
)
exp
=
path
.
Join
(
root
,
"pods/bothpod"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodDir
(
"neitherpod"
)
exp
=
path
.
Join
(
root
,
"pods/neitherpod"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
root
=
kubelet
.
GetPodDir
(
"newpod"
)
// Old-style container dir.
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/oldctr"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
// New-style container dir.
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/containers/newctr"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
// Both-style container dir.
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/bothctr"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
if
err
:=
os
.
MkdirAll
(
fmt
.
Sprintf
(
"%s/containers/bothctr"
,
root
),
0750
);
err
!=
nil
{
t
.
Fatalf
(
"can't mkdir(%q): %s"
,
root
,
err
)
}
got
=
kubelet
.
GetPodContainerDir
(
"newpod"
,
"oldctr"
)
exp
=
path
.
Join
(
root
,
"oldctr"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodContainerDir
(
"newpod"
,
"newctr"
)
exp
=
path
.
Join
(
root
,
"containers/newctr"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodContainerDir
(
"newpod"
,
"bothctr"
)
exp
=
path
.
Join
(
root
,
"containers/bothctr"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodContainerDir
(
"newpod"
,
"neitherctr"
)
exp
=
path
.
Join
(
root
,
"containers/neitherctr"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
...
...
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