Skip to content

Commit 7527347

Browse files
feat: Add more context to MetalLB config apply conflict errors (#1231)
**What problem does this PR solve?**: Backport of #1225 When there is a conflict writing the MetalLB configuration, we want to give more information to the user. **Which issue(s) this PR fixes**: Fixes https://jira.nutanix.com/browse/NCN-107584 **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. --> --------- **What problem does this PR solve?**: **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. --> Co-authored-by: Jimmi Dyson <jimmidyson@gmail.com>
1 parent a78807a commit 7527347

File tree

1 file changed

+19
-2
lines changed
  • pkg/handlers/generic/lifecycle/serviceloadbalancer/metallb

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/go-logr/logr"
1212
"github.com/spf13/pflag"
13+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
kwait "k8s.io/apimachinery/pkg/util/wait"
1516
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -132,11 +133,12 @@ func (n *MetalLB) Apply(
132133
),
133134
)
134135

135-
cos, err := ConfigurationObjects(&ConfigurationInput{
136+
configInput := &ConfigurationInput{
136137
Name: DefaultHelmReleaseName,
137138
Namespace: DefaultHelmReleaseNamespace,
138139
AddressRanges: slb.Configuration.AddressRanges,
139-
})
140+
}
141+
cos, err := ConfigurationObjects(configInput)
140142
if err != nil {
141143
return fmt.Errorf("failed to generate MetalLB configuration: %w", err)
142144
}
@@ -160,6 +162,21 @@ func (n *MetalLB) Apply(
160162
},
161163
},
162164
); err != nil {
165+
if apierrors.IsConflict(err) {
166+
switch o.GetKind() {
167+
case "IPAddressPool":
168+
err = fmt.Errorf(
169+
"%w. This resource has been modified in the workload cluster: it must contain exactly the addresses listed in the Cluster configuration", //nolint:lll // Long error message,
170+
err,
171+
)
172+
case "L2Advertisement":
173+
err = fmt.Errorf(
174+
"%w. This resource has been modified in the workload cluster, it must only contain the %q IP Address Pool", //nolint:lll // Long error message,
175+
err,
176+
configInput.Name,
177+
)
178+
}
179+
}
163180
applyErr = fmt.Errorf(
164181
"failed to apply MetalLB configuration %s %s: %w",
165182
o.GetKind(),

0 commit comments

Comments
 (0)