Skip to content

Commit

Permalink
chore(cert-manager): improve logging (#2279)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey1330 committed Oct 17, 2023
1 parent e2c5583 commit 859459d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,35 @@ type KeptnWebhookCertificateReconciler struct {
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/reconcile
func (r *KeptnWebhookCertificateReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
r.Log.Info("reconciling webhook certificates",
"namespace", request.Namespace, "name", request.Name)
requestInfo := common.GetRequestInfo(request)
r.Log.Info("reconciling webhook certificates", "requestInfo", requestInfo)

r.Log.Info("Retrieving MutatingWebhooks")
mutatingWebhookConfigurations, err := r.ResourceRetriever.GetMutatingWebhooks(ctx)
if err != nil {
r.Log.Error(err, "could not find mutating webhook configuration")
r.Log.Error(err, "could not find mutating webhook configuration", "requestInfo", requestInfo)
}
r.Log.Info(
"Found MutatingWebhooks to inject certificates",
"numberOfItems", len(mutatingWebhookConfigurations.Items),
"byteSize", mutatingWebhookConfigurations.Size(),
)

r.Log.Info("Retrieving ValidatingWebhooks")
r.Log.Info("Retrieving ValidatingWebhooks", "requestInfo", requestInfo)
validatingWebhookConfigurations, err := r.ResourceRetriever.GetValidatingWebhooks(ctx)
if err != nil {
r.Log.Error(err, "could not find validating webhook configuration")
r.Log.Error(err, "could not find validating webhook configuration", "requestInfo", requestInfo)
}
r.Log.Info(
"Found ValidatingWebhooks to inject certificates",
"numberOfItems", len(validatingWebhookConfigurations.Items),
"byteSize", validatingWebhookConfigurations.Size(),
)

r.Log.Info("Retrieving CRDs")
r.Log.Info("Retrieving CRDs", "requestInfo", requestInfo)
crds, err := r.ResourceRetriever.GetCRDs(ctx)
if err != nil {
r.Log.Error(err, "could not find CRDs")
r.Log.Error(err, "could not find CRDs", "requestInfo", requestInfo)
}
r.Log.Info(
"Found CRDs to inject certificates",
Expand All @@ -138,7 +138,7 @@ func (r *KeptnWebhookCertificateReconciler) Reconcile(ctx context.Context, reque
isCertSecretRecent := certSecret.isRecent()

if isCertSecretRecent && areMutatingWebhookConfigsValid && areValidatingWebhookConfigsValid && areCRDConversionsConfigValid {
r.Log.Info("secret for certificates up to date, skipping update")
r.Log.Info("secret for certificates up to date, skipping update", "requestInfo", requestInfo)
r.cancelMgr()
return reconcile.Result{RequeueAfter: common.SuccessDuration}, nil
}
Expand Down
11 changes: 11 additions & 0 deletions klt-cert-manager/pkg/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common

import ctrl "sigs.k8s.io/controller-runtime"

// GetRequestInfo extracts name and namespace from a controller request.
func GetRequestInfo(req ctrl.Request) map[string]string {
return map[string]string{
"name": req.Name,
"namespace": req.Namespace,
}
}
24 changes: 24 additions & 0 deletions klt-cert-manager/pkg/common/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

import (
"testing"

"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
)

func TestGetRequestInfo(t *testing.T) {
req := ctrl.Request{
NamespacedName: types.NamespacedName{
Name: "example",
Namespace: "test-namespace",
}}

info := GetRequestInfo(req)
expected := map[string]string{
"name": "example",
"namespace": "test-namespace",
}
require.Equal(t, expected, info)
}

0 comments on commit 859459d

Please sign in to comment.