Skip to content

Commit f3edeb8

Browse files
cfergeaugbraad
authored andcommitted
Issue #414 preflight: Move oc caching to common code
Now that 69f693f introduced a file for preflight checks common to all platforms, we can move the preflight check that the oc binary is present to that file rather than duplicating it between all the platforms. This fixes #380 and #414
1 parent 142196d commit f3edeb8

File tree

4 files changed

+22
-62
lines changed

4 files changed

+22
-62
lines changed

pkg/crc/preflight/preflight_checks_common.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package preflight
22

33
import (
44
"bufio"
5+
"errors"
56
"fmt"
67
"os"
78

@@ -11,6 +12,8 @@ import (
1112
cmdConfig "github.com/code-ready/crc/cmd/crc/cmd/config"
1213
"github.com/code-ready/crc/pkg/crc/config"
1314
"github.com/code-ready/crc/pkg/crc/constants"
15+
"github.com/code-ready/crc/pkg/crc/logging"
16+
"github.com/code-ready/crc/pkg/crc/oc"
1417
)
1518

1619
func checkBundleCached() (bool, error) {
@@ -46,3 +49,22 @@ func fixBundleCached() (bool, error) {
4649
}
4750
return false, fmt.Errorf("CRC bundle is not embedded in the binary, see 'crc help' for more details.")
4851
}
52+
53+
// Check if oc binary is cached or not
54+
func checkOcBinaryCached() (bool, error) {
55+
oc := oc.OcCached{}
56+
if !oc.IsCached() {
57+
return false, errors.New("oc binary is not cached.")
58+
}
59+
logging.Debug("oc binary already cached")
60+
return true, nil
61+
}
62+
63+
func fixOcBinaryCached() (bool, error) {
64+
oc := oc.OcCached{}
65+
if err := oc.EnsureIsCached(); err != nil {
66+
return false, fmt.Errorf("Not able to download oc %v", err)
67+
}
68+
logging.Debug("oc binary cached")
69+
return true, nil
70+
}

pkg/crc/preflight/preflight_checks_darwin.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/code-ready/crc/pkg/crc/constants"
1717
"github.com/code-ready/crc/pkg/crc/logging"
18-
"github.com/code-ready/crc/pkg/crc/oc"
1918
dl "github.com/code-ready/crc/pkg/download"
2019
crcos "github.com/code-ready/crc/pkg/os"
2120
)
@@ -237,25 +236,6 @@ func fixResolverFilePermissions() (bool, error) {
237236
return addFileWritePermissionToUser(resolverFile)
238237
}
239238

240-
// Check if oc binary is cached or not
241-
func checkOcBinaryCached() (bool, error) {
242-
oc := oc.OcCached{}
243-
if !oc.IsCached() {
244-
return false, errors.New("oc binary is not cached.")
245-
}
246-
logging.Debug("oc binary already cached")
247-
return true, nil
248-
}
249-
250-
func fixOcBinaryCached() (bool, error) {
251-
oc := oc.OcCached{}
252-
if err := oc.EnsureIsCached(); err != nil {
253-
return false, fmt.Errorf("Not able to download oc %v", err)
254-
}
255-
logging.Debug("oc binary cached")
256-
return true, nil
257-
}
258-
259239
func checkResolvConfFilePermissions() (bool, error) {
260240
return isUserHaveFileWritePermission(hostFile)
261241
}

pkg/crc/preflight/preflight_checks_linux.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/code-ready/crc/pkg/crc/constants"
1717
"github.com/code-ready/crc/pkg/crc/logging"
1818
"github.com/code-ready/crc/pkg/crc/machine/libvirt"
19-
"github.com/code-ready/crc/pkg/crc/oc"
2019
"github.com/code-ready/crc/pkg/crc/systemd"
2120
"github.com/code-ready/crc/pkg/download"
2221

@@ -447,22 +446,3 @@ func fixCrcNetworkManagerConfig() (bool, error) {
447446
logging.Debug("NetworkManager configuration fixed")
448447
return true, nil
449448
}
450-
451-
// Check if oc binary is cached or not
452-
func checkOcBinaryCached() (bool, error) {
453-
oc := oc.OcCached{}
454-
if !oc.IsCached() {
455-
return false, errors.New("oc binary is not cached.")
456-
}
457-
logging.Debug("oc binary already cached")
458-
return true, nil
459-
}
460-
461-
func fixOcBinaryCached() (bool, error) {
462-
oc := oc.OcCached{}
463-
if err := oc.EnsureIsCached(); err != nil {
464-
return false, fmt.Errorf("Not able to download oc %v", err)
465-
}
466-
logging.Debug("oc binary cached")
467-
return true, nil
468-
}

pkg/crc/preflight/preflight_checks_windows.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"strconv"
88
"strings"
99

10-
"github.com/code-ready/crc/pkg/crc/logging"
11-
"github.com/code-ready/crc/pkg/crc/oc"
12-
1310
"github.com/code-ready/crc/pkg/crc/errors"
1411
"github.com/code-ready/crc/pkg/os/windows/powershell"
1512
)
@@ -22,25 +19,6 @@ const (
2219
hypervDefaultVirtualSwitchId = "c08cb7b8-9b3c-408e-8e30-5e16a3aeb444"
2320
)
2421

25-
// Check if oc binary is cached or not
26-
func checkOcBinaryCached() (bool, error) {
27-
oc := oc.OcCached{}
28-
if !oc.IsCached() {
29-
return false, errors.New("oc binary is not cached.")
30-
}
31-
logging.Debug("oc binary already cached")
32-
return true, nil
33-
}
34-
35-
func fixOcBinaryCached() (bool, error) {
36-
oc := oc.OcCached{}
37-
if err := oc.EnsureIsCached(); err != nil {
38-
return false, fmt.Errorf("Not able to download oc %v", err)
39-
}
40-
logging.Debug("oc binary cached")
41-
return true, nil
42-
}
43-
4422
func checkVersionOfWindowsUpdate() (bool, error) {
4523
windowsReleaseId := `(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId`
4624

0 commit comments

Comments
 (0)