cri-o/server/container_update_resources.go
Antonio Murdaca b959f8996d
server: add prometheus metrics for CRI operations
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-11-09 16:51:00 +01:00

48 lines
1.5 KiB
Go

package server
import (
"time"
"github.com/gogo/protobuf/proto"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"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) (resp *pb.UpdateContainerResourcesResponse, err error) {
const operation = "update_container_resources"
defer func() {
recordOperation(operation, time.Now())
recordError(operation, err)
}()
logrus.Debugf("UpdateContainerResources %+v", req)
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
}
}