Skip to content

Commit b5cd73f

Browse files
Merge pull request #5033 from dkhater-redhat/misleading-error-render-cont
OCPBUGS-54697: error from generateAndValidateRenderedMachineConfig function can be misleading
2 parents 8323a86 + 920a271 commit b5cd73f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

pkg/controller/render/render_controller.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package render
22

33
import (
44
"context"
5-
goerrs "errors"
65
"fmt"
76
"reflect"
87
"sort"
8+
"strings"
99
"time"
1010

1111
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
@@ -667,8 +667,33 @@ func generateAndValidateRenderedMachineConfig(currentMC *mcfgv1.MachineConfig, p
667667

668668
klog.V(4).Infof("Considering generated MachineConfig %q", generated.Name)
669669

670-
if err := ctrlcommon.IsRenderedConfigReconcilable(currentMC, generated); err != nil {
671-
return nil, goerrs.Join(err, ctrlcommon.IsComponentConfigsReconcilable(currentMC, configs))
670+
if fullErr := ctrlcommon.IsRenderedConfigReconcilable(currentMC, generated); fullErr != nil {
671+
fullMsg := fullErr.Error()
672+
673+
// trying to match error reason suffix
674+
for _, cfg := range configs {
675+
singleErr := ctrlcommon.IsComponentConfigsReconcilable(
676+
currentMC, []*mcfgv1.MachineConfig{cfg},
677+
)
678+
if singleErr == nil {
679+
continue
680+
}
681+
singleMsg := singleErr.Error()
682+
683+
// split off prefix
684+
parts := strings.SplitN(singleMsg, ": ", 2)
685+
if len(parts) == 2 {
686+
reason := parts[1]
687+
if strings.Contains(fullMsg, reason) {
688+
klog.V(4).Infof("match found for base %q on reason %q", cfg.Name, reason)
689+
return nil, fmt.Errorf("reconciliation failed between current config %q and base config %q: %s", currentMC.Name, cfg.Name, reason)
690+
}
691+
}
692+
}
693+
694+
// fallback
695+
compErr := ctrlcommon.IsComponentConfigsReconcilable(currentMC, configs)
696+
return nil, fmt.Errorf("render reconciliation error: %v; component errors: %v", fullErr, compErr)
672697
}
673698

674699
klog.V(4).Infof("Rendered MachineConfig %q is reconcilable against %q", generated.Name, currentMC.Name)

0 commit comments

Comments
 (0)