mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Adding test coverage for NewPodContainerManager() (#110220)
This commit is contained in:
parent
ca7804fe13
commit
69465d2949
@ -24,8 +24,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
@ -259,3 +260,90 @@ func TestGetCapacity(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewPodContainerManager(t *testing.T) {
|
||||||
|
|
||||||
|
info := QOSContainersInfo{
|
||||||
|
Guaranteed: CgroupName{"guaranteed"},
|
||||||
|
BestEffort: CgroupName{"besteffort"},
|
||||||
|
Burstable: CgroupName{"burstable"},
|
||||||
|
}
|
||||||
|
QosEnabled := NodeConfig{
|
||||||
|
CgroupsPerQOS: true,
|
||||||
|
}
|
||||||
|
QosDisabled := NodeConfig{
|
||||||
|
CgroupsPerQOS: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
cm *containerManagerImpl
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "CgroupsPerQOS is disabled, return *podContainerManagerNoop",
|
||||||
|
cm: &containerManagerImpl{
|
||||||
|
qosContainerManager: &qosContainerManagerImpl{
|
||||||
|
qosContainersInfo: info,
|
||||||
|
cgroupManager: NewCgroupManager(&CgroupSubsystems{}, ""),
|
||||||
|
},
|
||||||
|
|
||||||
|
NodeConfig: QosDisabled,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "CgroupsPerQOS is enabled, return *podContainerManagerImpl",
|
||||||
|
cm: &containerManagerImpl{
|
||||||
|
qosContainerManager: &qosContainerManagerImpl{
|
||||||
|
qosContainersInfo: info,
|
||||||
|
cgroupManager: NewCgroupManager(&CgroupSubsystems{}, ""),
|
||||||
|
},
|
||||||
|
|
||||||
|
NodeConfig: QosEnabled,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "CgroupsPerQOS is enabled, use systemd",
|
||||||
|
cm: &containerManagerImpl{
|
||||||
|
qosContainerManager: &qosContainerManagerImpl{
|
||||||
|
qosContainersInfo: info,
|
||||||
|
cgroupManager: NewCgroupManager(&CgroupSubsystems{}, "systemd"),
|
||||||
|
},
|
||||||
|
|
||||||
|
NodeConfig: QosEnabled,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "CgroupsPerQOS is disabled, use systemd",
|
||||||
|
cm: &containerManagerImpl{
|
||||||
|
qosContainerManager: &qosContainerManagerImpl{
|
||||||
|
qosContainersInfo: info,
|
||||||
|
cgroupManager: NewCgroupManager(&CgroupSubsystems{}, "systemd"),
|
||||||
|
},
|
||||||
|
|
||||||
|
NodeConfig: QosDisabled,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
c := c
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
pcm := c.cm.NewPodContainerManager()
|
||||||
|
if c.cm.NodeConfig.CgroupsPerQOS {
|
||||||
|
assert.IsType(t, &podContainerManagerImpl{}, pcm)
|
||||||
|
got := pcm.(*podContainerManagerImpl)
|
||||||
|
assert.Equal(t, c.cm.subsystems, got.subsystems)
|
||||||
|
assert.Equal(t, c.cm.cgroupManager, got.cgroupManager)
|
||||||
|
assert.Equal(t, c.cm.PodPidsLimit, got.podPidsLimit)
|
||||||
|
assert.Equal(t, c.cm.EnforceCPULimits, got.enforceCPULimits)
|
||||||
|
assert.Equal(t, uint64(c.cm.CPUCFSQuotaPeriod/time.Microsecond), got.cpuCFSQuotaPeriod)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
assert.IsType(t, &podContainerManagerNoop{}, pcm)
|
||||||
|
got := pcm.(*podContainerManagerNoop)
|
||||||
|
assert.Equal(t, c.cm.cgroupRoot, got.cgroupRoot)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user