Skip to content

Commit

Permalink
Merge uki upgrade into the normal upgrade command (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka authored Jan 9, 2024
1 parent 775756f commit 174d69c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 67 deletions.
13 changes: 10 additions & 3 deletions internal/agent/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-agent/v2/pkg/uki"
internalutils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/utils"
Expand Down Expand Up @@ -61,6 +62,14 @@ func Upgrade(
source string, force, strictValidations bool, dirs []string, preReleases, upgradeRecovery bool) error {
bus.Manager.Initialize()

if internalutils.UkiBootMode() == internalutils.UkiRemovableMedia {
return upgradeUki(source, dirs, strictValidations)
} else {
return upgrade(source, force, strictValidations, dirs, preReleases, upgradeRecovery)
}
}

func upgrade(source string, force, strictValidations bool, dirs []string, preReleases, upgradeRecovery bool) error {
upgradeSpec, c, err := generateUpgradeSpec(source, force, strictValidations, dirs, preReleases, upgradeRecovery)
if err != nil {
return err
Expand Down Expand Up @@ -187,9 +196,7 @@ func getReleasesFromProvider(includePrereleases bool) ([]string, error) {
return result, nil
}

func UkiUpgrade(source string, dirs []string, strictValidations bool) error {
bus.Manager.Initialize()

func upgradeUki(source string, dirs []string, strictValidations bool) error {
cliConf, err := generateUpgradeConfForCLIArgs(source, false)
if err != nil {
return err
Expand Down
64 changes: 0 additions & 64 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/kairos-io/kairos-agent/v2/internal/webui"
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-agent/v2/pkg/uki"
"github.com/kairos-io/kairos-sdk/bundles"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/machine"
Expand Down Expand Up @@ -702,69 +701,6 @@ The validate command expects a configuration file as its only argument. Local fi
return nil
},
},
{
Name: "uki",
Usage: "UKI subcommands",
Description: "UKI subcommands",
// we could set the flag --source at this level so we could have the flag for all subcommands but that translates into an ugly command
// in which you need to put the source flag before the subcommand, which is a mess. Just bad UX.
// command level: kairos-agent uki --source oci:whatever install
// subcommand level: kairos-agent uki install --source oci:whatever
Subcommands: []*cli.Command{
{
Name: "upgrade",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
Action: func(c *cli.Context, s string) error {
return validateSource(s)
},
},
},
Before: func(c *cli.Context) error {
if c.String("source") == "" {
return fmt.Errorf("On uki, source is required")
}
return nil
},
Action: func(c *cli.Context) error {
source := c.String("source")
return agent.UkiUpgrade(source, configScanDir, c.Bool("strict-validation"))
},
},
{
Name: "reset",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
Action: func(c *cli.Context, s string) error {
return validateSource(s)
},
},
},
Before: func(c *cli.Context) error {
return fmt.Errorf("not implemented")
},
Action: func(c *cli.Context) error {
config, err := agentConfig.Scan(collector.Directories(configScanDir...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation")))
if err != nil {
return err
}

// Load the spec from the config
resetSpec, err := agentConfig.ReadUkiResetSpecFromConfig(config)
if err != nil {
return err
}

resetAction := uki.NewResetAction(config, resetSpec)
return resetAction.Run()
},
},
},
},
{
Name: "versioneer",
Usage: "versioneer subcommands",
Expand Down

0 comments on commit 174d69c

Please sign in to comment.