Skip to content

Commit

Permalink
gh-169 Initial support for multi IPPools
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Sep 12, 2024
1 parent ce636cd commit 4b8f5a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
17 changes: 12 additions & 5 deletions cmd/loxilb-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func run(o *Options) error {

if len(o.config.ExternalCIDRPoolDefs) > 0 {
for _, pool := range o.config.ExternalCIDRPoolDefs {
poolStrSlice := strings.Split(pool, "-")
// Format is pool1-123.123.123.1/32,pool2-124.124.124.124.1/32
poolStrSlice := strings.Split(pool, "=")
// Format is pool1=123.123.123.1/32,pool2=124.124.124.124.1/32
if len(poolStrSlice) <= 0 || len(poolStrSlice) > 2 {
return fmt.Errorf("externalCIDR %s config is invalid", o.config.ExternalCIDRPoolDefs)
}
Expand All @@ -138,8 +138,8 @@ func run(o *Options) error {

if len(o.config.ExternalCIDRPoolDefs) > 0 {
for _, pool := range o.config.ExternalCIDR6PoolDefs {
poolStrSlice := strings.Split(pool, "-")
// Format is pool1-3ffe::1/64,pool2-2001::1/64
poolStrSlice := strings.Split(pool, "=")
// Format is pool1=3ffe::1/64,pool2=2001::1/64
if len(poolStrSlice) <= 0 || len(poolStrSlice) > 2 {
return fmt.Errorf("externalCIDR %s config is invalid", o.config.ExternalCIDR6PoolDefs)
}
Expand Down Expand Up @@ -247,11 +247,18 @@ func run(o *Options) error {

// Run gateway API managers
if o.config.EnableGatewayAPI {
var ipPool *ippool.IPPool

for _, pool := range ipPoolTbl {
ipPool = pool
break
}

gatewayClassManager := gatewayapi.NewGatewayClassManager(
k8sClient, sigsClient, networkConfig, sigsInformerFactory)

gatewayManager := gatewayapi.NewGatewayManager(
k8sClient, sigsClient, networkConfig, ipPoolTbl["defaultPool"], sigsInformerFactory)
k8sClient, sigsClient, networkConfig, ipPool, sigsInformerFactory)

tcpRouteManager := gatewayapi.NewTCPRouteManager(
k8sClient, sigsClient, networkConfig, sigsInformerFactory)
Expand Down
4 changes: 2 additions & 2 deletions cmd/loxilb-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type AgentConfig struct {
// support LoadBalancer external IP
ExternalCIDR string `yaml:"externalCIDR,omitempty"`
// support LoadBalancer external IP Pool Definitions
ExternalCIDRPoolDefs []string `yaml:"externalCIDRPools,omitempty"`
ExternalCIDRPoolDefs []string `yaml:"cidrPools,omitempty"`
// support LoadBalancer external IP6 Pool Definitions
ExternalCIDR6PoolDefs []string `yaml:"externalCIDR6Pools,omitempty"`
ExternalCIDR6PoolDefs []string `yaml:"cidr6Pools,omitempty"`
// external BGP Peers. This is a comma separated list e.g. IP1:ASID1,IP2:ASID2
ExtBGPPeers []string `yaml:"extBGPPeers,omitempty"`
// support BGP protocol
Expand Down
21 changes: 12 additions & 9 deletions cmd/loxilb-agent/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ func (o *Options) validate(args []string) error {
}
}

fmt.Errorf("ExternalCIDRPoolDefs %v", o.config.ExternalCIDRPoolDefs)

if len(o.config.ExternalCIDRPoolDefs) > 0 {
for _, pool := range o.config.ExternalCIDRPoolDefs {
poolStrSlice := strings.Split(pool, "-")
// Format is pool1-123.123.123.1/32,pool2-124.124.124.124.1/32
if len(poolStrSlice) <= 0 || len(poolStrSlice) > 2 {
fmt.Errorf("ExternalCIDRPoolDefs Pool %s", pool)
poolStrSlice := strings.Split(pool, "=")
// Format is pool1=123.123.123.1/32,pool2=124.124.124.124.1/32
if len(poolStrSlice) != 2 {
return fmt.Errorf("externalCIDR %s config is invalid", o.config.ExternalCIDRPoolDefs)
}
if _, _, err := net.ParseCIDR(poolStrSlice[1]); err != nil {
Expand All @@ -123,9 +126,9 @@ func (o *Options) validate(args []string) error {

if len(o.config.ExternalCIDR6PoolDefs) > 0 {
for _, pool := range o.config.ExternalCIDR6PoolDefs {
poolStrSlice := strings.Split(pool, "-")
// Format is pool1-3ffe1::1/64,pool2-2001::1/64
if len(poolStrSlice) <= 0 || len(poolStrSlice) > 2 {
poolStrSlice := strings.Split(pool, "=")
// Format is pool1=3ffe1::1/64,pool2=2001::1/64
if len(poolStrSlice) != 2 {
return fmt.Errorf("externalCIDR6 %s config is invalid", o.config.ExternalCIDR6PoolDefs)
}
if _, _, err := net.ParseCIDR(poolStrSlice[1]); err != nil {
Expand Down Expand Up @@ -263,16 +266,16 @@ func (o *Options) setDefaults() {
}

if o.config.ExternalCIDR != "" {
poolStr := fmt.Sprintf("defaultPool:%s", o.config.ExternalCIDR)
poolStr := fmt.Sprintf("defaultPool=%s", o.config.ExternalCIDR)
o.config.ExternalCIDRPoolDefs = []string{poolStr}
} else {
if o.config.ExternalCIDRPoolDefs == nil {
o.config.ExternalCIDRPoolDefs = []string{"defaultPool:123.123.123.1/24"}
o.config.ExternalCIDRPoolDefs = []string{"defaultPool=123.123.123.1/24"}
}
}

if o.config.ExternalCIDR6PoolDefs == nil {
o.config.ExternalCIDR6PoolDefs = []string{"defaultPool:3ffe:cafe::1/96"}
o.config.ExternalCIDR6PoolDefs = []string{"defaultPool=3ffe:cafe::1/96"}
}

if o.config.ExtBGPPeers == nil {
Expand Down

0 comments on commit 4b8f5a9

Please sign in to comment.