From 4e6279cde0c3096e8a91860f0bc73ff3945b85af Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Thu, 31 Oct 2024 14:44:53 +0300 Subject: [PATCH] update zos worker to include v4 versions --- pkg/upgrade/README.md | 6 ++-- .../internal/update_worker.go | 33 +++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/pkg/upgrade/README.md b/pkg/upgrade/README.md index 669b07b28..607906c0a 100644 --- a/pkg/upgrade/README.md +++ b/pkg/upgrade/README.md @@ -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 diff --git a/tools/zos-update-worker/internal/update_worker.go b/tools/zos-update-worker/internal/update_worker.go index 32a1491dd..f0c546d18 100644 --- a/tools/zos-update-worker/internal/update_worker.go +++ b/tools/zos-update-worker/internal/update_worker.go @@ -129,42 +129,55 @@ 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) + // 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 current exists - if _, err := os.Lstat(zosCurrent); err != nil { + if _, err := os.Lstat(current); err != nil { return err } // 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