mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
DRA Node E2E: add call blocking to the Kubelet plugin APIs
This commit is contained in:
parent
af99df6a6b
commit
673d0aaa60
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user