Skip to content

Commit f9ef292

Browse files
authored
Merge pull request #218 from asm582/cust_pod_res
Read res req from custom pod res fix.
2 parents d5fb53b + 289701b commit f9ef292

File tree

4 files changed

+174
-9
lines changed

4 files changed

+174
-9
lines changed

CONTROLLER_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.29.41
1+
1.29.42

pkg/controller/queuejobresources/genericresource/genericresource.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,25 @@ func GetResources(awr *arbv1.AppWrapperGenericResource) (resource *clusterstatea
380380
var err error
381381
err = nil
382382
if awr.GenericTemplate.Raw != nil {
383+
if len(awr.CustomPodResources) > 0 {
384+
podresources := awr.CustomPodResources
385+
for _, item := range podresources {
386+
res := getPodResources(item)
387+
totalresource = totalresource.Add(res)
388+
}
389+
klog.V(4).Infof("[GetResources] Requested total allocation resource from custompodresources `%v`.\n", totalresource)
390+
return totalresource, err
391+
}
383392
hasContainer, replicas, containers := hasFields(awr.GenericTemplate)
384393
if hasContainer {
385394
for _, item := range containers {
386395
res := getContainerResources(item, replicas)
387396
totalresource = totalresource.Add(res)
388397
}
389-
klog.V(8).Infof("[GetResources] Requested total allocation resource from containers `%v`.\n", totalresource)
390-
} else {
391-
podresources := awr.CustomPodResources
392-
for _, item := range podresources {
393-
res := getPodResources(item)
394-
totalresource = totalresource.Add(res)
395-
}
396-
klog.V(8).Infof("[GetResources] Requested total allocation resource from pods `%v`.\n", totalresource)
398+
klog.V(4).Infof("[GetResources] Requested total allocation resource from containers `%v`.\n", totalresource)
399+
return totalresource, err
397400
}
401+
398402
} else {
399403
err = fmt.Errorf("generic template raw object is not defined (nil)")
400404
}

test/e2e/queue.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,79 @@ var _ = Describe("AppWrapper E2E Test", func() {
284284

285285
})
286286

287+
It("MCAD Custom Pod Resources Test", func() {
288+
fmt.Fprintf(os.Stdout, "[e2e] MCAD Custom Pod Resources Test - Started.\n")
289+
context := initTestContext()
290+
var appwrappers []*arbv1.AppWrapper
291+
appwrappersPtr := &appwrappers
292+
defer cleanupTestObjectsPtr(context, appwrappersPtr)
293+
294+
// This should fit on cluster with customPodResources matching deployment resource demands so AW pods are created
295+
aw := createGenericDeploymentCustomPodResourcesWithCPUAW(
296+
context, "aw-deployment-2-550-vs-550-cpu", "550m", "550m", 2)
297+
298+
appwrappers = append(appwrappers, aw)
299+
300+
err := waitAWAnyPodsExists(context, aw)
301+
Expect(err).NotTo(HaveOccurred())
302+
303+
err = waitAWPodsReady(context, aw)
304+
Expect(err).NotTo(HaveOccurred())
305+
})
306+
307+
308+
It("MCAD Bad Custom Pod Resources vs. Deployment Pod Resource Not Queuing Test", func() {
309+
fmt.Fprintf(os.Stdout, "[e2e] MCAD Bad Custom Pod Resources vs. Deployment Pod Resource Not Queuing Test - Started.\n")
310+
context := initTestContext()
311+
var appwrappers []*arbv1.AppWrapper
312+
appwrappersPtr := &appwrappers
313+
defer cleanupTestObjectsPtr(context, appwrappersPtr)
314+
315+
// This should fill up the worker node and most of the master node
316+
aw := createDeploymentAWwith550CPU(context, "aw-deployment-2-550cpu")
317+
appwrappers = append(appwrappers, aw)
318+
319+
err := waitAWPodsReady(context, aw)
320+
Expect(err).NotTo(HaveOccurred())
321+
322+
// This should not fit on cluster but customPodResources is incorrect so AW pods are created
323+
aw2 := createGenericDeploymentCustomPodResourcesWithCPUAW(
324+
context, "aw-deployment-2-425-vs-426-cpu", "425m", "426m", 2)
325+
326+
appwrappers = append(appwrappers, aw2)
327+
328+
err = waitAWAnyPodsExists(context, aw2)
329+
Expect(err).NotTo(HaveOccurred())
330+
331+
err = waitAWPodsReady(context, aw2)
332+
Expect(err).To(HaveOccurred())
333+
})
334+
335+
It("MCAD Bad Custom Pod Resources vs. Deployment Pod Resource Queuing Test 2", func() {
336+
fmt.Fprintf(os.Stdout, "[e2e] MCAD Bad Custom Pod Resources vs. Deployment Pod Resource Queuing Test 2 - Started.\n")
337+
context := initTestContext()
338+
var appwrappers []*arbv1.AppWrapper
339+
appwrappersPtr := &appwrappers
340+
defer cleanupTestObjectsPtr(context, appwrappersPtr)
341+
342+
// This should fill up the worker node and most of the master node
343+
aw := createDeploymentAWwith550CPU(context, "aw-deployment-2-550cpu")
344+
appwrappers = append(appwrappers, aw)
345+
346+
err := waitAWPodsReady(context, aw)
347+
Expect(err).NotTo(HaveOccurred())
348+
349+
// This should fit on cluster but customPodResources is incorrect so AW pods are not created
350+
aw2 := createGenericDeploymentCustomPodResourcesWithCPUAW(
351+
context, "aw-deployment-2-426-vs-425-cpu", "426m", "425m", 2)
352+
353+
appwrappers = append(appwrappers, aw2)
354+
355+
err = waitAWAnyPodsExists(context, aw2)
356+
Expect(err).To(HaveOccurred())
357+
358+
})
359+
287360
It("MCAD CPU Accounting Queuing Test", func() {
288361
fmt.Fprintf(os.Stdout, "[e2e] MCAD CPU Accounting Queuing Test - Started.\n")
289362
context := initTestContext()

test/e2e/util.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,94 @@ func createGenericDeploymentWithCPUAW(context *context, name string, cpuDemand s
15921592
return appwrapper
15931593
}
15941594

1595+
func createGenericDeploymentCustomPodResourcesWithCPUAW(context *context, name string, customPodCpuDemand string, cpuDemand string, replicas int) *arbv1.AppWrapper {
1596+
rb := []byte(fmt.Sprintf(`{
1597+
"apiVersion": "apps/v1",
1598+
"kind": "Deployment",
1599+
"metadata": {
1600+
"name": "%s",
1601+
"namespace": "test",
1602+
"labels": {
1603+
"app": "%s"
1604+
}
1605+
},
1606+
"spec": {
1607+
"replicas": %d,
1608+
"selector": {
1609+
"matchLabels": {
1610+
"app": "%s"
1611+
}
1612+
},
1613+
"template": {
1614+
"metadata": {
1615+
"labels": {
1616+
"app": "%s"
1617+
},
1618+
"annotations": {
1619+
"appwrapper.mcad.ibm.com/appwrapper-name": "%s"
1620+
}
1621+
},
1622+
"spec": {
1623+
"containers": [
1624+
{
1625+
"name": "%s",
1626+
"image": "k8s.gcr.io/echoserver:1.4",
1627+
"resources": {
1628+
"requests": {
1629+
"cpu": "%s"
1630+
}
1631+
},
1632+
"ports": [
1633+
{
1634+
"containerPort": 80
1635+
}
1636+
]
1637+
}
1638+
]
1639+
}
1640+
}
1641+
}} `, name, name, replicas, name, name, name, name, cpuDemand))
1642+
1643+
var schedSpecMin int = replicas
1644+
var customCpuResource = v1.ResourceList{"cpu": resource.MustParse(customPodCpuDemand)}
1645+
1646+
aw := &arbv1.AppWrapper{
1647+
ObjectMeta: metav1.ObjectMeta{
1648+
Name: name,
1649+
Namespace: context.namespace,
1650+
},
1651+
Spec: arbv1.AppWrapperSpec{
1652+
SchedSpec: arbv1.SchedulingSpecTemplate{
1653+
MinAvailable: schedSpecMin,
1654+
},
1655+
AggrResources: arbv1.AppWrapperResourceList{
1656+
GenericItems: []arbv1.AppWrapperGenericResource{
1657+
{
1658+
ObjectMeta: metav1.ObjectMeta{
1659+
Name: fmt.Sprintf("%s-%s", name, "item1"),
1660+
Namespace: context.namespace,
1661+
},
1662+
CustomPodResources: []arbv1.CustomPodResourceTemplate{
1663+
{
1664+
Replicas: replicas,
1665+
Requests: customCpuResource,
1666+
},
1667+
},
1668+
GenericTemplate: runtime.RawExtension{
1669+
Raw: rb,
1670+
},
1671+
},
1672+
},
1673+
},
1674+
},
1675+
}
1676+
1677+
appwrapper, err := context.karclient.ArbV1().AppWrappers(context.namespace).Create(aw)
1678+
Expect(err).NotTo(HaveOccurred())
1679+
1680+
return appwrapper
1681+
}
1682+
15951683
func createNamespaceAW(context *context, name string) *arbv1.AppWrapper {
15961684
rb := []byte(`{"apiVersion": "v1",
15971685
"kind": "Namespace",

0 commit comments

Comments
 (0)