Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cert-manager): improve logging #2279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]/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)
}
Loading