Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Jan 17, 2024
1 parent 36e4b64 commit 0820732
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
10 changes: 7 additions & 3 deletions pkg/controllers/loadbalancer/addresspool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package loadbalancer

import "fmt"
import (
"fmt"

"github.com/metal-stack/metal-lib/pkg/pointer"
)

const (
bgpProtocol = "bgp"
Expand All @@ -13,11 +17,11 @@ type AddressPool struct {
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: pointer.Pointer(false),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (l *LoadBalancerController) updateLoadBalancerConfig(ctx context.Context, n
return fmt.Errorf("could not find ips of this project's cluster: %w", err)
}

config := newMetalLBConfig(l.defaultExternalNetworkID)
config := newMetalLBConfig()
err = config.CalculateConfig(ips, l.additionalNetworks, nodes)
if err != nil {
return err
Expand Down
10 changes: 4 additions & 6 deletions pkg/controllers/loadbalancer/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type MetalLBConfig struct {
AddressPools []*AddressPool `json:"address-pools,omitempty" yaml:"address-pools,omitempty"`
}

func newMetalLBConfig(defaultNetworkID string) *MetalLBConfig {
func newMetalLBConfig() *MetalLBConfig {
return &MetalLBConfig{}
}

Expand Down Expand Up @@ -98,14 +98,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 @@ -115,13 +115,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 @@ -55,7 +55,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 @@ -96,7 +96,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 @@ -147,7 +147,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 @@ -247,7 +247,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

0 comments on commit 0820732

Please sign in to comment.