From ba4edae78e4ada6cdbdb7c8d6af84128dc3c13f2 Mon Sep 17 00:00:00 2001 From: Mikhail Avramenko Date: Thu, 1 Jul 2021 16:07:31 +0700 Subject: [PATCH 1/2] config option for network service register Signed-off-by: Mikhail Avramenko --- main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 8aebaee..da166b1 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,7 @@ type Config struct { 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"` + RegisterService bool `default:"true" desc:"register network service flag" split_words:"true"` } // Process prints and processes env to config @@ -219,14 +220,16 @@ func main() { ), ) - nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx, &config.ConnectTo, registryclient.WithDialOptions(clientOptions...)) - _, err = nsRegistryClient.Register(ctx, ®istryapi.NetworkService{ - Name: config.ServiceName, - Payload: config.Payload, - }) + if config.RegisterService { + nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx, &config.ConnectTo, registryclient.WithDialOptions(clientOptions...)) + _, err = nsRegistryClient.Register(ctx, ®istryapi.NetworkService{ + Name: config.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...)) From 48b783904e43c6795944779aa8d8c05c6490b3ba Mon Sep 17 00:00:00 2001 From: Mikhail Avramenko Date: Thu, 1 Jul 2021 17:20:52 +0700 Subject: [PATCH 2/2] post review refactoring Signed-off-by: Mikhail Avramenko --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index da166b1..82c8db0 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,7 @@ type Config struct { 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"` - RegisterService bool `default:"true" desc:"register network service flag" 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