Skip to content

Instantly share code, notes, and snippets.

@treacher
Last active October 15, 2017 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save treacher/f43489316983015423b2d15ddb1cf4d0 to your computer and use it in GitHub Desktop.
Save treacher/f43489316983015423b2d15ddb1cf4d0 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