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

fix(event): fix event display problem #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions pkg/upgrade/drain_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (m *DrainManagerImpl) ScheduleNodesDrain(ctx context.Context, drainConfig *
m.log.V(consts.LogLevelError).Error(err, "Failed to cordon node", "node", node.Name)
_ = m.nodeUpgradeStateProvider.ChangeNodeUpgradeState(ctx, node, UpgradeStateFailed)
logEventf(m.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to cordon the node, %s", err.Error())
fmt.Sprintf("Failed to cordon the node, %s", err.Error()))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can format in advance: Use fmt.Sprintf to format the complete log message string in advance to prevent problems when the logging function handles formatting internally.

return
}
m.log.V(consts.LogLevelInfo).Info("Cordoned the node", "node", node.Name)
Expand All @@ -122,7 +122,7 @@ func (m *DrainManagerImpl) ScheduleNodesDrain(ctx context.Context, drainConfig *
m.log.V(consts.LogLevelError).Error(err, "Failed to drain node", "node", node.Name)
_ = m.nodeUpgradeStateProvider.ChangeNodeUpgradeState(ctx, node, UpgradeStateFailed)
logEventf(m.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to drain the node, %s", err.Error())
fmt.Sprintf("Failed to drain the node, %s", err.Error()))
return
}
m.log.V(consts.LogLevelInfo).Info("Drained the node", "node", node.Name)
Expand Down
12 changes: 6 additions & 6 deletions pkg/upgrade/node_upgrade_state_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (p *NodeUpgradeStateProviderImpl) ChangeNodeUpgradeState(
"node", node,
"state", newNodeState)
logEventf(p.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to update node state label to %s, %s", newNodeState, err.Error())
fmt.Sprintf("Failed to update node state label to %s, %s", newNodeState, err.Error()))
return err
}

Expand Down Expand Up @@ -121,13 +121,13 @@ func (p *NodeUpgradeStateProviderImpl) ChangeNodeUpgradeState(
"node", node,
"state", newNodeState)
logEventf(p.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to update node state label to %s, %s", newNodeState, err.Error())
fmt.Sprintf("Failed to update node state label to %s, %s", newNodeState, err.Error()))
} else {
p.Log.V(consts.LogLevelInfo).Info("Successfully changed node upgrade state label",
"node", node.Name,
"new state", newNodeState)
logEventf(p.eventRecorder, node, corev1.EventTypeNormal, GetEventReason(),
"Successfully updated node state label to %s", newNodeState)
fmt.Sprintf("Successfully updated node state label to %s", newNodeState))
}

return err
Expand Down Expand Up @@ -156,7 +156,7 @@ func (p *NodeUpgradeStateProviderImpl) ChangeNodeUpgradeAnnotation(
"annotationKey", key,
"annotationValue", value)
logEventf(p.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to update node annotation %s=%s: %s", key, value, err.Error())
fmt.Sprintf("Failed to update node annotation %s=%s: %s", key, value, err.Error()))
return err
}

Expand Down Expand Up @@ -202,14 +202,14 @@ func (p *NodeUpgradeStateProviderImpl) ChangeNodeUpgradeAnnotation(
"annotationKey", key,
"annotationValue", value)
logEventf(p.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to update node annotation to %s=%s: %s", key, value, err.Error())
fmt.Sprintf("Failed to update node annotation to %s=%s: %s", key, value, err.Error()))
} else {
p.Log.V(consts.LogLevelInfo).Info("Successfully changed node upgrade state annotation",
"node", node.Name,
"annotationKey", key,
"annotationValue", value)
logEventf(p.eventRecorder, node, corev1.EventTypeNormal, GetEventReason(),
"Successfully updated node annotation to %s=%s", key, value)
fmt.Sprintf("Successfully updated node annotation to %s=%s", key, value))
}

return err
Expand Down
8 changes: 4 additions & 4 deletions pkg/upgrade/pod_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (m *PodManagerImpl) SchedulePodEviction(ctx context.Context, config *PodMan
if err != nil {
m.log.V(consts.LogLevelError).Error(err, "Failed to delete pods on the node", "node", node.Name)
logEventf(m.eventRecorder, &node, corev1.EventTypeWarning, GetEventReason(),
"Failed to delete workload pods on the node for the driver upgrade, %s", err.Error())
fmt.Sprintf("Failed to delete workload pods on the node for the driver upgrade, %s", err.Error()))
m.updateNodeToDrainOrFailed(ctx, node, config.DrainEnabled)
return
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (m *PodManagerImpl) SchedulePodsRestart(ctx context.Context, pods []*corev1
if err != nil {
m.log.V(consts.LogLevelInfo).Error(err, "Failed to delete pod", "pod", pod.Name)
logEventf(m.eventRecorder, pod, corev1.EventTypeWarning, GetEventReason(),
"Failed to restart driver pod %s", err.Error())
fmt.Sprintf("Failed to restart driver pod %s", err.Error()))
return err
}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ func (m *PodManagerImpl) ScheduleCheckOnPodCompletion(ctx context.Context, confi
err = m.HandleTimeoutOnPodCompletions(ctx, &node, int64(config.WaitForCompletionSpec.TimeoutSecond))
if err != nil {
logEventf(m.eventRecorder, &node, corev1.EventTypeWarning, GetEventReason(),
"Failed to handle timeout for job completions, %s", err.Error())
fmt.Sprintf("Failed to handle timeout for job completions, %s", err.Error()))
return
}
}
Expand All @@ -305,7 +305,7 @@ func (m *PodManagerImpl) ScheduleCheckOnPodCompletion(ctx context.Context, confi
err = m.nodeUpgradeStateProvider.ChangeNodeUpgradeAnnotation(ctx, &node, annotationKey, "null")
if err != nil {
logEventf(m.eventRecorder, &node, corev1.EventTypeWarning, GetEventReason(),
"Failed to remove annotation used to track job completions: %s", err.Error())
fmt.Sprintf("Failed to remove annotation used to track job completions: %s", err.Error()))
return
}
// update node state
Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/validation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (m *ValidationManagerImpl) Validate(ctx context.Context, node *corev1.Node)
err = m.handleTimeout(ctx, node, int64(validationTimeoutSeconds))
if err != nil {
logEventf(m.eventRecorder, node, corev1.EventTypeWarning, GetEventReason(),
"Failed to handle timeout for validation state", err.Error())
fmt.Sprintf("Failed to handle timeout for validation state: %s", err.Error()))
return false, fmt.Errorf("unable to handle timeout for validation state: %v", err)
}
done = false
Expand Down