Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove validation of os-release attribute when source has been given for upgrades #71

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions internal/agent/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"

"github.com/Masterminds/semver/v3"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
Expand Down Expand Up @@ -79,30 +80,14 @@ func Upgrade(
}
}

discoveredImage := ""
bus.Manager.Response(events.EventVersionImage, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
discoveredImage = r.Data
})

_, err := bus.Manager.Publish(events.EventVersionImage, &events.VersionImagePayload{
Version: version,
})
if err != nil {
return err
}

registry, err := utils.OSRelease("IMAGE_REPO")
if err != nil {
fmt.Printf("Cant find IMAGE_REPO key under /etc/os-release\n")
return err
}

img := fmt.Sprintf("%s:%s", registry, version)
if discoveredImage != "" {
img = discoveredImage
}
if source != "" {
img = source
img := source
var err error
if img == "" {
img, err = determineUpgradeImage(version)
if err != nil {
fmt.Println(err.Error())
return err
}
}

if debug {
Expand Down Expand Up @@ -146,3 +131,30 @@ func Upgrade(

return upgradeAction.Run()
}

// determineUpgradeImage asks the provider plugin for an image or constructs
// it using version and data from /etc/os-release
func determineUpgradeImage(version string) (string, error) {
var img string
bus.Manager.Response(events.EventVersionImage, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
img = r.Data
})

_, err := bus.Manager.Publish(events.EventVersionImage, &events.VersionImagePayload{
Version: version,
})
if err != nil {
return "", err
}

if img != "" {
return img, nil
}

registry, err := utils.OSRelease("IMAGE_REPO")
if err != nil {
return "", fmt.Errorf("can't find IMAGE_REPO key under /etc/os-release %w", err)
}

return fmt.Sprintf("%s:%s", registry, version), nil
}