-
Notifications
You must be signed in to change notification settings - Fork 81
/
main.go
59 lines (49 loc) · 1.48 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"os"
validation_webhook "github.com/openshift-pipelines/pipelines-as-code/pkg/webhook"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
"knative.dev/pkg/webhook"
"knative.dev/pkg/webhook/certificates"
)
func main() {
ctx := signals.NewContext()
serviceName := os.Getenv("WEBHOOK_SERVICE_NAME")
if serviceName == "" {
serviceName = "pipelines-as-code-webhook"
}
secretName := os.Getenv("WEBHOOK_SECRET_NAME")
if secretName == "" {
secretName = "pipelines-as-code-webhook-certs"
}
// Set up a signal context with our webhook options
ctx = webhook.WithOptions(ctx, webhook.Options{
ServiceName: serviceName,
Port: 8443,
SecretName: secretName,
})
sharedmain.WebhookMainWithConfig(ctx, "pipelines-as-code-webhook",
injection.ParseAndGetRESTConfigOrDie(),
certificates.NewController,
newValidationAdmissionController,
)
}
func newValidationAdmissionController(ctx context.Context, _ configmap.Watcher) *controller.Impl {
return validation_webhook.NewAdmissionController(ctx,
// Name of the resource webhook.
"validation.pipelinesascode.tekton.dev",
// The path on which to serve the webhook.
"/validate",
// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
return ctx
},
// Whether to disallow unknown fields.
true,
)
}