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
fbe89176
Unverified
Commit
fbe89176
authored
Dec 09, 2020
by
Chris Kim
Committed by
GitHub
Dec 09, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2668 from Oats87/issues/k3s/2548-mst-suppl2
Set kubelet-cgroups if we detect we are running under a `.scope`
parents
c5aad1b5
61ef2ce9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
11 deletions
+29
-11
agent.go
pkg/daemons/agent/agent.go
+29
-11
No files found.
pkg/daemons/agent/agent.go
View file @
fbe89176
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"github.com/opencontainers/runc/libcontainer/system"
"github.com/opencontainers/runc/libcontainer/system"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/daemons/executor"
"github.com/rancher/k3s/pkg/daemons/executor"
"github.com/rancher/k3s/pkg/version"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/component-base/logs"
"k8s.io/component-base/logs"
...
@@ -120,7 +121,7 @@ func startKubelet(cfg *config.Agent) error {
...
@@ -120,7 +121,7 @@ func startKubelet(cfg *config.Agent) error {
if
err
!=
nil
||
defaultIP
.
String
()
!=
cfg
.
NodeIP
{
if
err
!=
nil
||
defaultIP
.
String
()
!=
cfg
.
NodeIP
{
argsMap
[
"node-ip"
]
=
cfg
.
NodeIP
argsMap
[
"node-ip"
]
=
cfg
.
NodeIP
}
}
r
oot
,
hasCFS
,
hasPIDs
:=
checkCgroups
()
kubeletRoot
,
runtimeR
oot
,
hasCFS
,
hasPIDs
:=
checkCgroups
()
if
!
hasCFS
{
if
!
hasCFS
{
logrus
.
Warn
(
"Disabling CPU quotas due to missing cpu.cfs_period_us"
)
logrus
.
Warn
(
"Disabling CPU quotas due to missing cpu.cfs_period_us"
)
argsMap
[
"cpu-cfs-quota"
]
=
"false"
argsMap
[
"cpu-cfs-quota"
]
=
"false"
...
@@ -131,9 +132,11 @@ func startKubelet(cfg *config.Agent) error {
...
@@ -131,9 +132,11 @@ func startKubelet(cfg *config.Agent) error {
argsMap
[
"enforce-node-allocatable"
]
=
""
argsMap
[
"enforce-node-allocatable"
]
=
""
argsMap
[
"feature-gates"
]
=
addFeatureGate
(
argsMap
[
"feature-gates"
],
"SupportPodPidsLimit=false"
)
argsMap
[
"feature-gates"
]
=
addFeatureGate
(
argsMap
[
"feature-gates"
],
"SupportPodPidsLimit=false"
)
}
}
if
root
!=
""
{
if
kubeletRoot
!=
""
{
argsMap
[
"runtime-cgroups"
]
=
root
argsMap
[
"kubelet-cgroups"
]
=
kubeletRoot
argsMap
[
"kubelet-cgroups"
]
=
root
}
if
runtimeRoot
!=
""
{
argsMap
[
"runtime-cgroups"
]
=
runtimeRoot
}
}
if
system
.
RunningInUserNS
()
{
if
system
.
RunningInUserNS
()
{
argsMap
[
"feature-gates"
]
=
addFeatureGate
(
argsMap
[
"feature-gates"
],
"DevicePlugins=false"
)
argsMap
[
"feature-gates"
]
=
addFeatureGate
(
argsMap
[
"feature-gates"
],
"DevicePlugins=false"
)
...
@@ -172,10 +175,10 @@ func addFeatureGate(current, new string) string {
...
@@ -172,10 +175,10 @@ func addFeatureGate(current, new string) string {
return
current
+
","
+
new
return
current
+
","
+
new
}
}
func
checkCgroups
()
(
root
string
,
hasCFS
bool
,
hasPIDs
bool
)
{
func
checkCgroups
()
(
kubeletRoot
,
runtimeRoot
string
,
hasCFS
,
hasPIDs
bool
)
{
f
,
err
:=
os
.
Open
(
"/proc/self/cgroup"
)
f
,
err
:=
os
.
Open
(
"/proc/self/cgroup"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
false
,
false
return
""
,
""
,
false
,
false
}
}
defer
f
.
Close
()
defer
f
.
Close
()
...
@@ -194,10 +197,25 @@ func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
...
@@ -194,10 +197,25 @@ func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
if
_
,
err
:=
os
.
Stat
(
p
);
err
==
nil
{
if
_
,
err
:=
os
.
Stat
(
p
);
err
==
nil
{
hasCFS
=
true
hasCFS
=
true
}
}
}
else
if
system
==
"name=systemd"
{
// If we detect that we are running under a `.scope` unit with systemd
// we can assume we are being directly invoked from the command line
// and thus need to set our kubelet root to something out of the context
// of `/user.slice` to ensure that `CPUAccounting` and `MemoryAccounting`
// are enabled, as they are generally disabled by default for `user.slice`
// Note that we are not setting the `runtimeRoot` as if we are running with
// `--docker`, we will inadvertently move the cgroup `dockerd` lives in
// which is not ideal and causes dockerd to become unmanageable by systemd.
last
:=
parts
[
len
(
parts
)
-
1
]
i
:=
strings
.
LastIndex
(
last
,
".scope"
)
if
i
>
0
{
kubeletRoot
=
"/"
+
version
.
Program
}
}
}
}
}
}
}
if
kubeletRoot
==
""
{
// Examine process ID 1 to see if there is a cgroup assigned to it.
// Examine process ID 1 to see if there is a cgroup assigned to it.
// When we are not in a container, process 1 is likely to be systemd or some other service manager.
// When we are not in a container, process 1 is likely to be systemd or some other service manager.
// It either lives at `/` or `/init.scope` according to https://man7.org/linux/man-pages/man7/systemd.special.7.html
// It either lives at `/` or `/init.scope` according to https://man7.org/linux/man-pages/man7/systemd.special.7.html
...
@@ -205,10 +223,9 @@ func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
...
@@ -205,10 +223,9 @@ func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
// a host PID scenario but we don't support this.
// a host PID scenario but we don't support this.
g
,
err
:=
os
.
Open
(
"/proc/1/cgroup"
)
g
,
err
:=
os
.
Open
(
"/proc/1/cgroup"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
false
,
false
return
""
,
""
,
false
,
false
}
}
defer
g
.
Close
()
defer
g
.
Close
()
root
=
""
scan
=
bufio
.
NewScanner
(
g
)
scan
=
bufio
.
NewScanner
(
g
)
for
scan
.
Scan
()
{
for
scan
.
Scan
()
{
parts
:=
strings
.
Split
(
scan
.
Text
(),
":"
)
parts
:=
strings
.
Split
(
scan
.
Text
(),
":"
)
...
@@ -220,11 +237,12 @@ func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
...
@@ -220,11 +237,12 @@ func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
if
system
==
"name=systemd"
{
if
system
==
"name=systemd"
{
last
:=
parts
[
len
(
parts
)
-
1
]
last
:=
parts
[
len
(
parts
)
-
1
]
if
last
!=
"/"
&&
last
!=
"/init.scope"
{
if
last
!=
"/"
&&
last
!=
"/init.scope"
{
root
=
"/systemd"
kubeletRoot
=
"/"
+
version
.
Program
runtimeRoot
=
"/"
+
version
.
Program
}
}
}
}
}
}
}
}
}
return
r
oot
,
hasCFS
,
hasPIDs
return
kubeletRoot
,
runtimeR
oot
,
hasCFS
,
hasPIDs
}
}
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