ARO-RP/cmd/aro/operator.go

182 строки
6.4 KiB
Go
Исходник Обычный вид История

package main
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"flag"
"fmt"
"net"
"net/http"
configclient "github.com/openshift/client-go/config/clientset/versioned"
securityclient "github.com/openshift/client-go/security/clientset/versioned"
maoclient "github.com/openshift/machine-api-operator/pkg/generated/clientset/versioned"
mcoclient "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/Azure/ARO-RP/pkg/env"
pkgoperator "github.com/Azure/ARO-RP/pkg/operator"
2020-12-17 14:41:59 +03:00
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
"github.com/Azure/ARO-RP/pkg/operator/controllers"
"github.com/Azure/ARO-RP/pkg/operator/controllers/alertwebhook"
2020-07-24 09:31:45 +03:00
"github.com/Azure/ARO-RP/pkg/operator/controllers/checker"
2021-02-22 14:11:44 +03:00
"github.com/Azure/ARO-RP/pkg/operator/controllers/clusteroperatoraro"
2021-02-19 04:34:39 +03:00
"github.com/Azure/ARO-RP/pkg/operator/controllers/dnsmasq"
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
"github.com/Azure/ARO-RP/pkg/operator/controllers/monitoring"
2021-03-03 21:45:55 +03:00
"github.com/Azure/ARO-RP/pkg/operator/controllers/node"
"github.com/Azure/ARO-RP/pkg/operator/controllers/pullsecret"
"github.com/Azure/ARO-RP/pkg/operator/controllers/rbac"
2020-11-12 21:22:57 +03:00
"github.com/Azure/ARO-RP/pkg/operator/controllers/routefix"
"github.com/Azure/ARO-RP/pkg/operator/controllers/workaround"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
utillog "github.com/Azure/ARO-RP/pkg/util/log"
// +kubebuilder:scaffold:imports
)
func operator(ctx context.Context, log *logrus.Entry) error {
role := flag.Arg(1)
switch role {
case pkgoperator.RoleMaster, pkgoperator.RoleWorker:
default:
return fmt.Errorf("invalid role %s", role)
}
isLocalDevelopmentMode := env.IsLocalDevelopmentMode()
if isLocalDevelopmentMode {
log.Info("running in local development mode")
}
ctrl.SetLogger(utillog.LogrWrapper(log))
restConfig, err := ctrl.GetConfig()
if err != nil {
return err
}
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
MetricsBindAddress: "0", // disabled
Port: 8443,
})
if err != nil {
return err
}
kubernetescli, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return err
}
securitycli, err := securityclient.NewForConfig(restConfig)
if err != nil {
return err
}
configcli, err := configclient.NewForConfig(restConfig)
if err != nil {
return err
}
maocli, err := maoclient.NewForConfig(restConfig)
2020-07-24 09:31:45 +03:00
if err != nil {
return err
}
mcocli, err := mcoclient.NewForConfig(restConfig)
if err != nil {
return err
}
arocli, err := aroclient.NewForConfig(restConfig)
if err != nil {
return err
}
dh, err := dynamichelper.New(log, restConfig)
if err != nil {
return err
}
if role == pkgoperator.RoleMaster {
if err = (genevalogging.NewReconciler(
log.WithField("controller", controllers.GenevaLoggingControllerName),
kubernetescli, securitycli, arocli,
restConfig)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller Genevalogging: %v", err)
}
2021-02-22 14:11:44 +03:00
if err = (clusteroperatoraro.NewReconciler(
log.WithField("controller", controllers.ClusterOperatorAROName),
arocli, configcli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller ClusterOperatorARO: %v", err)
}
if err = (pullsecret.NewReconciler(
log.WithField("controller", controllers.PullSecretControllerName),
kubernetescli, arocli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller PullSecret: %v", err)
}
if err = (alertwebhook.NewReconciler(
log.WithField("controller", controllers.AlertwebhookControllerName),
kubernetescli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller AlertWebhook: %v", err)
}
if err = (workaround.NewReconciler(
log.WithField("controller", controllers.WorkaroundControllerName),
2020-08-27 09:45:19 +03:00
kubernetescli, configcli, mcocli, arocli, restConfig)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller Workaround: %v", err)
}
2020-11-12 21:22:57 +03:00
if err = (routefix.NewReconciler(
log.WithField("controller", controllers.RouteFixControllerName),
kubernetescli, securitycli, arocli, restConfig)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller RouteFix: %v", err)
}
if err = (monitoring.NewReconciler(
log.WithField("controller", controllers.MonitoringControllerName),
2020-12-17 14:41:59 +03:00
kubernetescli, arocli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller Monitoring: %v", err)
}
if err = (rbac.NewReconciler(
log.WithField("controller", controllers.RBACControllerName),
arocli, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller RBAC: %v", err)
}
2021-02-19 04:34:39 +03:00
if err = (dnsmasq.NewClusterReconciler(
log.WithField("controller", controllers.DnsmasqClusterControllerName),
arocli, mcocli, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller DnsmasqCluster: %v", err)
}
if err = (dnsmasq.NewMachineConfigReconciler(
log.WithField("controller", controllers.DnsmasqMachineConfigControllerName),
arocli, mcocli, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller DnsmasqMachineConfig: %v", err)
}
if err = (dnsmasq.NewMachineConfigPoolReconciler(
log.WithField("controller", controllers.DnsmasqMachineConfigPoolControllerName),
arocli, mcocli, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller DnsmasqMachineConfigPool: %v", err)
}
2021-03-03 21:45:55 +03:00
if err = (node.NewNodeReconciler(
log.WithField("controller", controllers.NodeControllerName),
kubernetescli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller Node: %v", err)
}
}
2020-07-24 09:31:45 +03:00
if err = (checker.NewReconciler(
log.WithField("controller", controllers.CheckerControllerName),
maocli, arocli, kubernetescli, role, isLocalDevelopmentMode)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller InternetChecker: %v", err)
}
2020-11-12 21:22:57 +03:00
// +kubebuilder:scaffold:builder
log.Info("starting manager")
l, err := net.Listen("tcp", ":8080")
if err != nil {
return err
}
go func() {
_ = http.Serve(l, http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
}()
return mgr.Start(ctrl.SetupSignalHandler())
}