Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable auto-assign for ephemeral IP pools. #56

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/controllers/loadbalancer/addresspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const (
type AddressPool struct {
Name string `json:"name" yaml:"name"`
Protocol string `json:"protocol" yaml:"protocol"`
AutoAssign *bool `json:"auto-assign" yaml:"auto-assign,omitempty"`
AutoAssign bool `json:"auto-assign" yaml:"auto-assign"`
CIDRs []string `json:"addresses,omitempty" yaml:"addresses,omitempty"` // It is assumed that only /32 addresses are used.
}

func NewBGPAddressPool(name string, autoAssign bool) *AddressPool {
func NewBGPAddressPool(name string) *AddressPool {
return &AddressPool{
Name: name,
Protocol: bgpProtocol,
AutoAssign: &autoAssign,
AutoAssign: false,
}
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/controllers/loadbalancer/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func (cfg *MetalLBConfig) Write(ctx context.Context, client clientset.Interface)

// getOrCreateAddressPool returns the address pool of the given network.
// It will be created if it does not exist yet.
func (cfg *MetalLBConfig) getOrCreateAddressPool(poolName string, autoAssign bool) *AddressPool {
func (cfg *MetalLBConfig) getOrCreateAddressPool(poolName string) *AddressPool {
for _, pool := range cfg.AddressPools {
if pool.Name == poolName {
return pool
}
}

pool := NewBGPAddressPool(poolName, autoAssign)
pool := NewBGPAddressPool(poolName)
cfg.AddressPools = append(cfg.AddressPools, pool)

return pool
Expand All @@ -118,13 +118,11 @@ func (cfg *MetalLBConfig) getOrCreateAddressPool(poolName string, autoAssign boo
func (cfg *MetalLBConfig) addIPToPool(network string, ip models.V1IPResponse) {
t := ip.Type
poolType := models.V1IPBaseTypeEphemeral
autoAssign := network == cfg.defaultNetworkID
if t != nil && *t == models.V1IPBaseTypeStatic {
poolType = models.V1IPBaseTypeStatic
autoAssign = false
}
poolName := fmt.Sprintf("%s-%s", network, poolType)
pool := cfg.getOrCreateAddressPool(poolName, autoAssign)
pool := cfg.getOrCreateAddressPool(poolName)
pool.appendIP(*ip.Ipaddress)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/loadbalancer/metallb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestMetalLBConfig_CalculateConfig(t *testing.T) {
"addresses": []string{
"84.1.1.1/32",
},
"auto-assign": true,
"auto-assign": false,
"name": "internet-ephemeral",
"protocol": "bgp",
},
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestMetalLBConfig_CalculateConfig(t *testing.T) {
"84.1.1.1/32",
"84.1.1.2/32",
},
"auto-assign": true,
"auto-assign": false,
"name": "internet-ephemeral",
"protocol": "bgp",
},
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestMetalLBConfig_CalculateConfig(t *testing.T) {
"84.1.1.1/32",
"84.1.1.2/32",
},
"auto-assign": true,
"auto-assign": false,
"name": "internet-ephemeral",
"protocol": "bgp",
},
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestMetalLBConfig_CalculateConfig(t *testing.T) {
"84.1.1.1/32",
"84.1.1.2/32",
},
"auto-assign": true,
"auto-assign": false,
"name": "internet-ephemeral",
"protocol": "bgp",
},
Expand Down