Skip to content

Commit

Permalink
Enable configuration of loadBalancerClass
Browse files Browse the repository at this point in the history
Add the ability to set a 'loadBalancerClass' value on the 'MetalLB' CRD.
The 'Service.Spec.LoadBalancerClass' field reached GA in Kubernetes 1.24
and support was introduced in MetalLB in v0.13 [1].

[1] metallb/metallb#1417

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Closes: #267
  • Loading branch information
stephenfin authored and fedepaol committed May 3, 2023
1 parent a116c4c commit eeac219
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/metallb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type MetalLBSpec struct {
// +kubebuilder:validation:Enum=all;debug;info;warn;error;none
LogLevel MetalLBLogLevel `json:"logLevel,omitempty"`

// The loadBalancerClass spec attribute that the MetalLB controller should
// be watching for
// +optional
LoadBalancerClass string `json:"loadBalancerClass,omitempty"`

// node selector applied to MetalLB controller deployment.
// +optional
ControllerNodeSelector map[string]string `json:"controllerNodeSelector,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions bin/metallb-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,10 @@ spec:
description: Foo is an example field of MetalLB. Edit MetalLB_types.go
to remove/update
type: string
loadBalancerClass:
description: The loadBalancerClass spec attribute that the MetalLB
controller should be watching for
type: string
logLevel:
description: 'Define the verbosity of the controller and the speaker
logging. Allowed values are: all, debug, info, warn, error, none.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/metallb.io_metallbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ spec:
description: Foo is an example field of MetalLB. Edit MetalLB_types.go
to remove/update
type: string
loadBalancerClass:
description: The loadBalancerClass spec attribute that the MetalLB
controller should be watching for
type: string
logLevel:
description: 'Define the verbosity of the controller and the speaker
logging. Allowed values are: all, debug, info, warn, error, none.
Expand Down
5 changes: 3 additions & 2 deletions config/samples/demo/metallb-advanced-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: myclass
handler: myconfiguration
name: myclass
handler: myconfiguration
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
Expand All @@ -19,6 +19,7 @@ spec:
logLevel: debug
nodeSelector:
feature.node.kubernetes.io/metalLB.capable: 'true'
loadBalancerClass: 'metallb.universe.tf/metallb'
speakerTolerations:
- key: "Example"
operator: "Exists"
Expand Down
1 change: 1 addition & 0 deletions config/samples/demo/metallb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
spec:
nodeSelector:
feature.node.kubernetes.io/metalLB.capable: 'true'
loadBalancerClass: 'metallb.universe.tf/metallb'
speakerTolerations:
- key: "Example"
operator: "Exists"
Expand Down
7 changes: 7 additions & 0 deletions pkg/helm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ type imageInfo struct {
}

func patchToChartValues(c *chartConfig, crdConfig *metallbv1beta1.MetalLB, withPrometheus bool, valueMap map[string]interface{}) {
withGeneralValues(c, crdConfig, valueMap)
withPrometheusValues(c, valueMap)
withControllerValues(c, crdConfig, valueMap)
withSpeakerValues(c, crdConfig, valueMap)
}

func withGeneralValues(c *chartConfig, crdConfig *metallbv1beta1.MetalLB, valueMap map[string]interface{}) {
if crdConfig.Spec.LoadBalancerClass != "" {
valueMap["loadBalancerClass"] = crdConfig.Spec.LoadBalancerClass
}
}

func withPrometheusValues(c *chartConfig, valueMap map[string]interface{}) {
speakerTLSConfig := map[string]interface{}{
"insecureSkipVerify": true,
Expand Down
3 changes: 3 additions & 0 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestParseMetalLBChartWithCustomValues(t *testing.T) {
Effect: v1.TaintEffectNoExecute,
},
}
loadBalancerClass := "metallb.universe.tf/metallb"
controllerNodeSelector := map[string]string{"kubernetes.io/os": "linux", "node-role.kubernetes.io/worker": "true"}
controllerConfig := &metallbv1beta1.Config{
PriorityClassName: "high-priority",
Expand Down Expand Up @@ -118,6 +119,7 @@ func TestParseMetalLBChartWithCustomValues(t *testing.T) {
ControllerTolerations: controllerTolerations,
ControllerConfig: controllerConfig,
SpeakerConfig: speakerConfig,
LoadBalancerClass: loadBalancerClass,
},
}

Expand Down Expand Up @@ -163,6 +165,7 @@ func TestParseMetalLBChartWithCustomValues(t *testing.T) {
if container.Name == "speaker" {
g.Expect(container.Resources).NotTo(BeNil())
g.Expect(container.Resources.Limits.Cpu().MilliValue()).To(Equal(int64(200)))
g.Expect(container.Args).To(ContainElement("--lb-class=metallb.universe.tf/metallb"))
speakerContainerFound = true
}
}
Expand Down

0 comments on commit eeac219

Please sign in to comment.