From d32b49b55c54ad8204b0aca95f894dbaf16fc5d0 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Fri, 7 Mar 2025 14:44:00 +0100 Subject: [PATCH] test: add cluster to logger to co-relate requests to clusters in tests --- test/extension/handlers/lifecycle/handlers.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/extension/handlers/lifecycle/handlers.go b/test/extension/handlers/lifecycle/handlers.go index 9b22b4887037..ff79b433a35f 100644 --- a/test/extension/handlers/lifecycle/handlers.go +++ b/test/extension/handlers/lifecycle/handlers.go @@ -61,7 +61,7 @@ func NewExtensionHandlers(client client.Client) *ExtensionHandlers { // control the hook behaviour during a test. // NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case. func (m *ExtensionHandlers) DoBeforeClusterCreate(ctx context.Context, request *runtimehooksv1.BeforeClusterCreateRequest, response *runtimehooksv1.BeforeClusterCreateResponse) { - log := ctrl.LoggerFrom(ctx) + log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster)) log.Info("BeforeClusterCreate is called") if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.BeforeClusterCreate, request.GetSettings(), response); err != nil { @@ -80,7 +80,7 @@ func (m *ExtensionHandlers) DoBeforeClusterCreate(ctx context.Context, request * // control the hook behaviour during a test. // NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case. func (m *ExtensionHandlers) DoBeforeClusterUpgrade(ctx context.Context, request *runtimehooksv1.BeforeClusterUpgradeRequest, response *runtimehooksv1.BeforeClusterUpgradeResponse) { - log := ctrl.LoggerFrom(ctx) + log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster)) log.Info("BeforeClusterUpgrade is called") if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.BeforeClusterUpgrade, request.GetSettings(), response); err != nil { @@ -100,7 +100,7 @@ func (m *ExtensionHandlers) DoBeforeClusterUpgrade(ctx context.Context, request // control the hook behaviour during a test. // NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case. func (m *ExtensionHandlers) DoAfterControlPlaneInitialized(ctx context.Context, request *runtimehooksv1.AfterControlPlaneInitializedRequest, response *runtimehooksv1.AfterControlPlaneInitializedResponse) { - log := ctrl.LoggerFrom(ctx) + log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster)) log.Info("AfterControlPlaneInitialized is called") if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.AfterControlPlaneInitialized, request.GetSettings(), response); err != nil { @@ -120,7 +120,7 @@ func (m *ExtensionHandlers) DoAfterControlPlaneInitialized(ctx context.Context, // control the hook behaviour during a test. // NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case. func (m *ExtensionHandlers) DoAfterControlPlaneUpgrade(ctx context.Context, request *runtimehooksv1.AfterControlPlaneUpgradeRequest, response *runtimehooksv1.AfterControlPlaneUpgradeResponse) { - log := ctrl.LoggerFrom(ctx) + log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster)) log.Info("AfterControlPlaneUpgrade is called") if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.AfterControlPlaneUpgrade, request.GetSettings(), response); err != nil { @@ -140,7 +140,7 @@ func (m *ExtensionHandlers) DoAfterControlPlaneUpgrade(ctx context.Context, requ // control the hook behaviour during a test. // NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case. func (m *ExtensionHandlers) DoAfterClusterUpgrade(ctx context.Context, request *runtimehooksv1.AfterClusterUpgradeRequest, response *runtimehooksv1.AfterClusterUpgradeResponse) { - log := ctrl.LoggerFrom(ctx) + log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster)) log.Info("AfterClusterUpgrade is called") if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.AfterClusterUpgrade, request.GetSettings(), response); err != nil { @@ -160,7 +160,7 @@ func (m *ExtensionHandlers) DoAfterClusterUpgrade(ctx context.Context, request * // control the hook behaviour during a test. // NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case. func (m *ExtensionHandlers) DoBeforeClusterDelete(ctx context.Context, request *runtimehooksv1.BeforeClusterDeleteRequest, response *runtimehooksv1.BeforeClusterDeleteResponse) { - log := ctrl.LoggerFrom(ctx) + log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster)) log.Info("BeforeClusterDelete is called") if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.BeforeClusterDelete, request.GetSettings(), response); err != nil {