Skip to content

Commit

Permalink
Setup logger in context in the patching reconciler
Browse files Browse the repository at this point in the history
Thus reconcilers that use the patching reconciler (i.e. all Korifi
reconcilers) can take a logger from the context
(`logr.FromContextOrDiscard`) that has been set up with object
namespace, name and an unique logID
  • Loading branch information
danail-branekov authored and davewalter committed Aug 29, 2023
1 parent b39ff78 commit 4346278
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 50 deletions.
3 changes: 1 addition & 2 deletions controllers/controllers/networking/cfdomain_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func (r *CFDomainReconciler) SetupWithManager(mgr ctrl.Manager) *builder.Builder
//+kubebuilder:rbac:groups=korifi.cloudfoundry.org,resources=cfdomains/finalizers,verbs=update

func (r *CFDomainReconciler) ReconcileResource(ctx context.Context, cfDomain *korifiv1alpha1.CFDomain) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfDomain)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

if !cfDomain.GetDeletionTimestamp().IsZero() {
return r.finalizeCFDomain(ctx, cfDomain)
Expand Down
4 changes: 1 addition & 3 deletions controllers/controllers/networking/cfroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/controllers/config"
"code.cloudfoundry.org/korifi/controllers/controllers/shared"
"code.cloudfoundry.org/korifi/tools/k8s"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -75,8 +74,7 @@ func (r *CFRouteReconciler) SetupWithManager(mgr ctrl.Manager) *builder.Builder
//+kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete

func (r *CFRouteReconciler) ReconcileResource(ctx context.Context, cfRoute *korifiv1alpha1.CFRoute) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfRoute)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

var err error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/controllers/controllers/shared"
"code.cloudfoundry.org/korifi/tools/k8s"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -73,8 +72,7 @@ func (r *CFServiceBindingReconciler) SetupWithManager(mgr ctrl.Manager) *builder
//+kubebuilder:rbac:groups=servicebinding.io,resources=servicebindings,verbs=get;list;create;update;patch;watch

func (r *CFServiceBindingReconciler) ReconcileResource(ctx context.Context, cfServiceBinding *korifiv1alpha1.CFServiceBinding) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfServiceBinding)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfServiceBinding.Status.ObservedGeneration = cfServiceBinding.Generation
log.V(1).Info("set observed generation", "generation", cfServiceBinding.Status.ObservedGeneration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/controllers/controllers/shared"
"code.cloudfoundry.org/korifi/tools/k8s"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -62,8 +61,7 @@ func (r *CFServiceInstanceReconciler) SetupWithManager(mgr ctrl.Manager) *builde
//+kubebuilder:rbac:groups=korifi.cloudfoundry.org,resources=cfserviceinstances/finalizers,verbs=update

func (r *CFServiceInstanceReconciler) ReconcileResource(ctx context.Context, cfServiceInstance *korifiv1alpha1.CFServiceInstance) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfServiceInstance)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfServiceInstance.Status.ObservedGeneration = cfServiceInstance.Generation
log.V(1).Info("set observed generation", "generation", cfServiceInstance.Status.ObservedGeneration)
Expand Down
5 changes: 0 additions & 5 deletions controllers/controllers/shared/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"

"github.com/go-logr/logr"
"github.com/google/uuid"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -140,7 +139,3 @@ func RemovePackageManagerKeys(src map[string]string, log logr.Logger) map[string

return dest
}

func ObjectLogger(log logr.Logger, obj client.Object) logr.Logger {
return log.WithValues("namespace", obj.GetNamespace(), "name", obj.GetName(), "logID", uuid.NewString())
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func (r *CFBuildReconciler) SetupWithManager(mgr ctrl.Manager) *builder.Builder
}

