diff --git a/main.go b/main.go index a529622..e6bcf35 100644 --- a/main.go +++ b/main.go @@ -68,7 +68,7 @@ type Config struct { ListenOn string `default:"listen.on.sock" desc:"listen on socket" split_words:"true"` ConnectTo url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to connect to" split_words:"true"` MaxTokenLifetime time.Duration `default:"10m" desc:"maximum lifetime of tokens" split_words:"true"` - ServiceName string `default:"icmp-responder" desc:"Name of providing service" split_words:"true"` + ServiceNames []string `default:"icmp-responder" desc:"Name of providing service" split_words:"true"` Payload string `default:"ETHERNET" desc:"Name of provided service payload" split_words:"true"` Labels map[string]string `default:"" desc:"Endpoint labels"` CidrPrefix string `default:"169.254.0.0/16" desc:"CIDR Prefix to assign IPs from" split_words:"true"` @@ -77,10 +77,10 @@ type Config struct { // Process prints and processes env to config func (c *Config) Process() error { - if err := envconfig.Usage("nse", c); err != nil { + if err := envconfig.Usage("nsm", c); err != nil { return errors.Wrap(err, "cannot show usage of envconfig nse") } - if err := envconfig.Process("nse", c); err != nil { + if err := envconfig.Process("nsm", c); err != nil { return errors.Wrap(err, "cannot process envconfig nse") } return nil @@ -221,28 +221,30 @@ func main() { ) if config.RegisterService { - nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx, &config.ConnectTo, registryclient.WithDialOptions(clientOptions...)) - _, err = nsRegistryClient.Register(ctx, ®istryapi.NetworkService{ - Name: config.ServiceName, - Payload: config.Payload, - }) + for _, serviceName := range config.ServiceNames { + nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx, &config.ConnectTo, registryclient.WithDialOptions(clientOptions...)) + _, err = nsRegistryClient.Register(ctx, ®istryapi.NetworkService{ + Name: serviceName, + Payload: config.Payload, + }) - if err != nil { - log.FromContext(ctx).Fatalf("unable to register ns %+v", err) + if err != nil { + log.FromContext(ctx).Fatalf("unable to register ns %+v", err) + } } } nseRegistryClient := registryclient.NewNetworkServiceEndpointRegistryClient(ctx, &config.ConnectTo, registryclient.WithDialOptions(clientOptions...)) - nse, err := nseRegistryClient.Register(ctx, ®istryapi.NetworkServiceEndpoint{ - Name: config.Name, - NetworkServiceNames: []string{config.ServiceName}, - NetworkServiceLabels: map[string]*registryapi.NetworkServiceLabels{ - config.ServiceName: { - Labels: config.Labels, - }, - }, - Url: listenOn.String(), - }) + nse := ®istryapi.NetworkServiceEndpoint{ + Name: config.Name, + NetworkServiceNames: config.ServiceNames, + NetworkServiceLabels: make(map[string]*registryapi.NetworkServiceLabels), + Url: listenOn.String(), + } + for _, serviceName := range config.ServiceNames { + nse.NetworkServiceLabels[serviceName] = ®istryapi.NetworkServiceLabels{Labels: config.Labels} + } + nse, err = nseRegistryClient.Register(ctx, nse) logrus.Infof("nse: %+v", nse) if err != nil {