in nri_device_injector/nri_device_injector.go [86:123]
func (p *plugin) CreateContainer(_ context.Context, pod *api.PodSandbox, container *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error) {
if pod == nil {
return nil, nil, nil
}
var (
ctrName = container.Name
l = log.WithFields(log.Fields{"container": ctrName, "pod": pod.Name, "namespace": pod.Namespace})
devices []device
err error
)
defer l.Info("Finished CreateContainer")
l.Info("Started CreateContainer")
devices, err = getDevices(ctrName, pod.Annotations)
if err != nil {
l.WithError(err).Warn("Failed to get device from pod annotation")
return nil, nil, err
}
adjust := &api.ContainerAdjustment{}
if len(devices) == 0 {
l.Debug("No devices annotated...")
return adjust, nil, nil
}
for _, d := range devices {
l.WithField("device", d.Path).Info("Annotated device")
deviceNRI, err := d.toNRIDevice()
if err != nil {
l.WithField("device", d.Path).WithError(err).Warn("Failed to get device from path")
return nil, nil, err
}
adjust.AddDevice(deviceNRI)
l.WithField("device", d.Path).Info("Injected device")
}
return adjust, nil, nil
}