Skip to content

Commit

Permalink
preflight: Add labels to checks
Browse files Browse the repository at this point in the history
This is done separately as this is quite noisy. This adds labels to
each preflight check defining when they should be used. The next commits
will then add a filter API making use of these labels. It will then be
able to automatically select which checks to use depending on the user
system configuration.
  • Loading branch information
cfergeau authored and praveenkumar committed Jun 3, 2021
1 parent 2f3c550 commit 1ef71c9
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/crc/preflight/labels.go
@@ -0,0 +1,33 @@
package preflight

type LabelName uint32

const (
Os LabelName = iota
NetworkMode

// Keep it last
lastLabelName // will be used in OS-specific go files to extend LabelName
)

type LabelValue uint32

const (
// os
Darwin LabelValue = iota
Linux
Windows

// network mode
User
System

// Keep it last
lastLabelValue // will be used in OS-specific go files to extend LabelValue
)

var (
None = labels{}
)

type labels map[LabelName]LabelValue
2 changes: 2 additions & 0 deletions pkg/crc/preflight/preflight.go
Expand Up @@ -30,6 +30,8 @@ type Check struct {
flags Flags
cleanupDescription string
cleanup CleanUpFunc

labels labels
}

func (check *Check) getSkipConfigName() string {
Expand Down
16 changes: 16 additions & 0 deletions pkg/crc/preflight/preflight_checks_common.go
Expand Up @@ -27,6 +27,8 @@ var bundleCheck = Check{
fixDescription: "Extracting bundle from the CRC executable",
fix: fixBundleExtracted,
flags: SetupOnly,

labels: None,
}

var genericPreflightChecks = []Check{
Expand All @@ -36,6 +38,8 @@ var genericPreflightChecks = []Check{
check: checkAdminHelperExecutableCached,
fixDescription: "Caching crc-admin-helper executable",
fix: fixAdminHelperExecutableCached,

labels: None,
},
{
configKeySuffix: "check-obsolete-admin-helper",
Expand All @@ -51,6 +55,8 @@ var genericPreflightChecks = []Check{
check: checkSupportedCPUArch,
fixDescription: "CodeReady Containers is only supported on x86_64 hardware",
flags: NoFix,

labels: None,
},
{
configKeySuffix: "check-ram",
Expand All @@ -60,26 +66,36 @@ var genericPreflightChecks = []Check{
},
fixDescription: fmt.Sprintf("crc requires at least %s to run", units.HumanSize(float64(constants.DefaultMemory*1024*1024))),
flags: NoFix,

labels: None,
},
{
cleanupDescription: "Removing CRC Machine Instance directory",
cleanup: removeCRCMachinesDir,
flags: CleanUpOnly,

labels: None,
},
{
cleanupDescription: "Removing hosts file records added by CRC",
cleanup: removeHostsFileEntry,
flags: CleanUpOnly,

labels: None,
},
{
cleanupDescription: "Removing older logs",
cleanup: removeOldLogs,
flags: CleanUpOnly,

labels: None,
},
{
cleanupDescription: "Removing pull secret from the keyring",
cleanup: cluster.ForgetPullSecret,
flags: CleanUpOnly,

labels: None,
},
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/crc/preflight/preflight_checks_network_linux.go
Expand Up @@ -21,20 +21,26 @@ var nmPreflightChecks = []Check{
check: checkSystemdNetworkdIsNotRunning,
fixDescription: "Network configuration with systemd-networkd is not supported. Perhaps you can try this new network mode: https://github.com/code-ready/crc/wiki/VPN-support--with-an--userland-network-stack",
flags: NoFix,

labels: labels{Os: Linux, NetworkMode: System},
},
{
configKeySuffix: "check-network-manager-installed",
checkDescription: "Checking if NetworkManager is installed",
check: checkNetworkManagerInstalled,
fixDescription: "NetworkManager is required and must be installed manually",
flags: NoFix,

labels: labels{Os: Linux, NetworkMode: System},
},
{
configKeySuffix: "check-network-manager-running",
checkDescription: "Checking if NetworkManager service is running",
check: checkNetworkManagerIsRunning,
fixDescription: "NetworkManager is required. Please make sure it is installed and running manually",
flags: NoFix,

labels: labels{Os: Linux, NetworkMode: System},
},
}

Expand All @@ -47,6 +53,8 @@ var dnsmasqPreflightChecks = []Check{
fix: fixCrcNetworkManagerConfig,
cleanupDescription: "Removing /etc/NetworkManager/conf.d/crc-nm-dnsmasq.conf file",
cleanup: removeCrcNetworkManagerConfig,

labels: labels{Os: Linux, NetworkMode: System, DNS: Dnsmasq},
},
{
configKeySuffix: "check-crc-dnsmasq-file",
Expand All @@ -56,6 +64,8 @@ var dnsmasqPreflightChecks = []Check{
fix: fixCrcDnsmasqConfigFile,
cleanupDescription: "Removing /etc/NetworkManager/dnsmasq.d/crc.conf file",
cleanup: removeCrcDnsmasqConfigFile,

labels: labels{Os: Linux, NetworkMode: System, DNS: Dnsmasq},
},
}

Expand Down Expand Up @@ -107,13 +117,17 @@ var systemdResolvedPreflightChecks = []Check{
check: checkCrcDnsmasqAndNetworkManagerConfigFile,
fixDescription: "Removing dnsmasq configuration file for NetworkManager",
fix: fixCrcDnsmasqAndNetworkManagerConfigFile,

labels: labels{Os: Linux, NetworkMode: System, DNS: SystemdResolved},
},
{
configKeySuffix: "check-systemd-resolved-running",
checkDescription: "Checking if the systemd-resolved service is running",
check: checkSystemdResolvedIsRunning,
fixDescription: "systemd-resolved is required on this distribution. Please make sure it is installed and running manually",
flags: NoFix,

labels: labels{Os: Linux, NetworkMode: System, DNS: SystemdResolved},
},
{
configKeySuffix: "check-network-manager-dispatcher-file",
Expand All @@ -123,6 +137,8 @@ var systemdResolvedPreflightChecks = []Check{
fix: fixCrcNetworkManagerDispatcherFile,
cleanupDescription: fmt.Sprintf("Removing %s file", crcNetworkManagerDispatcherPath),
cleanup: removeCrcNetworkManagerDispatcherFile,

labels: labels{Os: Linux, NetworkMode: System, DNS: SystemdResolved},
},
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/crc/preflight/preflight_checks_nonwin.go
Expand Up @@ -19,6 +19,9 @@ var nonWinPreflightChecks = []Check{
check: checkIfRunningAsNormalUser,
fixDescription: "crc should not be run as root",
flags: NoFix,

// no need for an "os" label as this is only built on relevant OSes through the use of golang build tags
labels: None,
},
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/crc/preflight/preflight_darwin.go
Expand Up @@ -16,25 +16,33 @@ func hyperkitPreflightChecks(networkMode network.Mode) []Check {
check: checkM1CPU,
fixDescription: "CodeReady Containers is unsupported on Apple M1 hardware",
flags: NoFix,

labels: labels{Os: Darwin},
},
{
configKeySuffix: "check-hyperkit-installed",
checkDescription: "Checking if HyperKit is installed",
check: checkHyperKitInstalled(networkMode),
fixDescription: "Setting up virtualization with HyperKit",
fix: fixHyperKitInstallation(networkMode),

labels: labels{Os: Darwin},
},
{
configKeySuffix: "check-hyperkit-driver",
checkDescription: "Checking if crc-driver-hyperkit is installed",
check: checkMachineDriverHyperKitInstalled(networkMode),
fixDescription: "Installing crc-machine-hyperkit",
fix: fixMachineDriverHyperKitInstalled(networkMode),

labels: labels{Os: Darwin},
},
{
cleanupDescription: "Stopping CRC Hyperkit process",
cleanup: stopCRCHyperkitProcess,
flags: CleanUpOnly,

labels: labels{Os: Darwin},
},
}
}
Expand All @@ -48,6 +56,8 @@ var resolverPreflightChecks = []Check{
fix: fixResolverFilePermissions,
cleanupDescription: fmt.Sprintf("Removing %s file", resolverFile),
cleanup: removeResolverFile,

labels: labels{Os: Darwin, NetworkMode: System},
},
}

Expand All @@ -60,6 +70,8 @@ var daemonSetupChecks = []Check{
flags: SetupOnly,
cleanupDescription: "Unload CodeReady Containers daemon",
cleanup: unLoadDaemonAgent,

labels: labels{Os: Darwin},
},
}

Expand All @@ -72,6 +84,8 @@ var traySetupChecks = []Check{
flags: SetupOnly,
cleanupDescription: "Removing launchd configuration for tray",
cleanup: removeTrayPlistFile,

labels: labels{Os: Darwin, Tray: Enabled},
},
{
checkDescription: "Check if CodeReady Containers tray is running",
Expand All @@ -81,9 +95,21 @@ var traySetupChecks = []Check{
flags: SetupOnly,
cleanupDescription: "Unload CodeReady Containers tray",
cleanup: unLoadTrayAgent,

labels: labels{Os: Darwin, Tray: Enabled},
},
}

const (
Tray LabelName = iota + lastLabelName
)

const (
// tray
Enabled LabelValue = iota + lastLabelValue
Disabled
)

// We want all preflight checks including
// - experimental checks
// - tray checks when using an installer, regardless of tray enabled or not
Expand Down

0 comments on commit 1ef71c9

Please sign in to comment.