From e7bca7cfa9f0eeb5557dd7eb2681e67cca116bcb Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Mon, 7 Aug 2023 11:07:35 +0100 Subject: [PATCH 1/3] keep Signed-off-by: geoffrey1330 --- .../crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml index 7cb6115e29..b515135f9c 100644 --- a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml +++ b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml @@ -3,7 +3,11 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: +<<<<<<< HEAD controller-gen.kubebuilder.io/version: v0.13.0 +======= + controller-gen.kubebuilder.io/version: v0.12.0 +>>>>>>> 9f2c6d64 (keep) name: keptnmetricsproviders.metrics.keptn.sh spec: group: metrics.keptn.sh From 5274f7097b34b2832cd94eeffc5d5ac6de363af0 Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Fri, 22 Sep 2023 10:56:53 +0100 Subject: [PATCH 2/3] keep Signed-off-by: geoffrey1330 --- .../crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml index b515135f9c..7cb6115e29 100644 --- a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml +++ b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml @@ -3,11 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: -<<<<<<< HEAD controller-gen.kubebuilder.io/version: v0.13.0 -======= - controller-gen.kubebuilder.io/version: v0.12.0 ->>>>>>> 9f2c6d64 (keep) name: keptnmetricsproviders.metrics.keptn.sh spec: group: metrics.keptn.sh From d262899a9fb4fd8fd6539a492c2d10bc69d3286f Mon Sep 17 00:00:00 2001 From: geoffrey1330 Date: Mon, 16 Oct 2023 13:43:22 +0100 Subject: [PATCH 3/3] Improve logging in cert manager using relevant context Signed-off-by: geoffrey1330 --- .../keptnwebhookcertificate_controller.go | 16 ++++++------- klt-cert-manager/pkg/common/common.go | 11 +++++++++ klt-cert-manager/pkg/common/common_test.go | 24 +++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 klt-cert-manager/pkg/common/common.go create mode 100644 klt-cert-manager/pkg/common/common_test.go diff --git a/klt-cert-manager/controllers/keptnwebhookcontroller/keptnwebhookcertificate_controller.go b/klt-cert-manager/controllers/keptnwebhookcontroller/keptnwebhookcertificate_controller.go index a002a35962..26d6f42533 100644 --- a/klt-cert-manager/controllers/keptnwebhookcontroller/keptnwebhookcertificate_controller.go +++ b/klt-cert-manager/controllers/keptnwebhookcontroller/keptnwebhookcertificate_controller.go @@ -87,13 +87,13 @@ 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", @@ -101,10 +101,10 @@ func (r *KeptnWebhookCertificateReconciler) Reconcile(ctx context.Context, reque "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", @@ -112,10 +112,10 @@ func (r *KeptnWebhookCertificateReconciler) Reconcile(ctx context.Context, reque "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", @@ -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 } diff --git a/klt-cert-manager/pkg/common/common.go b/klt-cert-manager/pkg/common/common.go new file mode 100644 index 0000000000..fdef5d8b8f --- /dev/null +++ b/klt-cert-manager/pkg/common/common.go @@ -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, + } +} diff --git a/klt-cert-manager/pkg/common/common_test.go b/klt-cert-manager/pkg/common/common_test.go new file mode 100644 index 0000000000..dfb6af3bee --- /dev/null +++ b/klt-cert-manager/pkg/common/common_test.go @@ -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) +}