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
4845e524
Commit
4845e524
authored
Dec 08, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2667 from thockin/klet-dirs
Kubelet directory-name builder funcs
parents
c5667e1c
acc6b95c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
5 deletions
+79
-5
kubelet.go
pkg/kubelet/kubelet.go
+37
-1
kubelet_test.go
pkg/kubelet/kubelet_test.go
+42
-4
No files found.
pkg/kubelet/kubelet.go
View file @
4845e524
...
@@ -145,6 +145,42 @@ type Kubelet struct {
...
@@ -145,6 +145,42 @@ type Kubelet struct {
maxContainerCount
int
maxContainerCount
int
}
}
// GetRootDir returns the full path to the directory under which kubelet can
// store data. These functions are useful to pass interfaces to other modules
// that may need to know where to write data without getting a whole kubelet
// instance.
func
(
kl
*
Kubelet
)
GetRootDir
()
string
{
return
kl
.
rootDirectory
}
// 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
()
}
// 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
)
}
// GetPodVolumesDir returns the full path to the per-pod data directory under
// which volumes are created for the specified pod. This directory may not
// exist if the pod does not exist.
func
(
kl
*
Kubelet
)
GetPodVolumesDir
(
podUID
string
)
string
{
return
path
.
Join
(
kl
.
GetPodDir
(
podUID
),
"volumes"
)
}
// GetPodContainerDir returns the full path to the per-pod data directory under
// 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
)
}
type
ByCreated
[]
*
docker
.
Container
type
ByCreated
[]
*
docker
.
Container
func
(
a
ByCreated
)
Len
()
int
{
return
len
(
a
)
}
func
(
a
ByCreated
)
Len
()
int
{
return
len
(
a
)
}
...
@@ -477,7 +513,7 @@ func (kl *Kubelet) runContainer(pod *api.BoundPod, container *api.Container, pod
...
@@ -477,7 +513,7 @@ func (kl *Kubelet) runContainer(pod *api.BoundPod, container *api.Container, pod
}
}
if
len
(
container
.
TerminationMessagePath
)
!=
0
{
if
len
(
container
.
TerminationMessagePath
)
!=
0
{
p
:=
path
.
Join
(
kl
.
rootDirectory
,
pod
.
Name
,
container
.
Name
)
p
:=
kl
.
GetPodContainerDir
(
pod
.
UID
,
container
.
Name
)
if
err
:=
os
.
MkdirAll
(
p
,
0750
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
p
,
0750
);
err
!=
nil
{
glog
.
Errorf
(
"Error on creating %s: %v"
,
p
,
err
)
glog
.
Errorf
(
"Error on creating %s: %v"
,
p
,
err
)
}
else
{
}
else
{
...
...
pkg/kubelet/kubelet_test.go
View file @
4845e524
...
@@ -19,6 +19,8 @@ package kubelet
...
@@ -19,6 +19,8 @@ package kubelet
import
(
import
(
"fmt"
"fmt"
"net/http"
"net/http"
"os"
"path"
"reflect"
"reflect"
"regexp"
"regexp"
"strconv"
"strconv"
...
@@ -78,6 +80,40 @@ func verifyBoolean(t *testing.T, expected, value bool) {
...
@@ -78,6 +80,40 @@ func verifyBoolean(t *testing.T, expected, value bool) {
}
}
}
}
func
TestKubeletDirs
(
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
got
=
kubelet
.
GetPodsDir
()
exp
=
root
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodDir
(
"abc123"
)
exp
=
path
.
Join
(
root
,
"abc123"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodVolumesDir
(
"abc123"
)
exp
=
path
.
Join
(
root
,
"abc123/volumes"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
got
=
kubelet
.
GetPodContainerDir
(
"abc123"
,
"def456"
)
exp
=
path
.
Join
(
root
,
"abc123/def456"
)
if
got
!=
exp
{
t
.
Errorf
(
"expected %q', got %q"
,
exp
,
got
)
}
}
func
TestKillContainerWithError
(
t
*
testing
.
T
)
{
func
TestKillContainerWithError
(
t
*
testing
.
T
)
{
fakeDocker
:=
&
dockertools
.
FakeDockerClient
{
fakeDocker
:=
&
dockertools
.
FakeDockerClient
{
Err
:
fmt
.
Errorf
(
"sample error"
),
Err
:
fmt
.
Errorf
(
"sample error"
),
...
@@ -196,6 +232,7 @@ func TestSyncPodsWithTerminationLog(t *testing.T) {
...
@@ -196,6 +232,7 @@ func TestSyncPodsWithTerminationLog(t *testing.T) {
err
:=
kubelet
.
SyncPods
([]
api
.
BoundPod
{
err
:=
kubelet
.
SyncPods
([]
api
.
BoundPod
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"0123-45-67-89ab-cdef"
,
Name
:
"foo"
,
Name
:
"foo"
,
Namespace
:
"new"
,
Namespace
:
"new"
,
Annotations
:
map
[
string
]
string
{
ConfigSourceAnnotationKey
:
"test"
},
Annotations
:
map
[
string
]
string
{
ConfigSourceAnnotationKey
:
"test"
},
...
@@ -216,10 +253,11 @@ func TestSyncPodsWithTerminationLog(t *testing.T) {
...
@@ -216,10 +253,11 @@ func TestSyncPodsWithTerminationLog(t *testing.T) {
fakeDocker
.
Lock
()
fakeDocker
.
Lock
()
parts
:=
strings
.
Split
(
fakeDocker
.
Container
.
HostConfig
.
Binds
[
0
],
":"
)
parts
:=
strings
.
Split
(
fakeDocker
.
Container
.
HostConfig
.
Binds
[
0
],
":"
)
if
fakeDocker
.
Container
.
HostConfig
==
nil
||
if
!
matchString
(
t
,
kubelet
.
GetPodContainerDir
(
"0123-45-67-89ab-cdef"
,
"bar"
)
+
"/k8s_bar
\\
.[a-f0-9]"
,
parts
[
0
])
{
!
matchString
(
t
,
"/tmp/kubelet/foo/bar/k8s_bar
\\
.[a-f0-9]"
,
parts
[
0
])
||
t
.
Errorf
(
"Unexpected host path: %s"
,
parts
[
0
])
parts
[
1
]
!=
"/dev/somepath"
{
}
t
.
Errorf
(
"Unexpected containers created %v"
,
fakeDocker
.
Container
)
if
parts
[
1
]
!=
"/dev/somepath"
{
t
.
Errorf
(
"Unexpected container path: %s"
,
parts
[
1
])
}
}
fakeDocker
.
Unlock
()
fakeDocker
.
Unlock
()
}
}
...
...
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