From 95fa60308d59a6888f7b8ea69b5b942b7ca54848 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 4 Sep 2024 16:14:42 -0400 Subject: [PATCH] ops: rename DryRebootHappened to FileExists Because that's effectively what it is. Also use that in another case that was manually calling `stat`. --- src/installer/installer.go | 2 +- src/main/drymock/dry_mode_k8s_mock.go | 4 ++-- src/ops/mock_ops.go | 12 ++++++------ src/ops/ops.go | 15 ++++++++------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/installer/installer.go b/src/installer/installer.go index 914388177..c44b0a064 100644 --- a/src/installer/installer.go +++ b/src/installer/installer.go @@ -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") diff --git a/src/main/drymock/dry_mode_k8s_mock.go b/src/main/drymock/dry_mode_k8s_mock.go index eaa1f523a..b959cef5c 100644 --- a/src/main/drymock/dry_mode_k8s_mock.go +++ b/src/main/drymock/dry_mode_k8s_mock.go @@ -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 } @@ -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 } diff --git a/src/ops/mock_ops.go b/src/ops/mock_ops.go index e4627769a..c17cf0a1a 100644 --- a/src/ops/mock_ops.go +++ b/src/ops/mock_ops.go @@ -83,18 +83,18 @@ func (mr *MockOpsMockRecorder) CreateRandomHostname(hostname any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRandomHostname", reflect.TypeOf((*MockOps)(nil).CreateRandomHostname), hostname) } -// DryRebootHappened mocks base method. -func (m *MockOps) DryRebootHappened(markerPath string) bool { +// FileExists mocks base method. +func (m *MockOps) FileExists(markerPath string) bool { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DryRebootHappened", markerPath) + ret := m.ctrl.Call(m, "FileExists", markerPath) ret0, _ := ret[0].(bool) return ret0 } -// DryRebootHappened indicates an expected call of DryRebootHappened. -func (mr *MockOpsMockRecorder) DryRebootHappened(markerPath any) *gomock.Call { +// FileExists indicates an expected call of FileExists. +func (mr *MockOpsMockRecorder) FileExists(markerPath any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DryRebootHappened", reflect.TypeOf((*MockOps)(nil).DryRebootHappened), markerPath) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FileExists", reflect.TypeOf((*MockOps)(nil).FileExists), markerPath) } // EvaluateDiskSymlink mocks base method. diff --git a/src/ops/ops.go b/src/ops/ops.go index 0640184c1..8a80ac729 100644 --- a/src/ops/ops.go +++ b/src/ops/ops.go @@ -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) @@ -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 } @@ -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 }