Skip to content

Commit

Permalink
Minor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Oct 24, 2024
1 parent 46b34a8 commit 05d04c6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
5 changes: 5 additions & 0 deletions metal/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"slices"
"strings"

metalgo "github.com/metal-stack/metal-go"
Expand Down Expand Up @@ -117,6 +118,10 @@ func (c *cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder,
clusterID := os.Getenv(constants.MetalClusterIDEnvVar)
loadbalancerType := os.Getenv(constants.Loadbalancer)

if !slices.Contains([]string{"cilium", "metallb", ""}, loadbalancerType) {
klog.Fatalf("only cilium or metallb load balancer types are supported")
}

k8sClientSet := clientBuilder.ClientOrDie("cloud-controller-manager")
k8sRestConfig, err := clientBuilder.Config("cloud-controller-manager")
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/controllers/loadbalancer/addresspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type AddressPool struct {
CIDRs []string `json:"addresses,omitempty" yaml:"addresses,omitempty"` // It is assumed that only host addresses (/32 for ipv4 or /128 for ipv6) are used.
}

func NewBGPAddressPool(name string) *AddressPool {
func newBGPAddressPool(name string) *AddressPool {
return &AddressPool{
Name: name,
Protocol: bgpProtocol,
Expand Down Expand Up @@ -56,7 +56,3 @@ func (pool *AddressPool) appendIP(ip string) error {
pool.CIDRs = append(pool.CIDRs, cidr)
return nil
}

func (pool *AddressPool) String() string {
return fmt.Sprintf("%s (%s): %v", pool.Name, pool.Protocol, pool.CIDRs)
}
4 changes: 2 additions & 2 deletions pkg/controllers/loadbalancer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (cfg *Config) computePeers(nodes []v1.Node) error {
return err
}

peer, err := NewPeer(n, asn)
peer, err := newPeer(n, asn)
if err != nil {
klog.Warningf("skipping peer: %v", err)
continue
Expand Down Expand Up @@ -102,7 +102,7 @@ func (cfg *Config) getOrCreateAddressPool(poolName string) *AddressPool {
}
}

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

return pool
Expand Down
9 changes: 9 additions & 0 deletions pkg/controllers/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,12 @@ func (l *LoadBalancerController) updateLoadBalancerConfig(ctx context.Context, n
}
return nil
}

func NodeAddress(node v1.Node) (string, error) {
for _, a := range node.Status.Addresses {
if a.Type == v1.NodeInternalIP {
return a.Address, nil
}
}
return "", fmt.Errorf("unable to determine node address")
}
13 changes: 1 addition & 12 deletions pkg/controllers/loadbalancer/peer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package loadbalancer

import (
"fmt"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -14,7 +12,7 @@ type Peer struct {
NodeSelector metav1.LabelSelector `json:"node-selectors,omitempty" yaml:"node-selectors,omitempty"`
}

func NewPeer(node v1.Node, asn int64) (*Peer, error) {
func newPeer(node v1.Node, asn int64) (*Peer, error) {
hostname := node.GetName()

matchExpression := metav1.LabelSelectorRequirement{
Expand Down Expand Up @@ -43,12 +41,3 @@ func NewPeer(node v1.Node, asn int64) (*Peer, error) {
},
}, nil
}

func NodeAddress(node v1.Node) (string, error) {
for _, a := range node.Status.Addresses {
if a.Type == v1.NodeInternalIP {
return a.Address, nil
}
}
return "", fmt.Errorf("unable to determine node address")
}

0 comments on commit 05d04c6

Please sign in to comment.