diff --git a/pkg/gateway_light/gateway.go b/pkg/gateway_light/gateway.go index c84e8bab..8c43df36 100644 --- a/pkg/gateway_light/gateway.go +++ b/pkg/gateway_light/gateway.go @@ -20,7 +20,6 @@ import ( "github.com/threefoldtech/zosbase/pkg/cache" "github.com/threefoldtech/zosbase/pkg/gridtypes" "github.com/threefoldtech/zosbase/pkg/gridtypes/zos" - "github.com/threefoldtech/zosbase/pkg/kernel" "github.com/threefoldtech/zosbase/pkg/netlight/types" "github.com/threefoldtech/zosbase/pkg/stubs" "github.com/threefoldtech/zosbase/pkg/zinit" @@ -342,8 +341,11 @@ func (g *gatewayModule) validateNameContracts() error { ctx, cancel := context.WithTimeout(context.Background(), validationPeriod/2) defer cancel() e := stubs.NewProvisionStub(g.cl) - baseDomain, found := kernel.GetParams().GetOne("domain") - if !found { + + netStub := stubs.NewNetworkerLightStub(g.cl) + config, err := netStub.LoadPublicConfig(context.Background()) + baseDomain := config.Domain + if baseDomain == "" || err == nil { // domain doesn't exist so no name workloads exist return nil } @@ -425,12 +427,12 @@ func (g *gatewayModule) traefikBinary(ctx context.Context, z *zinit.Client) (str // ensureGateway makes sure that gateway infrastructure is in place and // that it is supported. func (g *gatewayModule) ensureGateway(ctx context.Context, forceResstart bool) (string, error) { - var ( - flistd = stubs.NewFlisterStub(g.cl) - ) + flistd := stubs.NewFlisterStub(g.cl) - domain, found := kernel.GetParams().GetOne("domain") - if !found { + netStub := stubs.NewNetworkerLightStub(g.cl) + config, err := netStub.LoadPublicConfig(context.Background()) + domain := config.Domain + if domain == "" || err != nil { return "", fmt.Errorf("gateway is not supported on this node, domain is not set") } @@ -478,9 +480,10 @@ func (g *gatewayModule) ensureGateway(ctx context.Context, forceResstart bool) ( return domain, nil } - //other wise we start traefik + // other wise we start traefik return domain, g.startTraefik(z) } + func (g *gatewayModule) verifyDomainDestination(ctx context.Context, domain string) error { networker := stubs.NewNetworkerLightStub(g.cl) @@ -508,7 +511,6 @@ func (g *gatewayModule) verifyDomainDestination(ctx context.Context, domain stri } func (g *gatewayModule) startTraefik(z *zinit.Client) error { - cmd := fmt.Sprintf( "%s --configfile %s", g.binPath, @@ -540,7 +542,6 @@ func (g *gatewayModule) configPath(name string) string { } func (g *gatewayModule) validateNameContract(name string, twinID uint32) error { - contractID, subErr := g.substrateGateway.GetContractIDByNameRegistration(context.Background(), name) if subErr.IsCode(pkg.CodeNotFound) { return ErrContractNotReserved diff --git a/pkg/monitord/system.go b/pkg/monitord/system.go index 70353c63..e591721c 100644 --- a/pkg/monitord/system.go +++ b/pkg/monitord/system.go @@ -9,9 +9,11 @@ import ( "github.com/shirou/gopsutil/disk" "github.com/shirou/gopsutil/mem" "github.com/shirou/gopsutil/net" + "github.com/threefoldtech/zbus" "github.com/threefoldtech/zosbase/pkg" "github.com/threefoldtech/zosbase/pkg/gridtypes/zos" "github.com/threefoldtech/zosbase/pkg/kernel" + "github.com/threefoldtech/zosbase/pkg/stubs" ) var _ pkg.SystemMonitor = (*systemMonitor)(nil) @@ -20,15 +22,16 @@ var _ pkg.SystemMonitor = (*systemMonitor)(nil) type systemMonitor struct { duration time.Duration node uint32 + cl zbus.Client } // NewSystemMonitor creates new system of system monitor -func NewSystemMonitor(node uint32, duration time.Duration) (pkg.SystemMonitor, error) { +func NewSystemMonitor(node uint32, duration time.Duration, cl zbus.Client) (pkg.SystemMonitor, error) { if duration == 0 { duration = 2 * time.Second } - return &systemMonitor{duration: duration, node: node}, nil + return &systemMonitor{duration: duration, node: node, cl: cl}, nil } func (m *systemMonitor) NodeID() uint32 { @@ -215,8 +218,11 @@ func (n *systemMonitor) GetNodeFeatures() []pkg.NodeFeature { pkg.NodeFeature("mycelium"), } feat = append(feat, zosLightFeat...) - _, found := kernel.GetParams().GetOne("domain") - if found { + + netStub := stubs.NewNetworkerLightStub(n.cl) + config, err := netStub.LoadPublicConfig(context.Background()) + + if config.Domain != "" && err == nil { feat = append(feat, pkg.NodeFeature("gateway")) } return feat diff --git a/pkg/netlight/network.go b/pkg/netlight/network.go index a605e48b..0a139144 100644 --- a/pkg/netlight/network.go +++ b/pkg/netlight/network.go @@ -25,6 +25,7 @@ import ( "github.com/threefoldtech/zosbase/pkg/netlight/ipam" "github.com/threefoldtech/zosbase/pkg/netlight/namespace" "github.com/threefoldtech/zosbase/pkg/netlight/options" + "github.com/threefoldtech/zosbase/pkg/netlight/public" "github.com/threefoldtech/zosbase/pkg/netlight/resource" "github.com/threefoldtech/zosbase/pkg/versioned" "github.com/vishvananda/netlink" @@ -39,12 +40,10 @@ const ( networkDir = "networks" ) -var ( - NDMZGwIP = &net.IPNet{ - IP: net.ParseIP("100.127.0.1"), - Mask: net.CIDRMask(16, 32), - } -) +var NDMZGwIP = &net.IPNet{ + IP: net.ParseIP("100.127.0.1"), + Mask: net.CIDRMask(16, 32), +} var NetworkSchemaLatestVersion = semver.MustParse("0.1.0") @@ -90,7 +89,6 @@ func (n *networker) Delete(name string) error { } return resource.Delete(name) - } func (n *networker) AttachPrivate(name, id string, vmIp net.IP) (device localPkg.TapDevice, err error) { @@ -391,6 +389,38 @@ func (n *networker) Interfaces(iface string, netns string) (pkg.Interfaces, erro return pkg.Interfaces{Interfaces: interfaces}, nil } +func (n *networker) UnSetPublicConfig() error { + return public.DeletePublicConfig() +} + +// Set node public namespace config +func (n *networker) SetPublicConfig(cfg pkg.PublicConfig) error { + if cfg.Equal(pkg.PublicConfig{}) { + return fmt.Errorf("public config cannot be unset, only modified") + } + + current, err := public.LoadPublicConfig() + if err != nil && err != public.ErrNoPublicConfig { + return errors.Wrapf(err, "failed to load current public configuration") + } + + if current != nil && current.Equal(cfg) { + // nothing to do + return nil + } + + if err := public.SavePublicConfig(cfg); err != nil { + return errors.Wrap(err, "failed to store public config") + } + + return nil +} + +func (n *networker) LoadPublicConfig() (pkg.PublicConfig, error) { + cfg, err := public.LoadPublicConfig() + return *cfg, err +} + func CreateNDMZBridge() (*netlink.Bridge, error) { return createNDMZBridge(NDMZBridge, NDMZGw) } diff --git a/pkg/netlight/public/persist.go b/pkg/netlight/public/persist.go index ea905c43..0307ecb7 100644 --- a/pkg/netlight/public/persist.go +++ b/pkg/netlight/public/persist.go @@ -13,10 +13,8 @@ const ( publicConfigFile = "public-config.json" ) -var ( - // persistencePath is path to config file. - persistencePath = "" -) +// persistencePath is path to config file. +var persistencePath = "" func SetPersistence(path string) { stat, err := os.Stat(path) diff --git a/pkg/network_light.go b/pkg/network_light.go index ab6fefb4..179114ab 100644 --- a/pkg/network_light.go +++ b/pkg/network_light.go @@ -22,6 +22,9 @@ type NetworkerLight interface { Ready() error ZOSAddresses(ctx context.Context) <-chan NetlinkAddresses GetSubnet(networkID NetID) (net.IPNet, error) + SetPublicConfig(cfg PublicConfig) error + UnSetPublicConfig() error + LoadPublicConfig() (PublicConfig, error) } type TapDevice struct { diff --git a/pkg/stubs/network_light_stub.go b/pkg/stubs/network_light_stub.go index be868aa2..5bc99e01 100644 --- a/pkg/stubs/network_light_stub.go +++ b/pkg/stubs/network_light_stub.go @@ -159,6 +159,23 @@ func (s *NetworkerLightStub) Interfaces(ctx context.Context, arg0 string, arg1 s return } +func (s *NetworkerLightStub) LoadPublicConfig(ctx context.Context) (ret0 pkg.PublicConfig, ret1 error) { + args := []interface{}{} + result, err := s.client.RequestContext(ctx, s.module, s.object, "LoadPublicConfig", args...) + if err != nil { + panic(err) + } + result.PanicOnError() + ret1 = result.CallError() + loader := zbus.Loader{ + &ret0, + } + if err := result.Unmarshal(&loader); err != nil { + panic(err) + } + return +} + func (s *NetworkerLightStub) Namespace(ctx context.Context, arg0 string) (ret0 string) { args := []interface{}{arg0} result, err := s.client.RequestContext(ctx, s.module, s.object, "Namespace", args...) @@ -190,6 +207,36 @@ func (s *NetworkerLightStub) Ready(ctx context.Context) (ret0 error) { return } +func (s *NetworkerLightStub) SetPublicConfig(ctx context.Context, arg0 pkg.PublicConfig) (ret0 error) { + args := []interface{}{arg0} + result, err := s.client.RequestContext(ctx, s.module, s.object, "SetPublicConfig", args...) + if err != nil { + panic(err) + } + result.PanicOnError() + ret0 = result.CallError() + loader := zbus.Loader{} + if err := result.Unmarshal(&loader); err != nil { + panic(err) + } + return +} + +func (s *NetworkerLightStub) UnSetPublicConfig(ctx context.Context) (ret0 error) { + args := []interface{}{} + result, err := s.client.RequestContext(ctx, s.module, s.object, "UnSetPublicConfig", args...) + if err != nil { + panic(err) + } + result.PanicOnError() + ret0 = result.CallError() + loader := zbus.Loader{} + if err := result.Unmarshal(&loader); err != nil { + panic(err) + } + return +} + func (s *NetworkerLightStub) ZDBIPs(ctx context.Context, arg0 string) (ret0 [][]uint8, ret1 error) { args := []interface{}{arg0} result, err := s.client.RequestContext(ctx, s.module, s.object, "ZDBIPs", args...)