server: implement update container resources

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-09-28 10:52:56 +02:00
parent 7d7024999b
commit c25530ac0b
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
6 changed files with 107 additions and 5 deletions

View file

@ -1,13 +1,38 @@
package server
import (
"fmt"
"github.com/gogo/protobuf/proto"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)
// UpdateContainerResources updates ContainerConfig of the container.
func (s *Server) UpdateContainerResources(ctx context.Context, req *pb.UpdateContainerResourcesRequest) (*pb.UpdateContainerResourcesResponse, error) {
return nil, fmt.Errorf("not implemented")
c, err := s.GetContainerFromRequest(req.GetContainerId())
if err != nil {
return nil, err
}
resources := toOCIResources(req.GetLinux())
if err := s.Runtime().UpdateContainer(c, resources); err != nil {
return nil, err
}
return &pb.UpdateContainerResourcesResponse{}, nil
}
// toOCIResources converts CRI resource constraints to OCI.
func toOCIResources(r *pb.LinuxContainerResources) *rspec.LinuxResources {
return &rspec.LinuxResources{
CPU: &rspec.LinuxCPU{
Shares: proto.Uint64(uint64(r.GetCpuShares())),
Quota: proto.Int64(r.GetCpuQuota()),
Period: proto.Uint64(uint64(r.GetCpuPeriod())),
Cpus: r.GetCpusetCpus(),
Mems: r.GetCpusetMems(),
},
Memory: &rspec.LinuxMemory{
Limit: proto.Int64(r.GetMemoryLimitInBytes()),
},
// TODO(runcom): OOMScoreAdj is missing
}
}