|
| 1 | +/* |
| 2 | +Copyright 2021 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "os" |
| 21 | + |
| 22 | + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" |
| 23 | + "sigs.k8s.io/controller-runtime/pkg/client/config" |
| 24 | + "sigs.k8s.io/controller-runtime/pkg/log" |
| 25 | + "sigs.k8s.io/controller-runtime/pkg/log/zap" |
| 26 | + "sigs.k8s.io/controller-runtime/pkg/manager" |
| 27 | + "sigs.k8s.io/controller-runtime/pkg/manager/signals" |
| 28 | + "sigs.k8s.io/controller-runtime/pkg/webhook/authorization" |
| 29 | +) |
| 30 | + |
| 31 | +func init() { |
| 32 | + log.SetLogger(zap.New()) |
| 33 | +} |
| 34 | + |
| 35 | +func main() { |
| 36 | + entryLog := log.Log.WithName("entrypoint") |
| 37 | + |
| 38 | + // Setup a Manager |
| 39 | + entryLog.Info("setting up manager") |
| 40 | + mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{}) |
| 41 | + if err != nil { |
| 42 | + entryLog.Error(err, "unable to set up overall controller manager") |
| 43 | + os.Exit(1) |
| 44 | + } |
| 45 | + |
| 46 | + // Setup webhooks |
| 47 | + entryLog.Info("setting up webhook server") |
| 48 | + hookServer := mgr.GetWebhookServer() |
| 49 | + |
| 50 | + entryLog.Info("registering webhooks to the webhook server") |
| 51 | + hookServer.Register("/validate-v1-subjectaccessreview", &authorization.Webhook{Handler: &authorizer{}}) |
| 52 | + |
| 53 | + entryLog.Info("starting manager") |
| 54 | + if err := mgr.Start(signals.SetupSignalHandler()); err != nil { |
| 55 | + entryLog.Error(err, "unable to run manager") |
| 56 | + os.Exit(1) |
| 57 | + } |
| 58 | +} |
0 commit comments