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
8bc6e592
Commit
8bc6e592
authored
May 12, 2017
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kuberuntime: set sysctls for sandbox config
parent
a7c9638e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
5 deletions
+75
-5
BUILD
pkg/kubelet/kuberuntime/BUILD
+1
-0
helpers.go
pkg/kubelet/kuberuntime/helpers.go
+19
-0
helpers_test.go
pkg/kubelet/kuberuntime/helpers_test.go
+40
-0
kuberuntime_sandbox.go
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
+15
-5
No files found.
pkg/kubelet/kuberuntime/BUILD
View file @
8bc6e592
...
...
@@ -29,6 +29,7 @@ go_library(
deps = [
"//pkg/api:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/api/v1/helper:go_default_library",
"//pkg/api/v1/ref:go_default_library",
"//pkg/credentialprovider:go_default_library",
"//pkg/kubelet/apis/cri:go_default_library",
...
...
pkg/kubelet/kuberuntime/helpers.go
View file @
8bc6e592
...
...
@@ -24,6 +24,7 @@ import (
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api/v1"
v1helper
"k8s.io/kubernetes/pkg/api/v1/helper"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
)
...
...
@@ -236,3 +237,21 @@ func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus) *kubecontainer.Runtim
}
return
&
kubecontainer
.
RuntimeStatus
{
Conditions
:
conditions
}
}
// getSysctlsFromAnnotations gets sysctls and unsafeSysctls from annotations.
func
getSysctlsFromAnnotations
(
annotations
map
[
string
]
string
)
(
map
[
string
]
string
,
error
)
{
apiSysctls
,
apiUnsafeSysctls
,
err
:=
v1helper
.
SysctlsFromPodAnnotations
(
annotations
)
if
err
!=
nil
{
return
nil
,
err
}
sysctls
:=
make
(
map
[
string
]
string
)
for
_
,
c
:=
range
apiSysctls
{
sysctls
[
c
.
Name
]
=
c
.
Value
}
for
_
,
c
:=
range
apiUnsafeSysctls
{
sysctls
[
c
.
Name
]
=
c
.
Value
}
return
sysctls
,
nil
}
pkg/kubelet/kuberuntime/helpers_test.go
View file @
8bc6e592
...
...
@@ -46,3 +46,43 @@ func TestStableKey(t *testing.T) {
newKey
:=
getStableKey
(
pod
,
container
)
assert
.
NotEqual
(
t
,
oldKey
,
newKey
)
}
// TestGetSystclsFromAnnotations tests the logic of getting sysctls from annotations.
func
TestGetSystclsFromAnnotations
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
annotations
map
[
string
]
string
expectedSysctls
map
[
string
]
string
}{{
annotations
:
map
[
string
]
string
{
v1
.
SysctlsPodAnnotationKey
:
"kernel.shmmni=32768,kernel.shmmax=1000000000"
,
v1
.
UnsafeSysctlsPodAnnotationKey
:
"knet.ipv4.route.min_pmtu=1000"
,
},
expectedSysctls
:
map
[
string
]
string
{
"kernel.shmmni"
:
"32768"
,
"kernel.shmmax"
:
"1000000000"
,
"knet.ipv4.route.min_pmtu"
:
"1000"
,
},
},
{
annotations
:
map
[
string
]
string
{
v1
.
SysctlsPodAnnotationKey
:
"kernel.shmmni=32768,kernel.shmmax=1000000000"
,
},
expectedSysctls
:
map
[
string
]
string
{
"kernel.shmmni"
:
"32768"
,
"kernel.shmmax"
:
"1000000000"
,
},
},
{
annotations
:
map
[
string
]
string
{
v1
.
UnsafeSysctlsPodAnnotationKey
:
"knet.ipv4.route.min_pmtu=1000"
,
},
expectedSysctls
:
map
[
string
]
string
{
"knet.ipv4.route.min_pmtu"
:
"1000"
,
},
}}
for
i
,
test
:=
range
tests
{
actualSysctls
,
err
:=
getSysctlsFromAnnotations
(
test
.
annotations
)
assert
.
NoError
(
t
,
err
,
"TestCase[%d]"
,
i
)
assert
.
Len
(
t
,
actualSysctls
,
len
(
test
.
expectedSysctls
),
"TestCase[%d]"
,
i
)
assert
.
Equal
(
t
,
test
.
expectedSysctls
,
actualSysctls
,
"TestCase[%d]"
,
i
)
}
}
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
View file @
8bc6e592
...
...
@@ -116,18 +116,22 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
}
}
cgroupParent
:=
m
.
runtimeHelper
.
GetPodCgroupParent
(
pod
)
podSandboxConfig
.
Linux
=
m
.
generatePodSandboxLinuxConfig
(
pod
,
cgroupParent
)
if
len
(
portMappings
)
>
0
{
podSandboxConfig
.
PortMappings
=
portMappings
}
lc
,
err
:=
m
.
generatePodSandboxLinuxConfig
(
pod
)
if
err
!=
nil
{
return
nil
,
err
}
podSandboxConfig
.
Linux
=
lc
return
podSandboxConfig
,
nil
}
// generatePodSandboxLinuxConfig generates LinuxPodSandboxConfig from v1.Pod.
func
(
m
*
kubeGenericRuntimeManager
)
generatePodSandboxLinuxConfig
(
pod
*
v1
.
Pod
,
cgroupParent
string
)
*
runtimeapi
.
LinuxPodSandboxConfig
{
func
(
m
*
kubeGenericRuntimeManager
)
generatePodSandboxLinuxConfig
(
pod
*
v1
.
Pod
)
(
*
runtimeapi
.
LinuxPodSandboxConfig
,
error
)
{
cgroupParent
:=
m
.
runtimeHelper
.
GetPodCgroupParent
(
pod
)
lc
:=
&
runtimeapi
.
LinuxPodSandboxConfig
{
CgroupParent
:
cgroupParent
,
SecurityContext
:
&
runtimeapi
.
LinuxSandboxSecurityContext
{
...
...
@@ -135,6 +139,12 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxLinuxConfig(pod *v1.Pod, c
},
}
sysctls
,
err
:=
getSysctlsFromAnnotations
(
pod
.
Annotations
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get sysctls from annotations %v for pod %q: %v"
,
pod
.
Annotations
,
format
.
Pod
(
pod
),
err
)
}
lc
.
Sysctls
=
sysctls
if
pod
.
Spec
.
SecurityContext
!=
nil
{
sc
:=
pod
.
Spec
.
SecurityContext
if
sc
.
RunAsUser
!=
nil
{
...
...
@@ -167,7 +177,7 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxLinuxConfig(pod *v1.Pod, c
}
}
return
lc
return
lc
,
nil
}
// getKubeletSandboxes lists all (or just the running) sandboxes managed by kubelet.
...
...
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