mirror of
https://github.com/lukaszraczylo/jobs-manager-operator.git
synced 2026-10-11 05:28:07 +00:00
fix(controller): report Failed when a group fails
checkOverallStatus overwrote the Failed status with Running. A failed workflow stayed Running and kept requeueing. It now stays Failed and the failure event fires once. Also remove err shadowing in the visualization client.
This commit is contained in:
@@ -311,24 +311,28 @@ func (cp *connPackage) executeJob(j *jobsmanagerv1beta1.ManagedJobDefinition, g
|
||||
|
||||
func (cp *connPackage) checkOverallStatus() {
|
||||
groupsCompleted := 0
|
||||
failedGroup := ""
|
||||
negativeStatuses := []string{ExecutionStatusFailed, ExecutionStatusAborted}
|
||||
for _, group := range cp.mj.Spec.Groups {
|
||||
if group.Status == ExecutionStatusSucceeded {
|
||||
groupsCompleted++
|
||||
} else if pandati.ExistsInSlice(negativeStatuses, group.Status) {
|
||||
cp.mj.Status = ExecutionStatusFailed
|
||||
cp.r.Recorder.Eventf(cp.mj, corev1.EventTypeWarning, "Failure", "Run failed in group %s", group.Name)
|
||||
} else {
|
||||
continue
|
||||
} else if failedGroup == "" && pandati.ExistsInSlice(negativeStatuses, group.Status) {
|
||||
failedGroup = group.Name
|
||||
}
|
||||
}
|
||||
|
||||
if groupsCompleted == len(cp.mj.Spec.Groups) {
|
||||
switch {
|
||||
case failedGroup != "":
|
||||
if cp.mj.Status != ExecutionStatusFailed {
|
||||
cp.r.Recorder.Eventf(cp.mj, corev1.EventTypeWarning, "Failure", "Run failed in group %s", failedGroup)
|
||||
}
|
||||
cp.mj.Status = ExecutionStatusFailed
|
||||
case groupsCompleted == len(cp.mj.Spec.Groups):
|
||||
if cp.mj.Status != ExecutionStatusSucceeded {
|
||||
cp.r.Recorder.Eventf(cp.mj, corev1.EventTypeNormal, "Success", "Run completed successfuly")
|
||||
cp.r.Recorder.Eventf(cp.mj, corev1.EventTypeNormal, "Success", "Run completed successfully")
|
||||
}
|
||||
cp.mj.Status = ExecutionStatusSucceeded
|
||||
} else {
|
||||
default:
|
||||
cp.mj.Status = ExecutionStatusRunning
|
||||
}
|
||||
if err := cp.r.Status().Update(cp.ctx, cp.mj); err != nil {
|
||||
|
||||
@@ -315,10 +315,7 @@ func (s *ScrapperTestSuite) TestCheckOverallStatus_GroupFailed() {
|
||||
cp := s.newConnPackage(mj)
|
||||
cp.checkOverallStatus()
|
||||
|
||||
// Note: Current implementation sets running status after checking failed
|
||||
// This is the actual behavior - the status goes through the failed branch
|
||||
// but then gets overwritten by the final else block
|
||||
s.Equal(ExecutionStatusRunning, mj.Status)
|
||||
s.Equal(ExecutionStatusFailed, mj.Status)
|
||||
}
|
||||
|
||||
func (s *ScrapperTestSuite) TestCheckOverallStatus_GroupRunning() {
|
||||
|
||||
@@ -25,10 +25,10 @@ func NewClient() (*Client, error) {
|
||||
}
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
if err := clientgoscheme.AddToScheme(scheme); err != nil {
|
||||
if err = clientgoscheme.AddToScheme(scheme); err != nil {
|
||||
return nil, fmt.Errorf("failed to add client-go scheme: %w", err)
|
||||
}
|
||||
if err := jobsmanagerv1beta1.AddToScheme(scheme); err != nil {
|
||||
if err = jobsmanagerv1beta1.AddToScheme(scheme); err != nil {
|
||||
return nil, fmt.Errorf("failed to add jobsmanager scheme: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user