Skip to content

Commit

Permalink
remove old launchd config for tray from host during setup
Browse files Browse the repository at this point in the history
since the tray now handles the autostart and it is unaware
of old existing launchd configs, this is necessary to prevent
two instances of tray to be launched and interfering
  • Loading branch information
anjannath committed Mar 14, 2022
1 parent 94bb587 commit 248cec0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 23 additions & 0 deletions pkg/crc/preflight/preflight_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package preflight

import (
"fmt"
"os"
"path/filepath"

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/network"
Expand Down Expand Up @@ -58,6 +60,26 @@ func hyperkitPreflightChecks(networkMode network.Mode) []Check {
}
}

/*
* Following check should be removed after 2-3 releases
* since the tray now handles the autostart and it is unaware
* of existing launchd configs, this is necessary to prevent
* two instances of tray to be launched and interfering
*/
var trayLaunchdCleanupChecks = []Check{
{
configKeySuffix: "check-old-autostart",
checkDescription: "Checking if old launchd config for tray autostart exists",
check: func() error { return fmt.Errorf("force trigger cleanup to remove old launchd config for tray") },
fixDescription: "Removing old launchd config for tray autostart",
fix: func() error {
_ = os.Remove(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.tray.plist"))
return os.Remove(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.daemon.plist"))
},

labels: labels{Os: Darwin},
},
}
var resolverPreflightChecks = []Check{
{
configKeySuffix: "check-resolver-file-permissions",
Expand Down Expand Up @@ -92,6 +114,7 @@ func getChecks(mode network.Mode, bundlePath string, preset crcpreset.Preset) []
checks = append(checks, hyperkitPreflightChecks(mode)...)
checks = append(checks, resolverPreflightChecks...)
checks = append(checks, bundleCheck(bundlePath, preset))
checks = append(checks, trayLaunchdCleanupChecks...)

return checks
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/crc/preflight/preflight_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
func TestCountConfigurationOptions(t *testing.T) {
cfg := config.New(config.NewEmptyInMemoryStorage())
RegisterSettings(cfg)
assert.Len(t, cfg.AllConfigs(), 11)
assert.Len(t, cfg.AllConfigs(), 12)
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 16)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 16)
assert.Len(t, getPreflightChecks(true, 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(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 15)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 15)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 16)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 16)
}

0 comments on commit 248cec0

Please sign in to comment.