Skip to content

Commit

Permalink
Merge pull request #2417 from threefoldtech/development_rollout_update
Browse files Browse the repository at this point in the history
add rollout configs for zos update
  • Loading branch information
rawdaGastan authored Sep 25, 2024
2 parents 63db0ab + 77f7483 commit 0e077bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/environment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type Config struct {
Users struct {
Authorized []string `json:"authorized"`
} `json:"users"`
RolloutUpgrade struct {
TestFarms []uint32 `json:"test_farms"`
SafeToUpgrade bool `json:"safe_to_upgrade"`
} `json:"rollout_upgrade"`
}

// Merge, updates current config with cfg merging and override config
Expand Down
4 changes: 2 additions & 2 deletions pkg/upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Then run the upgrader `upgrader.Run(ctx)`

## How it works

The upgrader module has two running modes depeding on the booting method.
The upgrader module has two running modes depending on the booting method.

### Bootstrap Method

Running the upgrader on a node run with `bootstrap` will periodically check the hub for latest tag,
and if that tag differs from the current one, it updates the local packages to latest.

If the update failed, the upgrader would attempts to install the packages again every `10 secounds` until all packages are successfully updated to prevent partial updates.
If the update failed, the upgrader would attempts to install the packages again every `10 seconds` until all packages are successfully updated to prevent partial updates.

The upgrader runs periodically every hour to check for new updates.

Expand Down
19 changes: 18 additions & 1 deletion pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/threefoldtech/0-fs/rofs"
"github.com/threefoldtech/0-fs/storage"
"github.com/threefoldtech/zos/pkg/app"
"github.com/threefoldtech/zos/pkg/environment"
"github.com/threefoldtech/zos/pkg/upgrade/hub"
"github.com/threefoldtech/zos/pkg/zinit"

Expand Down Expand Up @@ -131,7 +132,7 @@ func NewUpgrader(root string, opts ...UpgraderOption) (*Upgrader, error) {
return u, nil
}

// Run strats the upgrader module and run the update according to the detected boot method
// Run starts the upgrader module and run the update according to the detected boot method
func (u *Upgrader) Run(ctx context.Context) error {
method := u.boot.DetectBootMethod()
if method == BootMethodOther {
Expand Down Expand Up @@ -235,6 +236,22 @@ func (u *Upgrader) update() error {
return nil
}

env := environment.MustGet()
config, err := environment.GetConfig()
if err != nil {
return errors.Wrap(err, "failed to get network config")
}

rolloutConfigs := config.RolloutUpgrade

if !rolloutConfigs.SafeToUpgrade {
if !slices.Contains(rolloutConfigs.TestFarms, uint32(env.FarmID)) {
// nothing to do! waiting for the flag `safe to upgrade to be enabled after A/B testing`
// node is not a part of A/B testing
return nil
}
}

log.Info().Str("version", filepath.Base(remote.Target)).Msg("updating system...")
if err := u.updateTo(remote, &current); err != nil {
return errors.Wrapf(err, "failed to update to new tag '%s'", remote.Target)
Expand Down

0 comments on commit 0e077bb

Please sign in to comment.