Skip to content

Commit 8742496

Browse files
committed
test: add registryMirror e2e test
1 parent a382c35 commit 8742496

6 files changed

+122
-0
lines changed

test/e2e/addon_helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type WaitForAddonsToBeReadyInWorkloadClusterInput struct {
2121
ClusterProxy framework.ClusterProxy
2222
DeploymentIntervals []interface{}
2323
DaemonSetIntervals []interface{}
24+
StatefulSetIntervals []interface{}
2425
HelmReleaseIntervals []interface{}
2526
ClusterResourceSetIntervals []interface{}
2627
ResourceIntervals []interface{}
@@ -119,4 +120,14 @@ func WaitForAddonsToBeReadyInWorkloadCluster(
119120
ResourceIntervals: input.ResourceIntervals,
120121
},
121122
)
123+
124+
WaitForRegistryMirrorToBeReadyInWorkloadCluster(
125+
ctx,
126+
WaitForRegistryMirrorToBeReadyInWorkloadClusterInput{
127+
RegistryMirror: input.AddonsConfig.RegistryMirror,
128+
WorkloadCluster: input.WorkloadCluster,
129+
ClusterProxy: input.ClusterProxy,
130+
StatefulSetIntervals: input.StatefulSetIntervals,
131+
},
132+
)
122133
}

test/e2e/config/caren.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ intervals:
219219
default/wait-nodes-ready: ["10m", "10s"]
220220
default/wait-deployment: ["10m", "10s"]
221221
default/wait-daemonset: [ "5m", "10s" ]
222+
default/wait-statefulset: [ "10m", "10s" ]
222223
default/wait-clusterresourceset: [ "5m", "10s" ]
223224
default/wait-helmrelease: [ "5m", "10s" ]
224225
default/wait-resource: [ "5m", "10s" ]

test/e2e/quick_start_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ var _ = Describe("Quick start", func() {
265265
flavour,
266266
"wait-daemonset",
267267
),
268+
StatefulSetIntervals: testE2EConfig.GetIntervals(
269+
flavour,
270+
"wait-statefulset",
271+
),
268272
HelmReleaseIntervals: testE2EConfig.GetIntervals(
269273
flavour,
270274
"wait-helmrelease",

test/e2e/registry_mirror_helpers.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//go:build e2e
2+
3+
// Copyright 2024 Nutanix. All rights reserved.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package e2e
7+
8+
import (
9+
"context"
10+
11+
appsv1 "k8s.io/api/apps/v1"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
14+
"sigs.k8s.io/cluster-api/test/framework"
15+
16+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
17+
)
18+
19+
type WaitForRegistryMirrorToBeReadyInWorkloadClusterInput struct {
20+
RegistryMirror *v1alpha1.RegistryMirror
21+
WorkloadCluster *clusterv1.Cluster
22+
ClusterProxy framework.ClusterProxy
23+
StatefulSetIntervals []interface{}
24+
HelmReleaseIntervals []interface{}
25+
}
26+
27+
func WaitForRegistryMirrorToBeReadyInWorkloadCluster(
28+
ctx context.Context,
29+
input WaitForRegistryMirrorToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests.
30+
) {
31+
if input.RegistryMirror == nil {
32+
return
33+
}
34+
35+
WaitForHelmReleaseProxyReadyForCluster(
36+
ctx,
37+
WaitForHelmReleaseProxyReadyForClusterInput{
38+
GetLister: input.ClusterProxy.GetClient(),
39+
Cluster: input.WorkloadCluster,
40+
HelmReleaseName: "docker-registry",
41+
},
42+
input.HelmReleaseIntervals...,
43+
)
44+
45+
workloadClusterClient := input.ClusterProxy.GetWorkloadCluster(
46+
ctx, input.WorkloadCluster.Namespace, input.WorkloadCluster.Name,
47+
).GetClient()
48+
49+
WaitForStatefulSetsAvailable(ctx, WaitForStatefulSetAvailableInput{
50+
Getter: workloadClusterClient,
51+
StatefulSet: &appsv1.StatefulSet{
52+
ObjectMeta: metav1.ObjectMeta{
53+
Name: "registry-mirror-docker-registry",
54+
Namespace: "registry-mirror-system",
55+
},
56+
},
57+
}, input.StatefulSetIntervals...)
58+
}

test/e2e/self_hosted_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ var _ = Describe("Self-hosted", Serial, func() {
127127
flavour,
128128
"wait-daemonset",
129129
),
130+
StatefulSetIntervals: e2eConfig.GetIntervals(
131+
flavour,
132+
"wait-statefulset",
133+
),
130134
HelmReleaseIntervals: e2eConfig.GetIntervals(
131135
flavour,
132136
"wait-helmrelease",

test/e2e/statefulset_helpers.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//go:build e2e
2+
3+
// Copyright 2024 Nutanix. All rights reserved.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package e2e
7+
8+
import (
9+
"context"
10+
"time"
11+
12+
. "github.com/onsi/gomega"
13+
appsv1 "k8s.io/api/apps/v1"
14+
capie2e "sigs.k8s.io/cluster-api/test/e2e"
15+
"sigs.k8s.io/cluster-api/test/framework"
16+
"sigs.k8s.io/controller-runtime/pkg/client"
17+
)
18+
19+
type WaitForStatefulSetAvailableInput struct {
20+
Getter framework.Getter
21+
StatefulSet *appsv1.StatefulSet
22+
}
23+
24+
// WaitForStatefulSetsAvailable waits until the Deployment has observedGeneration equal to generation and
25+
// status.Available = True, that signals that all the desired replicas are in place.
26+
func WaitForStatefulSetsAvailable(
27+
ctx context.Context, input WaitForStatefulSetAvailableInput, intervals ...interface{},
28+
) {
29+
start := time.Now()
30+
key := client.ObjectKeyFromObject(input.StatefulSet)
31+
capie2e.Byf("waiting for statefulset %s to be available", key)
32+
Log("starting to wait for statefulset to become available")
33+
Eventually(func() bool {
34+
if err := input.Getter.Get(ctx, key, input.StatefulSet); err == nil {
35+
if input.StatefulSet.Status.ObservedGeneration != input.StatefulSet.Generation {
36+
return false
37+
}
38+
39+
return input.StatefulSet.Status.AvailableReplicas == input.StatefulSet.Status.Replicas
40+
}
41+
return false
42+
}, intervals...).Should(BeTrue())
43+
Logf("Deployment %s is now available, took %v", key, time.Since(start))
44+
}

0 commit comments

Comments
 (0)