Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Nov 5, 2024
1 parent 1877022 commit 31aaf8f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
70 changes: 70 additions & 0 deletions test/e2e/dra/dra.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/format"
"github.com/onsi/gomega/gstruct"
"github.com/onsi/gomega/types"

Expand Down Expand Up @@ -1208,6 +1209,75 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
b1.create(ctx, claim1, claim1b, claim2, claim2b, pod)
b1.testPod(ctx, f.ClientSet, pod)
})

ginkgo.It("foobar", func(ctx context.Context) {
ginkgo.By("Running the multiclaim test")
name := "external-multiclaim"
params := `{"a":"b"}`
rc := &resourceapi.ResourceClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: resourceapi.ResourceClaimSpec{
Devices: resourceapi.DeviceClaim{
Requests: []resourceapi.DeviceRequest{{
Name: "my-request",
FirstAvailableOf: []resourceapi.DeviceRequest{
{
Name: "request-1",
DeviceClassName: b1.className(),
AllocationMode: resourceapi.DeviceAllocationModeExactCount,
Count: 1,
},
{
Name: "request-2",
DeviceClassName: b2.className(),
AllocationMode: resourceapi.DeviceAllocationModeExactCount,
Count: 1,
},
},
}},
Config: []resourceapi.DeviceClaimConfiguration{
{
Requests: []string{"request-1"},
DeviceConfiguration: resourceapi.DeviceConfiguration{
Opaque: &resourceapi.OpaqueDeviceConfiguration{
Driver: b1.driver.Name,
Parameters: runtime.RawExtension{
Raw: []byte(params),
},
},
},
},
{
Requests: []string{"request-2"},
DeviceConfiguration: resourceapi.DeviceConfiguration{
Opaque: &resourceapi.OpaqueDeviceConfiguration{
Driver: b2.driver.Name,
Parameters: runtime.RawExtension{
Raw: []byte(params),
},
},
},
},
},
},
},
}
framework.Logf("New ResourceClaim:\n%s", format.Object(rc, 1))
pod := b1.podExternal()
podClaimName := "resource-claim"
externalClaimName := "external-multiclaim"
pod.Spec.ResourceClaims = []v1.PodResourceClaim{
{
Name: podClaimName,
ResourceClaimName: &externalClaimName,
},
}
framework.Logf("New Pod:\n%s", format.Object(pod, 1))
b1.create(ctx, rc, pod)
b1.testPod(ctx, f.ClientSet, pod)
})
}
multipleDriversContext := func(prefix string, nodeV1alpha3 bool) {
ginkgo.Context(prefix, func() {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/dra/test-driver/app/kubeletplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,15 @@ func (ex *ExamplePlugin) nodePrepareResource(ctx context.Context, claimReq *drap
var devices []Device
for _, result := range claim.Status.Allocation.Devices.Results {
requestName := result.Request
subRequestName := result.SelectedSubRequest

// The driver joins all env variables in the order in which
// they appear in results (last one wins).
env := make(map[string]string)
for i, config := range claim.Status.Allocation.Devices.Config {
if config.Opaque == nil ||
config.Opaque.Driver != ex.driverName ||
len(config.Requests) > 0 && !slices.Contains(config.Requests, requestName) {
len(config.Requests) > 0 && !slices.Contains(config.Requests, requestName) && !slices.Contains(config.Requests, subRequestName) {
continue
}
if err := extractParameters(config.Opaque.Parameters, &env, config.Source == resourceapi.AllocationConfigSourceClass); err != nil {
Expand Down

0 comments on commit 31aaf8f

Please sign in to comment.