Skip to content

Commit 6b6da2a

Browse files
committed
fixup! test: Configure e2e client scheme for metallb types
1 parent 178630c commit 6b6da2a

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package metallb
55
import (
66
"fmt"
77

8+
"github.com/samber/lo"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
"sigs.k8s.io/controller-runtime/pkg/client"
1011

@@ -32,15 +33,13 @@ func ConfigurationObjects(input *ConfigurationInput) ([]client.Object, error) {
3233
Name: input.Name,
3334
Namespace: input.Namespace,
3435
},
36+
Spec: metallbv1.IPAddressPoolSpec{
37+
Addresses: lo.Map(input.AddressRanges, func(ar v1alpha1.AddressRange, _ int) string {
38+
return fmt.Sprintf("%s-%s", ar.Start, ar.End)
39+
}),
40+
},
3541
}
3642

37-
addresses := []string{}
38-
for _, ar := range input.AddressRanges {
39-
addresses = append(addresses, fmt.Sprintf("%s-%s", ar.Start, ar.End))
40-
}
41-
42-
ipAddressPool.Spec.Addresses = addresses
43-
4443
l2Advertisement := &metallbv1.L2Advertisement{
4544
TypeMeta: metav1.TypeMeta{
4645
Kind: "L2Advertisement",
@@ -50,10 +49,11 @@ func ConfigurationObjects(input *ConfigurationInput) ([]client.Object, error) {
5049
Name: input.Name,
5150
Namespace: input.Namespace,
5251
},
52+
Spec: metallbv1.L2AdvertisementSpec{
53+
IPAddressPools: []string{ipAddressPool.GetName()},
54+
},
5355
}
5456

55-
l2Advertisement.Spec.IPAddressPools = []string{ipAddressPool.GetName()}
56-
5757
return []client.Object{
5858
ipAddressPool,
5959
l2Advertisement,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ func (n *MetalLB) Apply(
162162
},
163163
},
164164
); err != nil {
165-
// Return early if the error is not a conflict.
166-
if !apierrors.IsConflict(err) {
165+
// Return early if the error is not a conflict or an internal error.
166+
// Internal errors are generally seen when the necessary CRD webhooks are not yet registered so are
167+
// retryable.
168+
if !apierrors.IsConflict(err) && !apierrors.IsInternalError(err) {
167169
return false, err
168170
}
169171

test/e2e/e2e_suite_test.go

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

2020
. "github.com/onsi/ginkgo/v2"
2121
. "github.com/onsi/gomega"
22-
storagev1 "k8s.io/api/storage/v1"
2322
"k8s.io/apimachinery/pkg/runtime"
2423
"k8s.io/klog/v2"
2524
capie2e "sigs.k8s.io/cluster-api/test/e2e"
@@ -28,6 +27,7 @@ import (
2827
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
2928
ctrl "sigs.k8s.io/controller-runtime"
3029

30+
metallbv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/go.universe.tf/metallb/api/v1beta1"
3131
helmaddonsv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
3232
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/e2e/framework"
3333
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/framework/bootstrap"
@@ -209,7 +209,7 @@ func initScheme() *runtime.Scheme {
209209
scheme := runtime.NewScheme()
210210
capie2eframework.TryAddDefaultSchemes(scheme)
211211
Expect(helmaddonsv1.AddToScheme(scheme)).To(Succeed())
212-
Expect(storagev1.AddToScheme(scheme)).To(Succeed())
212+
Expect(metallbv1.AddToScheme(scheme)).To(Succeed())
213213
return scheme
214214
}
215215

test/e2e/resource_helpers.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
. "github.com/onsi/gomega"
14+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1415
capie2e "sigs.k8s.io/cluster-api/test/e2e"
1516
"sigs.k8s.io/cluster-api/test/framework"
1617
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -30,8 +31,8 @@ func WaitForResources(
3031
) {
3132
start := time.Now()
3233

33-
for i := range input.Resources {
34-
obj := input.Resources[i].DeepCopyObject().(client.Object)
34+
for _, obj := range input.Resources {
35+
obj = obj.DeepCopyObject().(client.Object)
3536
key := client.ObjectKeyFromObject(obj)
3637
capie2e.Byf("waiting for resource %s %s to be present",
3738
obj.GetObjectKind().GroupVersionKind(),
@@ -41,11 +42,14 @@ func WaitForResources(
4142
obj.GetObjectKind().GroupVersionKind(),
4243
key,
4344
)
44-
Eventually(func() bool {
45+
Eventually(func() (bool, error) {
4546
if err := input.Getter.Get(ctx, key, obj); err != nil {
46-
return false
47+
if apierrors.IsNotFound(err) {
48+
return false, nil
49+
}
50+
return false, err
4751
}
48-
return true
52+
return true, nil
4953
}, intervals...).Should(BeTrue(),
5054
fmt.Sprintf("Resource %s %s was not found",
5155
obj.GetObjectKind().GroupVersionKind(),

0 commit comments

Comments
 (0)