Skip to content

Instantly share code, notes, and snippets.

@Savemech
Forked from treacher/main.go
Created October 15, 2017 20:11
Show Gist options
  • Save Savemech/7e725a9f00013fa0d3366741fbcd12f8 to your computer and use it in GitHub Desktop.
Save Savemech/7e725a9f00013fa0d3366741fbcd12f8 to your computer and use it in GitHub Desktop.
kubernetes-namespace-rolebinding-operator-main
func main() {
// Set logging output to standard console out
log.SetOutput(os.Stdout)
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.")
flag.Parse()
// Create clientset for interacting with the kubernetes cluster
clientset, err := newClientSet(*runOutsideCluster)
if err != nil {
panic(err.Error())
}
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