Skip to content

Commit 4e2a97c

Browse files
authored
test: reference new templates (#113)
1 parent 698b9ef commit 4e2a97c

File tree

5 files changed

+89
-8
lines changed

5 files changed

+89
-8
lines changed

test/e2e/frmwrk/cluster_basic_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var _ = Describe("Basic Cluster", Ordered, Label("basic"), func() {
5858
ClusterProxy: ec.Refs.Workload,
5959
ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath,
6060
InfrastructureProviders: e2eCtx.E2EConfig.InfrastructureProviders(),
61+
AddonProviders: e2eCtx.E2EConfig.AddonProviders(),
6162
LogFolder: path.Join(e2eCtx.Environment.artifactsPath, "clusters", ec.ClusterName, "init"),
6263
})
6364

@@ -111,6 +112,10 @@ var _ = Describe("Basic Cluster", Ordered, Label("basic"), func() {
111112
})
112113

113114
It("delete cluster", Label("basic", "teardown"), func() {
115+
if ec == nil {
116+
Skip("E2ECluster not initialized, skipping teardown")
117+
}
118+
114119
ec.Teardown(ctx)
115120
})
116121
})

test/e2e/frmwrk/config/capi-e2e-config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ providers:
112112
- old: --metrics-addr=127.0.0.1:8080
113113
new: --metrics-addr=:8080
114114

115-
- name: capms
115+
- name: metal-stack
116116
type: InfrastructureProvider
117117
versions:
118118
- name: "{go://github.com/metal-stack/[email protected]}"
@@ -122,6 +122,8 @@ providers:
122122
files:
123123
- sourcePath: "../../../../metadata.yaml"
124124
- sourcePath: "../../../../config/clusterctl-templates/cluster-template.yaml"
125+
- sourcePath: "../../../../config/clusterctl-templates/cluster-template-calico.yaml"
126+
- sourcePath: "../../../../config/clusterctl-templates/cluster-template-pre-v1.33.yaml"
125127
replacements:
126128
- old: --metrics-addr=127.0.0.1:8080
127129
new: --metrics-addr=:8080
@@ -151,9 +153,11 @@ intervals:
151153
metal-stack/machine-reclaim: ["10m", "10s"]
152154
default/wait-control-plane: ["10m", "10s"]
153155
default/wait-control-plane-machine: ["5m", "10s"]
156+
default/wait-control-plane-and-machines-ready: ["15m", "10s"]
154157
default/wait-worker-nodes: ["5m", "10s"]
155158
default/wait-machine-pool-nodes: ["5m", "10s"]
156159
default/wait-delete-cluster: ["3m", "10s"]
160+
default/wait-delete-resource: ["3m", "10s"]
157161
default/wait-machine-upgrade: ["20m", "10s"]
158162
default/wait-control-plane-upgrade: ["15m", "10s"]
159163
default/wait-machine-deployment-upgrade: ["10m", "10s"]

