-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setup public config for zos light #3
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as the above comment |
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as first comment |
||
feat = append(feat, pkg.NodeFeature("gateway")) | ||
} | ||
return feat | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for this method u already calling public.loadPublicConfig without changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is important to implement the networker interface https://github.com/threefoldtech/zoslight/blob/main/pkg/network_light.go#L34 which is used to generate the stubs https://github.com/threefoldtech/zoslight/blob/ff8a7a63a0c9c717a3e2ceed73112e8fbf99da83/pkg/stubs/network_light_stub.go#L163 this is used by the gateway module |
||
cfg, err := public.LoadPublicConfig() | ||
return *cfg, err | ||
} | ||
|
||
func CreateNDMZBridge() (*netlink.Bridge, error) { | ||
return createNDMZBridge(NDMZBridge, NDMZGw) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit confusing
u r calling config.domain without checking the error returned from
loadPublicConfig
the method returns nil in case of error which will result in an error when calling config.domainso plz check the error first then u can call config.Domain
this line
should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is wrong, it was a wip comment fixed in zoslight repo but didn't do the commit here https://github.com/threefoldtech/zoslight/blob/ff8a7a63a0c9c717a3e2ceed73112e8fbf99da83/pkg/gateway/gateway.go#L348
in case an err, config.Domain will be empty anyway. but you are right cleaner to check for the error first