Skip to content

Commit

Permalink
update zos worker
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Oct 31, 2024
1 parent 55e8310 commit 89c3556
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions pkg/upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

The upgrade module is responsible to keep a zos node always up to date.

It checks the hub for new releases of zos packages.
It checks the hub for new releases of zos packages. Also check version and `safe_to_upgrade` flag from the chain.

If a new release is available, it will then update the packages and restart the updated module with the new binaries if required.
If `safe_to_upgrade` is set to `false` and a new release is available then it will only update the [configured farms](https://github.com/threefoldtech/zos-config/blob/main/config.schema.json#L49)

If `safe_to_upgrade` is set to `true` and a new release is available, it will then update the packages and restart the updated module with the new binaries if required.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (u *Upgrader) update() error {

remoteVer := remote.Target[strings.LastIndex(remote.Target, "/")+1:]

if remoteVer != chainVer.Version {
if env.RunningMode != environment.RunningDev && remoteVer != chainVer.Version {
// nothing to do! hub version is not the same as the chain
return nil
}
Expand Down
26 changes: 14 additions & 12 deletions tools/zos-update-worker/internal/update_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,24 @@ func (w *Worker) updateZosVersion(network Network, manager client.Manager) error
}
defer con.Close()

currentZosVersions, err := con.GetZosVersion()
currentZosVersion, err := con.GetZosVersion()
if err != nil {
return err
}

type ZosVersions struct {
Zos string
ZosLight string
type ChainVersion struct {
SafeToUpgrade bool `json:"safe_to_upgrade"`
Version string `json:"version"`
}
versions := ZosVersions{}

err = json.Unmarshal([]byte(currentZosVersions), &versions)
var chainVersion ChainVersion
err = json.Unmarshal([]byte(currentZosVersion), &chainVersion)
if err != nil {
return err
log.Debug().Err(err).Msg("failed to unmarshal chain version")
chainVersion.Version = currentZosVersion
}
log.Debug().Msgf("getting substrate version %v for network %v", versions, network)

log.Debug().Msgf("getting substrate version %v for network %v", chainVersion.Version, network)

// now we need to find how dst is relative to src
path, err := filepath.Rel(w.dst, w.src)
Expand All @@ -128,16 +130,16 @@ func (w *Worker) updateZosVersion(network Network, manager client.Manager) error
}

//zos
zosCurrent := fmt.Sprintf("%v/.tag-%v", w.src, versions.Zos)
zosCurrent := fmt.Sprintf("%v/.tag-%v", w.src, chainVersion.Version)
zosLatest := fmt.Sprintf("%v/%v", w.dst, network)
// zos light
zosLightCurrent := fmt.Sprintf("%v/.tag-%v", w.src, versions.ZosLight)
zosLightCurrent := fmt.Sprintf("%v/.tag-%v", w.src, chainVersion.Version)
zosLightLatest := fmt.Sprintf("%v/%v-v4", w.dst, network)
// the link is like zosCurrent but it has the path relative from the symlink
// point of view (so relative to the symlink, how to reach zosCurrent)
// hence the link is instead used in all calls to symlink
zosLink := fmt.Sprintf("%v/.tag-%v", path, versions.Zos)
zosLightLink := fmt.Sprintf("%v/.tag-%v", path, versions.ZosLight)
zosLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
zosLightLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)

// update links for both zos and zoslight
if err = w.updateLink(zosCurrent, zosLatest, zosLink); err != nil {
Expand Down

0 comments on commit 89c3556

Please sign in to comment.