Skip to content

Commit

Permalink
update zos worker to include v4 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Oct 31, 2024
1 parent d2f6c02 commit e39d5e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 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
30 changes: 19 additions & 11 deletions tools/zos-update-worker/internal/update_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,42 +129,50 @@ func (w *Worker) updateZosVersion(network Network, manager client.Manager) error
return fmt.Errorf("failed to get dst relative path to src: %w", err)
}

//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, 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
link := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
zosLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
zosLightLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)

// check if current exists
if _, err := os.Lstat(zosCurrent); err != nil {
// update links for both zos and zoslight
if err = w.updateLink(zosCurrent, zosLatest, zosLink); err != nil {
return err
}
return w.updateLink(zosLightCurrent, zosLightLatest, zosLightLink)
}

func (w *Worker) updateLink(current string, latest string, link string) error {
// check if symlink exists
dst, err := os.Readlink(zosLatest)
dst, err := os.Readlink(latest)

// if no symlink, then create it
if os.IsNotExist(err) {
log.Info().Str("from", zosLatest).Str("to", zosCurrent).Msg("linking")
return os.Symlink(link, zosLatest)
log.Info().Str("from", latest).Str("to", current).Msg("linking")
return os.Symlink(link, latest)
} else if err != nil {
return err
}

// check if symlink is valid and exists
if filepath.Base(dst) == filepath.Base(zosCurrent) {
log.Debug().Msgf("symlink %v to %v already exists", zosCurrent, zosLatest)
if filepath.Base(dst) == filepath.Base(current) {
log.Debug().Msgf("symlink %v to %v already exists", current, latest)
return nil
}

// remove symlink if it is not valid and exists
if err := os.Remove(zosLatest); err != nil {
if err := os.Remove(latest); err != nil {
return err
}

log.Info().Str("from", zosLatest).Str("to", zosCurrent).Msg("linking")
return os.Symlink(link, zosLatest)
log.Info().Str("from", latest).Str("to", current).Msg("linking")
return os.Symlink(link, latest)
}

// UpdateWithInterval updates the latest zos flist for a specific network with the updated zos version
Expand Down

0 comments on commit e39d5e0

Please sign in to comment.