Skip to content

Commit

Permalink
remove creation of unsused metallb configmap (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwennrich authored Apr 2, 2024
1 parent b606e1f commit 74b1cc7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 83 deletions.
11 changes: 8 additions & 3 deletions pkg/controllers/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,14 @@ func (l *LoadBalancerController) updateLoadBalancerConfig(ctx context.Context, n
if err != nil {
return err
}
err = config.Write(ctx, l.K8sClientSet)
if err != nil {
return err

// TODO: in a future release this can be removed
err = l.K8sClient.Delete(ctx, &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{
Name: "config",
Namespace: metallbNamespace,
}})
if client.IgnoreNotFound(err) != nil {
return fmt.Errorf("unable to cleanup deprecated metallb configmap: %w", err)
}

err = config.WriteCRs(ctx, l.K8sClient)
Expand Down
27 changes: 2 additions & 25 deletions pkg/controllers/loadbalancer/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"strings"
"time"

"github.com/metal-stack/metal-ccm/pkg/resources/kubernetes"
"github.com/metal-stack/metal-lib/pkg/tag"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"

"github.com/metal-stack/metal-go/api/models"
Expand All @@ -27,9 +25,7 @@ import (
)

const (
metallbNamespace = "metallb-system"
metallbConfigMapName = "config"
metallbConfigMapKey = "config"
metallbNamespace = "metallb-system"
)

// MetalLBConfig is a struct containing a config for metallb
Expand Down Expand Up @@ -91,19 +87,6 @@ func (cfg *MetalLBConfig) computePeers(nodes []v1.Node) error {
return nil
}

// Write inserts or updates the Metal-LB config.
func (cfg *MetalLBConfig) Write(ctx context.Context, client clientset.Interface) error {
yaml, err := cfg.ToYAML()
if err != nil {
return err
}

cm := make(map[string]string, 1)
cm[metallbConfigMapKey] = yaml

return kubernetes.ApplyConfigMap(ctx, client, metallbNamespace, metallbConfigMapName, cm)
}

// 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) *AddressPool {
Expand Down Expand Up @@ -184,13 +167,7 @@ func (cfg *MetalLBConfig) WriteCRs(ctx context.Context, c client.Client) error {
HoldTime: metav1.Duration{Duration: 90 * time.Second},
KeepaliveTime: metav1.Duration{Duration: 0 * time.Second},
Address: peer.Address,
NodeSelectors: []metav1.LabelSelector{{
MatchExpressions: []metav1.LabelSelectorRequirement{{
Key: peer.NodeSelectors[0].MatchExpressions[0].Key,
Operator: metav1.LabelSelectorOpIn,
Values: peer.NodeSelectors[0].MatchExpressions[0].Values,
}},
}},
NodeSelectors: peer.NodeSelectors,
}
return nil
})
Expand Down
25 changes: 8 additions & 17 deletions pkg/controllers/loadbalancer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@ import (
"fmt"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type MatchExpression struct {
Key string `json:"key" yaml:"key"`
Operator string `json:"operator" yaml:"operator"`
Values []string `json:"values,omitempty" yaml:"values,omitempty"`
}

type NodeSelector struct {
MatchExpressions []*MatchExpression `json:"match-expressions,omitempty" yaml:"match-expressions,omitempty"`
}

type Peer struct {
MyASN int64 `json:"my-asn" yaml:"my-asn"`
ASN int64 `json:"peer-asn" yaml:"peer-asn"`
Address string `json:"peer-address" yaml:"peer-address"`
NodeSelectors []*NodeSelector `json:"node-selectors,omitempty" yaml:"node-selectors,omitempty"`
MyASN int64 `json:"my-asn" yaml:"my-asn"`
ASN int64 `json:"peer-asn" yaml:"peer-asn"`
Address string `json:"peer-address" yaml:"peer-address"`
NodeSelectors []metav1.LabelSelector `json:"node-selectors,omitempty" yaml:"node-selectors,omitempty"`
}

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

matchExpression := &MatchExpression{
matchExpression := metav1.LabelSelectorRequirement{
Key: "kubernetes.io/hostname",
Operator: "In",
Values: []string{
Expand All @@ -42,9 +33,9 @@ func newPeer(node v1.Node, asn int64) (*Peer, error) {
MyASN: asn,
ASN: asn,
Address: address,
NodeSelectors: []*NodeSelector{
NodeSelectors: []metav1.LabelSelector{
{
MatchExpressions: []*MatchExpression{
MatchExpressions: []metav1.LabelSelectorRequirement{
matchExpression,
},
},
Expand Down
38 changes: 0 additions & 38 deletions pkg/resources/kubernetes/configmap.go

This file was deleted.

0 comments on commit 74b1cc7

Please sign in to comment.