-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (55 loc) · 1.83 KB
/
Copy pathmain.go
File metadata and controls
69 lines (55 loc) · 1.83 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"context"
"errors"
"net/http"
"os"
"time"
"github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/hetzner/cert-manager-webhook-hetzner/internal/hetzner"
"github.com/hetzner/cert-manager-webhook-hetzner/internal/version"
)
func main() {
logger := newLogger()
groupName, ok := os.LookupEnv("GROUP_NAME")
if !ok || groupName == "" {
logger.Error("GROUP_NAME must be specified")
os.Exit(1)
}
logger.Info("starting webhook", "version", version.Version)
registry := prometheus.NewRegistry()
registry.MustRegister(collectors.NewBuildInfoCollector())
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{Registry: registry}))
server := &http.Server{
Addr: ":8080",
Handler: mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
}
go func() {
logger.Info("starting metrics server", "addr", server.Addr)
err := server.ListenAndServe()
if err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error(err.Error())
os.Exit(1)
}
}()
// This will register our custom DNS provider with the webhook serving
// library, making it available as an API under the provided GroupName.
// You can register multiple DNS provider implementations with a single
// webhook, where the Name() method will be used to disambiguate between
// the different implementations.
cmd.RunWebhookServer(groupName, hetzner.New(logger, registry))
{
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
logger.Info("shutting down metrics server")
if err := server.Shutdown(ctx); err != nil {
logger.Error(err.Error())
}
cancel()
}
}