Skip to content

Commit b0f13d9

Browse files
hongkailiuopenshift-cherrypick-robot
authored andcommitted
Extract two cases from convertErrorToProgressing into its own function
1 parent 7e4a336 commit b0f13d9

File tree

1 file changed

+53
-45
lines changed

1 file changed

+53
-45
lines changed

pkg/cvo/status.go

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -559,59 +559,67 @@ func convertErrorToProgressing(now time.Time, statusFailure error) (reason strin
559559
case payload.UpdateEffectReport:
560560
return uErr.Reason, uErr.Error(), false
561561
case payload.UpdateEffectNone:
562-
var exceeded []string
563-
names := uErr.Names
564-
if len(names) == 0 {
565-
names = []string{uErr.Name}
566-
}
567-
var machineConfig bool
568-
for _, name := range names {
569-
m := 30 * time.Minute
570-
// It takes longer to upgrade MCO
571-
if name == "machine-config" {
572-
m = 3 * m
573-
}
574-
t := payload.COUpdateStartTimesGet(name)
575-
if (!t.IsZero()) && t.Before(now.Add(-(m))) {
576-
if name == "machine-config" {
577-
machineConfig = true
578-
} else {
579-
exceeded = append(exceeded, name)
580-
}
581-
}
582-
}
583-
// returns true in those slow cases because it is still only a suspicion
584-
if len(exceeded) > 0 && !machineConfig {
585-
return slowCOUpdatePrefix + uErr.Reason, fmt.Sprintf("waiting on %s over 30 minutes which is longer than expected", strings.Join(exceeded, ", ")), true
586-
}
587-
if len(exceeded) > 0 && machineConfig {
588-
return slowCOUpdatePrefix + uErr.Reason, fmt.Sprintf("waiting on %s over 30 minutes and machine-config over 90 minutes which is longer than expected", strings.Join(exceeded, ", ")), true
589-
}
590-
if len(exceeded) == 0 && machineConfig {
591-
return slowCOUpdatePrefix + uErr.Reason, "waiting on machine-config over 90 minutes which is longer than expected", true
592-
}
593-
return uErr.Reason, fmt.Sprintf("waiting on %s", strings.Join(names, ", ")), true
562+
return convertErrorToProgressingForUpdateEffectNone(uErr, now)
594563
case payload.UpdateEffectFail:
595564
return "", "", false
596565
case payload.UpdateEffectFailAfterInterval:
597-
var exceeded []string
598-
threshold := now.Add(-(40 * time.Minute))
599-
names := uErr.Names
600-
if len(names) == 0 {
601-
names = []string{uErr.Name}
602-
}
603-
for _, name := range names {
604-
if payload.COUpdateStartTimesGet(name).Before(threshold) {
566+
return convertErrorToProgressingForUpdateEffectFailAfterInterval(uErr, now)
567+
}
568+
return "", "", false
569+
}
570+
571+
func convertErrorToProgressingForUpdateEffectNone(uErr *payload.UpdateError, now time.Time) (string, string, bool) {
572+
var exceeded []string
573+
names := uErr.Names
574+
if len(names) == 0 {
575+
names = []string{uErr.Name}
576+
}
577+
var machineConfig bool
578+
for _, name := range names {
579+
m := 30 * time.Minute
580+
// It takes longer to upgrade MCO
581+
if name == "machine-config" {
582+
m = 3 * m
583+
}
584+
t := payload.COUpdateStartTimesGet(name)
585+
if (!t.IsZero()) && t.Before(now.Add(-(m))) {
586+
if name == "machine-config" {
587+
machineConfig = true
588+
} else {
605589
exceeded = append(exceeded, name)
606590
}
607591
}
608-
if len(exceeded) > 0 {
609-
return uErr.Reason, fmt.Sprintf("wait has exceeded 40 minutes for these operators: %s", strings.Join(exceeded, ", ")), false
610-
} else {
611-
return uErr.Reason, fmt.Sprintf("waiting up to 40 minutes on %s", uErr.Name), true
592+
}
593+
// returns true in those slow cases because it is still only a suspicion
594+
if len(exceeded) > 0 && !machineConfig {
595+
return slowCOUpdatePrefix + uErr.Reason, fmt.Sprintf("waiting on %s over 30 minutes which is longer than expected", strings.Join(exceeded, ", ")), true
596+
}
597+
if len(exceeded) > 0 && machineConfig {
598+
return slowCOUpdatePrefix + uErr.Reason, fmt.Sprintf("waiting on %s over 30 minutes and machine-config over 90 minutes which is longer than expected", strings.Join(exceeded, ", ")), true
599+
}
600+
if len(exceeded) == 0 && machineConfig {
601+
return slowCOUpdatePrefix + uErr.Reason, "waiting on machine-config over 90 minutes which is longer than expected", true
602+
}
603+
return uErr.Reason, fmt.Sprintf("waiting on %s", strings.Join(names, ", ")), true
604+
}
605+
606+
func convertErrorToProgressingForUpdateEffectFailAfterInterval(uErr *payload.UpdateError, now time.Time) (string, string, bool) {
607+
var exceeded []string
608+
threshold := now.Add(-(40 * time.Minute))
609+
names := uErr.Names
610+
if len(names) == 0 {
611+
names = []string{uErr.Name}
612+
}
613+
for _, name := range names {
614+
if payload.COUpdateStartTimesGet(name).Before(threshold) {
615+
exceeded = append(exceeded, name)
612616
}
613617
}
614-
return "", "", false
618+
if len(exceeded) > 0 {
619+
return uErr.Reason, fmt.Sprintf("wait has exceeded 40 minutes for these operators: %s", strings.Join(exceeded, ", ")), false
620+
} else {
621+
return uErr.Reason, fmt.Sprintf("waiting up to 40 minutes on %s", uErr.Name), true
622+
}
615623
}
616624

617625
// syncFailingStatus handles generic errors in the cluster version. It tries to preserve

0 commit comments

Comments
 (0)