-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e_suite_test.go
More file actions
108 lines (92 loc) · 3.86 KB
/
Copy pathe2e_suite_test.go
File metadata and controls
108 lines (92 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package e2e
import (
"context"
"fmt"
"os"
"os/exec"
"slices"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// TestE2E runs the end-to-end (e2e) test suite for the MCM provider.
// These tests execute in an isolated kind cluster to validate the provider
// with mock STACKIT IAAS API endpoints.
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
_, _ = fmt.Fprintf(GinkgoWriter, "Starting MCM provider STACKIT integration test suite\n")
RunSpecs(t, "e2e suite")
}
var _ = BeforeSuite(func() {
var (
cmd *exec.Cmd
err error
output []byte
)
// Get the cluster name from environment (set by just recipe)
clusterName := os.Getenv("KIND_CLUSTER_NAME")
if clusterName == "" {
clusterName = "mcm-provider-stackit-e2e" // fallback default
}
_, _ = fmt.Fprintf(GinkgoWriter, "Using kind cluster: %s\n", clusterName)
By("determining test namespace")
// Use MCM_NAMESPACE env var or default to machine-controller-manager
testNamespace = os.Getenv("MCM_NAMESPACE")
if testNamespace == "" {
testNamespace = "machine-controller-manager"
}
_, _ = fmt.Fprintf(GinkgoWriter, "Using test namespace: %s (set MCM_NAMESPACE to override)\n", testNamespace)
By("deploying MCM provider with mock IAAS API")
cmd = exec.Command("kubectl", "apply", "-k", "../../config/overlays/e2e")
output, err = cmd.CombinedOutput()
if err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to deploy: %s\n", string(output))
}
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to deploy MCM provider with mock API")
By("waiting for deployments to be ready")
// Wait for MCM deployment
cmd = exec.Command("kubectl", "wait", "--for=condition=available", "--timeout=300s",
"deployment/machine-controller-manager", "-n", testNamespace)
output, err = cmd.CombinedOutput()
if err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "MCM deployment not ready: %s\n", string(output))
}
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "MCM deployment did not become ready")
// Wait for IAAS mock server
cmd = exec.Command("kubectl", "wait", "--for=condition=available", "--timeout=120s",
"deployment/iaas", "-n", "stackitcloud")
output, err = cmd.CombinedOutput()
if err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "IAAS mock not ready: %s\n", string(output))
}
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "IAAS mock server did not become ready")
_, _ = fmt.Fprintf(GinkgoWriter, "E2E environment setup complete\n")
})
var _ = AfterSuite(func(ctx context.Context) {
skipResourceCleanup := os.Getenv("SKIP_RESOURCE_CLEANUP") == "true"
skipClusterCleanup := os.Getenv("SKIP_CLUSTER_CLEANUP") == "true"
if skipResourceCleanup {
_, _ = fmt.Fprintf(GinkgoWriter, "Skipping resource cleanup (SKIP_RESOURCE_CLEANUP=true)\n")
_, _ = fmt.Fprintf(GinkgoWriter, "Test resources preserved in namespace: %s\n", testNamespace)
_, _ = fmt.Fprintf(GinkgoWriter, "To list test resources: kubectl get machines,secrets,machineclasses -n %s\n", testNamespace)
return
}
By("uninstalling MCM provider")
cmd := exec.Command("kubectl", "delete", "-k", "../../config/overlays/e2e", "--ignore-not-found=true")
output, _ := cmd.CombinedOutput()
_, _ = fmt.Fprintf(GinkgoWriter, "MCM uninstall output: %s\n", string(output))
By("cleaning up tracked test resources after MCM removal")
for _, resource := range slices.Backward(testResources) {
// Wrap each cleanup in a function with GinkgoRecover to prevent one failure
// from stopping cleanup of remaining resources
func(res TestResource) {
defer GinkgoRecover()
deleteK8sResource(ctx, res.Type, res.Name, res.Namespace)
verifyK8sResourceDeleted(ctx, res.Type, res.Name, res.Namespace)
}(resource)
}
// Note: We don't delete the namespace as it's managed by MCM deployment, not the tests
if !skipClusterCleanup {
_, _ = fmt.Fprintf(GinkgoWriter, "E2E cleanup complete. Set SKIP_CLUSTER_CLEANUP=true to preserve cluster.\n")
}
})