func (r *CFBuildReconciler) ReconcileResource(ctx context.Context, cfBuild *korifiv1alpha1.CFBuild) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfBuild)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfBuild.Status.ObservedGeneration = cfBuild.Generation
log.V(1).Info("set observed generation", "generation", cfBuild.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions controllers/controllers/workloads/cfapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func serviceBindingToApp(ctx context.Context, o client.Object) []reconcile.Reque
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;patch

func (r *CFAppReconciler) ReconcileResource(ctx context.Context, cfApp *korifiv1alpha1.CFApp) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfApp)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfApp.Status.ObservedGeneration = cfApp.Generation
log.V(1).Info("set observed generation", "generation", cfApp.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions controllers/controllers/workloads/cforg_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func (r *CFOrgReconciler) enqueueCFOrgRequests(ctx context.Context, object clien
//+kubebuilder:rbac:groups="policy",resources=podsecuritypolicies,verbs=use

func (r *CFOrgReconciler) ReconcileResource(ctx context.Context, cfOrg *korifiv1alpha1.CFOrg) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfOrg)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfOrg.Status.ObservedGeneration = cfOrg.Generation
log.V(1).Info("set observed generation", "generation", cfOrg.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions controllers/controllers/workloads/cfpackage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (r *CFPackageReconciler) SetupWithManager(mgr ctrl.Manager) *builder.Builde
//+kubebuilder:rbac:groups=korifi.cloudfoundry.org,resources=cfpackages/finalizers,verbs=get;update;patch

func (r *CFPackageReconciler) ReconcileResource(ctx context.Context, cfPackage *korifiv1alpha1.CFPackage) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfPackage)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfPackage.Status.ObservedGeneration = cfPackage.Generation
log.V(1).Info("set observed generation", "generation", cfPackage.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions controllers/controllers/workloads/cfprocess_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func (r *CFProcessReconciler) enqueueCFProcessRequests(ctx context.Context, o cl
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;patch

func (r *CFProcessReconciler) ReconcileResource(ctx context.Context, cfProcess *korifiv1alpha1.CFProcess) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfProcess)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfProcess.Status.ObservedGeneration = cfProcess.Generation
log.V(1).Info("set observed generation", "generation", cfProcess.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions controllers/controllers/workloads/cfspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ func (r *CFSpaceReconciler) enqueueCFSpaceRequestsForServiceAccount(ctx context.
//+kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;patch;delete

func (r *CFSpaceReconciler) ReconcileResource(ctx context.Context, cfSpace *korifiv1alpha1.CFSpace) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfSpace)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfSpace.Status.ObservedGeneration = cfSpace.Generation
log.V(1).Info("set observed generation", "generation", cfSpace.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions controllers/controllers/workloads/cftask_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ func (r *CFTaskReconciler) SetupWithManager(mgr ctrl.Manager) *builder.Builder {
//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch

func (r *CFTaskReconciler) ReconcileResource(ctx context.Context, cfTask *korifiv1alpha1.CFTask) (ctrl.Result, error) {
log := shared.ObjectLogger(r.log, cfTask)
ctx = logr.NewContext(ctx, log)
log := logr.FromContextOrDiscard(ctx)

cfTask.Status.ObservedGeneration = cfTask.Generation
log.V(1).Info("set observed generation", "generation", cfTask.Status.ObservedGeneration)
Expand Down
8 changes: 4 additions & 4 deletions job-task-runner/controllers/taskworkload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (r *TaskWorkloadReconciler) SetupWithManager(mgr ctrl.Manager) *builder.Bui
//+kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch

func (r *TaskWorkloadReconciler) ReconcileResource(ctx context.Context, taskWorkload *korifiv1alpha1.TaskWorkload) (ctrl.Result, error) {
logger := r.logger.WithValues("namespace", taskWorkload.Namespace, "name", taskWorkload.Name)
log := logr.FromContextOrDiscard(ctx)

taskWorkload.Status.ObservedGeneration = taskWorkload.Generation
logger.V(1).Info("set observed generation", "generation", taskWorkload.Status.ObservedGeneration)
log.V(1).Info("set observed generation", "generation", taskWorkload.Status.ObservedGeneration)

job, err := r.getOrCreateJob(ctx, logger, taskWorkload)
job, err := r.getOrCreateJob(ctx, log, taskWorkload)
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -104,7 +104,7 @@ func (r *TaskWorkloadReconciler) ReconcileResource(ctx context.Context, taskWork
}

if err = r.updateTaskWorkloadStatus(ctx, taskWorkload, job); err != nil {
logger.Info("failed to update task workload status", "reason", err)
log.Info("failed to update task workload status", "reason", err)
return ctrl.Result{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion kpack-image-builder/controllers/builderinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *BuilderInfoReconciler) filterBuilderInfos(object client.Object) bool {
//+kubebuilder:rbac:groups=kpack.io,resources=clusterbuilders/status,verbs=get

func (r *BuilderInfoReconciler) ReconcileResource(ctx context.Context, info *korifiv1alpha1.BuilderInfo) (ctrl.Result, error) {
log := r.log.WithValues("namespace", info.Namespace, "name", info.Name)
log := logr.FromContextOrDiscard(ctx)

info.Status.ObservedGeneration = info.Generation
log.V(1).Info("set observed generation", "generation", info.Status.ObservedGeneration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func filterBuildWorkloads(object client.Object) bool {
//+kubebuilder:rbac:groups="",resources=serviceaccounts/status;secrets/status,verbs=get

func (r *BuildWorkloadReconciler) ReconcileResource(ctx context.Context, buildWorkload *korifiv1alpha1.BuildWorkload) (ctrl.Result, error) {
log := r.log.WithValues("namespace", buildWorkload.Namespace, "name", buildWorkload.Name)
log := logr.FromContextOrDiscard(ctx)

buildWorkload.Status.ObservedGeneration = buildWorkload.Generation
log.V(1).Info("set observed generation", "generation", buildWorkload.Status.ObservedGeneration)
Expand Down
3 changes: 1 addition & 2 deletions kpack-image-builder/controllers/kpack_build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func (c KpackBuildController) SetupWithManager(mgr manager.Manager) *ctrl.Builde
//+kubebuilder:rbac:groups=kpack.io,resources=builds/finalizers,verbs=get;patch

func (c KpackBuildController) ReconcileResource(ctx context.Context, kpackBuild *kpackv1alpha2.Build) (ctrl.Result, error) {
log := c.log.WithValues("namespace", kpackBuild.Namespace, "name", kpackBuild.Name, "deletionTimestamp", kpackBuild.DeletionTimestamp)
log.Info("in finalizer")
log := logr.FromContextOrDiscard(ctx)

if !kpackBuild.GetDeletionTimestamp().IsZero() {
if !controllerutil.ContainsFinalizer(kpackBuild, KpackBuildFinalizer) {
Expand Down
2 changes: 1 addition & 1 deletion statefulset-runner/controllers/appworkload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func filterAppWorkloads(object client.Object) bool {
//+kubebuilder:rbac:groups=policy,resources=poddisruptionbudgets,verbs=create;patch;deletecollection

func (r *AppWorkloadReconciler) ReconcileResource(ctx context.Context, appWorkload *korifiv1alpha1.AppWorkload) (ctrl.Result, error) {
log := r.log.WithValues("namespace", appWorkload.Namespace, "name", appWorkload.Name)
log := logr.FromContextOrDiscard(ctx)

if appWorkload.Spec.RunnerName != AppWorkloadReconcilerName {
return ctrl.Result{}, nil
Expand Down
11 changes: 8 additions & 3 deletions statefulset-runner/controllers/appworkload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

const (
Expand Down Expand Up @@ -89,7 +88,7 @@ var _ = Describe("AppWorkload Reconcile", func() {
}
}

fakeClient.CreateStub = func(ctx context.Context, obj client.Object, option ...client.CreateOption) error {
fakeClient.CreateStub = func(_ context.Context, obj client.Object, _ ...client.CreateOption) error {
switch obj.(type) {
case *v1.StatefulSet:
return createStatefulSetError
Expand All @@ -98,7 +97,13 @@ var _ = Describe("AppWorkload Reconcile", func() {
}
}

reconciler = controllers.NewAppWorkloadReconciler(fakeClient, scheme.Scheme, fakeWorkloadToStSet, fakePDB, zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
reconciler = controllers.NewAppWorkloadReconciler(
fakeClient,
scheme.Scheme,
fakeWorkloadToStSet,
fakePDB,
ctrl.Log.WithName("controllers").WithName("TestAppWorkload"),
)
})

JustBeforeEach(func() {
Expand Down
2 changes: 1 addition & 1 deletion statefulset-runner/controllers/runnerinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func filterRunnerInfos(object client.Object) bool {
//+kubebuilder:rbac:groups=korifi.cloudfoundry.org,resources=runnerinfos/status,verbs=get;patch

func (r *RunnerInfoReconciler) ReconcileResource(ctx context.Context, runnerInfo *korifiv1alpha1.RunnerInfo) (ctrl.Result, error) {
log := r.log.WithValues("namespace", runnerInfo.Namespace, "name", runnerInfo.Name)
log := logr.FromContextOrDiscard(ctx)

runnerInfo.Status.ObservedGeneration = runnerInfo.Generation
log.V(1).Info("set observed generation", "generation", runnerInfo.Status.ObservedGeneration)
Expand Down
11 changes: 6 additions & 5 deletions statefulset-runner/controllers/runnerinfo_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

const (
Expand All @@ -26,7 +25,6 @@ var _ = Describe("RunnerInfo Reconcile", func() {
reconciler *k8s.PatchingReconciler[korifiv1alpha1.RunnerInfo, *korifiv1alpha1.RunnerInfo]
reconcileResult ctrl.Result
reconcileErr error
ctx context.Context
req ctrl.Request
getRunnerInfoError error
runnerInfo *korifiv1alpha1.RunnerInfo
Expand Down Expand Up @@ -58,9 +56,12 @@ var _ = Describe("RunnerInfo Reconcile", func() {
}
}

reconciler = controllers.NewRunnerInfoReconciler(fakeClient, scheme.Scheme, zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

reconcileResult, reconcileErr = reconciler.Reconcile(ctx, req)
reconciler = controllers.NewRunnerInfoReconciler(
fakeClient,
scheme.Scheme,
ctrl.Log.WithName("controllers").WithName("TestRunnerInfo"),
)
reconcileResult, reconcileErr = reconciler.Reconcile(context.Background(), req)
})

When("the RunnerInfo is being reconciled", func() {
Expand Down
7 changes: 7 additions & 0 deletions statefulset-runner/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package controllers_test
import (
"testing"

"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/statefulset-runner/fake"
Expand All @@ -13,6 +15,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

func TestAppWorkloadsController(t *testing.T) {
Expand All @@ -25,6 +28,10 @@ var (
fakeStatusWriter *fake.StatusWriter
)

var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true), zap.Level(zapcore.DebugLevel)))
})

var _ = BeforeEach(func() {
fakeClient = new(fake.Client)
fakeStatusWriter = &fake.StatusWriter{}
Expand Down
6 changes: 4 additions & 2 deletions tools/k8s/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/go-logr/logr"
"github.com/google/uuid"
apierrors "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand All @@ -24,14 +25,15 @@ type PatchingReconciler[T any, PT ObjectWithDeepCopy[T]] struct {

func NewPatchingReconciler[T any, PT ObjectWithDeepCopy[T]](log logr.Logger, k8sClient client.Client, objectReconciler ObjectReconciler[T, PT]) *PatchingReconciler[T, PT] {
return &PatchingReconciler[T, PT]{
log: log.WithName("patching-reconciler"),
log: log,
k8sClient: k8sClient,
objectReconciler: objectReconciler,
}
}

func (r *PatchingReconciler[T, PT]) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.log.WithValues("namespace", req.Namespace, "name", req.Name)
log := r.log.WithValues("namespace", req.Namespace, "name", req.Name, "logID", uuid.NewString())
ctx = logr.NewContext(ctx, log)

obj := PT(new(T))
err := r.k8sClient.Get(ctx, req.NamespacedName, obj)
Expand Down
26 changes: 26 additions & 0 deletions tools/k8s/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"errors"

"github.com/go-logr/logr"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -15,6 +17,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"code.cloudfoundry.org/korifi/controllers/fake"
"code.cloudfoundry.org/korifi/tools/k8s"
Expand All @@ -27,6 +31,9 @@ type fakeObjectReconciler struct {
}

func (f *fakeObjectReconciler) ReconcileResource(ctx context.Context, obj *corev1.Pod) (ctrl.Result, error) {
log := logr.FromContextOrDiscard(ctx)
log.V(1).Info("fake reconciler reconciling")

f.reconcileResourceCallCount++
f.reconcileResourceObj = obj

Expand Down Expand Up @@ -189,4 +196,23 @@ var _ = Describe("Reconcile", func() {
Expect(fakeStatusWriter.PatchCallCount()).To(Equal(1))
})
})

Describe("logging", func() {
var logOutput *gbytes.Buffer

BeforeEach(func() {
logOutput = gbytes.NewBuffer()
GinkgoWriter.TeeTo(logOutput)
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
})

It("captures logs from object reconciler", func() {
Eventually(logOutput).Should(SatisfyAll(
gbytes.Say("fake reconciler reconciling"),
gbytes.Say(`"namespace":`),
gbytes.Say(`"name":`),
gbytes.Say(`"logID":`),
))
})
})
})

0 comments on commit 4346278

Please sign in to comment.