diff --git a/cmd/config/config_test.go b/cmd/config/config_test.go index 8255b58130c..43540702a20 100644 --- a/cmd/config/config_test.go +++ b/cmd/config/config_test.go @@ -473,7 +473,7 @@ var _ = Describe("Config", Label("config"), func() { defer ghwTest.Clean() err := os.Setenv("ELEMENTAL_UPGRADE_RECOVERY", "true") - spec, err := ReadUpgradeSpec(cfg, nil) + spec, err := ReadUpgradeSpec(cfg, nil, false) Expect(err).ShouldNot(HaveOccurred()) // Overwrites recovery-system image, flags have priority over files and env vars Expect(spec.RecoverySystem.Source.Value() == "image/from:flag") diff --git a/cmd/install.go b/cmd/install.go index 0210c3371cf..7f2306fc787 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -24,7 +24,7 @@ import ( "github.com/rancher/elemental-toolkit/v2/cmd/config" "github.com/rancher/elemental-toolkit/v2/pkg/action" - "github.com/rancher/elemental-toolkit/v2/pkg/constants" + "github.com/rancher/elemental-toolkit/v2/pkg/constants" elementalError "github.com/rancher/elemental-toolkit/v2/pkg/error" "github.com/rancher/elemental-toolkit/v2/pkg/types" "github.com/rancher/elemental-toolkit/v2/pkg/utils" diff --git a/cmd/upgrade-recovery.go b/cmd/upgrade-recovery.go index e87f6661fc1..6da7a692beb 100644 --- a/cmd/upgrade-recovery.go +++ b/cmd/upgrade-recovery.go @@ -22,10 +22,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/rancher/elemental-toolkit/cmd/config" - "github.com/rancher/elemental-toolkit/pkg/action" - elementalError "github.com/rancher/elemental-toolkit/pkg/error" - v1 "github.com/rancher/elemental-toolkit/pkg/types/v1" + "github.com/rancher/elemental-toolkit/v2/cmd/config" + "github.com/rancher/elemental-toolkit/v2/pkg/action" + elementalError "github.com/rancher/elemental-toolkit/v2/pkg/error" + "github.com/rancher/elemental-toolkit/v2/pkg/types" ) // NewUpgradeCmd returns a new instance of the upgrade subcommand and appends it to @@ -48,7 +48,7 @@ func NewUpgradeRecoveryCmd(root *cobra.Command, addCheckRoot bool) *cobra.Comman if err != nil { return err } - mounter := v1.NewMounter(path) + mounter := types.NewMounter(path) cfg, err := config.ReadConfigRun(viper.GetString("config-dir"), cmd.Flags(), mounter) if err != nil { diff --git a/pkg/action/build-disk.go b/pkg/action/build-disk.go index 39767658ebc..849f57a52a9 100644 --- a/pkg/action/build-disk.go +++ b/pkg/action/build-disk.go @@ -426,7 +426,7 @@ func (b *BuildDiskAction) createStatePartitionImage() (*types.Image, error) { system := b.spec.System if b.spec.RecoverySystem.Source.String() == b.spec.System.String() { // Reuse already deployed root-tree from recovery image - system = v1.NewFileSrc(b.spec.RecoverySystem.File) + system = types.NewFileSrc(b.spec.RecoverySystem.File) b.spec.System.SetDigest(b.spec.RecoverySystem.Source.GetDigest()) } diff --git a/pkg/action/upgrade-recovery.go b/pkg/action/upgrade-recovery.go index 219a2926b24..c32b0a7ea92 100644 --- a/pkg/action/upgrade-recovery.go +++ b/pkg/action/upgrade-recovery.go @@ -22,19 +22,19 @@ import ( "path/filepath" "time" - "github.com/rancher/elemental-toolkit/pkg/constants" - "github.com/rancher/elemental-toolkit/pkg/elemental" - elementalError "github.com/rancher/elemental-toolkit/pkg/error" - v1 "github.com/rancher/elemental-toolkit/pkg/types/v1" - "github.com/rancher/elemental-toolkit/pkg/utils" + "github.com/rancher/elemental-toolkit/v2/pkg/constants" + "github.com/rancher/elemental-toolkit/v2/pkg/elemental" + elementalError "github.com/rancher/elemental-toolkit/v2/pkg/error" + "github.com/rancher/elemental-toolkit/v2/pkg/types" + "github.com/rancher/elemental-toolkit/v2/pkg/utils" ) var ErrUpgradeRecoveryFromRecovery = errors.New("Can not upgrade recovery from recovery partition") // UpgradeRecoveryAction represents the struct that will run the recovery upgrade from start to finish type UpgradeRecoveryAction struct { - cfg *v1.RunConfig - spec *v1.UpgradeSpec + cfg *types.RunConfig + spec *types.UpgradeSpec updateInstallState bool } @@ -47,7 +47,7 @@ func WithUpdateInstallState(updateInstallState bool) func(u *UpgradeRecoveryActi } } -func NewUpgradeRecoveryAction(config *v1.RunConfig, spec *v1.UpgradeSpec, opts ...UpgradeRecoveryActionOption) (*UpgradeRecoveryAction, error) { +func NewUpgradeRecoveryAction(config *types.RunConfig, spec *types.UpgradeSpec, opts ...UpgradeRecoveryActionOption) (*UpgradeRecoveryAction, error) { var err error u := &UpgradeRecoveryAction{cfg: config, spec: spec} @@ -111,9 +111,9 @@ func (u *UpgradeRecoveryAction) upgradeInstallStateYaml() error { recoveryPart := u.spec.State.Partitions[constants.RecoveryPartName] if recoveryPart == nil { - recoveryPart = &v1.PartitionState{ + recoveryPart = &types.PartitionState{ FSLabel: u.spec.Partitions.Recovery.FilesystemLabel, - RecoveryImage: &v1.SystemState{ + RecoveryImage: &types.SystemState{ FS: u.spec.RecoverySystem.FS, Label: u.spec.RecoverySystem.Label, Source: u.spec.RecoverySystem.Source, diff --git a/pkg/action/upgrade-recovery_test.go b/pkg/action/upgrade-recovery_test.go index 50748713542..06cb4779d6f 100644 --- a/pkg/action/upgrade-recovery_test.go +++ b/pkg/action/upgrade-recovery_test.go @@ -28,41 +28,41 @@ import ( "github.com/twpayne/go-vfs/v4" "github.com/twpayne/go-vfs/v4/vfst" - "github.com/rancher/elemental-toolkit/pkg/action" - conf "github.com/rancher/elemental-toolkit/pkg/config" - "github.com/rancher/elemental-toolkit/pkg/constants" - v1mock "github.com/rancher/elemental-toolkit/pkg/mocks" - v1 "github.com/rancher/elemental-toolkit/pkg/types/v1" - "github.com/rancher/elemental-toolkit/pkg/utils" + "github.com/rancher/elemental-toolkit/v2/pkg/action" + conf "github.com/rancher/elemental-toolkit/v2/pkg/config" + "github.com/rancher/elemental-toolkit/v2/pkg/constants" + "github.com/rancher/elemental-toolkit/v2/pkg/mocks" + "github.com/rancher/elemental-toolkit/v2/pkg/types" + "github.com/rancher/elemental-toolkit/v2/pkg/utils" ) var _ = Describe("Upgrade Recovery Actions", func() { - var config *v1.RunConfig - var runner *v1mock.FakeRunner + var config *types.RunConfig + var runner *mocks.FakeRunner var fs vfs.FS - var logger v1.Logger - var mounter *v1mock.FakeMounter - var syscall *v1mock.FakeSyscall - var client *v1mock.FakeHTTPClient - var cloudInit *v1mock.FakeCloudInitRunner - var extractor *v1mock.FakeImageExtractor + var logger types.Logger + var mounter *mocks.FakeMounter + var syscall *mocks.FakeSyscall + var client *mocks.FakeHTTPClient + var cloudInit *mocks.FakeCloudInitRunner + var extractor *mocks.FakeImageExtractor var cleanup func() var memLog *bytes.Buffer - var ghwTest v1mock.GhwMock + var ghwTest mocks.GhwMock BeforeEach(func() { - runner = v1mock.NewFakeRunner() - syscall = &v1mock.FakeSyscall{} - mounter = v1mock.NewFakeMounter() - client = &v1mock.FakeHTTPClient{} + runner = mocks.NewFakeRunner() + syscall = &mocks.FakeSyscall{} + mounter = mocks.NewFakeMounter() + client = &mocks.FakeHTTPClient{} memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) - extractor = v1mock.NewFakeImageExtractor(logger) + logger = types.NewBufferLogger(memLog) + extractor = mocks.NewFakeImageExtractor(logger) var err error fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{}) Expect(err).Should(BeNil()) - cloudInit = &v1mock.FakeCloudInitRunner{} + cloudInit = &mocks.FakeCloudInitRunner{} config = conf.NewRunConfig( conf.WithFs(fs), conf.WithRunner(runner), @@ -79,13 +79,13 @@ var _ = Describe("Upgrade Recovery Actions", func() { AfterEach(func() { cleanup() }) Describe("UpgradeRecovery Action", Label("upgrade-recovery"), func() { - var spec *v1.UpgradeSpec + var spec *types.UpgradeSpec var upgradeRecovery *action.UpgradeRecoveryAction var memLog *bytes.Buffer BeforeEach(func() { memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) + logger = types.NewBufferLogger(memLog) config.Logger = logger logger.SetLevel(logrus.DebugLevel) @@ -122,7 +122,7 @@ var _ = Describe("Upgrade Recovery Actions", func() { }, }, } - ghwTest = v1mock.GhwMock{} + ghwTest = mocks.GhwMock{} ghwTest.AddDisk(mainDisk) ghwTest.CreateDevices() }) @@ -137,8 +137,8 @@ var _ = Describe("Upgrade Recovery Actions", func() { spec, err = conf.NewUpgradeSpec(config.Config) Expect(err).ShouldNot(HaveOccurred()) - spec.System = v1.NewDockerSrc("alpine") - loopCfg, ok := config.Snapshotter.Config.(*v1.LoopDeviceConfig) + spec.System = types.NewDockerSrc("alpine") + loopCfg, ok := config.Snapshotter.Config.(*types.LoopDeviceConfig) Expect(ok).To(BeTrue()) loopCfg.Size = 16 @@ -252,18 +252,18 @@ var _ = Describe("Upgrade Recovery Actions", func() { }) }) -func PrepareTestRecoveryImage(config *v1.RunConfig, recoveryImgPath string, fs vfs.FS, runner *v1mock.FakeRunner) *v1.UpgradeSpec { +func PrepareTestRecoveryImage(config *types.RunConfig, recoveryImgPath string, fs vfs.FS, runner *mocks.FakeRunner) *types.UpgradeSpec { GinkgoHelper() // Create installState with squashed recovery statePath := filepath.Join(constants.RunningStateDir, constants.InstallStateFile) - installState := &v1.InstallState{ - Partitions: map[string]*v1.PartitionState{ + installState := &types.InstallState{ + Partitions: map[string]*types.PartitionState{ constants.RecoveryPartName: { FSLabel: constants.RecoveryLabel, - RecoveryImage: &v1.SystemState{ + RecoveryImage: &types.SystemState{ Label: constants.SystemLabel, FS: constants.SquashFs, - Source: v1.NewDirSrc("/some/dir"), + Source: types.NewDirSrc("/some/dir"), }, }, }, @@ -275,7 +275,7 @@ func PrepareTestRecoveryImage(config *v1.RunConfig, recoveryImgPath string, fs v spec, err := conf.NewUpgradeSpec(config.Config) Expect(err).ShouldNot(HaveOccurred()) - spec.System = v1.NewDockerSrc("alpine") + spec.System = types.NewDockerSrc("alpine") spec.RecoveryUpgrade = true spec.RecoverySystem.Source = spec.System spec.RecoverySystem.Size = 16 diff --git a/pkg/snapshotter/btrfs.go b/pkg/snapshotter/btrfs.go index a4754f8837a..206fe774312 100644 --- a/pkg/snapshotter/btrfs.go +++ b/pkg/snapshotter/btrfs.go @@ -133,7 +133,7 @@ func newBtrfsSnapshotter(cfg types.Config, snapCfg types.SnapshotterConfig, boot }, nil } -func (b *Btrfs) InitSnapshotter(state *v1.Partition, efiDir string) error { +func (b *Btrfs) InitSnapshotter(state *types.Partition, efiDir string) error { var err error var ok bool diff --git a/pkg/snapshotter/btrfs_test.go b/pkg/snapshotter/btrfs_test.go index 62406b367af..1714bfcc2a5 100644 --- a/pkg/snapshotter/btrfs_test.go +++ b/pkg/snapshotter/btrfs_test.go @@ -443,7 +443,7 @@ var _ = Describe("Btrfs", Label("snapshotter", " btrfs"), func() { It("fails to umount default subvolume", func() { failCmd = "nofail" mounter.ErrorOnUnmount = true - err = b.InitSnapshotter(rootDir) + err = b.InitSnapshotter(statePart, rootDir) Expect(err.Error()).To(ContainSubstring("unmount")) }) }) diff --git a/pkg/snapshotter/loopdevice.go b/pkg/snapshotter/loopdevice.go index ddf5b8db89b..6deec4d57ae 100644 --- a/pkg/snapshotter/loopdevice.go +++ b/pkg/snapshotter/loopdevice.go @@ -78,7 +78,7 @@ func newLoopDeviceSnapshotter(cfg types.Config, snapCfg types.SnapshotterConfig, // InitSnapshotter initiates the snapshotter to the given root directory. More over this method includes logic to migrate // from older elemental-toolkit versions. -func (l *LoopDevice) InitSnapshotter(state *v1.Partition, efiDir string) error { +func (l *LoopDevice) InitSnapshotter(state *types.Partition, efiDir string) error { var err error l.cfg.Logger.Infof("Initiating a LoopDevice snapshotter at %s", state.MountPoint)