github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/basic_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1" 6 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework" 7 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement" 8 "github.com/interconnectedcloud/qdr-operator/test/e2e/validation" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 12 "strings" 13 ) 14 15 var _ = Describe("[basic_test] Interconnect default deployment tests", func() { 16 f := framework.NewFramework("basic", nil) 17 18 It("Should be able to create a default interior deployment", func() { 19 testInteriorDefaults(f) 20 }) 21 22 It("Should be able to create a default edge deployment", func() { 23 testEdgeDefaults(f) 24 }) 25 26 }) 27 28 // testInteriorDefaults creates a simple Interior router using a minimal configuration 29 // and it asserts that all default elements and artifacts have been defined. 30 func testInteriorDefaults(f *framework.Framework) { 31 var ( 32 name = "interior-interconnect" 33 defaultSize = 3 34 ) 35 36 By("Creating a default interior interconnect") 37 ei, err := f.CreateInterconnect(f.Namespace, int32(defaultSize), func(ei *v1alpha1.Interconnect) { 38 ei.Name = name 39 }) 40 Expect(err).NotTo(HaveOccurred()) 41 42 // Make sure we cleanup the Interconnect resource after we're done testing. 43 defer func() { 44 ei, err := f.GetInterconnect(ei.Name) 45 // If not found, no need to delete 46 if err != nil && strings.Contains(err.Error(), "not found") { 47 return 48 } 49 Expect(err).NotTo(HaveOccurred()) 50 err = f.DeleteInterconnect(ei) 51 Expect(err).NotTo(HaveOccurred()) 52 }() 53 54 By("Creating an Interconnect resource in the namespace") 55 ei, err = f.GetInterconnect(name) 56 Expect(err).NotTo(HaveOccurred()) 57 58 By("Verifying the deployment plan defaults") 59 Expect(ei.Name).To(Equal(name)) 60 Expect(ei.Spec.DeploymentPlan.Role).To(Equal(v1alpha1.RouterRoleInterior)) 61 Expect(ei.Spec.DeploymentPlan.Placement).To(Equal(v1alpha1.PlacementAny)) 62 63 By("Waiting until full interconnect with version") 64 ctx, fn := context.WithTimeout(context.Background(), framework.Timeout) 65 defer fn() 66 err = f.WaitUntilFullInterconnectWithSize(ctx, ei, defaultSize) 67 Expect(err).NotTo(HaveOccurred()) 68 69 By("Waiting until full interconnect initial qdr entities") 70 ctx, fn = context.WithTimeout(context.Background(), framework.Timeout) 71 defer fn() 72 err = qdrmanagement.WaitUntilFullInterconnectWithQdrEntities(ctx, f, ei) 73 Expect(err).NotTo(HaveOccurred()) 74 75 By("Creating a service for the interconnect default listeners") 76 svc, err := f.GetService(name) 77 Expect(err).NotTo(HaveOccurred()) 78 79 By("Verifying the owner reference for the service") 80 Expect(svc.OwnerReferences[0].APIVersion).To(Equal(framework.GVR)) 81 Expect(svc.OwnerReferences[0].Name).To(Equal(name)) 82 Expect(*svc.OwnerReferences[0].Controller).To(Equal(true)) 83 84 By("Setting up default listener on qdr instances") 85 pods, err := f.PodsForInterconnect(ei) 86 Expect(err).NotTo(HaveOccurred()) 87 Expect(len(pods)).To(Equal(defaultSize)) 88 89 By("Verifying default listeners have been defined") 90 validation.ValidateDefaultListeners(ei, f, pods) 91 92 By("Verifying default connectors have been defined") 93 validation.ValidateDefaultConnectors(ei, f, pods) 94 95 By("Verifying default addresses have been defined") 96 validation.ValidateDefaultAddresses(ei, f, pods) 97 98 if f.CertManagerPresent { 99 By("Verifying expected sslProfiles have been defined") 100 validation.ValidateDefaultSslProfiles(ei, f, pods) 101 102 By("Automatically generating credentials") 103 _, err = f.GetSecret("interior-interconnect-default-credentials") 104 Expect(err).NotTo(HaveOccurred()) 105 _, err = f.GetSecret("interior-interconnect-inter-router-credentials") 106 Expect(err).NotTo(HaveOccurred()) 107 _, err = f.GetSecret("interior-interconnect-inter-router-ca") 108 Expect(err).NotTo(HaveOccurred()) 109 } 110 111 // Verify service has been defined 112 By("Validating service has been defined for Interconnect instance") 113 service, err := f.KubeClient.CoreV1().Services(f.Namespace).Get(ei.Name, v1.GetOptions{}) 114 Expect(err).NotTo(HaveOccurred()) 115 Expect(service).NotTo(BeNil()) 116 117 // ingress or routes / port <icname-[exposed port #]> 118 if !f.IsOpenShift() { 119 By("Validating Ingresses have been defined for exposed listeners") 120 ingress, err := f.KubeClient.ExtensionsV1beta1().Ingresses(f.Namespace).Get(ei.Name+"-8080", v1.GetOptions{}) 121 Expect(err).NotTo(HaveOccurred()) 122 Expect(ingress).NotTo(BeNil()) 123 124 // Verify exposed inter router TLS listener 125 if f.CertManagerPresent { 126 ingress, err = f.KubeClient.ExtensionsV1beta1().Ingresses(f.Namespace).Get(ei.Name+"-55671", v1.GetOptions{}) 127 Expect(err).NotTo(HaveOccurred()) 128 Expect(ingress).NotTo(BeNil()) 129 } 130 } else { 131 By("Validating Routes have been defined for exposed listeners") 132 route, err := f.OcpClient.RoutesClient.RouteV1().Routes(f.Namespace).Get(ei.Name+"-8080", v1.GetOptions{}) 133 Expect(err).NotTo(HaveOccurred()) 134 Expect(route).NotTo(BeNil()) 135 136 // Verify exposed inter router TLS listener 137 if f.CertManagerPresent { 138 route, err := f.OcpClient.RoutesClient.RouteV1().Routes(f.Namespace).Get(ei.Name+"-55671", v1.GetOptions{}) 139 Expect(err).NotTo(HaveOccurred()) 140 Expect(route).NotTo(BeNil()) 141 } 142 } 143 144 // Delete and verify related resources were deleted 145 By("Deleting the Interconnect instance") 146 err = f.DeleteInterconnect(ei) 147 Expect(err).NotTo(HaveOccurred()) 148 149 // Waiting till Interconnect is deleted 150 ctx, fn = context.WithTimeout(context.Background(), framework.Timeout) 151 defer fn() 152 err = framework.WaitForDeploymentDeleted(ctx, f.KubeClient, f.Namespace, ei.Name) 153 Expect(err).NotTo(HaveOccurred()) 154 155 // Verify service has been defined 156 By("Validating service has been deleted") 157 service, err = f.KubeClient.CoreV1().Services(f.Namespace).Get(ei.Name, v1.GetOptions{}) 158 Expect(err).To(HaveOccurred()) 159 160 // ingress or routes / port <icname-[exposed port #]> 161 if !f.IsOpenShift() { 162 By("Validating Ingresses have been deleted") 163 _, err := f.KubeClient.ExtensionsV1beta1().Ingresses(f.Namespace).Get(ei.Name+"-8080", v1.GetOptions{}) 164 Expect(err).To(HaveOccurred()) 165 166 // Verify exposed inter router TLS listener 167 if f.CertManagerPresent { 168 _, err = f.KubeClient.ExtensionsV1beta1().Ingresses(f.Namespace).Get(ei.Name+"-55671", v1.GetOptions{}) 169 Expect(err).To(HaveOccurred()) 170 } 171 } else { 172 By("Validating Routes have been deleted") 173 _, err := f.OcpClient.RoutesClient.RouteV1().Routes(f.Namespace).Get(ei.Name+"-8080", v1.GetOptions{}) 174 Expect(err).To(HaveOccurred()) 175 176 // Verify exposed inter router TLS listener 177 if f.CertManagerPresent { 178 _, err := f.OcpClient.RoutesClient.RouteV1().Routes(f.Namespace).Get(ei.Name+"-55671", v1.GetOptions{}) 179 Expect(err).To(HaveOccurred()) 180 } 181 } 182 183 } 184 185 // testEdgeDefaults defines a minimal edge Interconnect instance and validates 186 // that all default configuration and resources have been defined. 187 func testEdgeDefaults(f *framework.Framework) { 188 var ( 189 name = "edge-interconnect" 190 role = "edge" 191 defaultSize = 1 192 ) 193 194 By("Creating an edge interconnect with default size") 195 ei, err := f.CreateInterconnect(f.Namespace, 0, func(ei *v1alpha1.Interconnect) { 196 ei.Name = name 197 ei.Spec.DeploymentPlan.Role = v1alpha1.RouterRoleType(role) 198 }) 199 Expect(err).NotTo(HaveOccurred()) 200 201 // Make sure we cleanup the Interconnect resource after we're done testing. 202 defer func() { 203 err = f.DeleteInterconnect(ei) 204 Expect(err).NotTo(HaveOccurred()) 205 }() 206 207 By("Creating an Interconnect resource in the namespace") 208 ei, err = f.GetInterconnect(name) 209 Expect(err).NotTo(HaveOccurred()) 210 211 By("Verifying the deployment plan") 212 Expect(ei.Name).To(Equal(name)) 213 Expect(ei.Spec.DeploymentPlan.Role).To(Equal(v1alpha1.RouterRoleType(role))) 214 Expect(ei.Spec.DeploymentPlan.Placement).To(Equal(v1alpha1.PlacementAny)) 215 216 By("Waiting until full interconnect with version") 217 ctx, fn := context.WithTimeout(context.Background(), framework.Timeout) 218 defer fn() 219 err = f.WaitUntilFullInterconnectWithSize(ctx, ei, defaultSize) 220 Expect(err).NotTo(HaveOccurred()) 221 222 By("Creating a service for the interconnect default listeners") 223 svc, err := f.GetService(name) 224 Expect(err).NotTo(HaveOccurred()) 225 226 By("Verifying the owner reference for the service") 227 Expect(svc.OwnerReferences[0].APIVersion).To(Equal(framework.GVR)) 228 Expect(svc.OwnerReferences[0].Name).To(Equal(name)) 229 Expect(*svc.OwnerReferences[0].Controller).To(Equal(true)) 230 231 By("Setting up default listener on qdr instances") 232 pods, err := f.PodsForInterconnect(ei) 233 Expect(err).NotTo(HaveOccurred()) 234 Expect(len(pods)).To(Equal(defaultSize)) 235 validation.ValidateDefaultListeners(ei, f, pods) 236 237 By("Verifying default addresses have been defined") 238 validation.ValidateDefaultAddresses(ei, f, pods) 239 240 if f.CertManagerPresent { 241 By("Verifying expected sslProfiles have been defined") 242 validation.ValidateDefaultSslProfiles(ei, f, pods) 243 244 By("Automatically generating credentials") 245 _, err = f.GetSecret("edge-interconnect-default-credentials") 246 Expect(err).NotTo(HaveOccurred()) 247 } 248 }