Skip to content

Commit

Permalink
Reformating error output (#1024)
Browse files Browse the repository at this point in the history
* Providing startTime and currentTime to facilitate timeout in case of ytt wait rules

Signed-off-by: Rohit Aggarwal <rohit.aggarwal@broadcom.com>

* Update test/e2e/custom_wait_rules_test.go

Co-authored-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com>

* Reformating error output

Signed-off-by: Rohit Aggarwal <rohit.aggarwal@broadcom.com>

---------

Signed-off-by: Rohit Aggarwal <rohit.aggarwal@broadcom.com>
Co-authored-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com>
  • Loading branch information
rohitagg2020 and praveenrewar authored Oct 1, 2024
1 parent 2e0c8d2 commit ca6887d
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pkg/kapp/clusterapply/waiting_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (c *WaitingChanges) WaitForAny() ([]WaitingChange, []string, error) {
case state.Done && !state.Successful:
msg := ""
if len(state.Message) > 0 {
msg += " (" + state.Message + ")"
msg = ": " + state.Message
}
err := fmt.Errorf("%s: Finished unsuccessfully%s", desc, msg)
err := fmt.Errorf("%s: Finished waiting unsuccessfully%s", desc, msg)
if c.exitOnError {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kapp/resourcesmisc/apps_v1_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func (s AppsV1Deployment) IsDoneApplying() DoneApplyState {
case appsv1.DeploymentProgressing:
if cond.Status == corev1.ConditionFalse {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Deployment is not progressing: %s (message: %s)", cond.Reason, cond.Message)}
"Deployment is not progressing: %s, message: %s", cond.Reason, cond.Message)}
}

case appsv1.DeploymentReplicaFailure:
if cond.Status == corev1.ConditionTrue {
return DoneApplyState{Done: false, Successful: false, Message: fmt.Sprintf(
"Deployment has encountered replica failure: %s (message: %s)", cond.Reason, cond.Message)}
"Deployment has encountered replica failure: %s, message: %s", cond.Reason, cond.Message)}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kapp/resourcesmisc/apps_v1_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ status:
expectedState := ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: "Deployment is not progressing: ProgressDeadlineExceeded (message: Progress deadline exceeded)",
Message: "Deployment is not progressing: ProgressDeadlineExceeded, message: Progress deadline exceeded",
}

require.Equal(t, expectedState, state, "Found incorrect state")
Expand All @@ -107,7 +107,7 @@ status:
expectedState = ctlresm.DoneApplyState{
Done: false,
Successful: false,
Message: "Deployment has encountered replica failure: FailedCreate (message: Failed to create pods)",
Message: "Deployment has encountered replica failure: FailedCreate, message: Failed to create pods",
}

require.Equal(t, expectedState, state, "Found incorrect state")
Expand Down
4 changes: 2 additions & 2 deletions pkg/kapp/resourcesmisc/core_v1_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s CoreV1Pod) pendingDetailsReason(pod corev1.Pod) string {
if st.State.Waiting != nil {
msg := st.State.Waiting.Reason
if len(st.State.Waiting.Message) > 0 {
msg += fmt.Sprintf(" (message: %s)", st.State.Waiting.Message)
msg += fmt.Sprintf(", message: %s", st.State.Waiting.Message)
}
return msg
}
Expand All @@ -96,7 +96,7 @@ func (s CoreV1Pod) pendingDetailsReason(pod corev1.Pod) string {
if cond.Reason == corev1.PodReasonUnschedulable {
msg := cond.Reason
if len(cond.Message) > 0 {
msg += fmt.Sprintf(" (message: %s)", cond.Message)
msg += fmt.Sprintf(", message: %s", cond.Message)
}
return msg
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/resourcesmisc/custom_waiting_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {
isTimeOutConditionPresent = true
if s.hasTimeoutOccurred(condMatcher.Timeout, s.resource.Description()) {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Encountered failure condition %s == %s: %s (message: %s) continuously for %s duration",
cond.Type, condMatcher.Status, cond.Reason, cond.Message, condMatcher.Timeout)}
"Continuously failed for %s with %s: %s, message: %s",
condMatcher.Timeout, cond.Type, cond.Reason, cond.Message)}
}
return DoneApplyState{Done: false, Message: fmt.Sprintf(
"%s: %s (message: %s)",
Expand All @@ -116,7 +116,7 @@ func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {

if condMatcher.Failure {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Encountered failure condition %s == %s: %s (message: %s)",
"Encountered failure condition %s == %s: %s, message: %s",
cond.Type, condMatcher.Status, cond.Reason, cond.Message)}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kapp/resourcesmisc/kappctrl_k14s_io_v1alpha1_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (s KappctrlK14sIoV1alpha1App) IsDoneApplying() DoneApplyState {

case cond.Type == kcv1alpha1.ReconcileFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Reconcile failed: %s (message: %s)", cond.Reason, errorMsg)}
"Reconcile failed: message: %s", errorMsg)}

case cond.Type == kcv1alpha1.DeleteFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Delete failed: %s (message: %s)", cond.Reason, errorMsg)}
"Delete failed: message: %s", errorMsg)}
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/kapp/resourcesmisc/kappctrl_k14s_io_v1alpha1_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ status:
expectedState := ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: fmt.Sprintf("Reconcile failed: (message: %s)", usefulErrorMessage),
Message: fmt.Sprintf("Reconcile failed: message: %s", usefulErrorMessage),
}
require.Equal(t, expectedState, state)

