Skip to content

Commit

Permalink
fix: taskrun still fails even with onerror set to continue
Browse files Browse the repository at this point in the history
fix #6664

directly modifying the value returned by Lister may affect
the evaluation during the next reconciliation.
  • Loading branch information
l-qing committed May 17, 2023
1 parent 5abf7c2 commit 9f14a9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ func setTaskRunStatusBasedOnStepStatus(ctx context.Context, logger *zap.SugaredL
}
// Continue with extraction of termination messages
for _, s := range stepStatuses {
if s.State.Terminated != nil && len(s.State.Terminated.Message) != 0 {
msg := s.State.Terminated.Message
// Avoid changing the original value by modifying the pointer value.
state := s.State.DeepCopy()
if state.Terminated != nil && len(state.Terminated.Message) != 0 {
msg := state.Terminated.Message

results, err := termination.ParseMessage(logger, msg)
if err != nil {
Expand All @@ -217,18 +219,18 @@ func setTaskRunStatusBasedOnStepStatus(ctx context.Context, logger *zap.SugaredL
logger.Errorf("%v", err)
merr = multierror.Append(merr, err)
} else {
s.State.Terminated.Message = msg
state.Terminated.Message = msg
}
if time != nil {
s.State.Terminated.StartedAt = *time
state.Terminated.StartedAt = *time
}
if exitCode != nil {
s.State.Terminated.ExitCode = *exitCode
state.Terminated.ExitCode = *exitCode
}
}
}
trs.Steps = append(trs.Steps, v1beta1.StepState{
ContainerState: *s.State.DeepCopy(),
ContainerState: *state,
Name: trimStepPrefix(s.Name),
ContainerName: s.Name,
ImageID: s.ImageID,
Expand Down
18 changes: 18 additions & 0 deletions pkg/pod/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func TestSetTaskRunStatusBasedOnStepStatus(t *testing.T) {
},
},
}},
}, {
desc: "The ExitCode in the result cannot modify the original ExitCode",
ContainerStatuses: []corev1.ContainerStatus{{
Name: "step-bar-0",
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 0,
Message: `[{"key":"ExitCode","value":"1","type":3}]`,
},
},
}},
}} {
t.Run(c.desc, func(t *testing.T) {
startTime := time.Date(2010, 1, 1, 1, 1, 1, 1, time.UTC)
Expand All @@ -88,10 +99,17 @@ func TestSetTaskRunStatusBasedOnStepStatus(t *testing.T) {

logger, _ := logging.NewLogger("", "status")
kubeclient := fakek8s.NewSimpleClientset()
originalStatuses := make([]corev1.ContainerStatus, 0, len(c.ContainerStatuses))
for _, cs := range c.ContainerStatuses {
originalStatuses = append(originalStatuses, *cs.DeepCopy())
}
merr := setTaskRunStatusBasedOnStepStatus(context.Background(), logger, c.ContainerStatuses, &tr, corev1.PodRunning, kubeclient, &v1beta1.TaskSpec{})
if merr != nil {
t.Errorf("setTaskRunStatusBasedOnStepStatus: %s", merr)
}
if d := cmp.Diff(originalStatuses, c.ContainerStatuses); d != "" {
t.Errorf("container statuses changed: %s", diff.PrintWantGot(d))
}
})
}
}
Expand Down

0 comments on commit 9f14a9a

Please sign in to comment.