From 30c54c9c8a72be2d35e7c277cfb79db5bf6d09ef Mon Sep 17 00:00:00 2001 From: Atul Patel Date: Mon, 22 Apr 2024 17:55:43 +0100 Subject: [PATCH] fix(evpn-bridge): validate config and frr addr fix Signed-off-by: Atul Patel --- cmd/main.go | 5 +---- config-intele2000.yaml | 1 - config.yaml | 1 - pkg/config/config.go | 11 ++++------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 442d85ad..7ce10bb3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -49,9 +49,7 @@ var rootCmd = &cobra.Command{ Use: "opi-evpn-bridge", Short: "evpn bridge", Long: "evpn bridge application", - PreRunE: func(_ *cobra.Command, _ []string) error { - return config.ValidateConfig() - }, + Run: func(_ *cobra.Command, _ []string) { taskmanager.TaskMan.StartTaskManager() @@ -93,7 +91,6 @@ func initialize() error { rootCmd.PersistentFlags().Uint16Var(&config.GlobalConfig.HTTPPort, "httpport", 8082, "The HTTP server port") rootCmd.PersistentFlags().StringVar(&config.GlobalConfig.TLSFiles, "tlsfiles", "", "TLS files in server_cert:server_key:ca_cert format.") rootCmd.PersistentFlags().StringVar(&config.GlobalConfig.DBAddress, "dbaddress", "127.0.0.1:6379", "db address in ip_address:port format") - rootCmd.PersistentFlags().StringVar(&config.GlobalConfig.FRRAddress, "frraddress", "127.0.0.1", "Frr address in ip_address format, no port") rootCmd.PersistentFlags().StringVar(&config.GlobalConfig.Database, "database", "redis", "Database connection string") // Bind command-line flags to config fields diff --git a/config-intele2000.yaml b/config-intele2000.yaml index adbde601..4441bab7 100644 --- a/config-intele2000.yaml +++ b/config-intele2000.yaml @@ -3,7 +3,6 @@ httpport: 8082 tlsfiles: database: redis dbaddress: 127.0.0.1:6379 -frraddress: 127.0.0.1 buildenv: intel_e2000 subscribers: - name: "lvm" diff --git a/config.yaml b/config.yaml index 7bcb93c6..56ea77ff 100644 --- a/config.yaml +++ b/config.yaml @@ -3,7 +3,6 @@ httpport: 8082 tlsfiles: database: redis dbaddress: 127.0.0.1:6379 -frraddress: 127.0.0.1 buildenv: ci subscribers: - name: "lgm" diff --git a/pkg/config/config.go b/pkg/config/config.go index b99ec19d..954c65f0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -84,7 +84,6 @@ type Config struct { TLSFiles string `yaml:"tlsfiles"` Database string `yaml:"database"` DBAddress string `yaml:"dbaddress"` - FRRAddress string `yaml:"frraddress"` Buildenv string `yaml:"buildenv"` Subscribers []SubscriberConfig `yaml:"subscribers"` LinuxFrr LinuxFrrConfig `yaml:"linuxfrr"` @@ -145,6 +144,10 @@ func LoadConfig() error { return err } + if err := ValidateConfig(); err != nil { + log.Panic(err) + } + log.Printf("config %+v", GlobalConfig) return nil } @@ -183,11 +186,5 @@ func ValidateConfig() error { return err } - frrAddr := viper.GetString("frraddress") - if net.ParseIP(frrAddr) == nil { - err = fmt.Errorf("invalid FRRAddress format. It should be a valid IP address") - return err - } - return nil }