@@ -55,7 +55,10 @@ type DRAPlugin interface {
55
55
// to the API server.
56
56
//
57
57
// The caller must not modify the content after the call.
58
- PublishResources (ctx context.Context , resources Resources )
58
+ //
59
+ // Returns an error if KubeClient or NodeName options were not
60
+ // set in Start() to create the DRAPlugin instance.
61
+ PublishResources (ctx context.Context , resources Resources ) error
59
62
60
63
// This unexported method ensures that we can modify the interface
61
64
// without causing an API break of the package
@@ -254,6 +257,9 @@ type draPlugin struct {
254
257
// The context and/or DRAPlugin.Stop can be used to stop all background activity.
255
258
// Stop also blocks. A logger can be stored in the context to add values or
256
259
// a name to all log entries.
260
+ //
261
+ // If the plugin will be used to publish resources, [KubeClient] and [NodeName]
262
+ // options are mandatory.
257
263
func Start (ctx context.Context , nodeServer interface {}, opts ... Option ) (result DRAPlugin , finalErr error ) {
258
264
logger := klog .FromContext (ctx )
259
265
o := options {
@@ -365,8 +371,16 @@ func (d *draPlugin) Stop() {
365
371
d .wg .Wait ()
366
372
}
367
373
368
- // PublishResources implements [DRAPlugin.PublishResources].
369
- func (d * draPlugin ) PublishResources (ctx context.Context , resources Resources ) {
374
+ // PublishResources implements [DRAPlugin.PublishResources]. Returns en error if
375
+ // kubeClient or nodeName are unset.
376
+ func (d * draPlugin ) PublishResources (ctx context.Context , resources Resources ) error {
377
+ if d .kubeClient == nil {
378
+ return errors .New ("no KubeClient found to publish resources" )
379
+ }
380
+ if d .nodeName == "" {
381
+ return errors .New ("no NodeName was set to publish resources" )
382
+ }
383
+
370
384
d .mutex .Lock ()
371
385
defer d .mutex .Unlock ()
372
386
@@ -393,11 +407,13 @@ func (d *draPlugin) PublishResources(ctx context.Context, resources Resources) {
393
407
controllerLogger = klog .LoggerWithName (controllerLogger , "ResourceSlice controller" )
394
408
controllerCtx = klog .NewContext (controllerCtx , controllerLogger )
395
409
d .resourceSliceController = resourceslice .StartController (controllerCtx , d .kubeClient , d .driverName , owner , driverResources )
396
- return
410
+ return nil
397
411
}
398
412
399
413
// Inform running controller about new information.
400
414
d .resourceSliceController .Update (driverResources )
415
+
416
+ return nil
401
417
}
402
418
403
419
// RegistrationStatus implements [DRAPlugin.RegistrationStatus].
0 commit comments