Skip to content

Commit

Permalink
Merge pull request #217 from glazychev-art/qfix_multi_ns
Browse files Browse the repository at this point in the history
qfix: Add support for multiple network services
  • Loading branch information
denis-tingaikin authored Aug 16, 2021
2 parents a998c4d + e9ebcb0 commit 1e48b3e
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -221,28 +221,30 @@ func main() {
)

if config.RegisterService {
nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx, &config.ConnectTo, registryclient.WithDialOptions(clientOptions...))
_, err = nsRegistryClient.Register(ctx, &registryapi.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, &registryapi.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, &registryapi.NetworkServiceEndpoint{
Name: config.Name,
NetworkServiceNames: []string{config.ServiceName},
NetworkServiceLabels: map[string]*registryapi.NetworkServiceLabels{
config.ServiceName: {
Labels: config.Labels,
},
},
Url: listenOn.String(),
})
nse := &registryapi.NetworkServiceEndpoint{
Name: config.Name,
NetworkServiceNames: config.ServiceNames,
NetworkServiceLabels: make(map[string]*registryapi.NetworkServiceLabels),
Url: listenOn.String(),
}
for _, serviceName := range config.ServiceNames {
nse.NetworkServiceLabels[serviceName] = &registryapi.NetworkServiceLabels{Labels: config.Labels}
}
nse, err = nseRegistryClient.Register(ctx, nse)
logrus.Infof("nse: %+v", nse)

if err != nil {
Expand Down

0 comments on commit 1e48b3e

Please sign in to comment.