From 6af9303feca6b2a98472eb1aba18c768ce17844f Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Mon, 15 Aug 2022 10:46:45 +0530 Subject: [PATCH] Update the kernel args to instance config during stop This PR is going to update the kernel paramater to instance config when stop operation happen. In mac we use kernel parameter as part of vfkit driver to start the instance but during the reboot it changes because of MCO and we are getting error during `start => stop => start` operation. ``` systemctl[787]: Failed to switch root: Specified switch root path '/sysroot' does not seem to be an OS tree. os-release file is missing. ``` ostree changes from (`boot.0` => `boot.1`) ``` ostree=/ostree/boot.0/rhcos/b6f1ba590ef2df8e30bd88833fd145bfbbd424eca8ad235f573f2a136f09b0d6/0 ``` to ``` ostree=/ostree/boot.1/rhcos/b6f1ba590ef2df8e30bd88833fd145bfbbd424eca8ad235f573f2a136f09b0d6/0 ``` As part of the MCO logs ``` Bootloader updated; bootconfig swap: yes; bootversion: boot.1.1, deployment count change: -1 ``` --- pkg/crc/machine/driver_darwin.go | 35 +++++++++++++++++++++++++++++++ pkg/crc/machine/driver_linux.go | 4 ++++ pkg/crc/machine/driver_windows.go | 4 ++++ pkg/crc/machine/stop.go | 3 +++ 4 files changed, 46 insertions(+) diff --git a/pkg/crc/machine/driver_darwin.go b/pkg/crc/machine/driver_darwin.go index 5edbd341a7..4251bfe6e3 100644 --- a/pkg/crc/machine/driver_darwin.go +++ b/pkg/crc/machine/driver_darwin.go @@ -1,10 +1,13 @@ package machine import ( + "context" "encoding/json" "errors" + "time" "github.com/code-ready/crc/pkg/crc/constants" + "github.com/code-ready/crc/pkg/crc/logging" "github.com/code-ready/crc/pkg/crc/machine/config" "github.com/code-ready/crc/pkg/crc/machine/vfkit" machineVf "github.com/code-ready/crc/pkg/drivers/vfkit" @@ -35,3 +38,35 @@ func updateDriverConfig(host *host.Host, driver *machineVf.Driver) error { return host.UpdateConfig(driverData) } + +func updateKernelArgs(vm *virtualMachine) error { + logging.Info("Updating kernel args...") + sshRunner, err := vm.SSHRunner() + if err != nil { + return err + } + defer sshRunner.Close() + + if err := sshRunner.WaitForConnectivity(context.Background(), 20*time.Second); err != nil { + return err + } + + stdout, stderr, err := sshRunner.RunPrivileged("Get kernel args", `-- sh -c 'rpm-ostree kargs'`) + if err != nil { + logging.Errorf("Failed to get kernel args: %v - %s", err, stderr) + return err + } + logging.Debugf("Kernel args: %s", stdout) + + vfkitDriver, err := loadDriverConfig(vm.Host) + if err != nil { + return err + } + logging.Debugf("Current Kernel args: %s", vfkitDriver.Cmdline) + vfkitDriver.Cmdline = stdout + + if err := updateDriverConfig(vm.Host, vfkitDriver); err != nil { + return err + } + return vm.api.Save(vm.Host) +} diff --git a/pkg/crc/machine/driver_linux.go b/pkg/crc/machine/driver_linux.go index caa5b2ef98..9805696ad0 100644 --- a/pkg/crc/machine/driver_linux.go +++ b/pkg/crc/machine/driver_linux.go @@ -38,6 +38,10 @@ func updateDriverConfig(host *host.Host, driver *machineLibvirt.Driver) error { return host.UpdateConfig(driverData) } +func updateKernelArgs(vm *virtualMachine) error { + return nil +} + /* func (r *RPCServerDriver) SetConfigRaw(data []byte, _ *struct{}) error { return json.Unmarshal(data, &r.ActualDriver) diff --git a/pkg/crc/machine/driver_windows.go b/pkg/crc/machine/driver_windows.go index 1f99937881..95d1a9422a 100644 --- a/pkg/crc/machine/driver_windows.go +++ b/pkg/crc/machine/driver_windows.go @@ -33,3 +33,7 @@ func updateDriverConfig(host *host.Host, driver *machineHyperv.Driver) error { } return host.UpdateConfig(driverData) } + +func updateKernelArgs(vm *virtualMachine) error { + return nil +} diff --git a/pkg/crc/machine/stop.go b/pkg/crc/machine/stop.go index 6402f54279..f03fa12f49 100644 --- a/pkg/crc/machine/stop.go +++ b/pkg/crc/machine/stop.go @@ -23,6 +23,9 @@ func (client *client) Stop() (state.State, error) { logging.Debugf("%v", err) } } + if err := updateKernelArgs(vm); err != nil { + logging.Debugf("%v", err) + } logging.Info("Stopping the instance, this may take a few minutes...") if err := vm.Stop(); err != nil { status, stateErr := vm.State()