mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
dra controller: enhance testing
The allocation mode is relevant when clearing the reservedFor: for delayed allocation, deallocation gets requested, for immediate allocation not. Both should get tested. All pre-defined claims now use delayed allocation, just as they would if created normally.
This commit is contained in:
parent
5cec6d798c
commit
cffbb1f1b2
@ -56,8 +56,15 @@ var (
|
|||||||
otherTestPod = makePod(testPodName+"-II", testNamespace, testPodUID+"-II")
|
otherTestPod = makePod(testPodName+"-II", testNamespace, testPodUID+"-II")
|
||||||
testClaim = makeClaim(testPodName+"-"+podResourceClaimName, testNamespace, className, makeOwnerReference(testPodWithResource, true))
|
testClaim = makeClaim(testPodName+"-"+podResourceClaimName, testNamespace, className, makeOwnerReference(testPodWithResource, true))
|
||||||
generatedTestClaim = makeGeneratedClaim(podResourceClaimName, testPodName+"-"+podResourceClaimName, testNamespace, className, 1, makeOwnerReference(testPodWithResource, true))
|
generatedTestClaim = makeGeneratedClaim(podResourceClaimName, testPodName+"-"+podResourceClaimName, testNamespace, className, 1, makeOwnerReference(testPodWithResource, true))
|
||||||
testClaimReserved = func() *resourcev1alpha2.ResourceClaim {
|
testClaimAllocated = func() *resourcev1alpha2.ResourceClaim {
|
||||||
claim := testClaim.DeepCopy()
|
claim := testClaim.DeepCopy()
|
||||||
|
claim.Status.Allocation = &resourcev1alpha2.AllocationResult{
|
||||||
|
Shareable: true,
|
||||||
|
}
|
||||||
|
return claim
|
||||||
|
}()
|
||||||
|
testClaimReserved = func() *resourcev1alpha2.ResourceClaim {
|
||||||
|
claim := testClaimAllocated.DeepCopy()
|
||||||
claim.Status.ReservedFor = append(claim.Status.ReservedFor,
|
claim.Status.ReservedFor = append(claim.Status.ReservedFor,
|
||||||
resourcev1alpha2.ResourceClaimConsumerReference{
|
resourcev1alpha2.ResourceClaimConsumerReference{
|
||||||
Resource: "pods",
|
Resource: "pods",
|
||||||
@ -264,15 +271,35 @@ func TestSyncHandler(t *testing.T) {
|
|||||||
expectedMetrics: expectedMetrics{0, 0},
|
expectedMetrics: expectedMetrics{0, 0},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "clear-reserved",
|
name: "clear-reserved-delayed-allocation",
|
||||||
pods: []*v1.Pod{},
|
pods: []*v1.Pod{},
|
||||||
key: claimKey(testClaimReserved),
|
key: claimKey(testClaimReserved),
|
||||||
claims: []*resourcev1alpha2.ResourceClaim{testClaimReserved},
|
claims: []*resourcev1alpha2.ResourceClaim{testClaimReserved},
|
||||||
expectedClaims: []resourcev1alpha2.ResourceClaim{*testClaim},
|
expectedClaims: func() []resourcev1alpha2.ResourceClaim {
|
||||||
|
claim := testClaimAllocated.DeepCopy()
|
||||||
|
claim.Status.DeallocationRequested = true
|
||||||
|
return []resourcev1alpha2.ResourceClaim{*claim}
|
||||||
|
}(),
|
||||||
expectedMetrics: expectedMetrics{0, 0},
|
expectedMetrics: expectedMetrics{0, 0},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "clear-reserved-when-done",
|
name: "clear-reserved-immediate-allocation",
|
||||||
|
pods: []*v1.Pod{},
|
||||||
|
key: claimKey(testClaimReserved),
|
||||||
|
claims: func() []*resourcev1alpha2.ResourceClaim {
|
||||||
|
claim := testClaimReserved.DeepCopy()
|
||||||
|
claim.Spec.AllocationMode = resourcev1alpha2.AllocationModeImmediate
|
||||||
|
return []*resourcev1alpha2.ResourceClaim{claim}
|
||||||
|
}(),
|
||||||
|
expectedClaims: func() []resourcev1alpha2.ResourceClaim {
|
||||||
|
claim := testClaimAllocated.DeepCopy()
|
||||||
|
claim.Spec.AllocationMode = resourcev1alpha2.AllocationModeImmediate
|
||||||
|
return []resourcev1alpha2.ResourceClaim{*claim}
|
||||||
|
}(),
|
||||||
|
expectedMetrics: expectedMetrics{0, 0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "clear-reserved-when-done-delayed-allocation",
|
||||||
pods: func() []*v1.Pod {
|
pods: func() []*v1.Pod {
|
||||||
pods := []*v1.Pod{testPodWithResource.DeepCopy()}
|
pods := []*v1.Pod{testPodWithResource.DeepCopy()}
|
||||||
pods[0].Status.Phase = v1.PodSucceeded
|
pods[0].Status.Phase = v1.PodSucceeded
|
||||||
@ -285,9 +312,31 @@ func TestSyncHandler(t *testing.T) {
|
|||||||
return claims
|
return claims
|
||||||
}(),
|
}(),
|
||||||
expectedClaims: func() []resourcev1alpha2.ResourceClaim {
|
expectedClaims: func() []resourcev1alpha2.ResourceClaim {
|
||||||
claims := []resourcev1alpha2.ResourceClaim{*testClaimReserved.DeepCopy()}
|
claims := []resourcev1alpha2.ResourceClaim{*testClaimAllocated.DeepCopy()}
|
||||||
claims[0].OwnerReferences = nil
|
claims[0].OwnerReferences = nil
|
||||||
claims[0].Status.ReservedFor = nil
|
claims[0].Status.DeallocationRequested = true
|
||||||
|
return claims
|
||||||
|
}(),
|
||||||
|
expectedMetrics: expectedMetrics{0, 0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "clear-reserved-when-done-immediate-allocation",
|
||||||
|
pods: func() []*v1.Pod {
|
||||||
|
pods := []*v1.Pod{testPodWithResource.DeepCopy()}
|
||||||
|
pods[0].Status.Phase = v1.PodSucceeded
|
||||||
|
return pods
|
||||||
|
}(),
|
||||||
|
key: claimKey(testClaimReserved),
|
||||||
|
claims: func() []*resourcev1alpha2.ResourceClaim {
|
||||||
|
claims := []*resourcev1alpha2.ResourceClaim{testClaimReserved.DeepCopy()}
|
||||||
|
claims[0].OwnerReferences = nil
|
||||||
|
claims[0].Spec.AllocationMode = resourcev1alpha2.AllocationModeImmediate
|
||||||
|
return claims
|
||||||
|
}(),
|
||||||
|
expectedClaims: func() []resourcev1alpha2.ResourceClaim {
|
||||||
|
claims := []resourcev1alpha2.ResourceClaim{*testClaimAllocated.DeepCopy()}
|
||||||
|
claims[0].OwnerReferences = nil
|
||||||
|
claims[0].Spec.AllocationMode = resourcev1alpha2.AllocationModeImmediate
|
||||||
return claims
|
return claims
|
||||||
}(),
|
}(),
|
||||||
expectedMetrics: expectedMetrics{0, 0},
|
expectedMetrics: expectedMetrics{0, 0},
|
||||||
@ -412,6 +461,7 @@ func makeClaim(name, namespace, classname string, owner *metav1.OwnerReference)
|
|||||||
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
|
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
|
||||||
Spec: resourcev1alpha2.ResourceClaimSpec{
|
Spec: resourcev1alpha2.ResourceClaimSpec{
|
||||||
ResourceClassName: classname,
|
ResourceClassName: classname,
|
||||||
|
AllocationMode: resourcev1alpha2.AllocationModeWaitForFirstConsumer,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if owner != nil {
|
if owner != nil {
|
||||||
@ -506,6 +556,10 @@ func normalizeClaims(claims []resourcev1alpha2.ResourceClaim) []resourcev1alpha2
|
|||||||
if len(claims[i].Status.ReservedFor) == 0 {
|
if len(claims[i].Status.ReservedFor) == 0 {
|
||||||
claims[i].Status.ReservedFor = nil
|
claims[i].Status.ReservedFor = nil
|
||||||
}
|
}
|
||||||
|
if claims[i].Spec.AllocationMode == "" {
|
||||||
|
// This emulates defaulting.
|
||||||
|
claims[i].Spec.AllocationMode = resourcev1alpha2.AllocationModeWaitForFirstConsumer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return claims
|
return claims
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user