From 3168c11e8b39d6ef965f5ac2d89019c257fc70eb Mon Sep 17 00:00:00 2001 From: Neil-Jocelyn Schark <neil.schark@h-da.de> Date: Thu, 6 Jun 2024 09:49:36 +0000 Subject: [PATCH] Add opt to set default grpc scheme to passthrough See merge request danet/gosdn!900 Co-authored-by: Malte Bauch <malte.bauch@h-da.de> --- cli/cmd/root.go | 10 ++++++++++ controller/cmd/root.go | 2 ++ controller/controller.go | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/cli/cmd/root.go b/cli/cmd/root.go index ce1782a40..01e89117c 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -36,6 +36,7 @@ import ( "os" "code.fbi.h-da.de/danet/gosdn/cli/adapter" + "google.golang.org/grpc/resolver" "github.com/google/uuid" log "github.com/sirupsen/logrus" @@ -45,6 +46,7 @@ import ( var cfgFile string var verbose bool +var gRPCPassthrough bool var loglevel string var grpcPort string var cliPnd string @@ -85,6 +87,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (./.gosdnc.toml)") rootCmd.PersistentFlags().StringVarP(&loglevel, "log-level", "l", "", "log level 'debug' or 'trace'") rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "show mne and sbi info") + rootCmd.PersistentFlags().BoolVar(&gRPCPassthrough, "grpcPassthrough", true, "set the default resolve scheme for grpc to passthrough, default is true") rootCmd.Flags().StringVar(&grpcPort, "grpc-port", "55055", "port for gRPC NBI") } @@ -147,6 +150,13 @@ func initConfig() { cliPnd = uuid.New().String() } + if gRPCPassthrough { + log.Info("Setting gRPC default resolver scheme to passthrough. No DNS queries are being made when doing a gRPC request.") + resolver.SetDefaultScheme("passthrough") + } else { + log.Info("gRPC default resolver scheme is not set to passthrough. This might cause issues with the gRPC connection when no real DNS server is available as each gRPC requests requires a DNS request.") + } + adapter, err := adapter.NewPndAdapter(cliPnd, viper.GetString("controllerAPIEndpoint")) if err != nil { log.Fatal(err) diff --git a/controller/cmd/root.go b/controller/cmd/root.go index 293183319..cc00b4903 100644 --- a/controller/cmd/root.go +++ b/controller/cmd/root.go @@ -52,6 +52,7 @@ var csbiOrchestrator string var pluginRegistry string var pluginFolder string var security string +var gRPCPassthrough bool // rootCmd represents the base command when called without any subcommands. var rootCmd = &cobra.Command{ @@ -86,6 +87,7 @@ func init() { rootCmd.Flags().StringVar(&pluginRegistry, "plugin-registry", "", "plugin registry address") rootCmd.Flags().StringVar(&pluginFolder, "plugin-folder", "", "folder holding all goSDN specific plugins") rootCmd.Flags().StringVarP(&security, "security", "s", "", "security level 'secure' or 'insecure'") + rootCmd.Flags().BoolVar(&gRPCPassthrough, "grpcPassthrough", true, "set the default resolve scheme for grpc to passthrough, default is true") } const ( diff --git a/controller/controller.go b/controller/controller.go index d0d6ceee1..f79d5ff45 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -18,6 +18,7 @@ import ( "golang.org/x/crypto/argon2" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/resolver" apppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/app" cmpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement" @@ -201,6 +202,14 @@ func setupPluginRegistryClient() rpb.PluginRegistryServiceClient { } func startGrpc() error { + passthrough := viper.GetBool("passthrough") + if passthrough { + log.Info("Setting gRPC default resolver scheme to passthrough. No DNS queries are being made when doing a gRPC request.") + resolver.SetDefaultScheme("passthrough") + } else { + log.Info("gRPC default resolver scheme is not set to passthrough. This might cause issues with the gRPC connection when no real DNS server is available as each gRPC requests requires a DNS request.") + } + socket := viper.GetString("socket") lislisten, err := net.Listen("tcp", socket) if err != nil { -- GitLab