Skip to content

Commit 89c3556

Browse files
committed
update zos worker
1 parent 55e8310 commit 89c3556

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

pkg/upgrade/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

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

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

7-
If a new release is available, it will then update the packages and restart the updated module with the new binaries if required.
7+
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)
8+
9+
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.
810

911
## Usage
1012

pkg/upgrade/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (u *Upgrader) update() error {
283283

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

286-
if remoteVer != chainVer.Version {
286+
if env.RunningMode != environment.RunningDev && remoteVer != chainVer.Version {
287287
// nothing to do! hub version is not the same as the chain
288288
return nil
289289
}

tools/zos-update-worker/internal/update_worker.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,24 @@ func (w *Worker) updateZosVersion(network Network, manager client.Manager) error
104104
}
105105
defer con.Close()
106106

107-
currentZosVersions, err := con.GetZosVersion()
107+
currentZosVersion, err := con.GetZosVersion()
108108
if err != nil {
109109
return err
110110
}
111111

112-
type ZosVersions struct {
113-
Zos string
114-
ZosLight string
112+
type ChainVersion struct {
113+
SafeToUpgrade bool `json:"safe_to_upgrade"`
114+
Version string `json:"version"`
115115
}
116-
versions := ZosVersions{}
117116

118-
err = json.Unmarshal([]byte(currentZosVersions), &versions)
117+
var chainVersion ChainVersion
118+
err = json.Unmarshal([]byte(currentZosVersion), &chainVersion)
119119
if err != nil {
120-
return err
120+
log.Debug().Err(err).Msg("failed to unmarshal chain version")
121+
chainVersion.Version = currentZosVersion
121122
}
122-
log.Debug().Msgf("getting substrate version %v for network %v", versions, network)
123+
124+
log.Debug().Msgf("getting substrate version %v for network %v", chainVersion.Version, network)
123125

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

130132
//zos
131-
zosCurrent := fmt.Sprintf("%v/.tag-%v", w.src, versions.Zos)
133+
zosCurrent := fmt.Sprintf("%v/.tag-%v", w.src, chainVersion.Version)
132134
zosLatest := fmt.Sprintf("%v/%v", w.dst, network)
133135
// zos light
134-
zosLightCurrent := fmt.Sprintf("%v/.tag-%v", w.src, versions.ZosLight)
136+
zosLightCurrent := fmt.Sprintf("%v/.tag-%v", w.src, chainVersion.Version)
135137
zosLightLatest := fmt.Sprintf("%v/%v-v4", w.dst, network)
136138
// the link is like zosCurrent but it has the path relative from the symlink
137139
// point of view (so relative to the symlink, how to reach zosCurrent)
138140
// hence the link is instead used in all calls to symlink
139-
zosLink := fmt.Sprintf("%v/.tag-%v", path, versions.Zos)
140-
zosLightLink := fmt.Sprintf("%v/.tag-%v", path, versions.ZosLight)
141+
zosLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
142+
zosLightLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
141143

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

0 commit comments

Comments
 (0)