|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "os/exec" |
| 6 | + "path/filepath" |
| 7 | + "strings" |
| 8 | + |
| 9 | + bmov1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" |
| 10 | + . "github.com/onsi/ginkgo/v2" |
| 11 | + . "github.com/onsi/gomega" |
| 12 | + capi_e2e "sigs.k8s.io/cluster-api/test/e2e" |
| 13 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 14 | +) |
| 15 | + |
| 16 | +var _ = Describe("When testing K8S conformance [k8s-conformance]", Label("k8s-conformance"), func() { |
| 17 | + BeforeEach(func() { |
| 18 | + osType := strings.ToLower(os.Getenv("OS")) |
| 19 | + Expect(osType).ToNot(Equal("")) |
| 20 | + validateGlobals(specName) |
| 21 | + // We need to override clusterctl apply log folder to avoid getting our credentials exposed. |
| 22 | + clusterctlLogFolder = filepath.Join(os.TempDir(), "target_cluster_logs", bootstrapClusterProxy.GetName()) |
| 23 | + |
| 24 | + Logf("Removing existing BMHs from source") |
| 25 | + bmhData, err := os.ReadFile(filepath.Join(workDir, bmhCrsFile)) |
| 26 | + Expect(err).ToNot(HaveOccurred(), "BMH CRs file not found") |
| 27 | + kubeConfigPath := bootstrapClusterProxy.GetKubeconfigPath() |
| 28 | + err = KubectlDelete(ctx, kubeConfigPath, bmhData, "-n", "metal3") |
| 29 | + Expect(err).ToNot(HaveOccurred(), "Failed to delete existing BMHs") |
| 30 | + Logf("BMHs are removed") |
| 31 | + }) |
| 32 | + // Note: This installs a cluster based on KUBERNETES_VERSION and runs conformance tests. |
| 33 | + capi_e2e.K8SConformanceSpec(ctx, func() capi_e2e.K8SConformanceSpecInput { |
| 34 | + return capi_e2e.K8SConformanceSpecInput{ |
| 35 | + E2EConfig: e2eConfig, |
| 36 | + ClusterctlConfigPath: clusterctlConfigPath, |
| 37 | + BootstrapClusterProxy: bootstrapClusterProxy, |
| 38 | + ArtifactFolder: artifactFolder, |
| 39 | + SkipCleanup: skipCleanup, |
| 40 | + PostNamespaceCreated: postNamespaceCreated, |
| 41 | + Flavor: osType, |
| 42 | + } |
| 43 | + }) |
| 44 | + AfterEach(func() { |
| 45 | + ListBareMetalHosts(ctx, bootstrapClusterProxy.GetClient(), client.InNamespace(namespace)) |
| 46 | + ListMetal3Machines(ctx, bootstrapClusterProxy.GetClient(), client.InNamespace(namespace)) |
| 47 | + ListMachines(ctx, bootstrapClusterProxy.GetClient(), client.InNamespace(namespace)) |
| 48 | + // Recreate bmh that was used in capi namespace in metal3 |
| 49 | + //#nosec G204 -- We need to pass in the file name here. |
| 50 | + cmd := exec.Command("bash", "-c", "kubectl apply -f bmhosts_crs.yaml -n metal3") |
| 51 | + cmd.Dir = workDir |
| 52 | + output, err := cmd.CombinedOutput() |
| 53 | + Logf("Applying bmh to metal3 namespace : \n %v", string(output)) |
| 54 | + Expect(err).ToNot(HaveOccurred()) |
| 55 | + // wait for all bmh to become available |
| 56 | + bootstrapClient := bootstrapClusterProxy.GetClient() |
| 57 | + ListBareMetalHosts(ctx, bootstrapClient, client.InNamespace(namespace)) |
| 58 | + WaitForNumBmhInState(ctx, bmov1alpha1.StateAvailable, WaitForNumInput{ |
| 59 | + Client: bootstrapClient, |
| 60 | + Options: []client.ListOption{client.InNamespace(namespace)}, |
| 61 | + Replicas: 4, |
| 62 | + Intervals: e2eConfig.GetIntervals(specName, "wait-bmh-available"), |
| 63 | + }) |
| 64 | + ListBareMetalHosts(ctx, bootstrapClient, client.InNamespace(namespace)) |
| 65 | + }) |
| 66 | +}) |
0 commit comments