Skip to content

Commit a52cb9a

Browse files
authored
fix: Only create MetalLB configuration when necessary (#791)
**What problem does this PR solve?**: The ServiceLoadBalancer configuration is optional; when it is not set, we should not configure the provider. Thanks to @dkoshkin for finding this bug. The e2e tests in #788 did not catch this, because they do define configuration. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent c99069e commit a52cb9a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/handlers/generic/lifecycle/serviceloadbalancer/metallb/configuration.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ type configurationInput struct {
2626
}
2727

2828
func configurationObjects(input *configurationInput) ([]unstructured.Unstructured, error) {
29+
if len(input.addressRanges) == 0 {
30+
return nil, fmt.Errorf("must define one or more addressRanges")
31+
}
32+
2933
ipAddressPool := unstructured.Unstructured{}
3034
ipAddressPool.SetGroupVersionKind(groupVersionKind("IPAddressPool"))
3135
ipAddressPool.SetName(input.name)

pkg/handlers/generic/lifecycle/serviceloadbalancer/metallb/handler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (n *MetalLB) Apply(
178178
return fmt.Errorf("failed to wait for MetalLB to deploy: %w", err)
179179
}
180180

181+
if slb.Configuration == nil {
182+
// Nothing more to do.
183+
return nil
184+
}
185+
181186
log.Info(
182187
fmt.Sprintf("Applying MetalLB configuration to cluster %s",
183188
ctrlclient.ObjectKeyFromObject(cluster),

0 commit comments

Comments
 (0)