|
| 1 | +/* |
| 2 | +Copyright 2018 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/manager" |
| 25 | + logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" |
| 26 | + "sigs.k8s.io/controller-runtime/pkg/runtime/signals" |
| 27 | + "sigs.k8s.io/kubebuilder/test/project/pkg/apis" |
| 28 | + "sigs.k8s.io/kubebuilder/test/project/pkg/controller" |
| 29 | + "sigs.k8s.io/kubebuilder/test/project/pkg/webhook" |
| 30 | +) |
| 31 | + |
| 32 | +func main() { |
| 33 | + logf.SetLogger(logf.ZapLogger(false)) |
| 34 | + log := logf.Log.WithName("entrypoint") |
| 35 | + |
| 36 | + // Get a config to talk to the apiserver |
| 37 | + log.Info("setting up client for manager") |
| 38 | + cfg, err := config.GetConfig() |
| 39 | + if err != nil { |
| 40 | + log.Error(err, "unable to set up client config") |
| 41 | + os.Exit(1) |
| 42 | + } |
| 43 | + |
| 44 | + // Create a new Cmd to provide shared dependencies and start components |
| 45 | + log.Info("setting up manager") |
| 46 | + mgr, err := manager.New(cfg, manager.Options{}) |
| 47 | + if err != nil { |
| 48 | + log.Error(err, "unable to set up overall controller manager") |
| 49 | + os.Exit(1) |
| 50 | + } |
| 51 | + |
| 52 | + log.Info("Registering Components.") |
| 53 | + |
| 54 | + // Setup Scheme for all resources |
| 55 | + log.Info("setting up scheme") |
| 56 | + if err := apis.AddToScheme(mgr.GetScheme()); err != nil { |
| 57 | + log.Error(err, "unable add APIs to scheme") |
| 58 | + os.Exit(1) |
| 59 | + } |
| 60 | + |
| 61 | + // Setup all Controllers |
| 62 | + log.Info("Setting up controller") |
| 63 | + if err := controller.AddToManager(mgr); err != nil { |
| 64 | + log.Error(err, "unable to register controllers to the manager") |
| 65 | + os.Exit(1) |
| 66 | + } |
| 67 | + |
| 68 | + log.Info("setting up webhooks") |
| 69 | + if err := webhook.AddToManager(mgr); err != nil { |
| 70 | + log.Error(err, "unable to register webhooks to the manager") |
| 71 | + os.Exit(1) |
| 72 | + } |
| 73 | + |
| 74 | + // Start the Cmd |
| 75 | + log.Info("Starting the Cmd.") |
| 76 | + if err := mgr.Start(signals.SetupSignalHandler()); err != nil { |
| 77 | + log.Error(err, "unable to run the manager") |
| 78 | + os.Exit(1) |
| 79 | + } |
| 80 | +} |
0 commit comments