Skip to content

Commit 6bc0517

Browse files
committed
fix: require cluster-as and neighbor-as parameters in configuration
Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
1 parent 876516b commit 6bc0517

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

pkg/speaker/config.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828

2929
const (
3030
DefaultBGPGrpcPort = 50051
31-
DefaultBGPClusterAs = 65000
32-
DefaultBGPNeighborAs = 65001
3331
DefaultBGPHoldtime = 90 * time.Second
3432
DefaultPprofPort = 10667
3533
DefaultGracefulRestartDeferralTime = 360 * time.Second
@@ -77,12 +75,12 @@ func ParseFlags() (*Configuration, error) {
7775
argAnnounceClusterIP = pflag.BoolP("announce-cluster-ip", "", false, "The Cluster IP of the service to announce to the BGP peers.")
7876
argGrpcHost = pflag.IP("grpc-host", net.IP{127, 0, 0, 1}, "The host address for grpc to listen, default: 127.0.0.1")
7977
argGrpcPort = pflag.Int32("grpc-port", DefaultBGPGrpcPort, "The port for grpc to listen, default:50051")
80-
argClusterAs = pflag.Uint32("cluster-as", DefaultBGPClusterAs, "The AS number of container network, default 65000")
78+
argClusterAs = pflag.Uint32("cluster-as", 0, "The AS number of the local BGP speaker (required)")
8179
argRouterID = pflag.IP("router-id", nil, "The address for the speaker to use as router id, default the node ip")
8280
argNodeIPs = pflag.IPSlice("node-ips", nil, "The comma-separated list of node IP addresses to use instead of the pod IP address for the next hop router IP address.")
8381
argNeighborAddress = pflag.IPSlice("neighbor-address", nil, "Comma separated IPv4 router addresses the speaker connects to.")
8482
argNeighborIPv6Address = pflag.IPSlice("neighbor-ipv6-address", nil, "Comma separated IPv6 router addresses the speaker connects to.")
85-
argNeighborAs = pflag.Uint32("neighbor-as", DefaultBGPNeighborAs, "The router as number, default 65001")
83+
argNeighborAs = pflag.Uint32("neighbor-as", 0, "The AS number of the BGP neighbor/peer (required)")
8684
argAuthPassword = pflag.String("auth-password", "", "bgp peer auth password")
8785
argHoldTime = pflag.Duration("holdtime", DefaultBGPHoldtime, "ovn-speaker goes down abnormally, the local saving time of BGP route will be affected.Holdtime must be in the range 3s to 65536s. (default 90s)")
8886
argPprofPort = pflag.Int32("pprof-port", DefaultPprofPort, "The port to get profiling data, default: 10667")
@@ -169,8 +167,8 @@ func ParseFlags() (*Configuration, error) {
169167
LogPerm: *argLogPerm,
170168
}
171169

172-
if len(config.NeighborAddresses) == 0 && len(config.NeighborIPv6Addresses) == 0 {
173-
return nil, errors.New("at least one of --neighbor-address or --neighbor-ipv6-address must be specified")
170+
if err := config.validateRequiredFlags(); err != nil {
171+
return nil, err
174172
}
175173

176174
for _, addr := range config.NeighborAddresses {
@@ -206,6 +204,27 @@ func ParseFlags() (*Configuration, error) {
206204
return config, nil
207205
}
208206

207+
// validateRequiredFlags checks that all required BGP configuration flags are provided.
208+
// It collects all missing flags and returns them in a single error message.
209+
func (config *Configuration) validateRequiredFlags() error {
210+
var missingFlags []string
211+
212+
if len(config.NeighborAddresses) == 0 && len(config.NeighborIPv6Addresses) == 0 {
213+
missingFlags = append(missingFlags, "at least one of --neighbor-address or --neighbor-ipv6-address must be specified")
214+
}
215+
if config.ClusterAs == 0 {
216+
missingFlags = append(missingFlags, "--cluster-as must be specified")
217+
}
218+
if config.NeighborAs == 0 {
219+
missingFlags = append(missingFlags, "--neighbor-as must be specified")
220+
}
221+
222+
if len(missingFlags) > 0 {
223+
return fmt.Errorf("missing required flags: %s", strings.Join(missingFlags, "; "))
224+
}
225+
return nil
226+
}
227+
209228
func (config *Configuration) initKubeClient() error {
210229
var cfg *rest.Config
211230
var err error

0 commit comments

Comments
 (0)