Skip to content

Commit 8892f42

Browse files
committed
Extract two cases from convertErrorToProgressing into its own function
1 parent 4b6ad66 commit 8892f42

File tree

1 file changed

+53
-45
lines changed

1 file changed

+53
-45
lines changed

pkg/cvo/status.go

+53-45
Original file line numberDiff line numberDiff line change
@@ -565,59 +565,67 @@ func convertErrorToProgressing(now time.Time, statusFailure error) (reason strin
565565
case payload.UpdateEffectReport:
566566
return uErr.Reason, uErr.Error(), false
567567
case payload.UpdateEffectNone:
568-
var exceeded []string
569-
names := uErr.Names
570-
if len(names) == 0 {
571-
names = []string{uErr.Name}
572-
}
573-
var machineConfig bool
574-
for _, name := range names {
575-
m := 30 * time.Minute
576-
// It takes longer to upgrade MCO
577-
if name == "machine-config" {
578-
m = 3 * m
579-
}
580-
t := payload.COUpdateStartTimesGet(name)
581-
if (!t.IsZero()) && t.Before(now.Add(-(m))) {
582-
if name == "machine-config" {
583-
machineConfig = true
584-
} else {
585-
exceeded = append(exceeded, name)
586-
}
587-
}
588-
}
589-
// returns true in those slow cases because it is still only a suspicion
590-
if len(exceeded) > 0 && !machineConfig {
591-
return slowCOUpdatePrefix + uErr.Reason, fmt.Sprintf("waiting on %s over 30 minutes which is longer than expected", strings.Join(exceeded, ", ")), true
592-
}
593-
if len(exceeded) > 0 && machineConfig {
594-
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
595-
}
596-
if len(exceeded) == 0 && machineConfig {
597-
return slowCOUpdatePrefix + uErr.Reason, "waiting on machine-config over 90 minutes which is longer than expected", true
598-
}
599-
return uErr.Reason, fmt.Sprintf("waiting on %s", strings.Join(names, ", ")), true
568+
return convertErrorToProgressingForUpdateEffectNone(uErr, now)
600569
case payload.UpdateEffectFail:
601570
return "", "", false
602571
case payload.UpdateEffectFailAfterInterval:
603-
var exceeded []string
604-
threshold := now.Add(-(40 * time.Minute))
605-
names := uErr.Names
606-
if len(names) == 0 {
607-
names = []string{uErr.Name}
608-
}
609-
for _, name := range names {
610-
if payload.COUpdateStartTimesGet(name).Before(threshold) {
572+
return convertErrorToProgressingForUpdateEffectFailAfterInterval(uErr, now)
573+
}
574+
return "", "", false
575+
}
576+
577+
func convertErrorToProgressingForUpdateEffectNone(uErr *payload.UpdateError, now time.Time) (string, string, bool) {
578+
var exceeded []string
579+
names := uErr.Names
580+
if len(names) == 0 {
581+
names = []string{uErr.Name}
582+
}
583+
var machineConfig bool
584+
for _, name := range names {
585+
m := 30 * time.Minute
586+
// It takes longer to upgrade MCO
587+
if name == "machine-config" {
588+
m = 3 * m
589+
}
590+
t := payload.COUpdateStartTimesGet(name)
591+
if (!t.IsZero()) && t.Before(now.Add(-(m))) {
592+
if name == "machine-config" {
593+
machineConfig = true
594+
} else {
611595
exceeded = append(exceeded, name)
612596
}
613597
}
614-
if len(exceeded) > 0 {
615-
return uErr.Reason, fmt.Sprintf("wait has exceeded 40 minutes for these operators: %s", strings.Join(exceeded, ", ")), false
616-
} else {
617-
return uErr.Reason, fmt.Sprintf("waiting up to 40 minutes on %s", uErr.Name), true
598+
}
599+
// returns true in those slow cases because it is still only a suspicion
600+
if len(exceeded) > 0 && !machineConfig {
601+
return slowCOUpdatePrefix + uErr.Reason, fmt.Sprintf("waiting on %s over 30 minutes which is longer than expected", strings.Join(exceeded, ", ")), true
602+
}
603+
if len(exceeded) > 0 && machineConfig {
604+
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
605+
}
606+
if len(exceeded) == 0 && machineConfig {
607+
return slowCOUpdatePrefix + uErr.Reason, "waiting on machine-config over 90 minutes which is longer than expected", true
608+
}
609+
return uErr.Reason, fmt.Sprintf("waiting on %s", strings.Join(names, ", ")), true
610+
}
611+
612+
func convertErrorToProgressingForUpdateEffectFailAfterInterval(uErr *payload.UpdateError, now time.Time) (string, string, bool) {
613+
var exceeded []string
614+
threshold := now.Add(-(40 * time.Minute))
615+
names := uErr.Names
616+
if len(names) == 0 {
617+
names = []string{uErr.Name}
618+
}
619+
for _, name := range names {
620+
if payload.COUpdateStartTimesGet(name).Before(threshold) {
621+
exceeded = append(exceeded, name)
618622
}
619623
}
620-
return "", "", false
624+
if len(exceeded) > 0 {
625+
return uErr.Reason, fmt.Sprintf("wait has exceeded 40 minutes for these operators: %s", strings.Join(exceeded, ", ")), false
626+
} else {
627+
return uErr.Reason, fmt.Sprintf("waiting up to 40 minutes on %s", uErr.Name), true
628+
}
621629
}
622630

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

0 commit comments

Comments
 (0)