Skip to content

Commit ba81087

Browse files
committed
dra e2e: check that not generating a ResourceClaim works
This is not something that normally happens, but the API supports it because it might be needed at some point, so we have to test it.
1 parent 0fc62d5 commit ba81087

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

test/e2e/dra/dra.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ var _ = ginkgo.Describe("[sig-node] DRA [Feature:DynamicResourceAllocation]", fu
193193
b.testPod(ctx, f.ClientSet, pod)
194194
})
195195

196+
ginkgo.It("runs a pod without a generated resource claim", func(ctx context.Context) {
197+
pod, _ /* template */ := b.podInline(resourcev1alpha2.AllocationModeWaitForFirstConsumer)
198+
created := b.create(ctx, pod)
199+
pod = created[0].(*v1.Pod)
200+
201+
// Normally, this pod would be stuck because the
202+
// ResourceClaim cannot be created without the
203+
// template. We allow it to run by communicating
204+
// through the status that the ResourceClaim is not
205+
// needed.
206+
pod.Status.ResourceClaimStatuses = []v1.PodResourceClaimStatus{
207+
{Name: pod.Spec.ResourceClaims[0].Name, ResourceClaimName: nil},
208+
}
209+
_, err := f.ClientSet.CoreV1().Pods(pod.Namespace).UpdateStatus(ctx, pod, metav1.UpdateOptions{})
210+
framework.ExpectNoError(err)
211+
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(ctx, f.ClientSet, pod))
212+
})
213+
196214
// claimTests tries out several different combinations of pods with
197215
// claims, both inline and external.
198216
claimTests := func(allocationMode resourcev1alpha2.AllocationMode) {
@@ -832,27 +850,31 @@ func (b *builder) podExternalMultiple() *v1.Pod {
832850
}
833851

834852
// create takes a bunch of objects and calls their Create function.
835-
func (b *builder) create(ctx context.Context, objs ...klog.KMetadata) {
853+
func (b *builder) create(ctx context.Context, objs ...klog.KMetadata) []klog.KMetadata {
854+
var createdObjs []klog.KMetadata
836855
for _, obj := range objs {
837856
ginkgo.By(fmt.Sprintf("creating %T %s", obj, obj.GetName()), func() {
838857
var err error
858+
var createdObj klog.KMetadata
839859
switch obj := obj.(type) {
840860
case *resourcev1alpha2.ResourceClass:
841-
_, err = b.f.ClientSet.ResourceV1alpha2().ResourceClasses().Create(ctx, obj, metav1.CreateOptions{})
861+
createdObj, err = b.f.ClientSet.ResourceV1alpha2().ResourceClasses().Create(ctx, obj, metav1.CreateOptions{})
842862
case *v1.Pod:
843-
_, err = b.f.ClientSet.CoreV1().Pods(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
863+
createdObj, err = b.f.ClientSet.CoreV1().Pods(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
844864
case *v1.ConfigMap:
845865
_, err = b.f.ClientSet.CoreV1().ConfigMaps(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
846866
case *resourcev1alpha2.ResourceClaim:
847-
_, err = b.f.ClientSet.ResourceV1alpha2().ResourceClaims(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
867+
createdObj, err = b.f.ClientSet.ResourceV1alpha2().ResourceClaims(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
848868
case *resourcev1alpha2.ResourceClaimTemplate:
849-
_, err = b.f.ClientSet.ResourceV1alpha2().ResourceClaimTemplates(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
869+
createdObj, err = b.f.ClientSet.ResourceV1alpha2().ResourceClaimTemplates(b.f.Namespace.Name).Create(ctx, obj, metav1.CreateOptions{})
850870
default:
851871
framework.Fail(fmt.Sprintf("internal error, unsupported type %T", obj), 1)
852872
}
853873
framework.ExpectNoErrorWithOffset(1, err, "create %T", obj)
874+
createdObjs = append(createdObjs, createdObj)
854875
})
855876
}
877+
return createdObjs
856878
}
857879

858880
// testPod runs pod and checks if container logs contain expected environment variables

0 commit comments

Comments
 (0)