mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #24908 from pmorie/daemon-controller-loc
Reduce LOC in daemon controller tests
This commit is contained in:
commit
19169889d4
@ -211,25 +211,30 @@ func TestOutOfDiskNodeDaemonDoesNotLaunchPod(t *testing.T) {
|
|||||||
syncAndValidateDaemonSets(t, manager, ds, podControl, 0, 0)
|
syncAndValidateDaemonSets(t, manager, ds, podControl, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DaemonSets should not place onto nodes with insufficient free resource
|
func resourcePodSpec(nodeName, memory, cpu string) api.PodSpec {
|
||||||
func TestInsufficentCapacityNodeDaemonDoesNotLaunchPod(t *testing.T) {
|
return api.PodSpec{
|
||||||
podSpec := api.PodSpec{
|
NodeName: nodeName,
|
||||||
NodeName: "too-much-mem",
|
|
||||||
Containers: []api.Container{{
|
Containers: []api.Container{{
|
||||||
Resources: api.ResourceRequirements{
|
Resources: api.ResourceRequirements{
|
||||||
Requests: api.ResourceList{
|
Requests: allocatableResources(memory, cpu),
|
||||||
api.ResourceMemory: resource.MustParse("75M"),
|
|
||||||
api.ResourceCPU: resource.MustParse("75m"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func allocatableResources(memory, cpu string) api.ResourceList {
|
||||||
|
return api.ResourceList{
|
||||||
|
api.ResourceMemory: resource.MustParse(memory),
|
||||||
|
api.ResourceCPU: resource.MustParse(cpu),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DaemonSets should not place onto nodes with insufficient free resource
|
||||||
|
func TestInsufficentCapacityNodeDaemonDoesNotLaunchPod(t *testing.T) {
|
||||||
|
podSpec := resourcePodSpec("too-much-mem", "75M", "75m")
|
||||||
manager, podControl := newTestController()
|
manager, podControl := newTestController()
|
||||||
node := newNode("too-much-mem", nil)
|
node := newNode("too-much-mem", nil)
|
||||||
node.Status.Allocatable = api.ResourceList{
|
node.Status.Allocatable = allocatableResources("100M", "200m")
|
||||||
api.ResourceMemory: resource.MustParse("100M"),
|
|
||||||
api.ResourceCPU: resource.MustParse("200m"),
|
|
||||||
}
|
|
||||||
manager.nodeStore.Add(node)
|
manager.nodeStore.Add(node)
|
||||||
manager.podStore.Add(&api.Pod{
|
manager.podStore.Add(&api.Pod{
|
||||||
Spec: podSpec,
|
Spec: podSpec,
|
||||||
@ -241,23 +246,10 @@ func TestInsufficentCapacityNodeDaemonDoesNotLaunchPod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSufficentCapacityWithTerminatedPodsDaemonLaunchesPod(t *testing.T) {
|
func TestSufficentCapacityWithTerminatedPodsDaemonLaunchesPod(t *testing.T) {
|
||||||
podSpec := api.PodSpec{
|
podSpec := resourcePodSpec("too-much-mem", "75M", "75m")
|
||||||
NodeName: "too-much-mem",
|
|
||||||
Containers: []api.Container{{
|
|
||||||
Resources: api.ResourceRequirements{
|
|
||||||
Requests: api.ResourceList{
|
|
||||||
api.ResourceMemory: resource.MustParse("75M"),
|
|
||||||
api.ResourceCPU: resource.MustParse("75m"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
manager, podControl := newTestController()
|
manager, podControl := newTestController()
|
||||||
node := newNode("too-much-mem", nil)
|
node := newNode("too-much-mem", nil)
|
||||||
node.Status.Allocatable = api.ResourceList{
|
node.Status.Allocatable = allocatableResources("100M", "200m")
|
||||||
api.ResourceMemory: resource.MustParse("100M"),
|
|
||||||
api.ResourceCPU: resource.MustParse("200m"),
|
|
||||||
}
|
|
||||||
manager.nodeStore.Add(node)
|
manager.nodeStore.Add(node)
|
||||||
manager.podStore.Add(&api.Pod{
|
manager.podStore.Add(&api.Pod{
|
||||||
Spec: podSpec,
|
Spec: podSpec,
|
||||||
@ -271,23 +263,10 @@ func TestSufficentCapacityWithTerminatedPodsDaemonLaunchesPod(t *testing.T) {
|
|||||||
|
|
||||||
// DaemonSets should place onto nodes with sufficient free resource
|
// DaemonSets should place onto nodes with sufficient free resource
|
||||||
func TestSufficentCapacityNodeDaemonLaunchesPod(t *testing.T) {
|
func TestSufficentCapacityNodeDaemonLaunchesPod(t *testing.T) {
|
||||||
podSpec := api.PodSpec{
|
podSpec := resourcePodSpec("not-too-much-mem", "75M", "75m")
|
||||||
NodeName: "not-too-much-mem",
|
|
||||||
Containers: []api.Container{{
|
|
||||||
Resources: api.ResourceRequirements{
|
|
||||||
Requests: api.ResourceList{
|
|
||||||
api.ResourceMemory: resource.MustParse("75M"),
|
|
||||||
api.ResourceCPU: resource.MustParse("75m"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
manager, podControl := newTestController()
|
manager, podControl := newTestController()
|
||||||
node := newNode("not-too-much-mem", nil)
|
node := newNode("not-too-much-mem", nil)
|
||||||
node.Status.Allocatable = api.ResourceList{
|
node.Status.Allocatable = allocatableResources("200M", "200m")
|
||||||
api.ResourceMemory: resource.MustParse("200M"),
|
|
||||||
api.ResourceCPU: resource.MustParse("200m"),
|
|
||||||
}
|
|
||||||
manager.nodeStore.Add(node)
|
manager.nodeStore.Add(node)
|
||||||
manager.podStore.Add(&api.Pod{
|
manager.podStore.Add(&api.Pod{
|
||||||
Spec: podSpec,
|
Spec: podSpec,
|
||||||
|
Loading…
Reference in New Issue
Block a user