Skip to content

Commit

Permalink
bump elemental-toolkit to v2
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Mar 7, 2024
1 parent 744e9fd commit 8f6b9ca
Show file tree
Hide file tree
Showing 108 changed files with 1,202 additions and 1,203 deletions.
16 changes: 8 additions & 8 deletions cmd/build-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package cmd
import (
"os/exec"

"github.com/rancher/elemental-toolkit/pkg/constants"
eleError "github.com/rancher/elemental-toolkit/pkg/error"
v1 "github.com/rancher/elemental-toolkit/pkg/types/v1"
"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/spf13/cobra"
"github.com/spf13/viper"

"github.com/rancher/elemental-toolkit/cmd/config"
"github.com/rancher/elemental-toolkit/pkg/action"
"github.com/rancher/elemental-toolkit/v2/cmd/config"
"github.com/rancher/elemental-toolkit/v2/pkg/action"
)

// NewBuildDisk returns a new instance of the build-disk subcommand and appends it to
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 *v1.BuildConfig
var spec *v1.DiskSpec
var cfg *v2.BuildConfig
var spec *v2.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 := v1.NewMounter(path)
mounter := v2.NewMounter(path)

flags := cmd.Flags()
cfg, err = config.ReadConfigBuild(viper.GetString("config-dir"), flags, mounter)
Expand Down
24 changes: 12 additions & 12 deletions cmd/build-iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ 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/pkg/utils"
"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/utils"
)

// NewBuildISO returns a new instance of the buid-iso subcommand and appends it to
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 := v1.NewMounter(path)
mounter := v2.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 := v1.NewSrcFromURI(args[0])
imgSource, err := v2.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 = []*v1.ImageSource{imgSource}
spec.RootFS = []*v2.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, v1.NewDirSrc(oRootfs))
spec.RootFS = append(spec.RootFS, v2.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, v1.NewDirSrc(oUEFI))
spec.UEFI = append(spec.UEFI, v2.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, v1.NewDirSrc(oISO))
spec.Image = append(spec.Image, v2.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{v1.EFI}, v1.EFI)
firmType := newEnumFlag([]string{v2.EFI}, v2.EFI)

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

"github.com/rancher/elemental-toolkit/cmd/config"
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"
elementalError "github.com/rancher/elemental-toolkit/v2/pkg/error"
v2 "github.com/rancher/elemental-toolkit/v2/pkg/types/v2"

"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(), v1.NewDummyMounter())
cfg, err := config.ReadConfigRun(viper.GetString("config-dir"), cmd.Flags(), v2.NewDummyMounter())
if err != nil {
return elementalError.NewFromError(err, elementalError.ReadingRunConfig)
}
Expand Down
46 changes: 23 additions & 23 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/rancher/elemental-toolkit/internal/version"
"github.com/rancher/elemental-toolkit/pkg/config"
"github.com/rancher/elemental-toolkit/pkg/constants"
v1 "github.com/rancher/elemental-toolkit/pkg/types/v1"
"github.com/rancher/elemental-toolkit/pkg/utils"
"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/utils"
)

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

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

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

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

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

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

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

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

func applyKernelCmdline(r *v1.RunConfig, mount *v1.MountSpec) error {
func applyKernelCmdline(r *v2.RunConfig, mount *v2.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 *v1.RunConfig, mount *v1.MountSpec) error {
}
case "elemental.oemlabel":
oemdev := fmt.Sprintf("LABEL=%s", val)
var mnt *v1.VolumeMount
var mnt *v2.VolumeMount
for _, mnt = range mount.Volumes {
if mnt.Mountpoint == constants.OEMPath {
mnt.Device = oemdev
break
}
}
if mnt == nil {
mount.Volumes = append(mount.Volumes, &v1.VolumeMount{
mount.Volumes = append(mount.Volumes, &v2.VolumeMount{
Mountpoint: constants.OEMPath,
Device: oemdev,
Options: []string{"rw", "defaults"},
Expand All @@ -342,7 +342,7 @@ func applyKernelCmdline(r *v1.RunConfig, mount *v1.MountSpec) error {
return nil
}

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

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

func applyMountOverlay(mount *v1.MountSpec, overlay string) error {
func applyMountOverlay(mount *v2.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 *v1.MountSpec, overlay string) error {
return nil
}

func ReadResetSpec(r *v1.RunConfig, flags *pflag.FlagSet) (*v1.ResetSpec, error) {
func ReadResetSpec(r *v2.RunConfig, flags *pflag.FlagSet) (*v2.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 *v1.RunConfig, flags *pflag.FlagSet) (*v1.ResetSpec, error)
return reset, err
}

func ReadUpgradeSpec(r *v1.RunConfig, flags *pflag.FlagSet, recoveryOnly bool) (*v1.UpgradeSpec, error) {
func ReadUpgradeSpec(r *v2.RunConfig, flags *pflag.FlagSet, recoveryOnly bool) (*v2.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 *v1.RunConfig, flags *pflag.FlagSet, recoveryOnly bool) (
return upgrade, err
}

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

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

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

// Set formatter so both file and stdout format are equal
Expand Down
Loading

0 comments on commit 8f6b9ca

Please sign in to comment.