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
9fbf8f57
Commit
9fbf8f57
authored
May 19, 2017
by
Seth Jennings
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add UpdateContainerResources function to CRI
parent
1bc56825
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
107 additions
and
0 deletions
+107
-0
services.go
pkg/kubelet/apis/cri/services.go
+2
-0
fake_runtime_service.go
pkg/kubelet/apis/cri/testing/fake_runtime_service.go
+4
-0
api.pb.go
pkg/kubelet/apis/cri/v1alpha1/runtime/api.pb.go
+0
-0
api.proto
pkg/kubelet/apis/cri/v1alpha1/runtime/api.proto
+15
-0
docker_container.go
pkg/kubelet/dockershim/docker_container.go
+19
-0
client.go
pkg/kubelet/dockershim/libdocker/client.go
+1
-0
fake_client.go
pkg/kubelet/dockershim/libdocker/fake_client.go
+4
-0
instrumented_client.go
pkg/kubelet/dockershim/libdocker/instrumented_client.go
+9
-0
kube_docker_client.go
pkg/kubelet/dockershim/libdocker/kube_docker_client.go
+10
-0
docker_service.go
pkg/kubelet/dockershim/remote/docker_service.go
+8
-0
instrumented_services.go
pkg/kubelet/kuberuntime/instrumented_services.go
+9
-0
remote_runtime.go
pkg/kubelet/remote/remote_runtime.go
+17
-0
app-interface.go
pkg/kubelet/rktshim/app-interface.go
+5
-0
fake-app-interface.go
pkg/kubelet/rktshim/fake-app-interface.go
+4
-0
No files found.
pkg/kubelet/apis/cri/services.go
View file @
9fbf8f57
...
@@ -43,6 +43,8 @@ type ContainerManager interface {
...
@@ -43,6 +43,8 @@ type ContainerManager interface {
ListContainers
(
filter
*
runtimeapi
.
ContainerFilter
)
([]
*
runtimeapi
.
Container
,
error
)
ListContainers
(
filter
*
runtimeapi
.
ContainerFilter
)
([]
*
runtimeapi
.
Container
,
error
)
// ContainerStatus returns the status of the container.
// ContainerStatus returns the status of the container.
ContainerStatus
(
containerID
string
)
(
*
runtimeapi
.
ContainerStatus
,
error
)
ContainerStatus
(
containerID
string
)
(
*
runtimeapi
.
ContainerStatus
,
error
)
// UpdateContainerResources updates the cgroup resources for the container.
UpdateContainerResources
(
containerID
string
,
resources
*
runtimeapi
.
LinuxContainerResources
)
error
// ExecSync executes a command in the container, and returns the stdout output.
// ExecSync executes a command in the container, and returns the stdout output.
// If command exits with a non-zero exit code, an error is returned.
// If command exits with a non-zero exit code, an error is returned.
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
...
...
pkg/kubelet/apis/cri/testing/fake_runtime_service.go
View file @
9fbf8f57
...
@@ -362,6 +362,10 @@ func (r *FakeRuntimeService) ContainerStatus(containerID string) (*runtimeapi.Co
...
@@ -362,6 +362,10 @@ func (r *FakeRuntimeService) ContainerStatus(containerID string) (*runtimeapi.Co
return
&
status
,
nil
return
&
status
,
nil
}
}
func
(
r
*
FakeRuntimeService
)
UpdateContainerResources
(
string
,
*
runtimeapi
.
LinuxContainerResources
)
error
{
return
nil
}
func
(
r
*
FakeRuntimeService
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
func
(
r
*
FakeRuntimeService
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
r
.
Lock
()
r
.
Lock
()
defer
r
.
Unlock
()
defer
r
.
Unlock
()
...
...
pkg/kubelet/apis/cri/v1alpha1/runtime/api.pb.go
View file @
9fbf8f57
This diff is collapsed.
Click to expand it.
pkg/kubelet/apis/cri/v1alpha1/runtime/api.proto
View file @
9fbf8f57
...
@@ -61,6 +61,8 @@ service RuntimeService {
...
@@ -61,6 +61,8 @@ service RuntimeService {
// ContainerStatus returns status of the container. If the container is not
// ContainerStatus returns status of the container. If the container is not
// present, returns an error.
// present, returns an error.
rpc
ContainerStatus
(
ContainerStatusRequest
)
returns
(
ContainerStatusResponse
)
{}
rpc
ContainerStatus
(
ContainerStatusRequest
)
returns
(
ContainerStatusResponse
)
{}
// UpdateContainerResources updates ContainerConfig of the container.
rpc
UpdateContainerResources
(
UpdateContainerResourcesRequest
)
returns
(
UpdateContainerResourcesResponse
)
{}
// ExecSync runs a command in a container synchronously.
// ExecSync runs a command in a container synchronously.
rpc
ExecSync
(
ExecSyncRequest
)
returns
(
ExecSyncResponse
)
{}
rpc
ExecSync
(
ExecSyncRequest
)
returns
(
ExecSyncResponse
)
{}
...
@@ -445,6 +447,10 @@ message LinuxContainerResources {
...
@@ -445,6 +447,10 @@ message LinuxContainerResources {
int64
memory_limit_in_bytes
=
4
;
int64
memory_limit_in_bytes
=
4
;
// OOMScoreAdj adjusts the oom-killer score. Default: 0 (not specified).
// OOMScoreAdj adjusts the oom-killer score. Default: 0 (not specified).
int64
oom_score_adj
=
5
;
int64
oom_score_adj
=
5
;
// CpusetCpus constrains the allowed set of logical CPUs. Default: "" (not specified).
string
cpuset_cpus
=
6
;
// CpusetMems constrains the allowed set of memory nodes. Default: "" (not specified).
string
cpuset_mems
=
7
;
}
}
// SELinuxOption are the labels to be applied to the container.
// SELinuxOption are the labels to be applied to the container.
...
@@ -772,6 +778,15 @@ message ContainerStatusResponse {
...
@@ -772,6 +778,15 @@ message ContainerStatusResponse {
ContainerStatus
status
=
1
;
ContainerStatus
status
=
1
;
}
}
message
UpdateContainerResourcesRequest
{
// ID of the container to update.
string
container_id
=
1
;
// Resource configuration specific to Linux containers.
LinuxContainerResources
linux
=
2
;
}
message
UpdateContainerResourcesResponse
{}
message
ExecSyncRequest
{
message
ExecSyncRequest
{
// ID of the container.
// ID of the container.
string
container_id
=
1
;
string
container_id
=
1
;
...
...
pkg/kubelet/dockershim/docker_container.go
View file @
9fbf8f57
...
@@ -402,3 +402,22 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeapi.Contai
...
@@ -402,3 +402,22 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeapi.Contai
LogPath
:
r
.
Config
.
Labels
[
containerLogPathLabelKey
],
LogPath
:
r
.
Config
.
Labels
[
containerLogPathLabelKey
],
},
nil
},
nil
}
}
func
(
ds
*
dockerService
)
UpdateContainerResources
(
containerID
string
,
resources
*
runtimeapi
.
LinuxContainerResources
)
error
{
updateConfig
:=
dockercontainer
.
UpdateConfig
{
Resources
:
dockercontainer
.
Resources
{
CPUPeriod
:
resources
.
CpuPeriod
,
CPUQuota
:
resources
.
CpuQuota
,
CPUShares
:
resources
.
CpuShares
,
Memory
:
resources
.
MemoryLimitInBytes
,
CpusetCpus
:
resources
.
CpusetCpus
,
CpusetMems
:
resources
.
CpusetMems
,
},
}
err
:=
ds
.
client
.
UpdateContainerResources
(
containerID
,
updateConfig
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to update container %q: %v"
,
containerID
,
err
)
}
return
nil
}
pkg/kubelet/dockershim/libdocker/client.go
View file @
9fbf8f57
...
@@ -48,6 +48,7 @@ type Interface interface {
...
@@ -48,6 +48,7 @@ type Interface interface {
CreateContainer
(
dockertypes
.
ContainerCreateConfig
)
(
*
dockercontainer
.
ContainerCreateCreatedBody
,
error
)
CreateContainer
(
dockertypes
.
ContainerCreateConfig
)
(
*
dockercontainer
.
ContainerCreateCreatedBody
,
error
)
StartContainer
(
id
string
)
error
StartContainer
(
id
string
)
error
StopContainer
(
id
string
,
timeout
time
.
Duration
)
error
StopContainer
(
id
string
,
timeout
time
.
Duration
)
error
UpdateContainerResources
(
id
string
,
updateConfig
dockercontainer
.
UpdateConfig
)
error
RemoveContainer
(
id
string
,
opts
dockertypes
.
ContainerRemoveOptions
)
error
RemoveContainer
(
id
string
,
opts
dockertypes
.
ContainerRemoveOptions
)
error
InspectImageByRef
(
imageRef
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
InspectImageByRef
(
imageRef
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
InspectImageByID
(
imageID
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
InspectImageByID
(
imageID
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
...
...
pkg/kubelet/dockershim/libdocker/fake_client.go
View file @
9fbf8f57
...
@@ -625,6 +625,10 @@ func (f *FakeDockerClient) RemoveContainer(id string, opts dockertypes.Container
...
@@ -625,6 +625,10 @@ func (f *FakeDockerClient) RemoveContainer(id string, opts dockertypes.Container
return
fmt
.
Errorf
(
"container not stopped"
)
return
fmt
.
Errorf
(
"container not stopped"
)
}
}
func
(
f
*
FakeDockerClient
)
UpdateContainerResources
(
id
string
,
updateConfig
dockercontainer
.
UpdateConfig
)
error
{
return
nil
}
// Logs is a test-spy implementation of Interface.Logs.
// Logs is a test-spy implementation of Interface.Logs.
// It adds an entry "logs" to the internal method call record.
// It adds an entry "logs" to the internal method call record.
func
(
f
*
FakeDockerClient
)
Logs
(
id
string
,
opts
dockertypes
.
ContainerLogsOptions
,
sopts
StreamOptions
)
error
{
func
(
f
*
FakeDockerClient
)
Logs
(
id
string
,
opts
dockertypes
.
ContainerLogsOptions
,
sopts
StreamOptions
)
error
{
...
...
pkg/kubelet/dockershim/libdocker/instrumented_client.go
View file @
9fbf8f57
...
@@ -108,6 +108,15 @@ func (in instrumentedInterface) RemoveContainer(id string, opts dockertypes.Cont
...
@@ -108,6 +108,15 @@ func (in instrumentedInterface) RemoveContainer(id string, opts dockertypes.Cont
return
err
return
err
}
}
func
(
in
instrumentedInterface
)
UpdateContainerResources
(
id
string
,
updateConfig
dockercontainer
.
UpdateConfig
)
error
{
const
operation
=
"update_container"
defer
recordOperation
(
operation
,
time
.
Now
())
err
:=
in
.
client
.
UpdateContainerResources
(
id
,
updateConfig
)
recordError
(
operation
,
err
)
return
err
}
func
(
in
instrumentedInterface
)
InspectImageByRef
(
image
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
{
func
(
in
instrumentedInterface
)
InspectImageByRef
(
image
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
{
const
operation
=
"inspect_image"
const
operation
=
"inspect_image"
defer
recordOperation
(
operation
,
time
.
Now
())
defer
recordOperation
(
operation
,
time
.
Now
())
...
...
pkg/kubelet/dockershim/libdocker/kube_docker_client.go
View file @
9fbf8f57
...
@@ -171,6 +171,16 @@ func (d *kubeDockerClient) RemoveContainer(id string, opts dockertypes.Container
...
@@ -171,6 +171,16 @@ func (d *kubeDockerClient) RemoveContainer(id string, opts dockertypes.Container
return
err
return
err
}
}
func
(
d
*
kubeDockerClient
)
UpdateContainerResources
(
id
string
,
updateConfig
dockercontainer
.
UpdateConfig
)
error
{
ctx
,
cancel
:=
d
.
getTimeoutContext
()
defer
cancel
()
_
,
err
:=
d
.
client
.
ContainerUpdate
(
ctx
,
id
,
updateConfig
)
if
ctxErr
:=
contextError
(
ctx
);
ctxErr
!=
nil
{
return
ctxErr
}
return
err
}
func
(
d
*
kubeDockerClient
)
inspectImageRaw
(
ref
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
{
func
(
d
*
kubeDockerClient
)
inspectImageRaw
(
ref
string
)
(
*
dockertypes
.
ImageInspect
,
error
)
{
ctx
,
cancel
:=
d
.
getTimeoutContext
()
ctx
,
cancel
:=
d
.
getTimeoutContext
()
defer
cancel
()
defer
cancel
()
...
...
pkg/kubelet/dockershim/remote/docker_service.go
View file @
9fbf8f57
...
@@ -147,6 +147,14 @@ func (d *dockerService) ContainerStatus(ctx context.Context, r *runtimeapi.Conta
...
@@ -147,6 +147,14 @@ func (d *dockerService) ContainerStatus(ctx context.Context, r *runtimeapi.Conta
return
&
runtimeapi
.
ContainerStatusResponse
{
Status
:
status
},
nil
return
&
runtimeapi
.
ContainerStatusResponse
{
Status
:
status
},
nil
}
}
func
(
d
*
dockerService
)
UpdateContainerResources
(
ctx
context
.
Context
,
r
*
runtimeapi
.
UpdateContainerResourcesRequest
)
(
*
runtimeapi
.
UpdateContainerResourcesResponse
,
error
)
{
err
:=
d
.
runtimeService
.
UpdateContainerResources
(
r
.
ContainerId
,
r
.
Linux
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
runtimeapi
.
UpdateContainerResourcesResponse
{},
nil
}
func
(
d
*
dockerService
)
ExecSync
(
ctx
context
.
Context
,
r
*
runtimeapi
.
ExecSyncRequest
)
(
*
runtimeapi
.
ExecSyncResponse
,
error
)
{
func
(
d
*
dockerService
)
ExecSync
(
ctx
context
.
Context
,
r
*
runtimeapi
.
ExecSyncRequest
)
(
*
runtimeapi
.
ExecSyncResponse
,
error
)
{
stdout
,
stderr
,
err
:=
d
.
runtimeService
.
ExecSync
(
r
.
ContainerId
,
r
.
Cmd
,
time
.
Duration
(
r
.
Timeout
)
*
time
.
Second
)
stdout
,
stderr
,
err
:=
d
.
runtimeService
.
ExecSync
(
r
.
ContainerId
,
r
.
Cmd
,
time
.
Duration
(
r
.
Timeout
)
*
time
.
Second
)
var
exitCode
int32
var
exitCode
int32
...
...
pkg/kubelet/kuberuntime/instrumented_services.go
View file @
9fbf8f57
...
@@ -131,6 +131,15 @@ func (in instrumentedRuntimeService) ContainerStatus(containerID string) (*runti
...
@@ -131,6 +131,15 @@ func (in instrumentedRuntimeService) ContainerStatus(containerID string) (*runti
return
out
,
err
return
out
,
err
}
}
func
(
in
instrumentedRuntimeService
)
UpdateContainerResources
(
containerID
string
,
resources
*
runtimeapi
.
LinuxContainerResources
)
error
{
const
operation
=
"container_status"
defer
recordOperation
(
operation
,
time
.
Now
())
err
:=
in
.
service
.
UpdateContainerResources
(
containerID
,
resources
)
recordError
(
operation
,
err
)
return
err
}
func
(
in
instrumentedRuntimeService
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
([]
byte
,
[]
byte
,
error
)
{
func
(
in
instrumentedRuntimeService
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
([]
byte
,
[]
byte
,
error
)
{
const
operation
=
"exec_sync"
const
operation
=
"exec_sync"
defer
recordOperation
(
operation
,
time
.
Now
())
defer
recordOperation
(
operation
,
time
.
Now
())
...
...
pkg/kubelet/remote/remote_runtime.go
View file @
9fbf8f57
...
@@ -288,6 +288,23 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
...
@@ -288,6 +288,23 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
return
resp
.
Status
,
nil
return
resp
.
Status
,
nil
}
}
// UpdateContainerResources updates a containers resource config
func
(
r
*
RemoteRuntimeService
)
UpdateContainerResources
(
containerID
string
,
resources
*
runtimeapi
.
LinuxContainerResources
)
error
{
ctx
,
cancel
:=
getContextWithTimeout
(
r
.
timeout
)
defer
cancel
()
_
,
err
:=
r
.
runtimeClient
.
UpdateContainerResources
(
ctx
,
&
runtimeapi
.
UpdateContainerResourcesRequest
{
ContainerId
:
containerID
,
Linux
:
resources
,
})
if
err
!=
nil
{
glog
.
Errorf
(
"UpdateContainerResources %q from runtime service failed: %v"
,
containerID
,
err
)
return
err
}
return
nil
}
// ExecSync executes a command in the container, and returns the stdout output.
// ExecSync executes a command in the container, and returns the stdout output.
// If command exits with a non-zero exit code, an error is returned.
// If command exits with a non-zero exit code, an error is returned.
func
(
r
*
RemoteRuntimeService
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
func
(
r
*
RemoteRuntimeService
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
...
...
pkg/kubelet/rktshim/app-interface.go
View file @
9fbf8f57
...
@@ -65,6 +65,11 @@ func (*Runtime) ContainerStatus(string) (*runtimeapi.ContainerStatus, error) {
...
@@ -65,6 +65,11 @@ func (*Runtime) ContainerStatus(string) (*runtimeapi.ContainerStatus, error) {
panic
(
"not implemented"
)
panic
(
"not implemented"
)
}
}
// UpdateContainerResources updates the resource constraints for the container.
func
(
*
Runtime
)
UpdateContainerResources
(
string
,
*
runtimeapi
.
LinuxContainerResources
)
error
{
panic
(
"not implemented"
)
}
// ExecSync executes a command in the container, and returns the stdout output.
// ExecSync executes a command in the container, and returns the stdout output.
// If command exits with a non-zero exit code, an error is returned.
// If command exits with a non-zero exit code, an error is returned.
func
(
*
Runtime
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
func
(
*
Runtime
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
...
...
pkg/kubelet/rktshim/fake-app-interface.go
View file @
9fbf8f57
...
@@ -205,6 +205,10 @@ func (r *FakeRuntime) ContainerStatus(id string) (*runtimeapi.ContainerStatus, e
...
@@ -205,6 +205,10 @@ func (r *FakeRuntime) ContainerStatus(id string) (*runtimeapi.ContainerStatus, e
return
&
c
.
Status
,
nil
return
&
c
.
Status
,
nil
}
}
func
(
r
*
FakeRuntime
)
UpdateContainerResources
(
string
,
*
runtimeapi
.
LinuxContainerResources
)
error
{
return
nil
}
func
(
r
*
FakeRuntime
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
func
(
r
*
FakeRuntime
)
ExecSync
(
containerID
string
,
cmd
[]
string
,
timeout
time
.
Duration
)
(
stdout
[]
byte
,
stderr
[]
byte
,
err
error
)
{
c
,
ok
:=
r
.
Containers
[
containerID
]
c
,
ok
:=
r
.
Containers
[
containerID
]
if
!
ok
{
if
!
ok
{
...
...
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