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
1b7f028e
Commit
1b7f028e
authored
Nov 14, 2017
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If mountPath is missing, prefix with root dir.
parent
c3ed0f26
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
3 deletions
+66
-3
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+20
-3
kubelet_pods_test.go
pkg/kubelet/kubelet_pods_test.go
+46
-0
No files found.
pkg/kubelet/kubelet_pods.go
View file @
1b7f028e
...
@@ -111,6 +111,23 @@ func (kl *Kubelet) makeDevices(pod *v1.Pod, container *v1.Container) ([]kubecont
...
@@ -111,6 +111,23 @@ func (kl *Kubelet) makeDevices(pod *v1.Pod, container *v1.Container) ([]kubecont
return
devices
,
nil
return
devices
,
nil
}
}
func
makeAbsolutePath
(
goos
,
path
string
)
string
{
if
goos
!=
"windows"
{
return
"/"
+
path
}
// These are all for windows
// If there is a colon, give up.
if
strings
.
Contains
(
path
,
":"
)
{
return
path
}
// If there is a slash, but no drive, add 'c:'
if
strings
.
HasPrefix
(
path
,
"/"
)
||
strings
.
HasPrefix
(
path
,
"
\\
"
)
{
return
"c:"
+
path
}
// Otherwise, add 'c:\'
return
"c:
\\
"
+
path
}
// makeMounts determines the mount points for the given container.
// makeMounts determines the mount points for the given container.
func
makeMounts
(
pod
*
v1
.
Pod
,
podDir
string
,
container
*
v1
.
Container
,
hostName
,
hostDomain
,
podIP
string
,
podVolumes
kubecontainer
.
VolumeMap
)
([]
kubecontainer
.
Mount
,
error
)
{
func
makeMounts
(
pod
*
v1
.
Pod
,
podDir
string
,
container
*
v1
.
Container
,
hostName
,
hostDomain
,
podIP
string
,
podVolumes
kubecontainer
.
VolumeMap
)
([]
kubecontainer
.
Mount
,
error
)
{
// Kubernetes only mounts on /etc/hosts if:
// Kubernetes only mounts on /etc/hosts if:
...
@@ -187,9 +204,9 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
...
@@ -187,9 +204,9 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
if
(
strings
.
HasPrefix
(
hostPath
,
"/"
)
||
strings
.
HasPrefix
(
hostPath
,
"
\\
"
))
&&
!
strings
.
Contains
(
hostPath
,
":"
)
{
if
(
strings
.
HasPrefix
(
hostPath
,
"/"
)
||
strings
.
HasPrefix
(
hostPath
,
"
\\
"
))
&&
!
strings
.
Contains
(
hostPath
,
":"
)
{
hostPath
=
"c:"
+
hostPath
hostPath
=
"c:"
+
hostPath
}
}
if
(
strings
.
HasPrefix
(
containerPath
,
"/"
)
||
strings
.
HasPrefix
(
containerPath
,
"
\\
"
))
&&
!
strings
.
Contains
(
containerPath
,
":"
)
{
}
containerPath
=
"c:"
+
containerPath
if
!
filepath
.
IsAbs
(
containerPath
)
{
}
containerPath
=
makeAbsolutePath
(
runtime
.
GOOS
,
containerPath
)
}
}
propagation
,
err
:=
translateMountPropagation
(
mount
.
MountPropagation
)
propagation
,
err
:=
translateMountPropagation
(
mount
.
MountPropagation
)
...
...
pkg/kubelet/kubelet_pods_test.go
View file @
1b7f028e
...
@@ -49,6 +49,52 @@ import (
...
@@ -49,6 +49,52 @@ import (
"k8s.io/kubernetes/pkg/kubelet/server/remotecommand"
"k8s.io/kubernetes/pkg/kubelet/server/remotecommand"
)
)
func
TestMakeAbsolutePath
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
goos
string
path
string
expectedPath
string
name
string
}{
{
goos
:
"linux"
,
path
:
"non-absolute/path"
,
expectedPath
:
"/non-absolute/path"
,
name
:
"basic linux"
,
},
{
goos
:
"windows"
,
path
:
"some
\\
path"
,
expectedPath
:
"c:
\\
some
\\
path"
,
name
:
"basic windows"
,
},
{
goos
:
"windows"
,
path
:
"/some/path"
,
expectedPath
:
"c:/some/path"
,
name
:
"linux path on windows"
,
},
{
goos
:
"windows"
,
path
:
"
\\
some
\\
path"
,
expectedPath
:
"c:
\\
some
\\
path"
,
name
:
"windows path no drive"
,
},
{
goos
:
"windows"
,
path
:
"
\\
:
\\
some
\\
path"
,
expectedPath
:
"
\\
:
\\
some
\\
path"
,
name
:
"windows path with colon"
,
},
}
for
_
,
test
:=
range
tests
{
path
:=
makeAbsolutePath
(
test
.
goos
,
test
.
path
)
if
path
!=
test
.
expectedPath
{
t
.
Errorf
(
"[%s] Expected %s saw %s"
,
test
.
name
,
test
.
expectedPath
,
path
)
}
}
}
func
TestMakeMounts
(
t
*
testing
.
T
)
{
func
TestMakeMounts
(
t
*
testing
.
T
)
{
bTrue
:=
true
bTrue
:=
true
propagationHostToContainer
:=
v1
.
MountPropagationHostToContainer
propagationHostToContainer
:=
v1
.
MountPropagationHostToContainer
...
...
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