Skip to content

Commit

Permalink
Windows: Add check if admin helper service is running
Browse files Browse the repository at this point in the history
Admin helper service is created and started when installer is used.
Some of the issue we are getting is user directly try to use crc
from command line and see if the openshift routes are mapped in hosts
file. This PR is help to detect if the service is running and it doesn't
need any privilage permission but it doesn't create or start this
service because that need administrator privilages.
  • Loading branch information
praveenkumar committed Mar 28, 2022
1 parent 402eb95 commit 6e65f8f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/crc/constants/constants_windows.go
Expand Up @@ -6,4 +6,5 @@ const (
TapSocketPath = ""
DaemonHTTPNamedPipe = `\\.\pipe\crc-http`
DaemonTaskName = "crcDaemon"
AdminHelperServiceName = "CodeReadyContainersAdminHelper"
)
11 changes: 11 additions & 0 deletions pkg/crc/preflight/preflight_checks_windows.go
Expand Up @@ -183,3 +183,14 @@ func removeCrcVM() (err error) {
logging.Debug("'crc' VM is removed")
return nil
}

func checkIfAdminHelperServiceRunning() error {
stdout, stderr, err := powershell.Execute(fmt.Sprintf("(Get-Service %s).Status", constants.AdminHelperServiceName))
if err != nil {
return fmt.Errorf("%s service is not present %v: %s", constants.AdminHelperServiceName, err, stderr)
}
if strings.TrimSpace(stdout) != "Running" {
return fmt.Errorf("%s service is not running", constants.AdminHelperServiceName)
}
return nil
}
13 changes: 13 additions & 0 deletions pkg/crc/preflight/preflight_windows.go
Expand Up @@ -135,6 +135,18 @@ var daemonTaskChecks = []Check{
},
}

var adminHelperServiceCheks = []Check{
{
configKeySuffix: "check-admin-helper-service-running",
checkDescription: "Checking admin helper service is running",
check: checkIfAdminHelperServiceRunning,
fixDescription: "Make sure you installed the crc using installer",
flags: NoFix,

labels: labels{Os: Windows},
},
}

var errReboot = errors.New("Please reboot your system and run 'crc setup' to complete the setup process")

func username() string {
Expand Down Expand Up @@ -181,6 +193,7 @@ func getChecks(bundlePath string, preset crcpreset.Preset) []Check {
checks = append(checks, bundleCheck(bundlePath, preset))
checks = append(checks, genericCleanupChecks...)
checks = append(checks, daemonTaskChecks...)
checks = append(checks, adminHelperServiceCheks...)
return checks
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/crc/preflight/preflight_windows_test.go
Expand Up @@ -13,13 +13,13 @@ import (
func TestCountConfigurationOptions(t *testing.T) {
cfg := config.New(config.NewEmptyInMemoryStorage())
RegisterSettings(cfg)
assert.Len(t, cfg.AllConfigs(), 12)
assert.Len(t, cfg.AllConfigs(), 13)
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 17)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 17)
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)

assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
}

0 comments on commit 6e65f8f

Please sign in to comment.