Skip to content

Commit bfb2649

Browse files
authored
Merge pull request #11938 from chrischdi/pr-test-runtimesdk-debug-log-clustername
🌱 test: add cluster to logger to co-relate requests to clusters in tests
2 parents 445a0c7 + d32b49b commit bfb2649

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/extension/handlers/lifecycle/handlers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewExtensionHandlers(client client.Client) *ExtensionHandlers {
6161
// control the hook behaviour during a test.
6262
// NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case.
6363
func (m *ExtensionHandlers) DoBeforeClusterCreate(ctx context.Context, request *runtimehooksv1.BeforeClusterCreateRequest, response *runtimehooksv1.BeforeClusterCreateResponse) {
64-
log := ctrl.LoggerFrom(ctx)
64+
log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster))
6565
log.Info("BeforeClusterCreate is called")
6666

6767
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 *
8080
// control the hook behaviour during a test.
8181
// NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case.
8282
func (m *ExtensionHandlers) DoBeforeClusterUpgrade(ctx context.Context, request *runtimehooksv1.BeforeClusterUpgradeRequest, response *runtimehooksv1.BeforeClusterUpgradeResponse) {
83-
log := ctrl.LoggerFrom(ctx)
83+
log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster))
8484
log.Info("BeforeClusterUpgrade is called")
8585

8686
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
100100
// control the hook behaviour during a test.
101101
// NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case.
102102
func (m *ExtensionHandlers) DoAfterControlPlaneInitialized(ctx context.Context, request *runtimehooksv1.AfterControlPlaneInitializedRequest, response *runtimehooksv1.AfterControlPlaneInitializedResponse) {
103-
log := ctrl.LoggerFrom(ctx)
103+
log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster))
104104
log.Info("AfterControlPlaneInitialized is called")
105105

106106
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,
120120
// control the hook behaviour during a test.
121121
// NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case.
122122
func (m *ExtensionHandlers) DoAfterControlPlaneUpgrade(ctx context.Context, request *runtimehooksv1.AfterControlPlaneUpgradeRequest, response *runtimehooksv1.AfterControlPlaneUpgradeResponse) {
123-
log := ctrl.LoggerFrom(ctx)
123+
log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster))
124124
log.Info("AfterControlPlaneUpgrade is called")
125125

126126
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
140140
// control the hook behaviour during a test.
141141
// NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case.
142142
func (m *ExtensionHandlers) DoAfterClusterUpgrade(ctx context.Context, request *runtimehooksv1.AfterClusterUpgradeRequest, response *runtimehooksv1.AfterClusterUpgradeResponse) {
143-
log := ctrl.LoggerFrom(ctx)
143+
log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster))
144144
log.Info("AfterClusterUpgrade is called")
145145

146146
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 *
160160
// control the hook behaviour during a test.
161161
// NOTE: custom RuntimeExtension, must implement the body of this func according to the specific use case.
162162
func (m *ExtensionHandlers) DoBeforeClusterDelete(ctx context.Context, request *runtimehooksv1.BeforeClusterDeleteRequest, response *runtimehooksv1.BeforeClusterDeleteResponse) {
163-
log := ctrl.LoggerFrom(ctx)
163+
log := ctrl.LoggerFrom(ctx).WithValues("Cluster", klog.KObj(&request.Cluster))
164164
log.Info("BeforeClusterDelete is called")
165165

166166
if err := m.readResponseFromConfigMap(ctx, &request.Cluster, runtimehooksv1.BeforeClusterDelete, request.GetSettings(), response); err != nil {

0 commit comments

Comments
 (0)