Skip to content

Commit df02144

Browse files
committed
prevent capacityd and provisiond to start if networkd is not ready
fixes #632
1 parent 00a8899 commit df02144

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

cmds/capacityd/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const module = "monitor"
2626
func cap(ctx context.Context, client zbus.Client) {
2727
storage := stubs.NewStorageModuleStub(client)
2828
identity := stubs.NewIdentityManagerStub(client)
29+
network := stubs.NewNetworkerStub(client)
2930
cl, err := bcdbClient()
3031
if err != nil {
3132
log.Fatal().Err(err).Msg("failed to connect to bcdb backend")
@@ -34,6 +35,17 @@ func cap(ctx context.Context, client zbus.Client) {
3435
// call this now so we block here until identityd is ready to serve us
3536
nodeID := identity.NodeID().Identity()
3637

38+
// block until networkd is ready to serve request from zbus
39+
// this is used to prevent uptime and online status to the explorer if the node is not in a fully ready
40+
// https://github.com/threefoldtech/zos/issues/632
41+
bo := backoff.NewExponentialBackOff()
42+
bo.MaxElapsedTime = 0
43+
backoff.RetryNotify(func() error {
44+
return network.Ready()
45+
}, bo, func(err error, d time.Duration) {
46+
log.Error().Err(err).Msgf("networkd is not ready yet")
47+
})
48+
3749
r := capacity.NewResourceOracle(storage)
3850

3951
log.Info().Msg("inspect hardware resources")
@@ -75,7 +87,7 @@ func cap(ctx context.Context, client zbus.Client) {
7587
log.Info().Msg("sends capacity detail to BCDB")
7688
return cl.NodeSetCapacity(nodeID, ru, *dmi, disks, hypervisor)
7789
}
78-
bo := backoff.NewExponentialBackOff()
90+
bo = backoff.NewExponentialBackOff()
7991
bo.MaxElapsedTime = 0 // retry forever
8092
backoff.RetryNotify(setCapacity, bo, func(err error, d time.Duration) {
8193
log.Error().

cmds/provisiond/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"time"
99

10+
"github.com/cenkalti/backoff/v3"
1011
"github.com/threefoldtech/zos/pkg"
1112
"github.com/threefoldtech/zos/pkg/app"
1213
"github.com/threefoldtech/zos/pkg/environment"
@@ -92,6 +93,18 @@ func main() {
9293
identity := stubs.NewIdentityManagerStub(zbusCl)
9394
nodeID := identity.NodeID()
9495

96+
// block until networkd is ready to serve request from zbus
97+
// this is used to prevent uptime and online status to the explorer if the node is not in a fully ready
98+
// https://github.com/threefoldtech/zos/issues/632
99+
network := stubs.NewNetworkerStub(zbusCl)
100+
bo := backoff.NewExponentialBackOff()
101+
bo.MaxElapsedTime = 0
102+
backoff.RetryNotify(func() error {
103+
return network.Ready()
104+
}, bo, func(err error, d time.Duration) {
105+
log.Error().Err(err).Msgf("networkd is not ready yet")
106+
})
107+
95108
// to get reservation from tnodb
96109
e, err := app.ExplorerClient()
97110
if err != nil {

pkg/network.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type Member struct {
2020

2121
//Networker is the interface for the network module
2222
type Networker interface {
23+
// Ready return nil is networkd is ready to operate
24+
// This function is used by other deamon to test if networkd is done booting
25+
Ready() error
26+
2327
// Create a new network resource
2428
CreateNR(Network) (string, error)
2529
// Delete a network resource

pkg/network/networker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ func validatePeer(p pkg.Peer) error {
210210
return nil
211211
}
212212

213+
func (n *networker) Ready() error {
214+
return nil
215+
}
216+
213217
func (n *networker) Join(networkdID pkg.NetID, containerID string, addrs []string, publicIP6 bool) (join pkg.Member, err error) {
214218
// TODO:
215219
// 1- Make sure this network id is actually deployed

pkg/stubs/network_stub.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ func (s *NetworkerStub) PublicAddresses(ctx context.Context) (<-chan pkg.Netlink
168168
return ch, nil
169169
}
170170

171+
func (s *NetworkerStub) Ready() (ret0 error) {
172+
args := []interface{}{}
173+
result, err := s.client.Request(s.module, s.object, "Ready", args...)
174+
if err != nil {
175+
panic(err)
176+
}
177+
ret0 = new(zbus.RemoteError)
178+
if err := result.Unmarshal(0, &ret0); err != nil {
179+
panic(err)
180+
}
181+
return
182+
}
183+
171184
func (s *NetworkerStub) RemoveTap(arg0 pkg.NetID) (ret0 error) {
172185
args := []interface{}{arg0}
173186
result, err := s.client.Request(s.module, s.object, "RemoveTap", args...)

0 commit comments

Comments
 (0)