diff --git a/internal/config/config.go b/internal/config/config.go index 566f8e5..f5cb646 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -43,8 +43,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"` - LocalDNSServerAddress string `default:"127.0.0.1:53" desc:"Default address for local DNS server"` - + LocalDNSServerAddress string `default:"127.0.0.1:53" desc:"Default address for local DNS server"` + LocalDNSServerEnabled bool `default:"false" desc:"Local DNS Server enabled/disabled"` LivenessCheckEnabled bool `default:"true" desc:"Dataplane liveness check enabled/disabled"` LivenessCheckInterval time.Duration `default:"200ms" desc:"Dataplane liveness check interval"` LivenessCheckTimeout time.Duration `default:"1s" desc:"Dataplane liveness check timeout"` diff --git a/main.go b/main.go index d9f5669..03b0a3f 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/kernel" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" + "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" "github.com/networkservicemesh/sdk/pkg/networkservice/common/retry" "github.com/networkservicemesh/sdk/pkg/networkservice/common/upstreamrefresh" "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext" @@ -163,18 +164,21 @@ func main() { ), ) - dnsConfigsMap := new(dnsconfig.Map) - dnsServerHandler := next.NewDNSHandler( - checkmsg.NewDNSHandler(), - dnsconfigs.NewDNSHandler(dnsConfigsMap), - searches.NewDNSHandler(), - noloop.NewDNSHandler(), - cache.NewDNSHandler(), - fanout.NewDNSHandler(), - ) - - go dnsutils.ListenAndServe(ctx, dnsServerHandler, c.LocalDNSServerAddress) - + dnsClient := null.NewClient() + if c.LocalDNSServerEnabled { + dnsConfigsMap := new(dnsconfig.Map) + dnsClient = dnscontext.NewClient(dnscontext.WithChainContext(ctx), dnscontext.WithDNSConfigsMap(dnsConfigsMap)) + dnsServerHandler := next.NewDNSHandler( + checkmsg.NewDNSHandler(), + dnsconfigs.NewDNSHandler(dnsConfigsMap), + searches.NewDNSHandler(), + noloop.NewDNSHandler(), + cache.NewDNSHandler(), + fanout.NewDNSHandler(), + ) + + go dnsutils.ListenAndServe(ctx, dnsServerHandler, c.LocalDNSServerAddress) + } var healOptions = []heal.Option{heal.WithLivenessCheckInterval(c.LivenessCheckInterval), heal.WithLivenessCheckTimeout(c.LivenessCheckTimeout)} @@ -196,7 +200,7 @@ func main() { kernelmech.MECHANISM: chain.NewNetworkServiceClient(kernel.NewClient()), }), sendfd.NewClient(), - dnscontext.NewClient(dnscontext.WithChainContext(ctx), dnscontext.WithDNSConfigsMap(dnsConfigsMap)), + dnsClient, excludedprefixes.NewClient(excludedprefixes.WithAwarenessGroups(c.AwarenessGroups)), ), client.WithDialTimeout(c.DialTimeout), @@ -299,7 +303,6 @@ func main() { logger.Infof("successfully connected to %v. Response: %v", u.NetworkService(), resp) } - // Wait for cancel event to terminate <-signalCtx.Done() }