From 673d0aaa60cedd9904d40c8b9bceb7740dc777a7 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Thu, 8 Jun 2023 11:58:46 +0300 Subject: [PATCH] DRA Node E2E: add call blocking to the Kubelet plugin APIs --- test/e2e/dra/test-driver/app/kubeletplugin.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/e2e/dra/test-driver/app/kubeletplugin.go b/test/e2e/dra/test-driver/app/kubeletplugin.go index f899e8da404..a53de6b2116 100644 --- a/test/e2e/dra/test-driver/app/kubeletplugin.go +++ b/test/e2e/dra/test-driver/app/kubeletplugin.go @@ -43,6 +43,8 @@ type ExamplePlugin struct { mutex sync.Mutex prepared map[ClaimID]bool gRPCCalls []GRPCCall + + block bool } type GRPCCall struct { @@ -135,6 +137,12 @@ func (ex *ExamplePlugin) IsRegistered() bool { return status.PluginRegistered } +// Block sets a flag to block Node[Un]PrepareResources +// to emulate time consuming or stuck calls +func (ex *ExamplePlugin) Block() { + ex.block = true +} + // NodePrepareResource ensures that the CDI file for the claim exists. It uses // a deterministic name to simplify NodeUnprepareResource (no need to remember // or discover the name) and idempotency (when called again, the file simply @@ -142,6 +150,13 @@ func (ex *ExamplePlugin) IsRegistered() bool { func (ex *ExamplePlugin) NodePrepareResource(ctx context.Context, req *drapbv1.NodePrepareResourceRequest) (*drapbv1.NodePrepareResourceResponse, error) { logger := klog.FromContext(ctx) + // Block to emulate plugin stuckness or slowness. + // By default the call will not be blocked as ex.block = false. + if ex.block { + <-ctx.Done() + return nil, ctx.Err() + } + // Determine environment variables. var p parameters if err := json.Unmarshal([]byte(req.ResourceHandle), &p); err != nil { @@ -202,6 +217,13 @@ func (ex *ExamplePlugin) NodePrepareResource(ctx context.Context, req *drapbv1.N func (ex *ExamplePlugin) NodeUnprepareResource(ctx context.Context, req *drapbv1.NodeUnprepareResourceRequest) (*drapbv1.NodeUnprepareResourceResponse, error) { logger := klog.FromContext(ctx) + // Block to emulate plugin stuckness or slowness. + // By default the call will not be blocked as ex.block = false. + if ex.block { + <-ctx.Done() + return nil, ctx.Err() + } + filePath := ex.getJSONFilePath(req.ClaimUid) if err := ex.fileOps.Remove(filePath); err != nil { return nil, fmt.Errorf("error removing CDI file: %w", err)