Skip to content

Commit

Permalink
Extract a method to convert openshift status to a user-friendly string
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose committed Nov 5, 2020
1 parent bb5adac commit 1e8943c
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions pkg/crc/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,36 +554,37 @@ func (client *client) Status() (*ClusterStatusResult, error) {
}
sshRunner := crcssh.CreateRunner(ip, constants.DefaultSSHPort, constants.GetPrivateKeyPath())
// check if all the clusteroperators are running
ocConfig := oc.UseOCWithSSH(sshRunner)

openshiftStatus := "Stopped"
operatorsStatus, err := cluster.GetClusterOperatorsStatus(ocConfig)
if err != nil {
openshiftStatus = "Not Reachable"
logging.Debug(err.Error())
}
if operatorsStatus.Available {
openshiftStatus = "Running"
}
if operatorsStatus.Degraded {
openshiftStatus = "Degraded"
}
if operatorsStatus.Progressing {
openshiftStatus = "Starting"
}
diskSize, diskUse, err := cluster.GetRootPartitionUsage(sshRunner)
if err != nil {
return nil, errors.Wrap(err, "Cannot get root partition usage")
}
return &ClusterStatusResult{
CrcStatus: vmStatus,
OpenshiftStatus: openshiftStatus,
OpenshiftStatus: getOpenShiftStatus(sshRunner),
OpenshiftVersion: crcBundleMetadata.GetOpenshiftVersion(),
DiskUse: diskUse,
DiskSize: diskSize,
}, nil
}

func getOpenShiftStatus(sshRunner *crcssh.Runner) string {
status, err := cluster.GetClusterOperatorsStatus(oc.UseOCWithSSH(sshRunner))
if err != nil {
logging.Debugf("cannot get OpenShift status: %v", err)
return "Not Reachable"
}
if status.Progressing {
return "Starting"
}
if status.Degraded {
return "Degraded"
}
if status.Available {
return "Running"
}
return "Stopped"
}

func (client *client) Exists() (bool, error) {
libMachineAPIClient, cleanup, err := createLibMachineClient(client.debug)
defer cleanup()
Expand Down

0 comments on commit 1e8943c

Please sign in to comment.