Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ require (
github.com/rs/zerolog v1.19.0
github.com/shirou/gopsutil v2.19.11+incompatible
github.com/stretchr/testify v1.6.1
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae
github.com/threefoldtech/tfexplorer v0.3.2-0.20200716125715-b13151dae8f0
github.com/threefoldtech/tfexplorer v0.3.2-0.20200825120759-93de16888129
github.com/threefoldtech/zbus v0.1.3
github.com/urfave/cli v1.22.4
github.com/vishvananda/netlink v1.1.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,13 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 h1:b6uOv7YOFK0TYG7HtkIgExQo+2RdLuwRft63jn2HWj8=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae h1:vgGSvdW5Lqg+I1aZOlG32uyE6xHpLdKhZzcTEktz5wM=
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae/go.mod h1:quDq6Se6jlGwiIKia/itDZxqC5rj6/8OdFyMMAwTxCs=
github.com/threefoldtech/tfexplorer v0.2.5/go.mod h1:TugylEDgMNKk4ZIzee9PpVmIcLNLaRLdiXuhHTt/AR0=
github.com/threefoldtech/tfexplorer v0.3.2-0.20200713131646-d0479a0e84ca h1:EYcYpQchr0+dRf+a9qyNZFSiQXQHxIoOoz1rSut1jIQ=
github.com/threefoldtech/tfexplorer v0.3.2-0.20200713131646-d0479a0e84ca/go.mod h1:oFtPBaRLW4c6YuEfTrWYzAGw+wb6I4+og133zjDOYP0=
github.com/threefoldtech/tfexplorer v0.3.2-0.20200716125715-b13151dae8f0 h1:NNlni8J1a5Mkhk3nc2re+E9hDQoxhJsoHv18AaNr9fY=
github.com/threefoldtech/tfexplorer v0.3.2-0.20200716125715-b13151dae8f0/go.mod h1:oFtPBaRLW4c6YuEfTrWYzAGw+wb6I4+og133zjDOYP0=
github.com/threefoldtech/tfexplorer v0.3.2-0.20200825120759-93de16888129 h1:/FQOES+eaChbygFN33yE+NLVAKot4kqBKsgAK479c2w=
github.com/threefoldtech/tfexplorer v0.3.2-0.20200825120759-93de16888129/go.mod h1:oFtPBaRLW4c6YuEfTrWYzAGw+wb6I4+og133zjDOYP0=
github.com/threefoldtech/zbus v0.1.3 h1:18DnIzximRbATle5ZdZz0i84n/bCYB8k/gkhr2dXayc=
github.com/threefoldtech/zbus v0.1.3/go.mod h1:ZtiRpcqzEBJetVQDsEbw0p48h/AF3O1kf0tvd30I0BU=
github.com/threefoldtech/zos v0.2.4-rc2/go.mod h1:7A2oflcmSVsHFC4slOcydWgJyFBMFMH9wsaTRv+CnTA=
Expand Down
41 changes: 40 additions & 1 deletion pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

"github.com/pkg/errors"

"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/tfexplorer/schema"
"github.com/threefoldtech/zos/pkg/app"
"github.com/threefoldtech/zos/pkg/environment"
"github.com/threefoldtech/zos/pkg/zinit"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -43,7 +47,14 @@ type Upgrader struct {
// on a successfully update, upgrade WILL NOT RETURN
// instead the upgraded daemon will be completely stopped
func (u *Upgrader) Upgrade(from, to FListEvent) error {
return u.applyUpgrade(from, to)
upgrade, err := canUpgrade()
if err != nil {
return err
}
if upgrade {
return u.applyUpgrade(from, to)
}
return nil
}

// InstallBinary from a single flist.
Expand Down Expand Up @@ -446,3 +457,31 @@ func copyFile(dst, src string) error {
}
return nil
}

// instantiate the proper client based on the running mode
func bcdbClient() (client.Directory, error) {
client, err := app.ExplorerClient()
if err != nil {
return nil, err
}

return client.Directory, nil
}

func canUpgrade() (bool, error) {
env, err := environment.Get()
if err != nil {
return false, errors.Wrap(err, "failed to parse node environment")
}
cl, err := bcdbClient()
if err != nil {
return false, errors.Wrap(err, "failed to instantiate bcdb client")
}

farm, err := cl.FarmGet(schema.ID(env.FarmerID))
if err != nil {
return false, errors.Wrap(err, "failed to get farm")
}

return farm.AutomaticUpgrades, nil
}