Skip to content
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

Add RegisterService flag #415

Merged
Merged
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 internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ type Config struct {
LogLevel string `default:"INFO" desc:"Log level" split_words:"true"`
OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint"`

Services []ServiceConfig `default:"" desc:"list of supported services"`
ServiceNames []ServiceConfig `default:"" desc:"list of supported services" split_words:"true"`
RegisterService bool `default:"true" desc:"if true then registers network service on startup" split_words:"true"`
}

// Process prints and processes env to config
Expand Down
8 changes: 4 additions & 4 deletions internal/networkservice/mapserver/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -42,11 +42,11 @@ type entry struct {
// NewServer returns a new `network service -> { MAC, VLAN }` mapping server chain element
func NewServer(cfg *config.Config) networkservice.NetworkServiceServer {
s := &mapServer{
entries: make(map[string]*entry, len(cfg.Services)),
entries: make(map[string]*entry, len(cfg.ServiceNames)),
}

for i := range cfg.Services {
service := &cfg.Services[i]
for i := range cfg.ServiceNames {
service := &cfg.ServiceNames[i]
s.entries[service.Name] = &entry{
macAddr: service.MACAddr,
vlanTag: service.VLANTag,
Expand Down
34 changes: 18 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,20 @@ func main() {
grpcfd.WithChainUnaryInterceptor(),
)

nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx,
registryclient.WithClientURL(&cfg.ConnectTo),
registryclient.WithDialOptions(clientOptions...),
registryclient.WithAuthorizeNSRegistryClient(registryauthorize.NewNetworkServiceRegistryClient()))
for i := range cfg.Services {
nsName := cfg.Services[i].Name
nsPayload := cfg.Services[i].Payload
if _, err = nsRegistryClient.Register(ctx, &registry.NetworkService{
Name: nsName,
Payload: nsPayload,
}); err != nil {
log.FromContext(ctx).Fatalf("failed to register ns(%s) %s", nsName, err.Error())
if cfg.RegisterService {
nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx,
registryclient.WithClientURL(&cfg.ConnectTo),
registryclient.WithDialOptions(clientOptions...),
registryclient.WithAuthorizeNSRegistryClient(registryauthorize.NewNetworkServiceRegistryClient()))
for i := range cfg.ServiceNames {
nsName := cfg.ServiceNames[i].Name
nsPayload := cfg.ServiceNames[i].Payload
if _, err = nsRegistryClient.Register(ctx, &registry.NetworkService{
Name: nsName,
Payload: nsPayload,
}); err != nil {
log.FromContext(ctx).Fatalf("failed to register ns(%s) %s", nsName, err.Error())
}
}
}

Expand Down Expand Up @@ -267,14 +269,14 @@ func registryEndpoint(listenOn *url.URL, cfg *config.Config) *registry.NetworkSe

nse := &registry.NetworkServiceEndpoint{
Name: cfg.Name,
NetworkServiceNames: make([]string, len(cfg.Services)),
NetworkServiceLabels: make(map[string]*registry.NetworkServiceLabels, len(cfg.Services)),
NetworkServiceNames: make([]string, len(cfg.ServiceNames)),
NetworkServiceLabels: make(map[string]*registry.NetworkServiceLabels, len(cfg.ServiceNames)),
Url: grpcutils.URLToTarget(listenOn),
ExpirationTime: expireTime,
}

for i := range cfg.Services {
service := &cfg.Services[i]
for i := range cfg.ServiceNames {
service := &cfg.ServiceNames[i]

labels := service.Labels
if labels == nil {
Expand Down