mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Return an error from draplugin.PublishResources
When draplugin was instanciated without nodeName or kubeclient options, an error is returned when PublishResources is called. E2E: Update DRA test app to support error from PublishResources Signed-off-by: Alexey Fomenko <alexey.fomenko@intel.com>
This commit is contained in:
parent
f248c24456
commit
87871bd3ae
@ -55,7 +55,10 @@ type DRAPlugin interface {
|
|||||||
// to the API server.
|
// to the API server.
|
||||||
//
|
//
|
||||||
// The caller must not modify the content after the call.
|
// The caller must not modify the content after the call.
|
||||||
PublishResources(ctx context.Context, resources Resources)
|
//
|
||||||
|
// Returns an error if KubeClient or NodeName options were not
|
||||||
|
// set in Start() to create the DRAPlugin instance.
|
||||||
|
PublishResources(ctx context.Context, resources Resources) error
|
||||||
|
|
||||||
// This unexported method ensures that we can modify the interface
|
// This unexported method ensures that we can modify the interface
|
||||||
// without causing an API break of the package
|
// without causing an API break of the package
|
||||||
@ -254,6 +257,9 @@ type draPlugin struct {
|
|||||||
// The context and/or DRAPlugin.Stop can be used to stop all background activity.
|
// The context and/or DRAPlugin.Stop can be used to stop all background activity.
|
||||||
// Stop also blocks. A logger can be stored in the context to add values or
|
// Stop also blocks. A logger can be stored in the context to add values or
|
||||||
// a name to all log entries.
|
// a name to all log entries.
|
||||||
|
//
|
||||||
|
// If the plugin will be used to publish resources, [KubeClient] and [NodeName]
|
||||||
|
// options are mandatory.
|
||||||
func Start(ctx context.Context, nodeServer interface{}, opts ...Option) (result DRAPlugin, finalErr error) {
|
func Start(ctx context.Context, nodeServer interface{}, opts ...Option) (result DRAPlugin, finalErr error) {
|
||||||
logger := klog.FromContext(ctx)
|
logger := klog.FromContext(ctx)
|
||||||
o := options{
|
o := options{
|
||||||
@ -365,8 +371,16 @@ func (d *draPlugin) Stop() {
|
|||||||
d.wg.Wait()
|
d.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublishResources implements [DRAPlugin.PublishResources].
|
// PublishResources implements [DRAPlugin.PublishResources]. Returns en error if
|
||||||
func (d *draPlugin) PublishResources(ctx context.Context, resources Resources) {
|
// kubeClient or nodeName are unset.
|
||||||
|
func (d *draPlugin) PublishResources(ctx context.Context, resources Resources) error {
|
||||||
|
if d.kubeClient == nil {
|
||||||
|
return errors.New("no KubeClient found to publish resources")
|
||||||
|
}
|
||||||
|
if d.nodeName == "" {
|
||||||
|
return errors.New("no NodeName was set to publish resources")
|
||||||
|
}
|
||||||
|
|
||||||
d.mutex.Lock()
|
d.mutex.Lock()
|
||||||
defer d.mutex.Unlock()
|
defer d.mutex.Unlock()
|
||||||
|
|
||||||
@ -393,11 +407,13 @@ func (d *draPlugin) PublishResources(ctx context.Context, resources Resources) {
|
|||||||
controllerLogger = klog.LoggerWithName(controllerLogger, "ResourceSlice controller")
|
controllerLogger = klog.LoggerWithName(controllerLogger, "ResourceSlice controller")
|
||||||
controllerCtx = klog.NewContext(controllerCtx, controllerLogger)
|
controllerCtx = klog.NewContext(controllerCtx, controllerLogger)
|
||||||
d.resourceSliceController = resourceslice.StartController(controllerCtx, d.kubeClient, d.driverName, owner, driverResources)
|
d.resourceSliceController = resourceslice.StartController(controllerCtx, d.kubeClient, d.driverName, owner, driverResources)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform running controller about new information.
|
// Inform running controller about new information.
|
||||||
d.resourceSliceController.Update(driverResources)
|
d.resourceSliceController.Update(driverResources)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegistrationStatus implements [DRAPlugin.RegistrationStatus].
|
// RegistrationStatus implements [DRAPlugin.RegistrationStatus].
|
||||||
|
@ -182,7 +182,9 @@ func StartPlugin(ctx context.Context, cdiDir, driverName string, kubeClient kube
|
|||||||
resources := kubeletplugin.Resources{
|
resources := kubeletplugin.Resources{
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
}
|
}
|
||||||
ex.d.PublishResources(ctx, resources)
|
if err := ex.d.PublishResources(ctx, resources); err != nil {
|
||||||
|
return nil, fmt.Errorf("start kubelet plugin: publish resources: %w", err)
|
||||||
|
}
|
||||||
} else if len(ex.fileOps.Devices) > 0 {
|
} else if len(ex.fileOps.Devices) > 0 {
|
||||||
devices := make([]resourceapi.Device, len(ex.fileOps.Devices))
|
devices := make([]resourceapi.Device, len(ex.fileOps.Devices))
|
||||||
for i, deviceName := range sets.List(ex.deviceNames) {
|
for i, deviceName := range sets.List(ex.deviceNames) {
|
||||||
@ -194,7 +196,9 @@ func StartPlugin(ctx context.Context, cdiDir, driverName string, kubeClient kube
|
|||||||
resources := kubeletplugin.Resources{
|
resources := kubeletplugin.Resources{
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
}
|
}
|
||||||
ex.d.PublishResources(ctx, resources)
|
if err := ex.d.PublishResources(ctx, resources); err != nil {
|
||||||
|
return nil, fmt.Errorf("start kubelet plugin: publish resources: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ex, nil
|
return ex, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user