Skip to content

Commit

Permalink
use zos configs
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Sep 18, 2024
1 parent 119ec96 commit 0551c16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 89 deletions.
5 changes: 2 additions & 3 deletions cmds/identityd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ func main() {
version.ShowAndExit(false)
}

env := environment.MustGet()

if farm {
env := environment.MustGet()
fmt.Println(env.FarmID)
os.Exit(0)
} else if net {
Expand Down Expand Up @@ -108,7 +107,7 @@ func main() {
log.Fatal().Err(err).Msg("failed to create identity manager")
}

upgrader, err := upgrade.NewUpgrader(root, uint32(env.FarmID), upgrade.NoZosUpgrade(debug))
upgrader, err := upgrade.NewUpgrader(root, upgrade.NoZosUpgrade(debug))
if err != nil {
log.Fatal().Err(err).Msg("failed to initialize upgrader")
}
Expand Down
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
18 changes: 0 additions & 18 deletions pkg/upgrade/config.json

This file was deleted.

60 changes: 0 additions & 60 deletions pkg/upgrade/rollout.go

This file was deleted.

18 changes: 10 additions & 8 deletions 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 @@ -57,7 +58,6 @@ type Upgrader struct {
noZosUpgrade bool
hub *hub.HubClient
storage storage.Storage
farmID uint32
}

// UpgraderOption interface
Expand Down Expand Up @@ -97,12 +97,11 @@ func Zinit(socket string) UpgraderOption {
}

// NewUpgrader creates a new upgrader instance
func NewUpgrader(root string, farmID uint32, opts ...UpgraderOption) (*Upgrader, error) {
func NewUpgrader(root string, opts ...UpgraderOption) (*Upgrader, error) {
hubClient := hub.NewHubClient(defaultHubTimeout)
u := &Upgrader{
root: root,
farmID: farmID,
hub: hubClient,
root: root,
hub: hubClient,
}

for _, dir := range []string{u.fileCache(), u.flistCache()} {
Expand Down Expand Up @@ -237,13 +236,16 @@ func (u *Upgrader) update() error {
return nil
}

rolloutConfigs, err := readRolloutConfig(u.boot.RunMode().String())
env := environment.MustGet()
config, err := environment.GetConfig()
if err != nil {
return errors.Wrap(err, "failed to read rollout configs")
return errors.Wrap(err, "failed to get network config")
}

rolloutConfigs := config.RolloutUpgrade

if !rolloutConfigs.SafeToUpgrade {
if !slices.Contains(rolloutConfigs.TestFarms, u.farmID) {
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
Expand Down

0 comments on commit 0551c16

Please sign in to comment.