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"
|
|
|
|
|
|
|
|
"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-08-12 04:15:26 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/alertwebhook"
|
2021-11-30 12:50:34 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/autosizednodes"
|
2021-08-23 14:23:37 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/banner"
|
2022-12-09 19:56:39 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/clusterdnschecker"
|
2022-12-14 17:42:37 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/ingresscertificatechecker"
|
2022-12-05 17:49:22 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/internetchecker"
|
2022-12-07 19:36:08 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/serviceprincipalchecker"
|
2023-08-28 16:51:49 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/cloudproviderconfig"
|
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"
|
2022-10-17 01:35:52 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/guardrails"
|
2021-09-25 06:01:46 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/imageconfig"
|
2022-11-03 03:13:29 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/ingress"
|
2021-05-12 21:47:21 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/machine"
|
2022-04-05 15:46:47 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/machinehealthcheck"
|
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-11-18 08:21:50 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/muo"
|
2021-03-03 21:45:55 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/node"
|
2021-08-12 18:47:46 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/previewfeature"
|
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-09-10 14:02:13 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/storageaccounts"
|
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
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:15:53 +03:00
|
|
|
client := mgr.GetClient()
|
|
|
|
|
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-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(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", genevalogging.ControllerName),
|
2023-02-14 19:13:38 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", genevalogging.ControllerName, err)
|
2020-07-28 12:51:01 +03:00
|
|
|
}
|
2021-02-22 14:11:44 +03:00
|
|
|
if err = (clusteroperatoraro.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", clusteroperatoraro.ControllerName),
|
2023-01-13 19:35:23 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", clusteroperatoraro.ControllerName, err)
|
2021-02-22 14:11:44 +03:00
|
|
|
}
|
2020-08-12 04:15:26 +03:00
|
|
|
if err = (pullsecret.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", pullsecret.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", pullsecret.ControllerName, err)
|
2020-07-28 12:51:01 +03:00
|
|
|
}
|
2020-08-12 04:15:26 +03:00
|
|
|
if err = (alertwebhook.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", alertwebhook.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", alertwebhook.ControllerName, err)
|
2020-07-28 12:51:01 +03:00
|
|
|
}
|
2020-08-20 09:02:11 +03:00
|
|
|
if err = (workaround.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", workaround.ControllerName),
|
2023-02-14 18:04:34 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", workaround.ControllerName, err)
|
2020-08-20 09:02:11 +03:00
|
|
|
}
|
2020-11-12 21:22:57 +03:00
|
|
|
if err = (routefix.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", routefix.ControllerName),
|
2023-02-14 19:13:38 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", routefix.ControllerName, err)
|
2020-11-12 21:22:57 +03:00
|
|
|
}
|
2020-11-10 04:47:59 +03:00
|
|
|
if err = (monitoring.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", monitoring.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", monitoring.ControllerName, err)
|
2020-11-10 04:47:59 +03:00
|
|
|
}
|
2020-10-03 00:42:23 +03:00
|
|
|
if err = (rbac.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", rbac.ControllerName),
|
2023-01-17 17:15:53 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", rbac.ControllerName, err)
|
2020-10-03 00:42:23 +03:00
|
|
|
}
|
2021-02-19 04:34:39 +03:00
|
|
|
if err = (dnsmasq.NewClusterReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", dnsmasq.ClusterControllerName),
|
2023-02-08 19:36:31 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", dnsmasq.ClusterControllerName, err)
|
2021-02-19 04:34:39 +03:00
|
|
|
}
|
|
|
|
if err = (dnsmasq.NewMachineConfigReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", dnsmasq.MachineConfigControllerName),
|
2023-02-08 19:36:31 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", dnsmasq.MachineConfigControllerName, err)
|
2021-02-19 04:34:39 +03:00
|
|
|
}
|
|
|
|
if err = (dnsmasq.NewMachineConfigPoolReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", dnsmasq.MachineConfigPoolControllerName),
|
2023-02-08 19:36:31 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", dnsmasq.MachineConfigPoolControllerName, err)
|
2021-02-19 04:34:39 +03:00
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
if err = (node.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", node.ControllerName),
|
2023-01-17 17:15:53 +03:00
|
|
|
client, kubernetescli)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", node.ControllerName, err)
|
2021-03-03 21:45:55 +03:00
|
|
|
}
|
2021-08-09 09:40:23 +03:00
|
|
|
if err = (subnets.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", subnets.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", subnets.ControllerName, err)
|
2021-03-31 14:09:25 +03:00
|
|
|
}
|
2021-07-13 17:21:58 +03:00
|
|
|
if err = (machine.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", machine.ControllerName),
|
2023-01-18 19:42:22 +03:00
|
|
|
client, isLocalDevelopmentMode, role)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", machine.ControllerName, err)
|
2021-05-12 21:47:21 +03:00
|
|
|
}
|
2021-08-23 14:23:37 +03:00
|
|
|
if err = (banner.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", banner.ControllerName),
|
2023-01-17 17:15:53 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", banner.ControllerName, err)
|
2021-08-23 14:23:37 +03:00
|
|
|
}
|
2021-08-06 01:16:55 +03:00
|
|
|
if err = (machineset.NewReconciler(
|
2023-01-18 19:42:22 +03:00
|
|
|
log.WithField("controller", machineset.ControllerName), client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", machineset.ControllerName, err)
|
2021-08-06 01:16:55 +03:00
|
|
|
}
|
2022-12-06 19:57:02 +03:00
|
|
|
if err = (imageconfig.NewReconciler(
|
|
|
|
log.WithField("controller", imageconfig.ControllerName),
|
2023-01-13 19:35:23 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", imageconfig.ControllerName, err)
|
2021-11-26 17:58:55 +03:00
|
|
|
}
|
2021-08-12 18:47:46 +03:00
|
|
|
if err = (previewfeature.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", previewfeature.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", previewfeature.ControllerName, err)
|
2021-09-25 06:01:46 +03:00
|
|
|
}
|
2021-09-10 14:02:13 +03:00
|
|
|
if err = (storageaccounts.NewReconciler(
|
2022-01-31 18:32:08 +03:00
|
|
|
log.WithField("controller", storageaccounts.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", storageaccounts.ControllerName, err)
|
2021-09-10 14:02:13 +03:00
|
|
|
}
|
2022-12-06 19:57:02 +03:00
|
|
|
if err = (muo.NewReconciler(
|
|
|
|
log.WithField("controller", muo.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-01-31 18:32:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", muo.ControllerName, err)
|
2021-11-18 08:21:50 +03:00
|
|
|
}
|
2021-11-30 12:50:34 +03:00
|
|
|
if err = (autosizednodes.NewReconciler(
|
|
|
|
log.WithField("controller", autosizednodes.ControllerName),
|
2023-01-17 17:15:53 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2021-11-30 12:50:34 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", autosizednodes.ControllerName, err)
|
|
|
|
}
|
2022-04-05 15:46:47 +03:00
|
|
|
if err = (machinehealthcheck.NewReconciler(
|
2022-12-06 19:57:02 +03:00
|
|
|
log.WithField("controller", machinehealthcheck.ControllerName),
|
2023-01-17 17:15:53 +03:00
|
|
|
client, dh)).SetupWithManager(mgr); err != nil {
|
2022-04-05 15:46:47 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", machinehealthcheck.ControllerName, err)
|
|
|
|
}
|
2022-11-03 03:13:29 +03:00
|
|
|
if err = (ingress.NewReconciler(
|
|
|
|
log.WithField("controller", ingress.ControllerName),
|
2023-01-17 19:22:57 +03:00
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
2022-11-03 03:13:29 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", ingress.ControllerName, err)
|
|
|
|
}
|
2022-12-07 19:36:08 +03:00
|
|
|
if err = (serviceprincipalchecker.NewReconciler(
|
|
|
|
log.WithField("controller", serviceprincipalchecker.ControllerName),
|
2023-02-10 13:17:32 +03:00
|
|
|
client, role)).SetupWithManager(mgr); err != nil {
|
2022-12-07 19:36:08 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", serviceprincipalchecker.ControllerName, err)
|
|
|
|
}
|
2022-12-09 19:56:39 +03:00
|
|
|
if err = (clusterdnschecker.NewReconciler(
|
|
|
|
log.WithField("controller", clusterdnschecker.ControllerName),
|
2023-01-17 19:22:57 +03:00
|
|
|
client, role)).SetupWithManager(mgr); err != nil {
|
2022-12-09 19:56:39 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", clusterdnschecker.ControllerName, err)
|
|
|
|
}
|
2022-12-14 17:42:37 +03:00
|
|
|
if err = (ingresscertificatechecker.NewReconciler(
|
|
|
|
log.WithField("controller", ingresscertificatechecker.ControllerName),
|
2023-01-17 19:22:57 +03:00
|
|
|
client, role)).SetupWithManager(mgr); err != nil {
|
2022-12-14 17:42:37 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", ingresscertificatechecker.ControllerName, err)
|
|
|
|
}
|
2023-02-28 04:29:32 +03:00
|
|
|
if err = (guardrails.NewReconciler(
|
|
|
|
log.WithField("controller", guardrails.ControllerName),
|
2023-12-21 06:45:41 +03:00
|
|
|
client, dh, kubernetescli)).SetupWithManager(mgr); err != nil {
|
2022-10-17 01:35:52 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", guardrails.ControllerName, err)
|
|
|
|
}
|
2023-08-28 16:51:49 +03:00
|
|
|
if err = (cloudproviderconfig.NewReconciler(
|
|
|
|
log.WithField("controller", cloudproviderconfig.ControllerName),
|
|
|
|
client)).SetupWithManager(mgr); err != nil {
|
|
|
|
return fmt.Errorf("unable to create controller %s: %v", cloudproviderconfig.ControllerName, err)
|
|
|
|
}
|
2020-07-28 12:51:01 +03:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:49:22 +03:00
|
|
|
if err = (internetchecker.NewReconciler(
|
2023-01-17 17:15:53 +03:00
|
|
|
log.WithField("controller", internetchecker.ControllerName),
|
|
|
|
client, role)).SetupWithManager(mgr); err != nil {
|
2022-12-05 17:49:22 +03:00
|
|
|
return fmt.Errorf("unable to create controller %s: %v", internetchecker.ControllerName, 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())
|
|
|
|
}
|