mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-14 13:40:46 +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:
@@ -47,11 +47,11 @@ func ListReleases(includePrereleases bool) semver.Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Upgrade(
|
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 {
|
) error {
|
||||||
bus.Manager.Initialize()
|
bus.Manager.Initialize()
|
||||||
|
|
||||||
if version == "" && image == "" {
|
if version == "" && source == "" {
|
||||||
fmt.Println("Searching for releases")
|
fmt.Println("Searching for releases")
|
||||||
if preReleases {
|
if preReleases {
|
||||||
fmt.Println("Including pre-releases")
|
fmt.Println("Including pre-releases")
|
||||||
@@ -101,12 +101,12 @@ func Upgrade(
|
|||||||
if discoveredImage != "" {
|
if discoveredImage != "" {
|
||||||
img = discoveredImage
|
img = discoveredImage
|
||||||
}
|
}
|
||||||
if image != "" {
|
if source != "" {
|
||||||
img = image
|
img = source
|
||||||
}
|
}
|
||||||
|
|
||||||
if debug {
|
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))
|
c, err := config.Scan(collector.Directories(dirs...), collector.StrictValidation(strictValidations))
|
||||||
@@ -125,13 +125,16 @@ func Upgrade(
|
|||||||
upgradeConfig.Logger.SetLevel(log.DebugLevel)
|
upgradeConfig.Logger.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set image to local if true
|
||||||
|
upgradeConfig.LocalImage = isLocal
|
||||||
|
|
||||||
// Generate the upgrade spec
|
// Generate the upgrade spec
|
||||||
upgradeSpec, err := elementalConfig.NewUpgradeSpec(upgradeConfig.Config)
|
upgradeSpec, err := elementalConfig.NewUpgradeSpec(upgradeConfig.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Add the image source
|
// Add the image source
|
||||||
imgSource, err := v1.NewSrcFromURI(fmt.Sprintf("docker:%s", img))
|
imgSource, err := v1.NewSrcFromURI(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
36
main.go
36
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/kairos-io/kairos/v2/pkg/utils"
|
"github.com/kairos-io/kairos/v2/pkg/utils"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
@@ -63,9 +64,14 @@ var cmds = []*cli.Command{
|
|||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "image",
|
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: "pre", Usage: "Include pre-releases (rc, beta, alpha)"},
|
||||||
|
&cli.BoolFlag{Name: "local", Usage: "Get the upgrade source image from local daemon"},
|
||||||
},
|
},
|
||||||
Description: `
|
Description: `
|
||||||
Manually upgrade a kairos node.
|
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 {
|
Action: func(c *cli.Context) error {
|
||||||
var v string
|
var v string
|
||||||
if c.Args().Len() == 1 {
|
if c.Args().Len() == 1 {
|
||||||
v = c.Args().First()
|
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(
|
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("strict-validation"), configScanDir,
|
||||||
c.Bool("pre"),
|
c.Bool("pre"), isLocal,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user