Skip to content

Commit

Permalink
fix(evpn-bridge): validate config and frr addr fix
Browse files Browse the repository at this point in the history
Signed-off-by: Atul Patel <Atul.Patel@intel.com>
  • Loading branch information
atulpatel261194 authored and sandersms committed Apr 25, 2024
1 parent a164c52 commit 30c54c9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
5 changes: 1 addition & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion config-intele2000.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 4 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -145,6 +144,10 @@ func LoadConfig() error {
return err
}

if err := ValidateConfig(); err != nil {
log.Panic(err)
}

log.Printf("config %+v", GlobalConfig)
return nil
}
Expand Down Expand Up @@ -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
}

0 comments on commit 30c54c9

Please sign in to comment.