Skip to content

Commit e4aa639

Browse files
committed
test(e2e): Add self-hosted e2e test
1 parent 61d3a26 commit e4aa639

7 files changed

+721
-8
lines changed

test/e2e/addon_helpers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ func WaitForAddonsToBeReadyInWorkloadCluster(
5353
ClusterResourceSetIntervals: input.ClusterResourceSetIntervals,
5454
},
5555
)
56+
57+
WaitForClusterAutoscalerToBeReadyInWorkloadCluster(
58+
ctx,
59+
WaitForClusterAutoscalerToBeReadyInWorkloadClusterInput{
60+
ClusterAutoscaler: input.AddonsConfig.ClusterAutoscaler,
61+
WorkloadCluster: input.WorkloadCluster,
62+
ClusterProxy: input.ClusterProxy,
63+
DeploymentIntervals: input.DeploymentIntervals,
64+
DaemonSetIntervals: input.DaemonSetIntervals,
65+
HelmReleaseIntervals: input.HelmReleaseIntervals,
66+
ClusterResourceSetIntervals: input.ClusterResourceSetIntervals,
67+
},
68+
)
5669
}

test/e2e/clusterautoscaler_helpers.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//go:build e2e
2+
3+
// Copyright 2024 D2iQ, Inc. All rights reserved.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package e2e
7+
8+
import (
9+
"context"
10+
"fmt"
11+
12+
. "github.com/onsi/ginkgo/v2"
13+
. "github.com/onsi/gomega"
14+
appsv1 "k8s.io/api/apps/v1"
15+
corev1 "k8s.io/api/core/v1"
16+
"k8s.io/apimachinery/pkg/api/errors"
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
19+
"sigs.k8s.io/cluster-api/test/framework"
20+
"sigs.k8s.io/controller-runtime/pkg/client"
21+
22+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
23+
)
24+
25+
const clusterAutoscalerPrefix = "cluster-autoscaler-"
26+
27+
type WaitForClusterAutoscalerToBeReadyInWorkloadClusterInput struct {
28+
ClusterAutoscaler *v1alpha1.ClusterAutoscaler
29+
WorkloadCluster *capiv1.Cluster
30+
ClusterProxy framework.ClusterProxy
31+
DeploymentIntervals []interface{}
32+
DaemonSetIntervals []interface{}
33+
HelmReleaseIntervals []interface{}
34+
ClusterResourceSetIntervals []interface{}
35+
}
36+
37+
func WaitForClusterAutoscalerToBeReadyInWorkloadCluster(
38+
ctx context.Context,
39+
input WaitForClusterAutoscalerToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests.
40+
) {
41+
if input.ClusterAutoscaler == nil {
42+
return
43+
}
44+
45+
// Only check for ClusterAutoscaler if the cluster is self-managed. Check this by checking if the kubeconfig
46+
// exists in the workload cluster itself.
47+
workloadClusterClient := input.ClusterProxy.GetWorkloadCluster(
48+
ctx, input.WorkloadCluster.Namespace, input.WorkloadCluster.Name,
49+
).GetClient()
50+
err := workloadClusterClient.Get(
51+
ctx,
52+
client.ObjectKey{
53+
Namespace: input.WorkloadCluster.Namespace,
54+
Name: input.WorkloadCluster.Name + "-kubeconfig",
55+
},
56+
&corev1.Secret{},
57+
)
58+
if err != nil && errors.IsNotFound(err) {
59+
return
60+
}
61+
Expect(err).NotTo(HaveOccurred())
62+
63+
switch input.ClusterAutoscaler.Strategy {
64+
case v1alpha1.AddonStrategyClusterResourceSet:
65+
waitForClusterResourceSetToApplyResourcesInCluster(
66+
ctx,
67+
waitForClusterResourceSetToApplyResourcesInClusterInput{
68+
name: clusterAutoscalerPrefix + input.WorkloadCluster.Name,
69+
clusterProxy: input.ClusterProxy,
70+
cluster: input.WorkloadCluster,
71+
intervals: input.ClusterResourceSetIntervals,
72+
},
73+
)
74+
case v1alpha1.AddonStrategyHelmAddon:
75+
WaitForHelmReleaseProxyReadyForCluster(
76+
ctx,
77+
WaitForHelmReleaseProxyReadyForClusterInput{
78+
GetLister: input.ClusterProxy.GetClient(),
79+
Cluster: input.WorkloadCluster,
80+
HelmChartProxyName: clusterAutoscalerPrefix + input.WorkloadCluster.Name,
81+
},
82+
input.HelmReleaseIntervals...,
83+
)
84+
default:
85+
Fail(
86+
fmt.Sprintf(
87+
"Do not know how to wait for cluster autoscaler using strategy %s to be ready",
88+
input.ClusterAutoscaler.Strategy,
89+
),
90+
)
91+
}
92+
93+
WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{
94+
Getter: workloadClusterClient,
95+
Deployment: &appsv1.Deployment{
96+
ObjectMeta: metav1.ObjectMeta{
97+
Name: clusterAutoscalerPrefix + input.WorkloadCluster.Name,
98+
Namespace: input.WorkloadCluster.Namespace,
99+
},
100+
},
101+
}, input.DeploymentIntervals...)
102+
}

test/e2e/e2e_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
2828
ctrl "sigs.k8s.io/controller-runtime"
2929

30-
addonsv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
30+
helmaddonsv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
3131
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/framework/bootstrap"
3232
clusterctltemp "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/framework/clusterctl"
3333
)
@@ -205,7 +205,7 @@ func createClusterctlLocalRepository(config *clusterctl.E2EConfig, repositoryFol
205205
func initScheme() *runtime.Scheme {
206206
scheme := runtime.NewScheme()
207207
framework.TryAddDefaultSchemes(scheme)
208-
Expect(addonsv1.AddToScheme(scheme)).To(Succeed())
208+
Expect(helmaddonsv1.AddToScheme(scheme)).To(Succeed())
209209
return scheme
210210
}
211211

0 commit comments

Comments
 (0)