func (discovery *DeviceDiscovery) Start() error {
	klog.Info("starting device discovery")
	err := discovery.ensureDiscoveryResultCR()
	if err != nil {
		message := "failed to start device discovery"
		e := diskmaker.NewEvent(diskmaker.ErrorCreatingDiscoveryResultObject, fmt.Sprintf("%s. Error: %+v", message, err), "")
		discovery.eventSync.Report(e, discovery.localVolumeDiscovery)
		return errors.Wrapf(err, message)
	}

	err = discovery.discoverDevices()
	if err != nil {
		errors.Wrapf(err, "failed to discover devices")
	}

	// Watch udev events for continuous discovery of devices
	sigc := make(chan os.Signal, 1)
	signal.Notify(sigc, syscall.SIGTERM)

	udevEvents := make(chan string)
	go udevBlockMonitor(udevEvents, udevEventPeriod)
	for {
		select {
		case <-sigc:
			klog.Info("shutdown signal received, exiting...")
			return nil
		case <-time.After(probeInterval):
			if err := discovery.discoverDevices(); err != nil {
				klog.Errorf("failed to discover devices during probe interval. %v", err)
			}
		case _, ok := <-udevEvents:
			if ok {
				klog.Info("trigger probe from udev event")
				if err := discovery.discoverDevices(); err != nil {
					klog.Errorf("failed to discover devices triggered from udev event. %v", err)
				}
			} else {
				klog.Warningf("disabling udev monitoring")
				udevEvents = nil
			}
		}
	}
}
// Start the device discovery process
Start the device discovery process
// Start the device discovery process
func (discovery *DeviceDiscovery) Start() error {
	klog.Info("starting device discovery")
	err := discovery.ensureDiscoveryResultCR()
	if err != nil {
		message := "failed to start device discovery"
		e := diskmaker.NewEvent(diskmaker.ErrorCreatingDiscoveryResultObject, fmt.Sprintf("%s. Error: %+v", message, err), "")
		discovery.eventSync.Report(e, discovery.localVolumeDiscovery)
		return errors.Wrapf(err, message)
	}
	err = discovery.discoverDevices()
	if err != nil {
		errors.Wrapf(err, "failed to discover devices")
	}
	sigc := make(chan os.Signal, 1)
	signal.Notify(sigc, syscall.SIGTERM)
	udevEvents := make(chan string)
	go udevBlockMonitor(udevEvents, udevEventPeriod)
	for {
		select {
		case <-sigc:
			klog.Info("shutdown signal received, exiting...")
			return nil
		case <-time.After(probeInterval):
			if err := discovery.discoverDevices(); err != nil {
				klog.Errorf("failed to discover devices during probe interval. %v", err)
			}
		case _, ok := <-udevEvents:
			if ok {
				klog.Info("trigger probe from udev event")
				if err := discovery.discoverDevices(); err != nil {
					klog.Errorf("failed to discover devices triggered from udev event. %v", err)
				}
			} else {
				klog.Warningf("disabling udev monitoring")
				udevEvents = nil
			}
		}
	}
}
func ( discovery * DeviceDiscovery ) Start ( ) error { klog . Info ( " " ) err := discovery . ensureDiscoveryResultCR ( ) if err != nil { message := " " e := diskmaker . NewEvent ( diskmaker . ErrorCreatingDiscoveryResultObject , fmt . Sprintf ( " " , message , err ) , " " ) discovery . eventSync . Report ( e , discovery . localVolumeDiscovery ) return errors . Wrapf ( err , message ) } err = discovery . discoverDevices ( ) if err != nil { errors . Wrapf ( err , " " ) } sigc := make ( chan os . Signal , 1 ) signal . Notify ( sigc , syscall . SIGTERM ) udevEvents := make ( chan string ) go udevBlockMonitor ( udevEvents , udevEventPeriod ) for { select { case <- sigc : klog . Info ( " " ) return nil case <- time . After ( probeInterval ) : if err := discovery . discoverDevices ( ) ; err != nil { klog . Errorf ( " " , err ) } case _ , ok := <- udevEvents : if ok { klog . Info ( " " ) if err := discovery . discoverDevices ( ) ; err != nil { klog . Errorf ( " " , err ) } } else { klog . Warningf ( " " ) udevEvents = nil } } } }
Start the device discovery process
Start the device discovery process
// Watch udev events for continuous discovery of devices