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
e748a4b5
Commit
e748a4b5
authored
Jul 15, 2014
by
Tim Hockin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #479 from brendandburns/cpu
Add support for CPU limiting to the kubelet.
parents
74e17022
c331849e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
kubelet.go
pkg/kubelet/kubelet.go
+15
-0
No files found.
pkg/kubelet/kubelet.go
View file @
e748a4b5
...
...
@@ -47,6 +47,11 @@ import (
const
defaultChanSize
=
1024
// taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc
const
minShares
=
2
const
sharesPerCpu
=
1024
const
milliCpuToCpu
=
1000
// CadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client.
type
CadvisorInterface
interface
{
ContainerInfo
(
name
string
)
(
*
info
.
ContainerInfo
,
error
)
...
...
@@ -270,6 +275,15 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m
return
exposedPorts
,
portBindings
}
func
milliCpuToShares
(
milliCpu
int
)
int
{
// Conceptually (milliCpu / milliCpuToCpu) * sharesPerCpu, but factored to improve rounding.
shares
:=
(
milliCpu
*
sharesPerCpu
)
/
milliCpuToCpu
if
shares
<
minShares
{
return
minShares
}
return
shares
}
// Run a single container from a manifest. Returns the docker container ID
func
(
kl
*
Kubelet
)
runContainer
(
manifest
*
api
.
ContainerManifest
,
container
*
api
.
Container
,
netMode
string
)
(
id
DockerID
,
err
error
)
{
envVariables
:=
makeEnvironmentVariables
(
container
)
...
...
@@ -285,6 +299,7 @@ func (kl *Kubelet) runContainer(manifest *api.ContainerManifest, container *api.
Hostname
:
container
.
Name
,
Image
:
container
.
Image
,
Memory
:
int64
(
container
.
Memory
),
CpuShares
:
int64
(
milliCpuToShares
(
container
.
CPU
)),
Volumes
:
volumes
,
WorkingDir
:
container
.
WorkingDir
,
},
...
...
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