Skip to content

Commit

Permalink
ops: rename DryRebootHappened to FileExists
Browse files Browse the repository at this point in the history
Because that's effectively what it is. Also use that in another case
that was manually calling `stat`.
  • Loading branch information
jlebon committed Dec 20, 2024
1 parent 34b971a commit 95fa603
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (i *installer) waitForBootkube(ctx context.Context) {
return
case <-time.After(generalWaitInterval):
// check if bootkube is done every 5 seconds
if _, err := i.ops.ExecPrivilegeCommand(nil, "stat", "/opt/openshift/.bootkube.done"); err == nil {
if i.ops.FileExists("/opt/openshift/.bootkube.done") {
// in case bootkube is done log the status and return
i.log.Info("bootkube service completed")
out, _ := i.ops.ExecPrivilegeCommand(nil, "systemctl", "status", "bootkube.service")
Expand Down
4 changes: 2 additions & 2 deletions src/main/drymock/dry_mode_k8s_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func mockNodeList(mockk8sclient *k8s_client.MockK8SClient, clusterHosts config.DryClusterHosts, o ops.Ops) v1.NodeList {
nodeListPopulated := v1.NodeList{}
for _, clusterHost := range clusterHosts {
if !o.DryRebootHappened(clusterHost.RebootMarkerPath) {
if !o.FileExists(clusterHost.RebootMarkerPath) {
// Host didn't even reboot yet, don't pretend it's a node
continue
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func PrepareControllerDryMock(mockk8sclient *k8s_client.MockK8SClient, logger *l
mcsLogs := ""
for _, clusterHost := range clusterHosts {
// Add IP access log for each IP, this is how the controller determines which node has downloaded the ignition
if !o.DryRebootHappened(clusterHost.RebootMarkerPath) {
if !o.FileExists(clusterHost.RebootMarkerPath) {
// Host didn't even reboot yet, don't pretend it fetched the ignition
continue
}
Expand Down
12 changes: 6 additions & 6 deletions src/ops/mock_ops.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Ops interface {
EvaluateDiskSymlink(string) string
FormatDisk(string) error
CreateManifests(string, []byte) error
DryRebootHappened(markerPath string) bool
FileExists(markerPath string) bool
ExecPrivilegeCommand(liveLogger io.Writer, command string, args ...string) (string, error)
ReadFile(filePath string) ([]byte, error)
GetEncapsulatedMC(ignitionPath string) (*mcfgv1.MachineConfig, error)
Expand Down Expand Up @@ -434,7 +434,7 @@ func (o *ops) GetMCSLogs() (string, error) {
mcsLogs := ""
for _, clusterHost := range o.installerConfig.ParsedClusterHosts {
// Add IP access log for each IP, this is how the installer determines which node has downloaded the ignition
if !o.DryRebootHappened(clusterHost.RebootMarkerPath) {
if !o.FileExists(clusterHost.RebootMarkerPath) {
// Host didn't even reboot yet, don't pretend it fetched the ignition
continue
}
Expand Down Expand Up @@ -648,11 +648,12 @@ func (o *ops) CreateManifests(kubeconfig string, content []byte) error {
return nil
}

// DryRebootHappened checks if a reboot happened according to a particular reboot marker path
// The dry run installer creates this file on "Reboot" (instead of actually rebooting)
// We use this function to check whether the given node in the cluster have already rebooted
func (o *ops) DryRebootHappened(markerPath string) bool {
_, err := o.ExecPrivilegeCommand(nil, "stat", markerPath)
// FileExists checks if a file exists. It's notably used to check if a
// dry reboot happened. The dry run installer creates the marker file on
// "Reboot" (instead of actually rebooting) We use this function to check
// whether the given node in the cluster have already rebooted
func (o *ops) FileExists(path string) bool {
_, err := o.ExecPrivilegeCommand(nil, "stat", path)

return err == nil
}
Expand Down

0 comments on commit 95fa603

Please sign in to comment.