forked from liangrog/admission-webhook-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 924 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"log"
"net/http"
"path/filepath"
"github.com/liangrog/admission-webhook-server/pkg/admission/podnodesselector"
"github.com/liangrog/admission-webhook-server/pkg/utils"
)
// TLS secrets
const (
tlsDir = `/run/secrets/tls`
tlsCert = `tls.crt`
tlsKey = `tls.key`
)
// Port to listen to
const (
ENV_LISTEN_PORT = "LISTEN_PORT"
listenPort = ":8443"
)
func main() {
cert := filepath.Join(tlsDir, tlsCert)
key := filepath.Join(tlsDir, tlsKey)
mux := http.NewServeMux()
log.Print("Registering handlers...")
registerAllHandlers(mux)
// Config server
server := &http.Server{
Addr: utils.GetEnvVal(ENV_LISTEN_PORT, listenPort),
Handler: mux,
}
// Serve
log.Print("Starting admission webhook server...")
log.Fatal(server.ListenAndServeTLS(cert, key))
}
// Register all admission handlers
func registerAllHandlers(mux *http.ServeMux) {
podnodesselector.Register(mux)
}