Skip to content

Instantly share code, notes, and snippets.

@treacher treacher/main.go
Last active Oct 15, 2017

What would you like to do?
func main() {
// Set logging output to standard console out
sigs := make(chan os.Signal, 1) // Create channel to receive OS signals
stop := make(chan struct{}) // Create channel to receive stop signal
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) // Register the sigs channel to receieve SIGTERM
wg := &sync.WaitGroup{} // Goroutines can add themselves to this to be waited on so that they finish
runOutsideCluster := flag.Bool("run-outside-cluster", false, "Set this flag when running outside of the cluster.")
// Create clientset for interacting with the kubernetes cluster
clientset, err := newClientSet(*runOutsideCluster)
if err != nil {
controller.NewNamespaceController(clientset).Run(stop, wg)
<-sigs // Wait for signals (this hangs until a signal arrives)
log.Printf("Shutting down...")
close(stop) // Tell goroutines to stop themselves
wg.Wait() // Wait for all to be stopped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.