Skip to content

Commit 4d2ffe2

Browse files
authored
Merge pull request #762 from dmvolod/issue-757
🌱 Add more condition validations for providers in e2e tests
2 parents c874da0 + bc32262 commit 4d2ffe2

8 files changed

+201
-307
lines changed

api/v1alpha2/conditions_consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const (
5656
// WaitingForCoreProviderReadyReason documents that the provider is waiting for the core provider to be ready.
5757
WaitingForCoreProviderReadyReason = "WaitingForCoreProviderReady"
5858

59-
// InvalidGithubTokenReason documents that the provided github token is invalid.
59+
// InvalidGithubTokenReason documents that the provided GitHub token is invalid.
6060
InvalidGithubTokenReason = "InvalidGithubTokenError"
6161

6262
// NoDeploymentAvailableConditionReason documents that there is no Available condition for provider deployment yet.

test/e2e/air_gapped_test.go

Lines changed: 163 additions & 266 deletions
Large diffs are not rendered by default.

test/e2e/compressed_manifests_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the
6464

6565
By("Waiting for core provider to be ready")
6666
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(
67-
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
67+
HaveStatusConditionsTrue(coreProvider, operatorv1.ProviderInstalledCondition),
6868
), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
6969

7070
By("Waiting for status.InstalledVersion to be set")
@@ -91,7 +91,7 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the
9191

9292
By("Waiting for the infrastructure provider to be ready")
9393
WaitFor(ctx, For(infraProvider).In(bootstrapCluster).ToSatisfy(
94-
HaveStatusCondition(&infraProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
94+
HaveStatusConditionsTrue(infraProvider, operatorv1.ProviderInstalledCondition),
9595
), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
9696

9797
By("Waiting for status.InstalledVersion to be set")
@@ -165,7 +165,7 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the
165165

166166
By("Waiting for the infrastructure provider to be ready")
167167
WaitFor(ctx, For(infraProvider).In(bootstrapCluster).ToSatisfy(
168-
HaveStatusCondition(&infraProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
168+
HaveStatusConditionsTrue(infraProvider, operatorv1.ProviderInstalledCondition)),
169169
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
170170

171171
By("Waiting for status.InstalledVersion to be set")

test/e2e/e2e_suite_test.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131
appsv1 "k8s.io/api/apps/v1"
3232
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34+
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3435
configclient "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
3536

36-
"k8s.io/apimachinery/pkg/labels"
3737
"k8s.io/apimachinery/pkg/runtime"
3838
"k8s.io/klog/v2"
3939
operatorv1alpha1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
@@ -347,22 +347,13 @@ func ensureCertManager(clusterProxy framework.ClusterProxy, config *clusterctl.E
347347
}
348348

349349
func deleteClusterAPICRDs(clusterProxy framework.ClusterProxy) {
350-
// To get all Cluster API CRDs we need filter them by labels:
351-
// cluster.x-k8s.io/provider: cluster-api
352-
// clusterctl.cluster.x-k8s.io: ""
353-
crds := &apiextensionsv1.CustomResourceDefinitionList{}
354-
Expect(clusterProxy.GetClient().List(ctx, crds, &client.ListOptions{
355-
LabelSelector: labels.SelectorFromSet(
356-
map[string]string{
357-
clusterv1.ProviderNameLabel: configclient.ClusterAPIProviderName,
358-
"clusterctl.cluster.x-k8s.io": "",
359-
},
360-
),
350+
// To remove all Cluster API CRDs we need filter them by labels:
351+
// cluster.x-k8s.io/provider: cluster-api
352+
// clusterctl.cluster.x-k8s.io: ""
353+
Expect(clusterProxy.GetClient().DeleteAllOf(ctx, &apiextensionsv1.CustomResourceDefinition{}, client.MatchingLabels{
354+
clusterv1.ProviderNameLabel: configclient.ClusterAPIProviderName,
355+
clusterctlv1.ClusterctlLabel: "",
361356
})).To(Succeed())
362-
363-
for _, crd := range crds.Items {
364-
Expect(clusterProxy.GetClient().Delete(ctx, &crd)).To(Succeed())
365-
}
366357
}
367358

368359
func initHelmChart() {

test/e2e/helm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
8080

8181
By("Waiting for core provider to be ready")
8282
WaitFor(ctx, For(coreProvider).In(clusterProxy).ToSatisfy(
83-
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
83+
HaveStatusConditionsTrue(coreProvider, operatorv1.ProviderInstalledCondition),
8484
), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
8585

8686
By("Waiting for status.InstalledVersion to be set")
@@ -107,7 +107,7 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
107107

108108
By("Waiting for bootstrap provider to be ready")
109109
WaitFor(ctx, For(bootstrapProvider).In(clusterProxy).ToSatisfy(
110-
HaveStatusCondition(&bootstrapProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
110+
HaveStatusConditionsTrue(bootstrapProvider, operatorv1.ProviderInstalledCondition)),
111111
e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
112112

113113
By("Waiting for status.InstalledVersion to be set")

test/e2e/helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ const (
5454
ipamProviderURL = "https://github.com/kubernetes-sigs/cluster-api-ipam-provider-in-cluster/releases/latest/ipam-components.yaml"
5555
ipamProviderDeploymentName = "capi-ipam-in-cluster-controller-manager"
5656

57-
customManifestsFolder = "resources/"
57+
customManifestsFolder = "resources"
5858
customProviderName = "kubeadm-custom"
5959
)

test/e2e/minimal_configuration_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ metadata:
109109

110110
By("Waiting for core provider to be ready")
111111
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(
112-
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
112+
HaveStatusConditionsTrue(coreProvider, operatorv1.ProviderInstalledCondition)),
113113
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
114114

115115
By("Waiting for status.InstalledVersion to be set")
@@ -151,7 +151,7 @@ metadata:
151151

152152
By("Waiting for bootstrap provider to be ready")
153153
WaitFor(ctx, For(bootstrapProvider).In(bootstrapCluster).ToSatisfy(
154-
HaveStatusCondition(&bootstrapProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
154+
HaveStatusConditionsTrue(bootstrapProvider, operatorv1.ProviderInstalledCondition)),
155155
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
156156

157157
By("Waiting for status.InstalledVersion to be set")
@@ -186,7 +186,7 @@ metadata:
186186

187187
By("Waiting for the control plane provider to be ready")
188188
WaitFor(ctx, For(cpProvider).In(bootstrapCluster).ToSatisfy(
189-
HaveStatusCondition(&cpProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
189+
HaveStatusConditionsTrue(cpProvider, operatorv1.ProviderInstalledCondition)),
190190
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
191191

192192
By("Waiting for status.InstalledVersion to be set")
@@ -221,7 +221,7 @@ metadata:
221221

222222
By("Waiting for the infrastructure provider to be ready")
223223
WaitFor(ctx, For(infraProvider).In(bootstrapCluster).ToSatisfy(
224-
HaveStatusCondition(&infraProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
224+
HaveStatusConditionsTrue(infraProvider, operatorv1.ProviderInstalledCondition)),
225225
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
226226

227227
By("Waiting for status.InstalledVersion to be set")
@@ -263,7 +263,7 @@ metadata:
263263

264264
By("Waiting for the addon provider to be ready")
265265
WaitFor(ctx, For(addonProvider).In(bootstrapCluster).ToSatisfy(
266-
HaveStatusCondition(&addonProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
266+
HaveStatusConditionsTrue(addonProvider, operatorv1.ProviderInstalledCondition)),
267267
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
268268

269269
By("Waiting for status.InstalledVersion to be set")
@@ -307,7 +307,7 @@ metadata:
307307

308308
By("Waiting for the ipam provider to be ready")
309309
WaitFor(ctx, For(ipamProvider).In(bootstrapCluster).ToSatisfy(
310-
HaveStatusCondition(&ipamProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
310+
HaveStatusConditionsTrue(ipamProvider, operatorv1.ProviderInstalledCondition)),
311311
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
312312

313313
By("Waiting for status.InstalledVersion to be set")
@@ -342,7 +342,7 @@ metadata:
342342

343343
By("Waiting for core provider to be ready")
344344
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(
345-
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
345+
HaveStatusConditionsTrue(coreProvider, operatorv1.ProviderInstalledCondition)),
346346
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
347347

348348
By("Waiting for the core provide status.InstalledVersion to be set")
@@ -423,7 +423,7 @@ metadata:
423423

424424
By("Waiting for the custom provider to be ready")
425425
WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(
426-
HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
426+
HaveStatusConditionsTrue(provider, operatorv1.ProviderInstalledCondition)),
427427
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
428428

429429
By("Waiting for status.InstalledVersion to be set")
@@ -510,7 +510,7 @@ metadata:
510510

511511
By("Waiting for the docker provider to be ready")
512512
WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(
513-
HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
513+
HaveStatusConditionsTrue(provider, operatorv1.ProviderInstalledCondition)),
514514
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
515515

516516
By("Waiting for status.InstalledVersion to be set")
@@ -597,7 +597,7 @@ metadata:
597597

598598
By("Waiting for the docker provider to be ready")
599599
WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(
600-
HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
600+
HaveStatusConditionsTrue(provider, operatorv1.ProviderInstalledCondition)),
601601
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
602602

603603
By("Waiting for status.InstalledVersion to be set")
@@ -616,7 +616,7 @@ metadata:
616616

617617
By("Waiting for the docker provider to be ready")
618618
WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(
619-
HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
619+
HaveStatusConditionsTrue(provider, operatorv1.ProviderInstalledCondition)),
620620
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
621621

622622
Expect(bootstrapCluster.Delete(ctx, provider)).To(Succeed())

test/framework/conditions.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,26 @@ import (
2222
"fmt"
2323

2424
. "github.com/onsi/ginkgo/v2" //nolint:stylecheck
25-
corev1 "k8s.io/api/core/v1"
2625
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
26+
capiconditions "sigs.k8s.io/cluster-api/util/conditions"
2727
)
2828

29-
func HaveStatusCondition(conditions *clusterv1.Conditions, condition clusterv1.ConditionType) Condition {
29+
func HaveStatusConditionsTrue(getter capiconditions.Getter, conditions ...clusterv1.ConditionType) Condition {
3030
return func() bool {
31-
By(fmt.Sprintf("Checking if %s condition is set...", condition))
31+
if len(conditions) == 0 {
32+
By("Empty condition list provided. Can't be validated...")
3233

33-
for _, c := range *conditions {
34-
if c.Type == condition && c.Status == corev1.ConditionTrue {
35-
return true
34+
return false
35+
}
36+
37+
for _, condition := range conditions {
38+
By(fmt.Sprintf("Checking if %s condition is set...", condition))
39+
40+
if !capiconditions.IsTrue(getter, condition) {
41+
return false
3642
}
3743
}
3844

39-
return false
45+
return true
4046
}
4147
}

0 commit comments

Comments
 (0)