mcc: refactor node controller to use helper function
replace repetitive error checks with helper function in updateNode()
@@ -205,17 +205,10 @@ func (ctrl *Controller) updateNode(old, cur interface{}) {
var changed bool
oldReadyErr := checkNodeReady(oldNode)
newReadyErr := checkNodeReady(curNode)
- var oldReady, newReady string
- if oldReadyErr != nil {
- oldReady = oldReadyErr.Error()
- } else {
- oldReady = ""
- }
- if newReadyErr != nil {
- newReady = newReadyErr.Error()
- } else {
- newReady = ""
- }
+
+ oldReady := getErrorString(oldReadyErr)
+ newReady := getErrorString(newReadyErr)
+
if oldReady != newReady {
changed = true
if newReadyErr != nil {
@@ -573,3 +566,11 @@ func maxUnavailable(pool *mcfgv1.MachineConfigPool, nodes []*corev1.Node) (int,
}
return maxunavail, nil
}
+
+// getErrorString returns error string if not nil and empty string if error is nil
+func getErrorString(err error) string {
+ if err != nil {
+ return err.Error()
+ }
+ return ""
+}
