Skip to content

Commit

Permalink
Move pkg/types/v2 to simply pkg/types
Browse files Browse the repository at this point in the history
This commit leaves the code with a single set of types
and in refers to it as the types packge instead of
v1 or v2.

For the time being we do not foresee managing more
than one single major version of type within the
same code.

Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Mar 7, 2024
1 parent 8f6b9ca commit 84fec48
Show file tree
Hide file tree
Showing 87 changed files with 813 additions and 813 deletions.
8 changes: 4 additions & 4 deletions cmd/build-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/rancher/elemental-toolkit/v2/pkg/constants"
eleError "github.com/rancher/elemental-toolkit/v2/pkg/error"
v2 "github.com/rancher/elemental-toolkit/v2/pkg/types/v2"
"github.com/rancher/elemental-toolkit/v2/pkg/types"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -45,8 +45,8 @@ func NewBuildDisk(root *cobra.Command, addCheckRoot bool) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, _ []string) (err error) {
var cfg *v2.BuildConfig
var spec *v2.DiskSpec
var cfg *types.BuildConfig
var spec *types.DiskSpec

defer func() {
if cfg != nil && err != nil {
Expand All @@ -58,7 +58,7 @@ func NewBuildDisk(root *cobra.Command, addCheckRoot bool) *cobra.Command {
if err != nil {
return err
}
mounter := v2.NewMounter(path)
mounter := types.NewMounter(path)

flags := cmd.Flags()
cfg, err = config.ReadConfigBuild(viper.GetString("config-dir"), flags, mounter)
Expand Down
16 changes: 8 additions & 8 deletions cmd/build-iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"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"
v2 "github.com/rancher/elemental-toolkit/v2/pkg/types/v2"
"github.com/rancher/elemental-toolkit/v2/pkg/types"
"github.com/rancher/elemental-toolkit/v2/pkg/utils"
)

Expand All @@ -53,7 +53,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command {
if err != nil {
return elementalError.NewFromError(err, elementalError.StatFile)
}
mounter := v2.NewMounter(path)
mounter := types.NewMounter(path)

cfg, err := config.ReadConfigBuild(viper.GetString("config-dir"), cmd.Flags(), mounter)
if err != nil {
Expand All @@ -78,12 +78,12 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command {
}

if len(args) == 1 {
imgSource, err := v2.NewSrcFromURI(args[0])
imgSource, err := types.NewSrcFromURI(args[0])
if err != nil {
cfg.Logger.Errorf("not a valid rootfs source image argument: %s", args[0])
return elementalError.NewFromError(err, elementalError.IdentifySource)
}
spec.RootFS = []*v2.ImageSource{imgSource}
spec.RootFS = []*types.ImageSource{imgSource}
} else if len(spec.RootFS) == 0 {
errmsg := "rootfs source image for building ISO was not provided"
cfg.Logger.Errorf(errmsg)
Expand All @@ -98,7 +98,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command {

if oRootfs != "" {
if ok, err := utils.Exists(cfg.Fs, oRootfs); ok {
spec.RootFS = append(spec.RootFS, v2.NewDirSrc(oRootfs))
spec.RootFS = append(spec.RootFS, types.NewDirSrc(oRootfs))
} else {
msg := fmt.Sprintf("Invalid path '%s': %v", oRootfs, err)
cfg.Logger.Errorf(msg)
Expand All @@ -107,7 +107,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command {
}
if oUEFI != "" {
if ok, err := utils.Exists(cfg.Fs, oUEFI); ok {
spec.UEFI = append(spec.UEFI, v2.NewDirSrc(oUEFI))
spec.UEFI = append(spec.UEFI, types.NewDirSrc(oUEFI))
} else {
msg := fmt.Sprintf("Invalid path '%s': %v", oUEFI, err)
cfg.Logger.Errorf(msg)
Expand All @@ -116,7 +116,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command {
}
if oISO != "" {
if ok, err := utils.Exists(cfg.Fs, oISO); ok {
spec.Image = append(spec.Image, v2.NewDirSrc(oISO))
spec.Image = append(spec.Image, types.NewDirSrc(oISO))
} else {
msg := fmt.Sprintf("Invalid path '%s': %v", oISO, err)
cfg.Logger.Errorf(msg)
Expand All @@ -129,7 +129,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command {
},
}

firmType := newEnumFlag([]string{v2.EFI}, v2.EFI)
firmType := newEnumFlag([]string{types.EFI}, types.EFI)

root.AddCommand(c)
c.Flags().StringP("name", "n", "", "Basename of the generated ISO file")
Expand Down
4 changes: 2 additions & 2 deletions cmd/cloud-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/rancher/elemental-toolkit/v2/cmd/config"
elementalError "github.com/rancher/elemental-toolkit/v2/pkg/error"
v2 "github.com/rancher/elemental-toolkit/v2/pkg/types/v2"
"github.com/rancher/elemental-toolkit/v2/pkg/types"

"github.com/rancher/yip/pkg/schema"
"github.com/spf13/cobra"
Expand All @@ -38,7 +38,7 @@ func NewCloudInitCmd(root *cobra.Command) *cobra.Command {
_ = viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.ReadConfigRun(viper.GetString("config-dir"), cmd.Flags(), v2.NewDummyMounter())
cfg, err := config.ReadConfigRun(viper.GetString("config-dir"), cmd.Flags(), types.NewDummyMounter())
if err != nil {
return elementalError.NewFromError(err, elementalError.ReadingRunConfig)
}
Expand Down
38 changes: 19 additions & 19 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/rancher/elemental-toolkit/v2/internal/version"
"github.com/rancher/elemental-toolkit/v2/pkg/config"
"github.com/rancher/elemental-toolkit/v2/pkg/constants"
v2 "github.com/rancher/elemental-toolkit/v2/pkg/types/v2"
"github.com/rancher/elemental-toolkit/v2/pkg/types"
"github.com/rancher/elemental-toolkit/v2/pkg/utils"
)

Expand Down Expand Up @@ -96,8 +96,8 @@ func bindGivenFlags(vp *viper.Viper, flagSet *pflag.FlagSet) {
}
}

func ReadConfigBuild(configDir string, flags *pflag.FlagSet, mounter v2.Mounter) (*v2.BuildConfig, error) {
logger := v2.NewLogger()
func ReadConfigBuild(configDir string, flags *pflag.FlagSet, mounter types.Mounter) (*types.BuildConfig, error) {
logger := types.NewLogger()

cfg := config.NewBuildConfig(
config.WithLogger(logger),
Expand Down Expand Up @@ -142,9 +142,9 @@ func ReadConfigBuild(configDir string, flags *pflag.FlagSet, mounter v2.Mounter)
return cfg, err
}

func ReadConfigRun(configDir string, flags *pflag.FlagSet, mounter v2.Mounter) (*v2.RunConfig, error) {
func ReadConfigRun(configDir string, flags *pflag.FlagSet, mounter types.Mounter) (*types.RunConfig, error) {
cfg := config.NewRunConfig(
config.WithLogger(v2.NewLogger()),
config.WithLogger(types.NewLogger()),
config.WithMounter(mounter),
config.WithOCIImageExtractor(),
)
Expand Down Expand Up @@ -214,7 +214,7 @@ func ReadConfigRun(configDir string, flags *pflag.FlagSet, mounter v2.Mounter) (
return cfg, err
}

func ReadInstallSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.InstallSpec, error) {
func ReadInstallSpec(r *types.RunConfig, flags *pflag.FlagSet) (*types.InstallSpec, error) {
install := config.NewInstallSpec(r.Config)
vp := viper.Sub("install")
if vp == nil {
Expand All @@ -234,7 +234,7 @@ func ReadInstallSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.InstallSpec, er
return install, err
}

func ReadInitSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.InitSpec, error) {
func ReadInitSpec(r *types.RunConfig, flags *pflag.FlagSet) (*types.InitSpec, error) {
init := config.NewInitSpec()
vp := viper.Sub("init")
if vp == nil {
Expand All @@ -252,7 +252,7 @@ func ReadInitSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.InitSpec, error) {
return init, err
}

func ReadMountSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.MountSpec, error) {
func ReadMountSpec(r *types.RunConfig, flags *pflag.FlagSet) (*types.MountSpec, error) {
mount := config.NewMountSpec()

vp := viper.Sub("mount")
Expand Down Expand Up @@ -285,7 +285,7 @@ func ReadMountSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.MountSpec, error)
return mount, err
}

func applyKernelCmdline(r *v2.RunConfig, mount *v2.MountSpec) error {
func applyKernelCmdline(r *types.RunConfig, mount *types.MountSpec) error {
cmdline, err := r.Config.Fs.ReadFile("/proc/cmdline")
if err != nil {
r.Logger.Errorf("Error reading /proc/cmdline: %s", err.Error())
Expand Down Expand Up @@ -322,15 +322,15 @@ func applyKernelCmdline(r *v2.RunConfig, mount *v2.MountSpec) error {
}
case "elemental.oemlabel":
oemdev := fmt.Sprintf("LABEL=%s", val)
var mnt *v2.VolumeMount
var mnt *types.VolumeMount
for _, mnt = range mount.Volumes {
if mnt.Mountpoint == constants.OEMPath {
mnt.Device = oemdev
break
}
}
if mnt == nil {
mount.Volumes = append(mount.Volumes, &v2.VolumeMount{
mount.Volumes = append(mount.Volumes, &types.VolumeMount{
Mountpoint: constants.OEMPath,
Device: oemdev,
Options: []string{"rw", "defaults"},
Expand All @@ -342,7 +342,7 @@ func applyKernelCmdline(r *v2.RunConfig, mount *v2.MountSpec) error {
return nil
}

func applyMountEnvVars(r *v2.RunConfig, mount *v2.MountSpec) error {
func applyMountEnvVars(r *types.RunConfig, mount *types.MountSpec) error {
r.Logger.Debugf("Applying mount env-vars")

overlay := os.Getenv("OVERLAY")
Expand Down Expand Up @@ -376,7 +376,7 @@ func applyMountEnvVars(r *v2.RunConfig, mount *v2.MountSpec) error {
return nil
}

func applyMountOverlay(mount *v2.MountSpec, overlay string) error {
func applyMountOverlay(mount *types.MountSpec, overlay string) error {
split := strings.Split(overlay, ":")

if len(split) == 2 && split[0] == constants.Tmpfs {
Expand Down Expand Up @@ -406,7 +406,7 @@ func applyMountOverlay(mount *v2.MountSpec, overlay string) error {
return nil
}

func ReadResetSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.ResetSpec, error) {
func ReadResetSpec(r *types.RunConfig, flags *pflag.FlagSet) (*types.ResetSpec, error) {
reset, err := config.NewResetSpec(r.Config)
if err != nil {
return nil, fmt.Errorf("failed initializing reset spec: %v", err)
Expand All @@ -429,7 +429,7 @@ func ReadResetSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.ResetSpec, error)
return reset, err
}

func ReadUpgradeSpec(r *v2.RunConfig, flags *pflag.FlagSet, recoveryOnly bool) (*v2.UpgradeSpec, error) {
func ReadUpgradeSpec(r *types.RunConfig, flags *pflag.FlagSet, recoveryOnly bool) (*types.UpgradeSpec, error) {
upgrade, err := config.NewUpgradeSpec(r.Config)
if err != nil {
return nil, fmt.Errorf("failed initializing upgrade spec: %v", err)
Expand Down Expand Up @@ -457,7 +457,7 @@ func ReadUpgradeSpec(r *v2.RunConfig, flags *pflag.FlagSet, recoveryOnly bool) (
return upgrade, err
}

func ReadBuildISO(b *v2.BuildConfig, flags *pflag.FlagSet) (*v2.LiveISO, error) {
func ReadBuildISO(b *types.BuildConfig, flags *pflag.FlagSet) (*types.LiveISO, error) {
iso := config.NewISO()
vp := viper.Sub("iso")
if vp == nil {
Expand All @@ -477,7 +477,7 @@ func ReadBuildISO(b *v2.BuildConfig, flags *pflag.FlagSet) (*v2.LiveISO, error)
return iso, err
}

func ReadBuildDisk(b *v2.BuildConfig, flags *pflag.FlagSet) (*v2.DiskSpec, error) {
func ReadBuildDisk(b *types.BuildConfig, flags *pflag.FlagSet) (*types.DiskSpec, error) {
disk := config.NewDisk(b)
vp := viper.Sub("disk")
if vp == nil {
Expand All @@ -497,10 +497,10 @@ func ReadBuildDisk(b *v2.BuildConfig, flags *pflag.FlagSet) (*v2.DiskSpec, error
return disk, err
}

func configLogger(log v2.Logger, vfs v2.FS) {
func configLogger(log types.Logger, vfs types.FS) {
// Set debug level
if viper.GetBool("debug") {
log.SetLevel(v2.DebugLevel())
log.SetLevel(types.DebugLevel())
}

// Set formatter so both file and stdout format are equal
Expand Down
24 changes: 12 additions & 12 deletions cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

"github.com/rancher/elemental-toolkit/v2/pkg/constants"
v2mock "github.com/rancher/elemental-toolkit/v2/pkg/mocks"
v2 "github.com/rancher/elemental-toolkit/v2/pkg/types/v2"
"github.com/rancher/elemental-toolkit/v2/pkg/types"
)

var _ = Describe("Config", Label("config"), func() {
Expand All @@ -58,7 +58,7 @@ var _ = Describe("Config", Label("config"), func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(cfg.Snapshotter.MaxSnaps).To(Equal(7), litter.Sdump(cfg))
Expect(cfg.Snapshotter.Type).To(Equal(constants.LoopDeviceSnapshotterType), litter.Sdump(cfg))
loop, ok := cfg.Snapshotter.Config.(*v2.LoopDeviceConfig)
loop, ok := cfg.Snapshotter.Config.(*types.LoopDeviceConfig)
Expect(ok).To(BeTrue())
Expect(loop.Size).To(Equal(uint(2000)))

Expand Down Expand Up @@ -132,10 +132,10 @@ var _ = Describe("Config", Label("config"), func() {
})

Describe("Read build specs", Label("build"), func() {
var cfg *v2.BuildConfig
var cfg *types.BuildConfig
var runner *v2mock.FakeRunner
var fs vfs.FS
var logger v2.Logger
var logger types.Logger
var mounter *v2mock.FakeMounter
var syscall *v2mock.FakeSyscall
var client *v2mock.FakeHTTPClient
Expand All @@ -150,7 +150,7 @@ var _ = Describe("Config", Label("config"), func() {
mounter = v2mock.NewFakeMounter()
client = &v2mock.FakeHTTPClient{}
memLog = &bytes.Buffer{}
logger = v2.NewBufferLogger(memLog)
logger = types.NewBufferLogger(memLog)
cloudInit = &v2mock.FakeCloudInitRunner{}

fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{})
Expand Down Expand Up @@ -219,7 +219,7 @@ var _ = Describe("Config", Label("config"), func() {
Expect(cfg.Mounter == mounter).To(BeTrue())
// Sets a RealRunner instance by default
Expect(cfg.Runner != nil).To(BeTrue())
_, ok := cfg.Runner.(*v2.RealRunner)
_, ok := cfg.Runner.(*types.RealRunner)
Expect(ok).To(BeTrue())
})
It("uses provided configs and flags, flags have priority", func() {
Expand Down Expand Up @@ -257,7 +257,7 @@ var _ = Describe("Config", Label("config"), func() {
Expect(cfg.Reboot).To(BeTrue())
Expect(cfg.Snapshotter.Type).To(Equal(constants.LoopDeviceSnapshotterType))
Expect(cfg.Snapshotter.MaxSnaps).To(Equal(constants.LoopDeviceMaxSnaps))
snapshooterCfg, ok := cfg.Snapshotter.Config.(*v2.LoopDeviceConfig)
snapshooterCfg, ok := cfg.Snapshotter.Config.(*types.LoopDeviceConfig)
Expect(ok).To(BeTrue())
Expect(snapshooterCfg.FS).To(Equal("xfs"))
Expect(snapshooterCfg.Size).To(Equal(uint(1024)))
Expand All @@ -274,10 +274,10 @@ var _ = Describe("Config", Label("config"), func() {
})
})
Describe("Read runtime specs", Label("spec"), func() {
var cfg *v2.RunConfig
var cfg *types.RunConfig
var runner *v2mock.FakeRunner
var fs vfs.FS
var logger v2.Logger
var logger types.Logger
var mounter *v2mock.FakeMounter
var syscall *v2mock.FakeSyscall
var client *v2mock.FakeHTTPClient
Expand All @@ -292,7 +292,7 @@ var _ = Describe("Config", Label("config"), func() {
mounter = v2mock.NewFakeMounter()
client = &v2mock.FakeHTTPClient{}
memLog = &bytes.Buffer{}
logger = v2.NewBufferLogger(memLog)
logger = types.NewBufferLogger(memLog)
cloudInit = &v2mock.FakeCloudInitRunner{}

fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{})
Expand Down Expand Up @@ -329,8 +329,8 @@ var _ = Describe("Config", Label("config"), func() {
spec, err := ReadInstallSpec(cfg, nil)
Expect(err).ShouldNot(HaveOccurred())
Expect(spec.Target == "")
Expect(spec.PartTable == v2.GPT)
Expect(spec.Firmware == v2.BIOS)
Expect(spec.PartTable == types.GPT)
Expect(spec.Firmware == types.BIOS)
Expect(spec.NoFormat == false)
})
It("inits an install spec according to given configs", func() {
Expand Down
Loading

0 comments on commit 84fec48

Please sign in to comment.