Expand All @@ -46,7 +46,7 @@ status:
expectedState = ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: fmt.Sprintf("Reconcile failed: (message: %s)", conditionMessage),
Message: fmt.Sprintf("Reconcile failed: message: %s", conditionMessage),
}
require.Equal(t, state, expectedState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func (s PackagingCarvelDevV1alpha1PackageInstall) IsDoneApplying() DoneApplyStat

case cond.Type == appv1alpha1.ReconcileFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Reconcile failed: %s (message: %s)", cond.Reason, errorMsg)}
"Reconcile failed: message: %s", errorMsg)}

case cond.Type == appv1alpha1.DeleteFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Delete failed: %s (message: %s)", cond.Reason, errorMsg)}
"Delete failed: message: %s", errorMsg)}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ status:
expectedState := ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: fmt.Sprintf("Reconcile failed: (message: %s)", usefulErrorMessage),
Message: fmt.Sprintf("Reconcile failed: message: %s", usefulErrorMessage),
}
require.Equal(t, expectedState, state)

Expand All @@ -46,7 +46,7 @@ status:
expectedState = ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: fmt.Sprintf("Reconcile failed: (message: %s)", conditionMessage),
Message: fmt.Sprintf("Reconcile failed: message: %s", conditionMessage),
}
require.Equal(t, state, expectedState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func (s PackagingCarvelDevV1alpha1PackageRepo) IsDoneApplying() DoneApplyState {

case cond.Type == appv1alpha1.ReconcileFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Reconcile failed: %s (message: %s)", cond.Reason, errorMsg)}
"Reconcile failed: message: %s", errorMsg)}

case cond.Type == appv1alpha1.DeleteFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Delete failed: %s (message: %s)", cond.Reason, errorMsg)}
"Delete failed: message: %s", errorMsg)}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ status:
expectedState := ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: fmt.Sprintf("Reconcile failed: (message: %s)", usefulErrorMessage),
Message: fmt.Sprintf("Reconcile failed: message: %s", usefulErrorMessage),
}
require.Equal(t, expectedState, state)

Expand All @@ -46,7 +46,7 @@ status:
expectedState = ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: fmt.Sprintf("Reconcile failed: (message: %s)", conditionMessage),
Message: fmt.Sprintf("Reconcile failed: message: %s", conditionMessage),
}
require.Equal(t, state, expectedState)

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/apply_wait_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ spec:

expectedErrs := []string{
`kapp: Error:`,
fmt.Sprintf(`- waiting on reconcile job/my-job-fail-2 (batch/v1) namespace: %s: Finished unsuccessfully (Failed with reason BackoffLimitExceeded: Job has reached the specified backoff limit)`, env.Namespace),
fmt.Sprintf(`- waiting on reconcile job/my-job-fail (batch/v1) namespace: %s: Finished unsuccessfully (Failed with reason BackoffLimitExceeded: Job has reached the specified backoff limit)`, env.Namespace),
fmt.Sprintf(`- waiting on reconcile job/my-job-fail-2 (batch/v1) namespace: %s: Finished waiting unsuccessfully: Failed with reason BackoffLimitExceeded: Job has reached the specified backoff limit`, env.Namespace),
fmt.Sprintf(`- waiting on reconcile job/my-job-fail (batch/v1) namespace: %s: Finished waiting unsuccessfully: Failed with reason BackoffLimitExceeded: Job has reached the specified backoff limit`, env.Namespace),
fmt.Sprintf(`- create service/service-fail (v1) namespace: %s: Creating resource service/service-fail (v1) namespace: kapp-test: API server says: Service "service-fail" is invalid: spec.ports: Required value (reason: Invalid)`, env.Namespace),
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/wait_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ waitRules:
RunOpts{IntoNs: true, AllowError: true, StdinReader: strings.NewReader(fmt.Sprintf(yaml2, "nginx:200"))})

require.Error(t, err)
require.Contains(t, err.Error(), "message: containers with unready status: [nginx]) continuously for 50s duration")
require.Contains(t, err.Error(), "Continuously failed for 50s with")
})

cleanUp()
Expand Down

0 comments on commit ca6887d

Please sign in to comment.