func main()

in cmd/metadata_prefetch/main.go [35:83]


func main() {
	klog.InitFlags(nil)
	flag.Parse()

	// Create cancellable context to pass into exec.
	ctx, cancel := context.WithCancel(context.Background())

	// Handle SIGTERM signal.
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGTERM)

	go func() {
		<-sigs
		klog.Info("Caught SIGTERM signal: Terminating...")
		cancel()

		os.Exit(0) // Exit gracefully
	}()

	// Start the "ls" command in the background.
	// All our volumes are mounted under the /volumes/ directory.
	cmd := exec.CommandContext(ctx, "ls", "-R", mountPathsLocation)
	cmd.Stdout = nil // Connects file descriptor to the null device (os.DevNull).

	// TODO(hime): We should research stratergies to parallelize ls execution and speed up cache population.
	err := cmd.Start()
	if err == nil {
		mountPaths, err := getDirectoryNames(mountPathsLocation)
		if err == nil {
			klog.Infof("Running ls on mountPath(s): %s", strings.Join(mountPaths, ", "))
		} else {
			klog.Warningf("failed to get mountPaths: %v", err)
		}

		err = cmd.Wait()
		if err != nil {
			klog.Errorf("Error while executing ls command: %v", err)
		} else {
			klog.Info("Metadata prefetch complete")
		}
	} else {
		klog.Errorf("Error starting ls command: %v.", err)
	}

	klog.Info("Going to sleep...")

	// Keep the process running.
	select {}
}