@@ -20,9 +20,14 @@ package e2e
2020import (
2121 "context"
2222 solrv1beta1 "github.com/apache/solr-operator/api/v1beta1"
23+ "github.com/apache/solr-operator/controllers"
2324 . "github.com/onsi/ginkgo/v2"
2425 . "github.com/onsi/gomega"
26+ appsv1 "k8s.io/api/apps/v1"
27+ corev1 "k8s.io/api/core/v1"
2528 "k8s.io/utils/pointer"
29+ "sigs.k8s.io/controller-runtime/pkg/client"
30+ "time"
2631)
2732
2833var _ = FDescribe ("E2E - SolrCloud - Security JSON" , func () {
@@ -35,10 +40,6 @@ var _ = FDescribe("E2E - SolrCloud - Security JSON", func() {
3540 })
3641
3742 JustBeforeEach (func (ctx context.Context ) {
38- By ("generating the security.json secret and basic auth secret" )
39- generateSolrSecuritySecret (ctx , solrCloud )
40- generateSolrBasicAuthSecret (ctx , solrCloud )
41-
4243 By ("creating the SolrCloud" )
4344 Expect (k8sClient .Create (ctx , solrCloud )).To (Succeed ())
4445
@@ -50,20 +51,64 @@ var _ = FDescribe("E2E - SolrCloud - Security JSON", func() {
5051 solrCloud = expectSolrCloudToBeReady (ctx , solrCloud )
5152
5253 By ("creating a first Solr Collection" )
53- createAndQueryCollection (ctx , solrCloud , "basic" , 1 , 1 )
54+ createAndQueryCollection (ctx , solrCloud , "basic" , 2 , 1 )
5455 })
5556
56- FContext ("Provided Zookeeper " , func () {
57- BeforeEach (func () {
57+ FContext ("Provided Security JSON " , func () {
58+ BeforeEach (func (ctx context. Context ) {
5859 solrCloud .Spec .ZookeeperRef = & solrv1beta1.ZookeeperRef {
5960 ProvidedZookeeper : & solrv1beta1.ZookeeperSpec {
6061 Replicas : pointer .Int32 (1 ),
6162 Ephemeral : & solrv1beta1.ZKEphemeral {},
6263 },
6364 }
65+
66+ solrCloud .Spec .SolrSecurity = & solrv1beta1.SolrSecurityOptions {
67+ AuthenticationType : "Basic" ,
68+ BasicAuthSecret : solrCloud .Name + "-basic-auth-secret" ,
69+ BootstrapSecurityJson : & corev1.SecretKeySelector {
70+ LocalObjectReference : corev1.LocalObjectReference {
71+ Name : solrCloud .Name + "-security-secret" ,
72+ },
73+ Key : "security.json" ,
74+ },
75+ }
76+
77+ By ("generating the security.json secret and basic auth secret" )
78+ generateSolrSecuritySecret (ctx , solrCloud )
79+ generateSolrBasicAuthSecret (ctx , solrCloud )
6480 })
6581
6682 // All testing will be done in the "JustBeforeEach" logic, no additional tests required here
6783 FIt ("Starts correctly" , func (ctx context.Context ) {})
6884 })
85+
86+ FContext ("Bootstrapped Security" , func () {
87+
88+ BeforeEach (func () {
89+ solrCloud .Spec .SolrSecurity = & solrv1beta1.SolrSecurityOptions {
90+ AuthenticationType : "Basic" ,
91+ }
92+ })
93+
94+ FIt ("Scales up with replica migration" , func (ctx context.Context ) {
95+ originalSolrCloud := solrCloud .DeepCopy ()
96+ solrCloud .Spec .Replicas = pointer .Int32 (int32 (2 ))
97+ By ("triggering a scale up via solrCloud replicas" )
98+ Expect (k8sClient .Patch (ctx , solrCloud , client .MergeFrom (originalSolrCloud ))).To (Succeed (), "Could not patch SolrCloud replicas to initiate scale down" )
99+
100+ By ("make sure scaleDown happens without a clusterLock and eventually the replicas are removed" )
101+ // Once the scale down actually occurs, the statefulSet annotations should be removed very soon
102+ expectStatefulSetWithChecksAndTimeout (ctx , solrCloud , solrCloud .StatefulSetName (), time .Minute * 2 , time .Millisecond * 500 , func (g Gomega , found * appsv1.StatefulSet ) {
103+ g .Expect (found .Spec .Replicas ).To (HaveValue (BeEquivalentTo (2 )), "StatefulSet should eventually have 2 pods." )
104+ clusterOp , err := controllers .GetCurrentClusterOp (found )
105+ g .Expect (err ).ToNot (HaveOccurred (), "Error occurred while finding clusterLock for SolrCloud" )
106+ g .Expect (clusterOp ).To (BeNil (), "StatefulSet should have a ScaleDown lock after scaling is complete." )
107+ })
108+
109+ queryCollection (ctx , solrCloud , "basic" , 0 )
110+
111+ // TODO: When balancing is in all Operator supported Solr versions, add a test to make sure balancing occurred
112+ })
113+ })
69114})
0 commit comments