Skip to content

Commit 88c17d2

Browse files
committed
add v4hub url to env
1 parent f493ae2 commit 88c17d2

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

pkg/environment/environment.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Environment struct {
5656

5757
FlistURL string
5858
HubURL string
59+
V4HubURL string
5960
HubStorage string
6061
BinRepo string
6162

@@ -143,6 +144,7 @@ var (
143144
},
144145
FlistURL: flistURL,
145146
HubURL: hubURL,
147+
V4HubURL: v4HubURL,
146148
HubStorage: defaultHubStorage,
147149
BinRepo: "tf-zos-v3-bins.dev",
148150
GraphQL: []string{
@@ -170,6 +172,7 @@ var (
170172
},
171173
FlistURL: flistURL,
172174
HubURL: hubURL,
175+
V4HubURL: v4HubURL,
173176
HubStorage: defaultHubStorage,
174177
BinRepo: "tf-zos-v3-bins.test",
175178
GraphQL: []string{
@@ -197,6 +200,7 @@ var (
197200
},
198201
FlistURL: flistURL,
199202
HubURL: hubURL,
203+
V4HubURL: v4HubURL,
200204
HubStorage: defaultHubStorage,
201205
BinRepo: "tf-zos-v3-bins.qanet",
202206
GraphQL: []string{
@@ -228,6 +232,7 @@ var (
228232
},
229233
FlistURL: flistURL,
230234
HubURL: hubURL,
235+
V4HubURL: v4HubURL,
231236
HubStorage: defaultHubStorage,
232237
BinRepo: "tf-zos-v3-bins",
233238
GraphQL: []string{
@@ -368,22 +373,35 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) {
368373
env.GeoipURLs = geoip
369374
}
370375

376+
if flist := config.FlistURL; len(flist) > 0 {
377+
env.FlistURL = flist
378+
}
379+
380+
if storage := config.HubStorage; len(storage) > 0 {
381+
env.HubStorage = storage
382+
}
383+
384+
if hub := config.HubURL; len(hub) > 0 {
385+
env.HubURL = hub
386+
}
387+
388+
// some modules needs v3 hub url even if the node is of v4
389+
if hub := config.V4HubURL; len(hub) > 0 {
390+
env.V4HubURL = hub
391+
}
392+
371393
// if the node running v4 chage urls to use v4 hub
372394
if params.IsV4() {
373395
env.FlistURL = v4FlistURL
374396
if flist := config.V4FlistURL; len(flist) > 0 {
375397
env.FlistURL = flist
376398
}
377399

378-
env.HubURL = v4HubURL
379-
if hub := config.V4HubURL; len(hub) > 0 {
380-
env.HubURL = hub
381-
}
382-
383400
env.HubStorage = defaultV4HubStorage
384401
if storage := config.V4HubStorage; len(storage) > 0 {
385402
env.HubStorage = storage
386403
}
404+
387405
}
388406

389407
if farmSecret, ok := params.Get("secret"); ok {

pkg/primitives/zdb/zdb.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
)
3030

3131
const (
32-
// https://hub.grid.tf/api/flist/tf-autobuilder/threefoldtech-0-db-development.flist/light
3332
// To get the latest symlink pointer
3433
flistRepo = "tf-autobuilder"
3534
flistName = "threefoldtech-0-db-release-v2.0.8-55737c9202.flist"
@@ -290,7 +289,7 @@ func (p *Manager) createZdbContainer(ctx context.Context, device pkg.Device) err
290289
)
291290

292291
env := environment.MustGet()
293-
zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName)
292+
zdbFlistURL, err := url.JoinPath(env.HubURL, flistRepo, flistName)
294293
if err != nil {
295294
return errors.Wrap(err, "failed to construct zdb flist url")
296295
}
@@ -394,7 +393,7 @@ func (p *Manager) createZdbContainerLight(ctx context.Context, device pkg.Device
394393
)
395394

396395
env := environment.MustGet()
397-
zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName)
396+
zdbFlistURL, err := url.JoinPath(env.HubURL, flistRepo, flistName)
398397
if err != nil {
399398
return errors.Wrap(err, "failed to construct zdb flist url")
400399
}
@@ -952,7 +951,7 @@ func (p *Manager) initialize(ctx context.Context) error {
952951
)
953952
// fetching extected hash
954953
env := environment.MustGet()
955-
zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName)
954+
zdbFlistURL, err := url.JoinPath(env.HubURL, flistRepo, flistName)
956955
if err != nil {
957956
return errors.Wrap(err, "failed to construct zdb flist url")
958957
}
@@ -1019,7 +1018,7 @@ func (p *Manager) initializeLight(ctx context.Context) error {
10191018
)
10201019
// fetching extected hash
10211020
env := environment.MustGet()
1022-
zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName)
1021+
zdbFlistURL, err := url.JoinPath(env.HubURL, flistRepo, flistName)
10231022
if err != nil {
10241023
return errors.Wrap(err, "failed to construct zdb flist url")
10251024
}

pkg/upgrade/hub/hub.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/rs/zerolog/log"
1717
"github.com/threefoldtech/0-fs/meta"
1818
"github.com/threefoldtech/zosbase/pkg/environment"
19+
"github.com/threefoldtech/zosbase/pkg/kernel"
1920
)
2021

2122
const (
@@ -97,11 +98,11 @@ func (h *HubClient) StorageURL() string {
9798
// StorageURL return hub storage url
9899
func (h *HubClient) HubBaseURL() string {
99100
env := environment.MustGet()
100-
return env.HubURL
101-
// if kernel.GetParams().IsV4() {
102-
// return hubv4BaseURL
103-
// }
104-
// return hubBaseURL
101+
hubBaseURL := env.HubURL
102+
if kernel.GetParams().IsV4() {
103+
return env.V4HubURL
104+
}
105+
return hubBaseURL
105106
}
106107

107108
// Info gets flist info from hub
@@ -302,9 +303,10 @@ func (b *Regular) Files(repo string) ([]FileInfo, error) {
302303
}
303304
env := environment.MustGet()
304305
baseURL := env.HubURL
305-
// if kernel.GetParams().IsV4() {
306-
// baseURL = hubv4BaseURL
307-
// }
306+
if kernel.GetParams().IsV4() {
307+
baseURL = env.V4HubURL
308+
}
309+
308310
u, err := url.Parse(baseURL)
309311
if err != nil {
310312
panic("invalid base url")

0 commit comments

Comments
 (0)