Skip to content

Commit 3cd57bd

Browse files
committed
Align code with private repository
1 parent 7e40509 commit 3cd57bd

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

test/extended-priv/machineconfigpool.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,11 @@ func (mcp *MachineConfigPool) RecoverFromDegraded() error {
600600
mcpNodes, _ := mcp.GetNodes()
601601
for _, node := range mcpNodes {
602602
logger.Infof("Restoring desired config in node: %s", node)
603-
if node.IsUpdated() {
603+
isUpdated, err := node.IsUpdated()
604+
if err != nil {
605+
return fmt.Errorf("Error checking if node %s is updated: %s", node.GetName(), err)
606+
}
607+
if isUpdated {
604608
logger.Infof("node is updated, don't need to recover")
605609
} else {
606610
err := node.RestoreDesiredConfig()
@@ -814,9 +818,13 @@ func DebugDegradedStatus(mcp *MachineConfigPool) {
814818
allNodes, err := nodeList.GetAll()
815819
if err == nil {
816820
for _, node := range allNodes {
817-
state := node.GetMachineConfigState()
818-
if state != "Done" {
819-
logger.Infof("NODE %s IS %s", node.GetName(), state)
821+
state, err := node.GetMachineConfigState()
822+
if state != "Done" || err != nil {
823+
if err != nil {
824+
logger.Infof("Error getting machine config state for node %s: %v", node.GetName(), err)
825+
} else {
826+
logger.Infof("NODE %s IS %s", node.GetName(), state)
827+
}
820828
logger.Infof("%s", node.PrettyString())
821829
logger.Infof("#######################\n\n")
822830
mcdLogs, err := node.GetMCDaemonLogs("")

test/extended-priv/node.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ func (n *Node) GetCurrentBootOSImage() (string, error) {
212212

213213
// RestoreDesiredConfig changes the value of the desiredConfig annotation to equal the value of currentConfig. desiredConfig=currentConfig.
214214
func (n *Node) RestoreDesiredConfig() error {
215-
currentConfig := n.GetCurrentMachineConfig()
215+
currentConfig, err := n.GetCurrentMachineConfig()
216+
if err != nil {
217+
return err
218+
}
216219
if currentConfig == "" {
217220
return fmt.Errorf("currentConfig annotation has an empty value in node %s", n.GetName())
218221
}
@@ -227,8 +230,8 @@ func (n *Node) RestoreDesiredConfig() error {
227230
}
228231

229232
// GetCurrentMachineConfig returns the ID of the current machine config used in the node
230-
func (n *Node) GetCurrentMachineConfig() string {
231-
return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/currentConfig}`)
233+
func (n *Node) GetCurrentMachineConfig() (string, error) {
234+
return n.Get(`{.metadata.annotations.machineconfiguration\.openshift\.io/currentConfig}`)
232235
}
233236

234237
// GetCurrentImage returns the current image used in this node
@@ -237,13 +240,13 @@ func (n *Node) GetCurrentImage() string {
237240
}
238241

239242
// GetDesiredMachineConfig returns the ID of the machine config that we want the node to use
240-
func (n *Node) GetDesiredMachineConfig() string {
241-
return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/desiredConfig}`)
243+
func (n *Node) GetDesiredMachineConfig() (string, error) {
244+
return n.Get(`{.metadata.annotations.machineconfiguration\.openshift\.io/desiredConfig}`)
242245
}
243246

244247
// GetMachineConfigState returns the State of machineconfiguration process
245-
func (n *Node) GetMachineConfigState() string {
246-
return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/state}`)
248+
func (n *Node) GetMachineConfigState() (string, error) {
249+
return n.Get(`{.metadata.annotations.machineconfiguration\.openshift\.io/state}`)
247250
}
248251

249252
// PatchDesiredConfig patches the desiredConfig annotation with the provided value
@@ -272,8 +275,23 @@ func (n *Node) HasBeenDrained() bool {
272275
}
273276

274277
// IsUpdated returns if the node is pending for machineconfig configuration or it is up to date
275-
func (n *Node) IsUpdated() bool {
276-
return (n.GetCurrentMachineConfig() == n.GetDesiredMachineConfig()) && (n.GetMachineConfigState() == "Done")
278+
func (n *Node) IsUpdated() (bool, error) {
279+
currentConfig, err := n.GetCurrentMachineConfig()
280+
if err != nil {
281+
return false, err
282+
}
283+
284+
desiredConfig, err := n.GetDesiredMachineConfig()
285+
if err != nil {
286+
return false, err
287+
}
288+
289+
state, err := n.GetMachineConfigState()
290+
if err != nil {
291+
return false, err
292+
}
293+
294+
return (currentConfig == desiredConfig) && (state == "Done"), nil
277295
}
278296

279297
// IsTainted returns if the node hast taints or not

0 commit comments

Comments
 (0)