mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-06-03 01:44:53 +00:00
✨ Modify upgrade image flag to accept more formats (#39)
Co-authored-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
parent
ba72c14346
commit
1e1638f258
@ -47,11 +47,11 @@ func ListReleases(includePrereleases bool) semver.Collection {
|
||||
}
|
||||
|
||||
func Upgrade(
|
||||
version, image string, force, debug, strictValidations bool, dirs []string, preReleases bool,
|
||||
version, source string, force, debug, strictValidations bool, dirs []string, preReleases, isLocal bool,
|
||||
) error {
|
||||
bus.Manager.Initialize()
|
||||
|
||||
if version == "" && image == "" {
|
||||
if version == "" && source == "" {
|
||||
fmt.Println("Searching for releases")
|
||||
if preReleases {
|
||||
fmt.Println("Including pre-releases")
|
||||
@ -101,12 +101,12 @@ func Upgrade(
|
||||
if discoveredImage != "" {
|
||||
img = discoveredImage
|
||||
}
|
||||
if image != "" {
|
||||
img = image
|
||||
if source != "" {
|
||||
img = source
|
||||
}
|
||||
|
||||
if debug {
|
||||
fmt.Printf("Upgrading to image: '%s'\n", img)
|
||||
fmt.Printf("Upgrading to source: '%s'\n", img)
|
||||
}
|
||||
|
||||
c, err := config.Scan(collector.Directories(dirs...), collector.StrictValidation(strictValidations))
|
||||
@ -125,13 +125,16 @@ func Upgrade(
|
||||
upgradeConfig.Logger.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
// Set image to local if true
|
||||
upgradeConfig.LocalImage = isLocal
|
||||
|
||||
// Generate the upgrade spec
|
||||
upgradeSpec, err := elementalConfig.NewUpgradeSpec(upgradeConfig.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Add the image source
|
||||
imgSource, err := v1.NewSrcFromURI(fmt.Sprintf("docker:%s", img))
|
||||
imgSource, err := v1.NewSrcFromURI(img)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
36
main.go
36
main.go
@ -9,6 +9,7 @@ import (
|
||||
"github.com/kairos-io/kairos/v2/pkg/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
"os"
|
||||
@ -63,9 +64,14 @@ var cmds = []*cli.Command{
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "image",
|
||||
Usage: "Specify an full image reference, e.g.: quay.io/some/image:tag",
|
||||
Usage: "[DEPRECATED] Specify a full image reference, e.g.: quay.io/some/image:tag",
|
||||
},
|
||||
&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`",
|
||||
},
|
||||
&cli.BoolFlag{Name: "pre", Usage: "Include pre-releases (rc, beta, alpha)"},
|
||||
&cli.BoolFlag{Name: "local", Usage: "Get the upgrade source image from local daemon"},
|
||||
},
|
||||
Description: `
|
||||
Manually upgrade a kairos node.
|
||||
@ -103,17 +109,39 @@ See https://kairos.io/docs/upgrade/manual/ for documentation.
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
source := c.String("source")
|
||||
if source != "" {
|
||||
r, err := regexp.Compile(`^oci:|dir:|file:`)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if !r.MatchString(source) {
|
||||
return fmt.Errorf("source %s does not match any of oci:, dir: or file: ", source)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
var v string
|
||||
if c.Args().Len() == 1 {
|
||||
v = c.Args().First()
|
||||
}
|
||||
|
||||
image := c.String("image")
|
||||
source := c.String("source")
|
||||
|
||||
if image != "" {
|
||||
fmt.Println("--image flag is deprecated, please use --source")
|
||||
// override source with image for now until we drop it
|
||||
source = fmt.Sprintf("oci:%s", image)
|
||||
}
|
||||
|
||||
isLocal := c.Bool("local")
|
||||
return agent.Upgrade(
|
||||
v, c.String("image"), c.Bool("force"), c.Bool("debug"),
|
||||
v, source, c.Bool("force"), c.Bool("debug"),
|
||||
c.Bool("strict-validation"), configScanDir,
|
||||
c.Bool("pre"),
|
||||
c.Bool("pre"), isLocal,
|
||||
)
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user