func Run()

in cmd/exporter/app/server.go [85:132]


func Run(cc *exporterconfig.CompletedConfig, stopCh <-chan struct{}) error {
	// Init client SDK and exporter
	apiClient := client.NewAPIClient(client.NewConfiguration())
	e, err := exporter.New(cc.ClusterClient, apiClient, cc.Recorder)
	if err != nil {
		return fmt.Errorf("new syncer: %v", err)
	}

	// Prepare the event broadcaster.
	if cc.Broadcaster != nil && cc.ClusterClient != nil {
		cc.Broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: cc.ClusterClient.CoreV1().Events("")})
	}

	// Start all informers.
	cc.ClusterInformerFactory.Start(stopCh)

	// Wait for all caches to sync before resource sync.
	cc.ClusterInformerFactory.WaitForCacheSync(stopCh)

	ctx, cancel := context.WithCancel(context.TODO())
	defer cancel()

	// Prepare a reusable runCommand function.
	run := startExporter(e, stopCh)

	go func() {
		select {
		case <-stopCh:
			cancel()
		case <-ctx.Done():
		}
	}()

	go func() {
		// start a pprof http server
		klog.Fatal(http.ListenAndServe(":6060", nil))
	}()

	go func() {
		// start a health http server.
		mux := http.NewServeMux()
		healthz.InstallHandler(mux)
		klog.Fatal(http.ListenAndServe(":8080", mux))
	}()

	run(ctx)
	return fmt.Errorf("finished without leader elect")
}