Merge pull request #698 from liubin/feature/146-add-cgroup-v2-for-agent

agent: add cgroup v2 support
This commit is contained in:
Peng Tao
2020-09-18 14:45:38 +08:00
committed by GitHub
17 changed files with 1513 additions and 1338 deletions

View File

@@ -1036,3 +1036,13 @@ func GetOCIConfig(status vc.ContainerStatus) (specs.Spec, error) {
return *status.Spec, nil
}
// IsCRIOContainerManager check if a Pod is created from CRI-O
func IsCRIOContainerManager(spec *specs.Spec) bool {
if val, ok := spec.Annotations[crioAnnotations.ContainerType]; ok {
if val == crioAnnotations.ContainerTypeSandbox || val == crioAnnotations.ContainerTypeContainer {
return true
}
}
return false
}

View File

@@ -17,6 +17,7 @@ import (
"testing"
"github.com/cri-o/cri-o/pkg/annotations"
crioAnnotations "github.com/cri-o/cri-o/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"golang.org/x/sys/unix"
@@ -866,3 +867,34 @@ func TestAddRuntimeAnnotations(t *testing.T) {
assert.Equal(config.NetworkConfig.DisableNewNetNs, true)
assert.Equal(config.NetworkConfig.InterworkingModel, vc.NetXConnectMacVtapModel)
}
func TestIsCRIOContainerManager(t *testing.T) {
assert := assert.New(t)
testCases := []struct {
annotations map[string]string
result bool
}{
{
annotations: map[string]string{crioAnnotations.ContainerType: "abc"},
result: false,
},
{
annotations: map[string]string{crioAnnotations.ContainerType: crioAnnotations.ContainerTypeSandbox},
result: true,
},
{
annotations: map[string]string{crioAnnotations.ContainerType: crioAnnotations.ContainerTypeContainer},
result: true,
},
}
for i := range testCases {
tc := testCases[i]
ocispec := specs.Spec{
Annotations: tc.annotations,
}
result := IsCRIOContainerManager(&ocispec)
assert.Equal(tc.result, result, "test case %d", (i + 1))
}
}

View File

@@ -1203,10 +1203,10 @@ func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, erro
// Rollback if error happens.
if err != nil {
logger := s.Logger().WithFields(logrus.Fields{"container-id": c.id, "sandox-id": s.id, "rollback": true})
logger.Warning("Cleaning up partially created container")
logger.WithError(err).Error("Cleaning up partially created container")
if err2 := c.stop(true); err2 != nil {
logger.WithError(err2).Warning("Could not delete container")
logger.WithError(err2).Error("Could not delete container")
}
logger.Debug("Removing stopped container from sandbox store")
@@ -1894,9 +1894,11 @@ func (s *Sandbox) updateResources() error {
return err
}
s.Logger().Debugf("Request to hypervisor to update oldCPUs/newCPUs: %d/%d", oldCPUs, newCPUs)
// If the CPUs were increased, ask agent to online them
if oldCPUs < newCPUs {
vcpusAdded := newCPUs - oldCPUs
s.Logger().Debugf("Request to onlineCPUMem with %d CPUs", vcpusAdded)
if err := s.agent.onlineCPUMem(vcpusAdded, true); err != nil {
return err
}