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
dcfff45a
Commit
dcfff45a
authored
Jul 06, 2016
by
Buddha Prakash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add checks in Create and Update Cgroup methods
parent
c0b67b62
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
67 deletions
+106
-67
cgroup_manager_linux.go
pkg/kubelet/cm/cgroup_manager_linux.go
+100
-27
cgroup_manager_unsupported.go
pkg/kubelet/cm/cgroup_manager_unsupported.go
+4
-0
helpers_linux.go
pkg/kubelet/cm/helpers_linux.go
+0
-40
types.go
pkg/kubelet/cm/types.go
+2
-0
No files found.
pkg/kubelet/cm/cgroup_manager_linux.go
View file @
dcfff45a
...
...
@@ -18,7 +18,10 @@ package cm
import
(
"fmt"
"path"
libcontainercgroups
"github.com/opencontainers/runc/libcontainer/cgroups"
cgroupfs
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
libcontainerconfigs
"github.com/opencontainers/runc/libcontainer/configs"
)
...
...
@@ -42,17 +45,46 @@ func NewCgroupManager(cs *cgroupSubsystems) CgroupManager {
}
}
// Exists checks if all subsystem cgroups already exist
func
(
m
*
cgroupManagerImpl
)
Exists
(
name
string
)
bool
{
// Get map of all cgroup paths on the system for the particular cgroup
cgroupPaths
:=
make
(
map
[
string
]
string
,
len
(
m
.
subsystems
.
mountPoints
))
for
key
,
val
:=
range
m
.
subsystems
.
mountPoints
{
cgroupPaths
[
key
]
=
path
.
Join
(
val
,
name
)
}
// If even one cgroup doesn't exist we go on to create it
// @TODO(dubstack) We skip check for systemd until we update
// libcontainer in vendor
for
key
,
path
:=
range
cgroupPaths
{
if
key
!=
"systemd"
&&
!
libcontainercgroups
.
PathExists
(
path
)
{
return
false
}
}
return
true
}
// Destroy destroys the specified cgroup
func
(
m
*
cgroupManagerImpl
)
Destroy
(
cgroupConfig
*
CgroupConfig
)
error
{
//cgroup name
name
:=
cgroupConfig
.
Name
// get the fscgroup Manager with the specified cgroup configuration
fsCgroupManager
,
err
:=
getLibcontainerCgroupManager
(
cgroupConfig
,
m
.
subsystems
)
// Get map of all cgroup paths on the system for the particular cgroup
cgroupPaths
:=
make
(
map
[
string
]
string
,
len
(
m
.
subsystems
.
mountPoints
))
for
key
,
val
:=
range
m
.
subsystems
.
mountPoints
{
cgroupPaths
[
key
]
=
path
.
Join
(
val
,
name
)
}
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to destroy cgroup paths for cgroup %v : %v"
,
name
,
err
)
// Initialize libcontainer's cgroup config
libcontainerCgroupConfig
:=
&
libcontainerconfigs
.
Cgroup
{
Name
:
path
.
Base
(
name
),
Parent
:
path
.
Dir
(
name
),
}
fsCgroupManager
:=
cgroupfs
.
Manager
{
Cgroups
:
libcontainerCgroupConfig
,
Paths
:
cgroupPaths
,
}
// Delete cgroups using libcontainers Managers Destroy() method
if
err
:=
fsCgroupManager
.
Destroy
();
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to destroy cgroup paths for cgroup %v : %v"
,
name
,
err
)
...
...
@@ -60,41 +92,86 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error {
return
nil
}
type
subsystem
interface
{
// Name returns the name of the subsystem.
Name
()
string
// Set the cgroup represented by cgroup.
Set
(
path
string
,
cgroup
*
libcontainerconfigs
.
Cgroup
)
error
}
// Cgroup subsystems we currently support
var
supportedSubsystems
[]
subsystem
=
[]
subsystem
{
&
cgroupfs
.
MemoryGroup
{},
&
cgroupfs
.
CpuGroup
{},
}
// setSupportedSubsytems sets cgroup resource limits only on the supported
// subsytems. ie. cpu and memory. We don't use libcontainer's cgroup/fs/Set()
// method as it dosn't allow us to skip updates on the devices cgroup
// Allowing or denying all devices by writing 'a' to devices.allow or devices.deny is
// not possible once the device cgroups has children. Once the pod level cgroup are
// created under the QOS level cgroup we cannot update the QOS level device cgroup.
// We would like to skip setting any values on the device cgroup in this case
// but this is not possible with libcontainers Set() method
// See https://github.com/opencontainers/runc/issues/932
func
setSupportedSubsytems
(
cgroupConfig
*
libcontainerconfigs
.
Cgroup
)
error
{
for
_
,
sys
:=
range
supportedSubsystems
{
if
_
,
ok
:=
cgroupConfig
.
Paths
[
sys
.
Name
()];
!
ok
{
return
fmt
.
Errorf
(
"Failed to find subsytem mount for subsytem"
)
}
if
err
:=
sys
.
Set
(
cgroupConfig
.
Paths
[
sys
.
Name
()],
cgroupConfig
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to set config for supported subsystems : %v"
,
err
)
}
}
return
nil
}
// Update updates the cgroup with the specified Cgroup Configuration
func
(
m
*
cgroupManagerImpl
)
Update
(
cgroupConfig
*
CgroupConfig
)
error
{
//cgroup name
name
:=
cgroupConfig
.
Name
// get the fscgroup Manager with the specified cgroup configuration
fsCgroupManager
,
err
:=
getLibcontainerCgroupManager
(
cgroupConfig
,
m
.
subsystems
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to update cgroup for %v : %v"
,
name
,
err
)
// Extract the cgroup resource parameters
resourceConfig
:=
cgroupConfig
.
ResourceParameters
resources
:=
&
libcontainerconfigs
.
Resources
{}
if
resourceConfig
.
Memory
!=
nil
{
resources
.
Memory
=
*
resourceConfig
.
Memory
}
if
resourceConfig
.
CpuShares
!=
nil
{
resources
.
CpuShares
=
*
resourceConfig
.
CpuShares
}
// get config object for passing to Set()
config
:=
&
libcontainerconfigs
.
Config
{
Cgroups
:
fsCgroupManager
.
Cgroups
,
if
resourceConfig
.
CpuQuota
!=
nil
{
resources
.
CpuQuota
=
*
resourceConfig
.
CpuQuota
}
// Update cgroup configuration using libcontainers Managers Set() method
if
err
:=
fsCgroupManager
.
Set
(
config
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to update cgroup for %v: %v"
,
name
,
err
)
// Initialize libcontainer's cgroup config
libcontainerCgroupConfig
:=
&
libcontainerconfigs
.
Cgroup
{
Name
:
path
.
Base
(
name
),
Parent
:
path
.
Dir
(
name
),
Resources
:
resources
,
}
if
err
:=
setSupportedSubsytems
(
libcontainerCgroupConfig
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to set supported cgroup subsystems for cgroup %v: %v"
,
name
,
err
)
}
return
nil
}
// Create creates the specified cgroup
func
(
m
*
cgroupManagerImpl
)
Create
(
cgroupConfig
*
CgroupConfig
)
error
{
//cgroup name
//
get
cgroup name
name
:=
cgroupConfig
.
Name
// get the fscgroup Manager with the specified cgroup configuration
fsCgroupManager
,
err
:=
getLibcontainerCgroupManager
(
cgroupConfig
,
m
.
subsystems
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to create cgroup for %v : %v"
,
name
,
err
)
// Initialize libcontainer's cgroup config
libcontainerCgroupConfig
:=
&
libcontainerconfigs
.
Cgroup
{
Name
:
path
.
Base
(
name
),
Parent
:
path
.
Dir
(
name
),
Resources
:
&
libcontainerconfigs
.
Resources
{},
}
// get config object for passing to libcontainer's Set() method
config
:=
&
libcontainerconfigs
.
Config
{
Cgroups
:
fsCgroupManager
.
Cgroups
,
// get the fscgroup Manager with the specified cgroup configuration
fsCgroupManager
:=
&
cgroupfs
.
Manager
{
Cgroups
:
libcontainerCgroupConfig
,
}
//Apply(0) is a hack to create the cgroup directories for each resource
// subsystem. The function [cgroups.Manager.apply()] applies cgroup
...
...
@@ -103,11 +180,7 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
// in the tasks file. We use the function to create all the required
// cgroup files but not attach any "real" pid to the cgroup.
if
err
:=
fsCgroupManager
.
Apply
(
0
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to create cgroup for %v: %v"
,
name
,
err
)
}
// Update cgroup configuration using libcontainers Managers Set() method
if
err
:=
fsCgroupManager
.
Set
(
config
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to create cgroup for %v: %v"
,
name
,
err
)
return
fmt
.
Errorf
(
"Failed to apply cgroup config for %v: %v"
,
name
,
err
)
}
return
nil
}
pkg/kubelet/cm/cgroup_manager_unsupported.go
View file @
dcfff45a
...
...
@@ -29,6 +29,10 @@ func NewCgroupManager(_ interface{}) CgroupManager {
return
&
unsupportedCgroupManager
{}
}
func
(
m
*
unsupportedCgroupManager
)
Exists
(
_
string
)
bool
{
return
false
}
func
(
m
*
unsupportedCgroupManager
)
Destroy
(
_
*
CgroupConfig
)
error
{
return
nil
}
...
...
pkg/kubelet/cm/helpers_linux.go
View file @
dcfff45a
...
...
@@ -18,11 +18,8 @@ package cm
import
(
"fmt"
"path"
libcontainercgroups
"github.com/opencontainers/runc/libcontainer/cgroups"
cgroupfs
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
libcontainerconfigs
"github.com/opencontainers/runc/libcontainer/configs"
)
// cgroupSubsystems holds information about the mounted cgroup subsytems
...
...
@@ -59,40 +56,3 @@ func getCgroupSubsystems() (*cgroupSubsystems, error) {
mountPoints
:
mountPoints
,
},
nil
}
// getLibcontainerCgroupManager returns libcontainer's cgroups manager
// object with the specified cgroup configuration
func
getLibcontainerCgroupManager
(
cgroupConfig
*
CgroupConfig
,
subsystems
*
cgroupSubsystems
)
(
*
cgroupfs
.
Manager
,
error
)
{
// get cgroup name
name
:=
cgroupConfig
.
Name
// Get map of all cgroup paths on the system for the particular cgroup
cgroupPaths
:=
make
(
map
[
string
]
string
,
len
(
subsystems
.
mountPoints
))
for
key
,
val
:=
range
subsystems
.
mountPoints
{
cgroupPaths
[
key
]
=
path
.
Join
(
val
,
name
)
}
// Extract the cgroup resource parameters
resourceConfig
:=
cgroupConfig
.
ResourceParameters
resources
:=
&
libcontainerconfigs
.
Resources
{}
resources
.
AllowAllDevices
=
true
if
resourceConfig
.
Memory
!=
nil
{
resources
.
Memory
=
*
resourceConfig
.
Memory
}
if
resourceConfig
.
CpuShares
!=
nil
{
resources
.
CpuShares
=
*
resourceConfig
.
CpuShares
}
if
resourceConfig
.
CpuQuota
!=
nil
{
resources
.
CpuQuota
=
*
resourceConfig
.
CpuQuota
}
// Initialize libcontainer's cgroup config
libcontainerCgroupConfig
:=
&
libcontainerconfigs
.
Cgroup
{
Name
:
path
.
Base
(
name
),
Parent
:
path
.
Dir
(
name
),
Resources
:
resources
,
}
return
&
cgroupfs
.
Manager
{
Cgroups
:
libcontainerCgroupConfig
,
Paths
:
cgroupPaths
,
},
nil
}
pkg/kubelet/cm/types.go
View file @
dcfff45a
...
...
@@ -53,4 +53,6 @@ type CgroupManager interface {
Destroy
(
*
CgroupConfig
)
error
// Update cgroup configuration.
Update
(
*
CgroupConfig
)
error
// Exists checks if the cgroup already exists
Exists
(
string
)
bool
}
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