mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00

* Move CRDS from apiextensions v1beta1 to v1. Ensure that our code based schema validation matches the types in the api. Signed-off-by: Alexander Wels <awels@redhat.com> * Ran go mod tidy and vendor in attempt to see if we could use newer runtime controller, but our go version too old. Addressed review comments. Signed-off-by: Alexander Wels <awels@redhat.com> * Addressed more review comments and fixed k8s-1.18 functional test failing. Signed-off-by: Alexander Wels <awels@redhat.com> * Remove categories 'all' from cluster scoped CRDs Signed-off-by: Alexander Wels <awels@redhat.com>
121 lines
3.1 KiB
Go
121 lines
3.1 KiB
Go
/*
|
|
Copyright 2018 The CDI Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
|
|
routev1 "github.com/openshift/api/route/v1"
|
|
secv1 "github.com/openshift/api/security/v1"
|
|
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
apiregistrationv1beta1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
|
|
"sigs.k8s.io/controller-runtime/pkg/client/config"
|
|
"sigs.k8s.io/controller-runtime/pkg/manager"
|
|
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
|
|
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
|
|
|
|
cdiv1 "kubevirt.io/containerized-data-importer/pkg/apis/core/v1beta1"
|
|
"kubevirt.io/containerized-data-importer/pkg/operator/controller"
|
|
"kubevirt.io/containerized-data-importer/pkg/util"
|
|
)
|
|
|
|
var log = logf.Log.WithName("cmd")
|
|
|
|
func printVersion() {
|
|
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
|
|
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
// The logger instantiated here can be changed to any logger
|
|
// implementing the logr.Logger interface. This logger will
|
|
// be propagated through the whole operator, generating
|
|
// uniform and structured logs.
|
|
logf.SetLogger(logf.ZapLogger(false))
|
|
|
|
printVersion()
|
|
|
|
namespace := util.GetNamespace()
|
|
|
|
// Get a config to talk to the apiserver
|
|
cfg, err := config.GetConfig()
|
|
if err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
managerOpts := manager.Options{
|
|
Namespace: namespace,
|
|
LeaderElection: true,
|
|
LeaderElectionNamespace: namespace,
|
|
LeaderElectionID: "cdi-operator-leader-election-helper",
|
|
}
|
|
|
|
// Create a new Manager to provide shared dependencies and start components
|
|
mgr, err := manager.New(cfg, managerOpts)
|
|
if err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
log.Info("Registering Components.")
|
|
|
|
if err := cdiv1.AddToScheme(mgr.GetScheme()); err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err := extv1.AddToScheme(mgr.GetScheme()); err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err := apiregistrationv1beta1.AddToScheme(mgr.GetScheme()); err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err := secv1.Install(mgr.GetScheme()); err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err := routev1.Install(mgr.GetScheme()); err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Setup the controller
|
|
if err := controller.Add(mgr); err != nil {
|
|
log.Error(err, "")
|
|
os.Exit(1)
|
|
}
|
|
|
|
log.Info("Starting the Manager.")
|
|
|
|
// Start the Manager
|
|
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
|
|
log.Error(err, "manager exited non-zero")
|
|
os.Exit(1)
|
|
}
|
|
}
|