2020-07-28 12:51:01 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
|
2020-08-20 09:02:11 +03:00
|
|
|
configclient "github.com/openshift/client-go/config/clientset/versioned"
|
2021-08-23 14:23:37 +03:00
|
|
|
consoleclient "github.com/openshift/client-go/console/clientset/versioned"
|
2020-07-28 12:51:01 +03:00
|
|
|
securityclient "github.com/openshift/client-go/security/clientset/versioned"
|
2020-10-31 21:53:28 +03:00
|
|
|
maoclient "github.com/openshift/machine-api-operator/pkg/generated/clientset/versioned"
|
2020-08-20 09:02:11 +03:00
|
|
|
mcoclient "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
|
2020-07-28 12:51:01 +03:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
2021-10-19 18:29:44 +03:00
|
|
|
"sigs.k8s.io/controller-runtime/pkg/healthz"
|
2020-07-28 12:51:01 +03:00
|
|
|
|
2021-03-10 05:03:57 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/env"
|
2020-07-28 12:51:01 +03:00
|
|
|
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"
|
2020-07-28 12:51:01 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers"
|
2020-08-12 04:15:26 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/alertwebhook"
|
2021-08-23 14:23:37 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/banner"
|
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"
|
2020-08-12 04:15:26 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
|
2021-09-25 06:01:46 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/imageconfig"
|
2021-05-12 21:47:21 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/machine"
|
2021-08-06 01:16:55 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/machineset"
|
2020-11-10 04:47:59 +03:00
|
|
|
"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"
|
2020-08-12 04:15:26 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/pullsecret"
|
2020-10-03 00:42:23 +03:00
|
|
|
"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"
|
2021-08-09 09:40:23 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/subnets"
|
2020-08-20 09:02:11 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/workaround"
|
2020-10-03 00:42:23 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
|
2020-07-28 12:51:01 +03:00
|
|
|
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)
|
|
|
|
}
|
2021-04-22 00:44:31 +03:00
|
|
|
isLocalDevelopmentMode := env.IsLocalDevelopmentMode()
|
|
|
|
if isLocalDevelopmentMode {
|
|
|
|
log.Info("running in local development mode")
|
2021-03-10 05:03:57 +03:00
|
|
|
}
|
2020-07-28 12:51:01 +03:00
|
|
|
|
|
|
|
ctrl.SetLogger(utillog.LogrWrapper(log))
|
|
|
|
|
|
|
|
restConfig, err := ctrl.GetConfig()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
|
2021-10-19 18:29:44 +03:00
|
|
|
HealthProbeBindAddress: ":8080",
|
|
|
|
MetricsBindAddress: "0", // disabled
|
|
|
|
Port: 8443,
|
2020-07-28 12:51:01 +03:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, err := aroclient.NewForConfig(restConfig)
|
2020-07-28 12:51:01 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
configcli, err := configclient.NewForConfig(restConfig)
|
2020-07-28 12:51:01 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-23 14:23:37 +03:00
|
|
|
consolecli, err := consoleclient.NewForConfig(restConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
kubernetescli, err := kubernetes.NewForConfig(restConfig)
|
2020-08-20 09:02:11 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-14 00:34:33 +03:00
|
|
|
maocli, err := maoclient.NewForConfig(restConfig)
|
2020-07-24 09:31:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 09:02:11 +03:00
|
|
|
mcocli, err := mcoclient.NewForConfig(restConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
securitycli, err := securityclient.NewForConfig(restConfig)
|
2020-07-28 12:51:01 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
// TODO (NE): dh is sometimes passed, sometimes created later. Can we standardize?
|
2020-10-03 00:42:23 +03:00
|
|
|
dh, err := dynamichelper.New(log, restConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-28 12:51:01 +03:00
|
|
|
|
|
|
|
if role == pkgoperator.RoleMaster {
|
2020-08-12 04:15:26 +03:00
|
|
|
if err = (genevalogging.NewReconciler(
|
2020-07-28 12:51:01 +03:00
|
|
|
log.WithField("controller", controllers.GenevaLoggingControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, kubernetescli, securitycli,
|
2020-07-28 12:51:01 +03:00
|
|
|
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)
|
|
|
|
}
|
2020-08-12 04:15:26 +03:00
|
|
|
if err = (pullsecret.NewReconciler(
|
2020-07-28 12:51:01 +03:00
|
|
|
log.WithField("controller", controllers.PullSecretControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, kubernetescli)).SetupWithManager(mgr); err != nil {
|
2020-07-28 12:51:01 +03:00
|
|
|
return fmt.Errorf("unable to create controller PullSecret: %v", err)
|
|
|
|
}
|
2020-08-12 04:15:26 +03:00
|
|
|
if err = (alertwebhook.NewReconciler(
|
2020-07-28 12:51:01 +03:00
|
|
|
log.WithField("controller", controllers.AlertwebhookControllerName),
|
2021-07-12 18:31:23 +03:00
|
|
|
arocli, kubernetescli)).SetupWithManager(mgr); err != nil {
|
2020-07-28 12:51:01 +03:00
|
|
|
return fmt.Errorf("unable to create controller AlertWebhook: %v", err)
|
|
|
|
}
|
2020-08-20 09:02:11 +03:00
|
|
|
if err = (workaround.NewReconciler(
|
|
|
|
log.WithField("controller", controllers.WorkaroundControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, configcli, kubernetescli, mcocli, restConfig)).SetupWithManager(mgr); err != nil {
|
2020-08-20 09:02:11 +03:00
|
|
|
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),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, configcli, kubernetescli, securitycli, restConfig)).SetupWithManager(mgr); err != nil {
|
2020-11-12 21:22:57 +03:00
|
|
|
return fmt.Errorf("unable to create controller RouteFix: %v", err)
|
|
|
|
}
|
2020-11-10 04:47:59 +03:00
|
|
|
if err = (monitoring.NewReconciler(
|
|
|
|
log.WithField("controller", controllers.MonitoringControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, kubernetescli)).SetupWithManager(mgr); err != nil {
|
2020-11-10 04:47:59 +03:00
|
|
|
return fmt.Errorf("unable to create controller Monitoring: %v", err)
|
|
|
|
}
|
2020-10-03 00:42:23 +03:00
|
|
|
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-07-13 17:21:58 +03:00
|
|
|
if err = (node.NewReconciler(
|
2021-03-03 21:45:55 +03:00
|
|
|
log.WithField("controller", controllers.NodeControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, kubernetescli)).SetupWithManager(mgr); err != nil {
|
2021-03-03 21:45:55 +03:00
|
|
|
return fmt.Errorf("unable to create controller Node: %v", err)
|
|
|
|
}
|
2021-08-09 09:40:23 +03:00
|
|
|
if err = (subnets.NewReconciler(
|
|
|
|
log.WithField("controller", controllers.AzureSubnetsControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, kubernetescli, maocli)).SetupWithManager(mgr); err != nil {
|
2021-08-09 09:40:23 +03:00
|
|
|
return fmt.Errorf("unable to create controller Subnets: %v", err)
|
2021-03-31 14:09:25 +03:00
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
if err = (machine.NewReconciler(
|
2021-05-12 21:47:21 +03:00
|
|
|
log.WithField("controller", controllers.MachineControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, maocli, isLocalDevelopmentMode, role)).SetupWithManager(mgr); err != nil {
|
2021-05-12 21:47:21 +03:00
|
|
|
return fmt.Errorf("unable to create controller Machine: %v", err)
|
|
|
|
}
|
2021-08-23 14:23:37 +03:00
|
|
|
if err = (banner.NewReconciler(
|
|
|
|
log.WithField("controller", controllers.BannerControllerName),
|
|
|
|
arocli, consolecli)).SetupWithManager(mgr); err != nil {
|
|
|
|
return fmt.Errorf("unable to create controller Banner: %v", err)
|
|
|
|
}
|
2021-08-06 01:16:55 +03:00
|
|
|
if err = (machineset.NewReconciler(
|
|
|
|
log.WithField("controller", controllers.MachineSetControllerName),
|
|
|
|
arocli, maocli)).SetupWithManager(mgr); err != nil {
|
|
|
|
return fmt.Errorf("unable to create controller MachineSet: %v", err)
|
|
|
|
}
|
2021-09-25 06:01:46 +03:00
|
|
|
if err = (imageconfig.NewReconciler(
|
|
|
|
arocli, configcli)).SetupWithManager(mgr); err != nil {
|
|
|
|
return fmt.Errorf("unable to create controller ImageConfig: %v", err)
|
|
|
|
}
|
2020-07-28 12:51:01 +03:00
|
|
|
}
|
|
|
|
|
2020-07-24 09:31:45 +03:00
|
|
|
if err = (checker.NewReconciler(
|
|
|
|
log.WithField("controller", controllers.CheckerControllerName),
|
2021-07-13 17:21:58 +03:00
|
|
|
arocli, kubernetescli, maocli, role)).SetupWithManager(mgr); err != nil {
|
|
|
|
return fmt.Errorf("unable to create controller Checker: %v", err)
|
2020-07-28 12:51:01 +03:00
|
|
|
}
|
2020-11-12 21:22:57 +03:00
|
|
|
|
2020-07-28 12:51:01 +03:00
|
|
|
// +kubebuilder:scaffold:builder
|
|
|
|
|
|
|
|
log.Info("starting manager")
|
2020-11-23 22:22:08 +03:00
|
|
|
|
2021-10-19 18:29:44 +03:00
|
|
|
if err := mgr.AddHealthzCheck("ready", healthz.Ping); err != nil {
|
|
|
|
log.Error(err, "unable to set up health check")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := mgr.AddReadyzCheck("ready", healthz.Ping); err != nil {
|
|
|
|
log.Error(err, "unable to set up ready check")
|
2020-11-23 22:22:08 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-28 12:51:01 +03:00
|
|
|
return mgr.Start(ctrl.SetupSignalHandler())
|
|
|
|
}
|