@@ -163,6 +163,92 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
163163 })
164164 })
165165
166+ FContext ("Full Ingress - Switch off after creation" , func () {
167+ BeforeEach (func () {
168+ solrCloud .Spec .SolrAddressability = solrv1beta1.SolrAddressabilityOptions {
169+ External : & solrv1beta1.ExternalAddressability {
170+ Method : solrv1beta1 .Ingress ,
171+ UseExternalAddress : true ,
172+ DomainName : testDomain ,
173+ NodePortOverride : 100 ,
174+ },
175+ PodPort : 3000 ,
176+ CommonServicePort : 4000 ,
177+ }
178+ })
179+ FIt ("has the correct resources" , func (ctx context.Context ) {
180+ By ("testing the Solr StatefulSet" )
181+ statefulSet := expectStatefulSet (ctx , solrCloud , solrCloud .StatefulSetName ())
182+ // Pod Annotations test
183+ Expect (statefulSet .Spec .Template .Annotations ).To (HaveKeyWithValue (util .ServiceTypeAnnotation , util .PerNodeServiceType ), "Since external address is used for advertising, the perNode service should be specified in the pod annotations." )
184+
185+ By ("testing the Solr Common Service" )
186+ commonService := expectService (ctx , solrCloud , solrCloud .CommonServiceName (), statefulSet .Spec .Selector .MatchLabels , false )
187+ Expect (commonService .Annotations ).To (Equal (testCommonServiceAnnotations ), "Incorrect common service annotations" )
188+ Expect (commonService .Spec .Ports [0 ].Name ).To (Equal ("solr-client" ), "Wrong port name on common Service" )
189+ Expect (commonService .Spec .Ports [0 ].Port ).To (Equal (int32 (4000 )), "Wrong port on common Service" )
190+ Expect (commonService .Spec .Ports [0 ].TargetPort .StrVal ).To (Equal ("solr-client" ), "Wrong podPort name on common Service" )
191+
192+ By ("ensuring the Solr Headless Service does not exist" )
193+ expectNoService (ctx , solrCloud , solrCloud .HeadlessServiceName (), "Headless service shouldn't exist, but it does." )
194+
195+ By ("making sure the individual Solr Node Services exist and route correctly" )
196+ nodeNames := solrCloud .GetAllSolrPodNames ()
197+ Expect (nodeNames ).To (HaveLen (replicas ), "SolrCloud has incorrect number of nodeNames." )
198+ for _ , nodeName := range nodeNames {
199+ service := expectService (ctx , solrCloud , nodeName , util .MergeLabelsOrAnnotations (statefulSet .Spec .Selector .MatchLabels , map [string ]string {"statefulset.kubernetes.io/pod-name" : nodeName }), false )
200+ expectedNodeServiceLabels := util .MergeLabelsOrAnnotations (solrCloud .SharedLabelsWith (solrCloud .Labels ), map [string ]string {"service-type" : "external" })
201+ Expect (service .Labels ).To (Equal (util .MergeLabelsOrAnnotations (expectedNodeServiceLabels , testNodeServiceLabels )), "Incorrect node '" + nodeName + "' service labels" )
202+ Expect (service .Annotations ).To (Equal (testNodeServiceAnnotations ), "Incorrect node '" + nodeName + "' service annotations" )
203+ Expect (service .Spec .Ports [0 ].Name ).To (Equal ("solr-client" ), "Wrong port name on common Service" )
204+ Expect (service .Spec .Ports [0 ].Port ).To (Equal (int32 (100 )), "Wrong port on node Service" )
205+ Expect (service .Spec .Ports [0 ].TargetPort .StrVal ).To (Equal ("solr-client" ), "Wrong podPort name on node Service" )
206+ }
207+
208+ By ("making sure Ingress was created correctly" )
209+ ingress := expectIngress (ctx , solrCloud , solrCloud .CommonIngressName ())
210+ Expect (ingress .Labels ).To (Equal (util .MergeLabelsOrAnnotations (solrCloud .SharedLabelsWith (solrCloud .Labels ), testIngressLabels )), "Incorrect ingress labels" )
211+ Expect (ingress .Annotations ).To (Equal (ingressLabelsWithDefaults (testIngressAnnotations )), "Incorrect ingress annotations" )
212+ Expect (ingress .Spec .IngressClassName ).To (Not (BeNil ()), "Ingress class name should not be nil" )
213+ Expect (* ingress .Spec .IngressClassName ).To (Equal (testIngressClass ), "Incorrect ingress class name" )
214+ testIngressRules (solrCloud , ingress , true , replicas , 4000 , 100 , testDomain )
215+
216+ By ("making sure the node addresses in the Status are correct" )
217+ expectSolrCloudStatusWithChecks (ctx , solrCloud , func (g Gomega , found * solrv1beta1.SolrCloudStatus ) {
218+ g .Expect (found .InternalCommonAddress ).To (Equal ("http://" + solrCloud .CommonServiceName ()+ "." + solrCloud .Namespace + ":4000" ), "Wrong internal common address in status" )
219+ g .Expect (found .ExternalCommonAddress ).To (Not (BeNil ()), "External common address in status should not be nil" )
220+ g .Expect (* found .ExternalCommonAddress ).To (Equal ("http://" + solrCloud .Namespace + "-" + solrCloud .Name + "-solrcloud" + "." + testDomain ), "Wrong external common address in status" )
221+ })
222+
223+ By ("Turning off node external addressability and making sure the node services are deleted" )
224+ expectSolrCloudWithChecks (ctx , solrCloud , func (g Gomega , found * solrv1beta1.SolrCloud ) {
225+ found .Spec .SolrAddressability .External .UseExternalAddress = false
226+ found .Spec .SolrAddressability .External .HideNodes = true
227+ g .Expect (k8sClient .Update (ctx , found )).To (Succeed (), "Couldn't update the solrCloud to not advertise the nodes externally." )
228+ })
229+
230+ // Since node external addressability is off, but common external addressability is on, the ingress should exist, but the node services should not
231+ eventuallyExpectNoServices (ctx , solrCloud , "Node services shouldn't exist after the update, but they do." , nodeNames )
232+
233+ expectIngress (ctx , solrCloud , solrCloud .CommonIngressName ())
234+
235+ headlessService := expectService (ctx , solrCloud , solrCloud .HeadlessServiceName (), statefulSet .Spec .Selector .MatchLabels , true )
236+ Expect (headlessService .Annotations ).To (Equal (testHeadlessServiceAnnotations ), "Incorrect headless service annotations" )
237+ Expect (headlessService .Spec .Ports [0 ].Name ).To (Equal ("solr-client" ), "Wrong port name on common Service" )
238+ Expect (headlessService .Spec .Ports [0 ].Port ).To (Equal (int32 (3000 )), "Wrong port on headless Service" )
239+ Expect (headlessService .Spec .Ports [0 ].TargetPort .StrVal ).To (Equal ("solr-client" ), "Wrong podPort name on headless Service" )
240+ Expect (headlessService .Spec .Ports [0 ].Protocol ).To (Equal (corev1 .ProtocolTCP ), "Wrong protocol on headless Service" )
241+ Expect (headlessService .Spec .Ports [0 ].AppProtocol ).To (BeNil (), "AppProtocol on headless Service should be nil when not running with TLS" )
242+
243+ By ("Turning off common external addressability and making sure the ingress is deleted" )
244+ expectSolrCloudWithChecks (ctx , solrCloud , func (g Gomega , found * solrv1beta1.SolrCloud ) {
245+ found .Spec .SolrAddressability .External = nil
246+ g .Expect (k8sClient .Update (ctx , found )).To (Succeed (), "Couldn't update the solrCloud to remove external addressability" )
247+ })
248+ eventuallyExpectNoIngress (ctx , solrCloud , solrCloud .CommonIngressName ())
249+ })
250+ })
251+
166252 FContext ("Hide Nodes from external connections - Using default ingress class" , func () {
167253 ingressClass := & netv1.IngressClass {
168254 ObjectMeta : metav1.ObjectMeta {
@@ -206,6 +292,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
206292
207293 By ("testing the Solr StatefulSet" )
208294 statefulSet := expectStatefulSet (ctx , solrCloud , solrCloud .StatefulSetName ())
295+ Expect (statefulSet .Spec .Template .Annotations ).To (HaveKeyWithValue (util .ServiceTypeAnnotation , util .HeadlessServiceType ), "Since external address is not used for advertising, the headless service should be specified in the pod annotations." )
209296
210297 Expect (statefulSet .Spec .Template .Spec .Containers ).To (HaveLen (1 ), "Solr StatefulSet requires a container." )
211298
0 commit comments