Adds debug logs to controllers

This commit is contained in:
Mikalai Radchuk 2022-12-06 16:57:02 +00:00 коммит произвёл Mikalai Radchuk
Родитель 538097085e
Коммит a928f0ea2c
26 изменённых файлов: 82 добавлений и 30 удалений

Просмотреть файл

@ -202,7 +202,9 @@ func operator(ctx context.Context, log *logrus.Entry) error {
arocli, maocli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", machineset.ControllerName, err)
}
if err = (imageconfig.NewReconciler(arocli, configcli)).SetupWithManager(mgr); err != nil {
if err = (imageconfig.NewReconciler(
log.WithField("controller", imageconfig.ControllerName),
arocli, configcli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", imageconfig.ControllerName, err)
}
if err = (previewfeature.NewReconciler(
@ -215,7 +217,9 @@ func operator(ctx context.Context, log *logrus.Entry) error {
arocli, maocli, kubernetescli, imageregistrycli)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", storageaccounts.ControllerName, err)
}
if err = (muo.NewReconciler(arocli, kubernetescli, dh)).SetupWithManager(mgr); err != nil {
if err = (muo.NewReconciler(
log.WithField("controller", muo.ControllerName),
arocli, kubernetescli, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", muo.ControllerName, err)
}
if err = (autosizednodes.NewReconciler(
@ -224,6 +228,7 @@ func operator(ctx context.Context, log *logrus.Entry) error {
return fmt.Errorf("unable to create controller %s: %v", autosizednodes.ControllerName, err)
}
if err = (machinehealthcheck.NewReconciler(
log.WithField("controller", machinehealthcheck.ControllerName),
arocli, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", machinehealthcheck.ControllerName, err)
}

Просмотреть файл

@ -55,10 +55,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
return reconcile.Result{}, r.setAlertManagerWebhook(ctx, "http://aro-operator-master.openshift-azure-operator.svc.cluster.local:8080/healthz/ready")
}
@ -117,8 +118,6 @@ func (r *Reconciler) setAlertManagerWebhook(ctx context.Context, addr string) er
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
r.log.Info("starting alertmanager sink")
isAlertManagerPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == alertManagerName.Name && o.GetNamespace() == alertManagerName.Namespace
})

Просмотреть файл

@ -8,6 +8,7 @@ import (
"context"
"testing"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
@ -146,6 +147,7 @@ func TestSetAlertManagerWebhook(t *testing.T) {
{
name: "old cluster, enabled",
reconciler: &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
kubernetescli: fake.NewSimpleClientset(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "alertmanager-main",
@ -173,6 +175,7 @@ func TestSetAlertManagerWebhook(t *testing.T) {
{
name: "new cluster, enabled",
reconciler: &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
kubernetescli: fake.NewSimpleClientset(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "alertmanager-main",
@ -200,6 +203,7 @@ func TestSetAlertManagerWebhook(t *testing.T) {
{
name: "old cluster, disabled",
reconciler: &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
kubernetescli: fake.NewSimpleClientset(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "alertmanager-main",
@ -227,6 +231,7 @@ func TestSetAlertManagerWebhook(t *testing.T) {
{
name: "new cluster, disabled",
reconciler: &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
kubernetescli: fake.NewSimpleClientset(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "alertmanager-main",

Просмотреть файл

@ -53,10 +53,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
return reconcile.Result{}, r.reconcileBanner(ctx, instance)
}

Просмотреть файл

@ -72,10 +72,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
for _, c := range r.checkers {
thisErr := c.Check(ctx)
if thisErr != nil {

Просмотреть файл

@ -54,10 +54,11 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, request ctrl.Request)
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
mcps, err := r.mcocli.MachineconfigurationV1().MachineConfigPools().List(ctx, metav1.ListOptions{})
if err != nil {
r.log.Error(err)

Просмотреть файл

@ -52,10 +52,11 @@ func (r *MachineConfigReconciler) Reconcile(ctx context.Context, request ctrl.Re
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
m := rxARODNS.FindStringSubmatch(request.Name)
if m == nil {
return reconcile.Result{}, nil

Просмотреть файл

@ -49,10 +49,11 @@ func (r *MachineConfigPoolReconciler) Reconcile(ctx context.Context, request ctr
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
_, err = r.mcocli.MachineconfigurationV1().MachineConfigPools().Get(ctx, request.Name, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return reconcile.Result{}, nil

Просмотреть файл

@ -65,10 +65,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
mysec, err := r.kubernetescli.CoreV1().Secrets(operator.Namespace).Get(ctx, operator.SecretName, metav1.GetOptions{})
if err != nil {
return reconcile.Result{}, err

Просмотреть файл

@ -12,6 +12,7 @@ import (
"github.com/Azure/go-autorest/autorest/azure"
configv1 "github.com/openshift/api/config/v1"
configclient "github.com/openshift/client-go/config/clientset/versioned"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
@ -34,12 +35,15 @@ const (
)
type Reconciler struct {
log *logrus.Entry
arocli aroclient.Interface
configcli configclient.Interface
}
func NewReconciler(arocli aroclient.Interface, configcli configclient.Interface) *Reconciler {
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, configcli configclient.Interface) *Reconciler {
return &Reconciler{
log: log,
arocli: arocli,
configcli: configcli,
}
@ -57,11 +61,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
// Check for cloud type
r.log.Debug("running")
requiredRegistries, err := GetCloudAwareRegistries(instance)
if err != nil {
// Not returning error as it will requeue again

Просмотреть файл

@ -12,6 +12,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
configclient "github.com/openshift/client-go/config/clientset/versioned"
configfake "github.com/openshift/client-go/config/clientset/versioned/fake"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
@ -244,6 +245,7 @@ func TestImageConfigReconciler(t *testing.T) {
}
r := &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
arocli: arocli,
configcli: tt.configcli,
}

Просмотреть файл

@ -53,10 +53,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
ingress, err := r.operatorcli.OperatorV1().IngressControllers(openshiftIngressControllerNamespace).Get(ctx, openshiftIngressControllerName, metav1.GetOptions{})
if err != nil {
r.log.Error(err)

Просмотреть файл

@ -54,10 +54,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
// Update cluster object's status.
cond := &operatorv1.OperatorCondition{
Type: arov1alpha1.MachineValid,

Просмотреть файл

@ -11,6 +11,7 @@ import (
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
@ -38,12 +39,15 @@ const (
)
type Reconciler struct {
log *logrus.Entry
arocli aroclient.Interface
dh dynamichelper.Interface
}
func NewReconciler(arocli aroclient.Interface, dh dynamichelper.Interface) *Reconciler {
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, dh dynamichelper.Interface) *Reconciler {
return &Reconciler{
log: log,
arocli: arocli,
dh: dh,
}
@ -56,9 +60,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(enabled) {
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
if !instance.Spec.OperatorFlags.GetSimpleBoolean(managed) {
err := r.dh.EnsureDeleted(ctx, "MachineHealthCheck", "openshift-machine-api", "aro-machinehealthcheck")
if err != nil {

Просмотреть файл

@ -11,6 +11,7 @@ import (
"time"
"github.com/golang/mock/gomock"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
@ -163,7 +164,7 @@ func TestReconciler(t *testing.T) {
tt.mocks(mdh)
ctx := context.Background()
r := NewReconciler(tt.arocli, mdh)
r := NewReconciler(logrus.NewEntry(logrus.StandardLogger()), tt.arocli, mdh)
request := ctrl.Request{}
request.Name = "cluster"

Просмотреть файл

@ -52,10 +52,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(ControllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
modifiedMachineset, err := r.maocli.MachineV1beta1().MachineSets(machineSetsNamespace).Get(ctx, request.Name, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return reconcile.Result{}, err

Просмотреть файл

@ -66,9 +66,10 @@ type Reconciler struct {
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, kubernetescli kubernetes.Interface) *Reconciler {
return &Reconciler{
log: log,
arocli: arocli,
kubernetescli: kubernetescli,
log: log,
jsonHandle: new(codec.JsonHandle),
}
}
@ -80,10 +81,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
for _, f := range []func(context.Context, ctrl.Request) (ctrl.Result, error){
r.reconcileConfiguration,
r.reconcilePVC, // TODO(mj): This should be removed once we don't have PVC anymore

Просмотреть файл

@ -10,6 +10,7 @@ import (
"strings"
"time"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -57,6 +58,8 @@ type MUODeploymentConfig struct {
}
type Reconciler struct {
log *logrus.Entry
arocli aroclient.Interface
kubernetescli kubernetes.Interface
deployer deployer.Deployer
@ -65,8 +68,10 @@ type Reconciler struct {
readinessTimeout time.Duration
}
func NewReconciler(arocli aroclient.Interface, kubernetescli kubernetes.Interface, dh dynamichelper.Interface) *Reconciler {
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, kubernetescli kubernetes.Interface, dh dynamichelper.Interface) *Reconciler {
return &Reconciler{
log: log,
arocli: arocli,
kubernetescli: kubernetescli,
deployer: deployer.NewDeployer(kubernetescli, dh, staticFiles, "staticresources"),
@ -83,10 +88,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
managed := instance.Spec.OperatorFlags.GetWithDefault(controllerManaged, "")
// If enabled and managed=true, install MUO

Просмотреть файл

@ -10,6 +10,7 @@ import (
"time"
"github.com/golang/mock/gomock"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
@ -279,6 +280,7 @@ func TestMUOReconciler(t *testing.T) {
}
r := &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
arocli: arocli,
kubernetescli: kubecli,
deployer: deployer,

Просмотреть файл

@ -51,10 +51,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
node, err := r.kubernetescli.CoreV1().Nodes().Get(ctx, request.Name, metav1.GetOptions{})
if err != nil {
r.log.Error(err)

Просмотреть файл

@ -77,10 +77,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
var userSecret *corev1.Secret
userSecret, err = r.kubernetescli.CoreV1().Secrets(pullSecretName.Namespace).Get(ctx, pullSecretName.Name, metav1.GetOptions{})

Просмотреть файл

@ -50,10 +50,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
var resources []kruntime.Object
for _, assetName := range AssetNames() {
b, err := Asset(assetName)

Просмотреть файл

@ -75,10 +75,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
// cluster version is not set to final until upgrade is completed. We need to
// detect if desired version is with the fix, so we can prevent stuck upgrade
// by deleting fix resources

Просмотреть файл

@ -78,10 +78,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
// Get endpoints from operator
azEnv, err := azureclient.EnvironmentFromName(instance.Spec.AZEnvironment)
if err != nil {

Просмотреть файл

@ -77,10 +77,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerNSGManaged) && !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerServiceEndpointManaged) {
// controller is disabled
return reconcile.Result{}, nil

Просмотреть файл

@ -65,10 +65,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
// controller is disabled
r.log.Debug("controller is disabled")
return reconcile.Result{}, nil
}
r.log.Debug("running")
clusterVersion, err := version.GetClusterVersion(ctx, r.configcli)
if err != nil {
r.log.Errorf("error getting the OpenShift version: %v", err)