|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + nutanixv1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1" |
| 5 | + . "github.com/onsi/ginkgo/v2" |
| 6 | + . "github.com/onsi/gomega" |
| 7 | + configv1 "github.com/openshift/api/config/v1" |
| 8 | + "github.com/openshift/cluster-capi-operator/e2e/framework" |
| 9 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 10 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 11 | +) |
| 12 | + |
| 13 | +var _ = Describe("Cluster API Nutanix InfraCluster", Ordered, func() { |
| 14 | + var nutanixCluster *nutanixv1.NutanixCluster |
| 15 | + |
| 16 | + BeforeAll(func() { |
| 17 | + if platform != configv1.NutanixPlatformType { |
| 18 | + Skip("Skipping Nutanix E2E tests") |
| 19 | + } |
| 20 | + }) |
| 21 | + |
| 22 | + AfterEach(func() { |
| 23 | + if platform != configv1.NutanixPlatformType { |
| 24 | + // Because AfterEach always runs, even when tests are skipped, we have to |
| 25 | + // explicitly skip it here for other platforms. |
| 26 | + Skip("Skipping Nutanix E2E tests") |
| 27 | + } |
| 28 | + }) |
| 29 | + |
| 30 | + It("should have a NutanixCluster created by the infracluster controller", func() { |
| 31 | + By("Fetching the NutanixCluster object") |
| 32 | + nutanixCluster = &nutanixv1.NutanixCluster{} |
| 33 | + err := cl.Get(ctx, client.ObjectKey{ |
| 34 | + Name: clusterName, |
| 35 | + Namespace: framework.CAPINamespace, |
| 36 | + }, nutanixCluster) |
| 37 | + Expect(err).ToNot(HaveOccurred(), "should be able to get the NutanixCluster") |
| 38 | + Expect(nutanixCluster).ToNot(BeNil()) |
| 39 | + }) |
| 40 | + |
| 41 | + It("should have the correct ManagedBy annotation", func() { |
| 42 | + By("Validating the ManagedBy annotation") |
| 43 | + Expect(nutanixCluster.Annotations).To(HaveKey(clusterv1.ManagedByAnnotation)) |
| 44 | + Expect(nutanixCluster.Annotations[clusterv1.ManagedByAnnotation]).To(Equal(managedByAnnotationValueClusterCAPIOperatorInfraClusterController)) |
| 45 | + }) |
| 46 | + |
| 47 | + It("should have the control plane endpoint configured", func() { |
| 48 | + By("Validating control plane endpoint") |
| 49 | + Expect(nutanixCluster.Spec.ControlPlaneEndpoint.Host).ToNot(BeEmpty(), "control plane endpoint host should not be empty") |
| 50 | + Expect(nutanixCluster.Spec.ControlPlaneEndpoint.Port).To(BeNumerically(">", 0), "control plane endpoint port should be greater than 0") |
| 51 | + }) |
| 52 | + |
| 53 | + It("should have PrismCentral configuration if specified in Infrastructure", func() { |
| 54 | + By("Checking Infrastructure for Nutanix PrismCentral configuration") |
| 55 | + if mapiInfrastructure.Spec.PlatformSpec.Nutanix != nil && |
| 56 | + mapiInfrastructure.Spec.PlatformSpec.Nutanix.PrismCentral.Address != "" { |
| 57 | + By("Validating PrismCentral configuration in NutanixCluster") |
| 58 | + Expect(nutanixCluster.Spec.PrismCentral).ToNot(BeNil(), "PrismCentral should be configured") |
| 59 | + Expect(nutanixCluster.Spec.PrismCentral.Address).To(Equal(mapiInfrastructure.Spec.PlatformSpec.Nutanix.PrismCentral.Address)) |
| 60 | + Expect(nutanixCluster.Spec.PrismCentral.Port).To(Equal(mapiInfrastructure.Spec.PlatformSpec.Nutanix.PrismCentral.Port)) |
| 61 | + } |
| 62 | + }) |
| 63 | + |
| 64 | + It("should have failure domains configured if specified in Infrastructure", func() { |
| 65 | + By("Checking Infrastructure for Nutanix failure domains") |
| 66 | + if mapiInfrastructure.Spec.PlatformSpec.Nutanix != nil && |
| 67 | + len(mapiInfrastructure.Spec.PlatformSpec.Nutanix.FailureDomains) > 0 { |
| 68 | + By("Validating failure domains in NutanixCluster") |
| 69 | + Expect(nutanixCluster.Spec.ControlPlaneFailureDomains).ToNot(BeEmpty(), "failure domains should be configured") |
| 70 | + Expect(len(nutanixCluster.Spec.ControlPlaneFailureDomains)).To(Equal(len(mapiInfrastructure.Spec.PlatformSpec.Nutanix.FailureDomains))) |
| 71 | + |
| 72 | + // Verify that each failure domain from Infrastructure is present in NutanixCluster |
| 73 | + infraFDNames := make(map[string]bool) |
| 74 | + for _, fd := range mapiInfrastructure.Spec.PlatformSpec.Nutanix.FailureDomains { |
| 75 | + infraFDNames[fd.Name] = true |
| 76 | + } |
| 77 | + |
| 78 | + for _, fd := range nutanixCluster.Spec.ControlPlaneFailureDomains { |
| 79 | + Expect(infraFDNames).To(HaveKey(fd.Name), "failure domain %s should exist in Infrastructure spec", fd.Name) |
| 80 | + } |
| 81 | + } |
| 82 | + }) |
| 83 | + |
| 84 | + It("should eventually become ready", func() { |
| 85 | + By("Waiting for NutanixCluster to become ready") |
| 86 | + Eventually(func() bool { |
| 87 | + updatedCluster := &nutanixv1.NutanixCluster{} |
| 88 | + err := cl.Get(ctx, client.ObjectKey{ |
| 89 | + Name: clusterName, |
| 90 | + Namespace: framework.CAPINamespace, |
| 91 | + }, updatedCluster) |
| 92 | + if err != nil { |
| 93 | + return false |
| 94 | + } |
| 95 | + return updatedCluster.Status.Ready |
| 96 | + }, framework.WaitLong).Should(BeTrue(), "NutanixCluster should eventually become ready") |
| 97 | + }) |
| 98 | +}) |
| 99 | + |
| 100 | +var _ = Describe("Cluster API Nutanix Cluster", Ordered, func() { |
| 101 | + var capiCluster *clusterv1.Cluster |
| 102 | + |
| 103 | + BeforeAll(func() { |
| 104 | + if platform != configv1.NutanixPlatformType { |
| 105 | + Skip("Skipping Nutanix E2E tests") |
| 106 | + } |
| 107 | + }) |
| 108 | + |
| 109 | + It("should have a CAPI Cluster with NutanixCluster infrastructure reference", func() { |
| 110 | + By("Fetching the CAPI Cluster object") |
| 111 | + capiCluster = &clusterv1.Cluster{} |
| 112 | + err := cl.Get(ctx, client.ObjectKey{ |
| 113 | + Name: clusterName, |
| 114 | + Namespace: framework.CAPINamespace, |
| 115 | + }, capiCluster) |
| 116 | + Expect(err).ToNot(HaveOccurred(), "should be able to get the CAPI Cluster") |
| 117 | + Expect(capiCluster).ToNot(BeNil()) |
| 118 | + |
| 119 | + By("Validating infrastructure reference") |
| 120 | + Expect(capiCluster.Spec.InfrastructureRef).ToNot(BeNil()) |
| 121 | + Expect(capiCluster.Spec.InfrastructureRef.Kind).To(Equal("NutanixCluster")) |
| 122 | + Expect(capiCluster.Spec.InfrastructureRef.Name).To(Equal(clusterName)) |
| 123 | + Expect(capiCluster.Spec.InfrastructureRef.Namespace).To(Equal(framework.CAPINamespace)) |
| 124 | + }) |
| 125 | + |
| 126 | + It("should have control plane endpoint initialized", func() { |
| 127 | + By("Validating CAPI Cluster control plane endpoint") |
| 128 | + Expect(capiCluster.Spec.ControlPlaneEndpoint.Host).ToNot(BeEmpty()) |
| 129 | + Expect(capiCluster.Spec.ControlPlaneEndpoint.Port).To(BeNumerically(">", 0)) |
| 130 | + }) |
| 131 | +}) |
0 commit comments