test/e2e/frmwrk/frmwrk_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func TestE2E(t *testing.T) {
2525

2626
var _ = ginkgo.BeforeSuite(func() {
2727
e2eCtx = NewE2EContext()
28-
e2eCtx.TeardownMetalStackProject(context.TODO())
2928
e2eCtx.ProvideBootstrapCluster()
3029
e2eCtx.CreateClusterctlConfig(context.TODO())
3130
e2eCtx.InitManagementCluster(context.TODO())
31+
e2eCtx.TeardownMetalStackProject(context.TODO())
3232
})
3333

3434
var _ = ginkgo.AfterSuite(func() {

test/e2e/frmwrk/shared_cluster.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import (
1919
metalmodels "github.com/metal-stack/metal-go/api/models"
2020

2121
corev1 "k8s.io/api/core/v1"
22+
apierrors "k8s.io/apimachinery/pkg/api/errors"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2325
"k8s.io/utils/ptr"
2426

2527
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2628
kubeadmvbootstrap1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
2729
"sigs.k8s.io/cluster-api/test/framework"
2830
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
31+
"sigs.k8s.io/controller-runtime/pkg/client"
2932

3033
capmsv1alpha1 "github.com/metal-stack/cluster-api-provider-metal-stack/api/v1alpha1"
3134
)
@@ -310,10 +313,9 @@ func (e2e *E2ECluster) GenerateAndApplyClusterTemplate(ctx context.Context) {
310313
WorkerMachineCount: &e2e.WorkerMachineCount,
311314
ClusterctlConfigPath: e2e.E2EContext.Environment.ClusterctlConfigPath,
312315
Flavor: e2e.E2EContext.Environment.Flavor,
313-
// TODO: why does this not work with clusterctl.DefaultInfrastructureProvider?
314-
InfrastructureProvider: "capms:v0.6.2",
315-
LogFolder: path.Join(e2e.E2EContext.Environment.artifactsPath, "clusters", e2e.ClusterName),
316-
ClusterctlVariables: e2e.Variables(),
316+
LogFolder: path.Join(e2e.E2EContext.Environment.artifactsPath, "clusters", e2e.ClusterName),
317+
ClusterctlVariables: e2e.Variables(),
318+
InfrastructureProvider: "metal-stack:v0.6.2",
317319
})
318320

319321
By("Apply cluster template")
@@ -343,6 +345,47 @@ func (e2e *E2ECluster) teardownCluster(ctx context.Context) {
343345
}
344346
Expect(e2e.Refs.Cluster).NotTo(BeNil(), "cluster not created yet")
345347

348+
resources := framework.GetCAPIResources(ctx, framework.GetCAPIResourcesInput{
349+
Lister: e2e.E2EContext.Environment.Bootstrap.GetClient(),
350+
Namespace: e2e.NamespaceName,
351+
IncludeTypes: []metav1.TypeMeta{
352+
{
353+
Kind: "HelmReleaseProxy",
354+
APIVersion: "addons.cluster.x-k8s.io/v1alpha1",
355+
},
356+
{
357+
Kind: "HelmChartProxy",
358+
APIVersion: "addons.cluster.x-k8s.io/v1alpha1",
359+
},
360+
{
361+
Kind: "ClusterResourceSetBinding",
362+
APIVersion: "addons.cluster.x-k8s.io/v1beta1",
363+
},
364+
{
365+
Kind: "ClusterResourceSet",
366+
APIVersion: "addons.cluster.x-k8s.io/v1beta1",
367+
},
368+
},
369+
})
370+
371+
for _, r := range resources {
372+
err := e2e.E2EContext.Environment.Bootstrap.GetClient().Delete(ctx, r)
373+
Expect(err).To(Or(
374+
Not(HaveOccurred()),
375+
Satisfy(apierrors.IsNotFound)),
376+
fmt.Sprintf("failed to delete resource %s/%s of kind %s", r.GetNamespace(), r.GetName(), r.GetObjectKind().GroupVersionKind().Kind),
377+
)
378+
}
379+
380+
for _, r := range resources {
381+
Eventually(func() bool {
382+
err := e2e.E2EContext.Environment.Bootstrap.GetClient().Get(ctx, client.ObjectKeyFromObject(r), r)
383+
return apierrors.IsNotFound(err)
384+
}, e2e.E2EContext.E2EConfig.GetIntervals("default", "wait-delete-resource")...).Should(BeTrue(),
385+
fmt.Sprintf("resource %s/%s of kind %s still exists", r.GetNamespace(), r.GetName(), r.GetObjectKind().GroupVersionKind().Kind),
386+
)
387+
}
388+
346389
deleteClusterAndWait(ctx, framework.DeleteClusterAndWaitInput{
347390
ClusterProxy: e2e.E2EContext.Environment.Bootstrap,
348391
ClusterctlConfigPath: e2e.E2EContext.Environment.ClusterctlConfigPath,

test/e2e/frmwrk/shared_context.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/metal-stack/metal-go/api/client/network"
2020
"github.com/metal-stack/metal-go/api/models"
2121
corev1 "k8s.io/api/core/v1"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
"k8s.io/apimachinery/pkg/runtime"
2324
"sigs.k8s.io/cluster-api/test/framework"
2425
"sigs.k8s.io/cluster-api/test/framework/bootstrap"
@@ -207,8 +208,8 @@ func (ee *E2EContext) InitManagementCluster(ctx context.Context) {
207208
ClusterProxy: ee.Environment.Bootstrap,
208209
ClusterctlConfigPath: ee.Environment.ClusterctlConfigPath,
209210
InfrastructureProviders: ee.E2EConfig.InfrastructureProviders(),
210-
LogFolder: path.Join(ee.Environment.artifactsPath, "clusters", "bootstrap"),
211211
AddonProviders: ee.E2EConfig.AddonProviders(),
212+
LogFolder: path.Join(ee.Environment.artifactsPath, "clusters", "bootstrap"),
212213
})
213214
}
214215

@@ -245,12 +246,40 @@ func (ee *E2EContext) TeardownMetalStackProject(ctx context.Context) {
245246
for _, ns := range namespaces.Items {
246247
By(fmt.Sprintf("Deleting all clusters in namespace %s", ns.Name))
247248
framework.DeleteAllClustersAndWait(ctx, framework.DeleteAllClustersAndWaitInput{
248-
ClusterProxy: nil,
249+
ClusterProxy: ee.Environment.Bootstrap,
249250
ClusterctlConfigPath: ee.Environment.ClusterctlConfigPath,
250251
Namespace: ns.Name,
251252
ArtifactFolder: path.Join(ee.Environment.artifactsPath, "clusters", "bootstrap"),
253+
}, ee.E2EConfig.GetIntervals("default", "wait-delete-cluster")...)
254+
255+
resources := framework.GetCAPIResources(ctx, framework.GetCAPIResourcesInput{
256+
Lister: ee.Environment.Bootstrap.GetClient(),
257+
Namespace: ns.Name,
258+
IncludeTypes: []metav1.TypeMeta{
259+
{
260+
Kind: "HelmReleaseProxy",
261+
APIVersion: "addons.cluster.x-k8s.io/v1alpha1",
262+
},
263+
{
264+
Kind: "HelmChartProxy",
265+
APIVersion: "addons.cluster.x-k8s.io/v1alpha1",
266+
},
267+
{
268+
Kind: "ClusterResourceSetBinding",
269+
APIVersion: "addons.cluster.x-k8s.io/v1beta1",
270+
},
271+
{
272+
Kind: "ClusterResourceSet",
273+
APIVersion: "addons.cluster.x-k8s.io/v1beta1",
274+
},
275+
},
252276
})
253277

278+
for _, r := range resources {
279+
err := ee.Environment.Bootstrap.GetClient().Delete(ctx, r)
280+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("failed to delete resource %s/%s of kind %s", r.GetNamespace(), r.GetName(), r.GetObjectKind().GroupVersionKind().Kind))
281+
}
282+
254283
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
255284
Deleter: ee.Environment.Bootstrap.GetClient(),
256285
Name: ns.Name,

0 commit comments

Comments
 (0)