Skip to content

Commit

Permalink
make shutdown endpoint optional via CLI flag.
Browse files Browse the repository at this point in the history
this change adds a new CLI flag, which allows the `/quitquitquit`
endpoint to be replaced with a noop action instead of the default
"shutdown the application" behaviour.

for backwards compatibility, the endpoint remains armed by default.

closes planetlabs#46
  • Loading branch information
UiP9AV6Y committed Jan 26, 2022
1 parent 75b0795 commit 1f4e44e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/kubehook/kubehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func main() {
app = kingpin.New(filepath.Base(os.Args[0]), "Authenticates Kubernetes users via JWT tokens.").DefaultEnvars()
listen = app.Flag("listen", "Address at which to expose HTTP webhook.").Default(":10003").String()
debug = app.Flag("debug", "Run with debug logging.").Short('d').Bool()
term = app.Flag("shutdown-handler", "Provide endpoint to shutdown the service.").Short('S').Default("true").Bool()
grace = app.Flag("shutdown-grace-period", "Wait this long for sessions to end before shutting down.").Default("1m").Duration()
audience = app.Flag("audience", "Audience for JWT HMAC creation and verification.").Default(jwt.DefaultAudience).String()
userHeader = app.Flag("user-header", "HTTP header specifying the authenticated user sending a token generation request.").Default(handlers.DefaultUserHeader).String()
Expand Down Expand Up @@ -186,9 +187,14 @@ func main() {
r.HandlerFunc("GET", "/", handlers.Content(index, filepath.Base(indexPath)))
r.HandlerFunc("POST", "/generate", generate.Handler(m, h))
r.HandlerFunc("POST", "/authenticate", authenticate.Handler(m))
r.HandlerFunc("GET", "/quitquitquit", handlers.Run(shutdown))
r.HandlerFunc("GET", "/healthz", handlers.Ping())

if *term {
r.HandlerFunc("GET", "/quitquitquit", handlers.Run(shutdown))
} else {
r.HandlerFunc("GET", "/quitquitquit", handlers.NotImplemented())
}

if *template != "" {
t, err := kubecfg.LoadTemplate(*template)
kingpin.FatalIfError(err, "cannot load kubeconfig template")
Expand Down

0 comments on commit 1f4e44e

Please sign in to comment.