Run is the entry point of that package execution
(ctx context.Context, context *clusterd.Context, probeInterval time.Duration, useCV bool)
| 75 | |
| 76 | // Run is the entry point of that package execution |
| 77 | func Run(ctx context.Context, context *clusterd.Context, probeInterval time.Duration, useCV bool) error { |
| 78 | if context == nil { |
| 79 | return fmt.Errorf("nil context") |
| 80 | } |
| 81 | logger.Debugf("device discovery interval is %q", probeInterval.String()) |
| 82 | logger.Debugf("use ceph-volume inventory is %t", useCV) |
| 83 | nodeName = os.Getenv(k8sutil.NodeNameEnvVar) |
| 84 | namespace = os.Getenv(k8sutil.PodNamespaceEnvVar) |
| 85 | cmName = k8sutil.TruncateNodeName(LocalDiskCMName, nodeName) |
| 86 | useCVInventory = useCV |
| 87 | sigc := make(chan os.Signal, 1) |
| 88 | signal.Notify(sigc, syscall.SIGTERM) |
| 89 | |
| 90 | err := updateDeviceCM(ctx, context) |
| 91 | if err != nil { |
| 92 | logger.Infof("failed to update device configmap: %v", err) |
| 93 | return err |
| 94 | } |
| 95 | |
| 96 | udevEvents := make(chan struct{}) |
| 97 | go udevBlockMonitor(udevEvents, udevEventPeriod) |
| 98 | for { |
| 99 | select { |
| 100 | case <-sigc: |
| 101 | logger.Infof("shutdown signal received, exiting...") |
| 102 | return nil |
| 103 | case <-time.After(probeInterval): |
| 104 | if err := updateDeviceCM(ctx, context); err != nil { |
| 105 | logger.Errorf("failed to update device configmap during probe interval. %v", err) |
| 106 | } |
| 107 | case _, ok := <-udevEvents: |
| 108 | if ok { |
| 109 | logger.Info("trigger probe from udev event") |
| 110 | if err := updateDeviceCM(ctx, context); err != nil { |
| 111 | logger.Errorf("failed to update device configmap triggered from udev event. %v", err) |
| 112 | } |
| 113 | } else { |
| 114 | logger.Warningf("disabling udev monitoring") |
| 115 | udevEvents = nil |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func matchUdevEvent(text string, matches, exclusions []string) (bool, error) { |
| 122 | for _, match := range matches { |
no test coverage detected