Skip to content

Commit

Permalink
Support TLS with recent Solr 9.x versions (#610)
Browse files Browse the repository at this point in the history
- Add upgrade notes for minimum Solr version
- SNI is handled by default in Solr 9.4, so don't worry about it
- Lots of testing fixes
- New environment variables are used for Solr Pods
  • Loading branch information
HoustonPutman authored Sep 19, 2023
1 parent 0f8b9a2 commit 696faff
Show file tree
Hide file tree
Showing 23 changed files with 1,107 additions and 778 deletions.
18 changes: 7 additions & 11 deletions controllers/solrcloud_controller_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ import (

var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
var (
ctx context.Context

solrCloud *solrv1beta1.SolrCloud
)

BeforeEach(func() {
ctx = context.Background()

solrCloud = &solrv1beta1.SolrCloud{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Expand All @@ -49,7 +45,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
}
})

JustBeforeEach(func() {
JustBeforeEach(func(ctx context.Context) {
By("creating the SolrCloud")
Expect(k8sClient.Create(ctx, solrCloud)).To(Succeed())

Expand All @@ -59,7 +55,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
})
})

AfterEach(func() {
AfterEach(func(ctx context.Context) {
cleanupTest(ctx, solrCloud)
})

Expand Down Expand Up @@ -89,7 +85,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
},
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("testing the Solr ConfigMap")
configMap := expectConfigMap(ctx, solrCloud, solrCloud.ConfigMapName(), map[string]string{"solr.xml": util.GenerateSolrXMLStringForCloud(solrCloud)})

Expand All @@ -107,7 +103,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace,
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -155,7 +151,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + foundSolrCloud.HeadlessServiceName() + "." + foundSolrCloud.Namespace,
"SOLR_HOST": "$(POD_NAME)." + foundSolrCloud.HeadlessServiceName() + "." + foundSolrCloud.Namespace,
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_LOG_LEVEL": "INFO",
Expand Down Expand Up @@ -209,7 +205,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + foundSolrCloud.HeadlessServiceName() + "." + foundSolrCloud.Namespace,
"SOLR_HOST": "$(POD_NAME)." + foundSolrCloud.HeadlessServiceName() + "." + foundSolrCloud.Namespace,
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_LOG_LEVEL": "INFO",
Expand Down Expand Up @@ -310,7 +306,7 @@ var _ = FDescribe("SolrCloud controller - Backup Repositories", func() {
},
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("testing the Solr ConfigMap")
configMap := expectConfigMap(ctx, solrCloud, solrCloud.ConfigMapName(), map[string]string{"solr.xml": util.GenerateSolrXMLStringForCloud(solrCloud)})

Expand Down
27 changes: 10 additions & 17 deletions controllers/solrcloud_controller_basic_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ import (

var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
var (
ctx context.Context

solrCloud *solrv1beta1.SolrCloud
)

BeforeEach(func() {
ctx = context.Background()

replicas := int32(1)
solrCloud = &solrv1beta1.SolrCloud{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -57,7 +53,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
}
})

JustBeforeEach(func() {
JustBeforeEach(func(ctx context.Context) {
By("creating the SolrCloud")
Expect(k8sClient.Create(ctx, solrCloud)).To(Succeed())

Expand All @@ -67,7 +63,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
})
})

AfterEach(func() {
AfterEach(func(ctx context.Context) {
cleanupTest(ctx, solrCloud)
})

Expand All @@ -78,7 +74,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
ProbesRequireAuth: true,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
expectStatefulSetBasicAuthConfig(ctx, solrCloud, true)
})
})
Expand Down Expand Up @@ -106,7 +102,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
ProbesRequireAuth: true,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
expectStatefulSetBasicAuthConfig(ctx, solrCloud, true)
})
})
Expand All @@ -128,7 +124,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
PasswordKey: "read-only-pass",
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
expectStatefulSetBasicAuthConfig(ctx, solrCloud, true)
})
})
Expand All @@ -139,7 +135,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
AuthenticationType: solrv1beta1.Basic,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("Testing that the statefulSet exists and has the correct information")
expectStatefulSetBasicAuthConfig(ctx, solrCloud, true)

Expand All @@ -161,7 +157,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
BasicAuthSecret: basicAuthSecretName,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("Making sure that no statefulSet exists until the BasicAuth Secret is created")
expectNoStatefulSet(ctx, solrCloud, solrCloud.StatefulSetName())

Expand All @@ -186,7 +182,7 @@ var _ = FDescribe("SolrCloud controller - Basic Auth", func() {
},
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("Making sure that no statefulSet exists until the BasicAuth Secret is created")
expectNoStatefulSet(ctx, solrCloud, solrCloud.StatefulSetName())

Expand Down Expand Up @@ -286,11 +282,8 @@ func expectBasicAuthConfigOnPodTemplateWithGomega(g Gomega, solrCloud *solrv1bet
g.Expect(basicAuthSecretVolMount).To(Not(BeNil()), "No Basic Auth volume mount used in Solr container")
g.Expect(basicAuthSecretVolMount.MountPath).To(Equal("/etc/secrets/"+secretName), "Wrong path used to mount Basic Auth volume")

expProbeCmd := fmt.Sprintf("JAVA_TOOL_OPTIONS=\"-Dbasicauth=$(cat /etc/secrets/%s-solrcloud-basic-auth/username):$(cat /etc/secrets/%s-solrcloud-basic-auth/password)\" java "+
"-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory "+
"-Dsolr.install.dir=\"/opt/solr\" -Dlog4j.configurationFile=\"/opt/solr/server/resources/log4j2-console.xml\" "+
"-classpath \"/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/*:/opt/solr/server/lib/ext/*:/opt/solr/server/lib/*\" "+
"org.apache.solr.util.SolrCLI api -get http://localhost:8983%s",
expProbeCmd := fmt.Sprintf("JAVA_TOOL_OPTIONS=\"-Dbasicauth=$(cat /etc/secrets/%s-solrcloud-basic-auth/username):$(cat /etc/secrets/%s-solrcloud-basic-auth/password) -Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory\" "+
"solr api -get \"http://${POD_NAME}:8983%s\"",
solrCloud.Name, solrCloud.Name, expProbePath)
g.Expect(mainContainer.LivenessProbe).To(Not(BeNil()), "main container should have a liveness probe defined")
g.Expect(mainContainer.LivenessProbe.Exec).To(Not(BeNil()), "liveness probe should have an exec when auth is enabled")
Expand Down
36 changes: 16 additions & 20 deletions controllers/solrcloud_controller_externaldns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ import (

var _ = FDescribe("SolrCloud controller - External DNS", func() {
var (
ctx context.Context

solrCloud *solrv1beta1.SolrCloud
)

BeforeEach(func() {
ctx = context.Background()

replicas := int32(2)
solrCloud = &solrv1beta1.SolrCloud{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -64,7 +60,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
}
})

JustBeforeEach(func() {
JustBeforeEach(func(ctx context.Context) {
By("creating the SolrCloud")
Expect(k8sClient.Create(ctx, solrCloud)).To(Succeed())

Expand All @@ -74,7 +70,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
})
})

AfterEach(func() {
AfterEach(func(ctx context.Context) {
cleanupTest(ctx, solrCloud)
})

Expand All @@ -90,7 +86,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
CommonServicePort: 4000,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("testing the Solr StatefulSet")
statefulSet := expectStatefulSet(ctx, solrCloud, solrCloud.StatefulSetName())

Expand All @@ -102,7 +98,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -164,7 +160,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
CommonServicePort: 5000,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("ensuring the SolrCloud resource is updated with correct specs")
expectSolrCloudWithChecks(ctx, solrCloud, func(g Gomega, found *solrv1beta1.SolrCloud) {
g.Expect(found.Spec.SolrAddressability.External).To(Not(BeNil()), "Solr External addressability settings should not be nullified while setting defaults")
Expand All @@ -182,7 +178,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace,
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -235,7 +231,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
CommonServicePort: 2000,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("ensuring the SolrCloud resource is updated with correct specs")
expectSolrCloudWithChecks(ctx, solrCloud, func(g Gomega, found *solrv1beta1.SolrCloud) {
g.Expect(found.Spec.SolrAddressability.External).To(Not(BeNil()), "Solr External addressability settings should not be nullified while setting defaults")
Expand All @@ -253,7 +249,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -305,7 +301,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
CommonServicePort: 4000,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("ensuring the SolrCloud resource is updated with correct specs")
expectSolrCloudWithChecks(ctx, solrCloud, func(g Gomega, found *solrv1beta1.SolrCloud) {
g.Expect(found.Spec.SolrAddressability.External).To(Not(BeNil()), "Solr External addressability settings should not be nullified while setting defaults")
Expand All @@ -323,7 +319,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace,
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -379,7 +375,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
CommonServicePort: 4000,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("testing the Solr StatefulSet")
statefulSet := expectStatefulSet(ctx, solrCloud, solrCloud.StatefulSetName())

Expand All @@ -391,7 +387,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -453,7 +449,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
KubeDomain: testKubeDomain,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("ensuring the SolrCloud resource is updated with correct specs")
expectSolrCloudWithChecks(ctx, solrCloud, func(g Gomega, found *solrv1beta1.SolrCloud) {
g.Expect(found.Spec.SolrAddressability.External).To(Not(BeNil()), "Solr External addressability settings should not be nullified while setting defaults")
Expand All @@ -471,7 +467,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace + ".svc." + testKubeDomain,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.HeadlessServiceName() + "." + solrCloud.Namespace + ".svc." + testKubeDomain,
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down Expand Up @@ -524,7 +520,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
KubeDomain: testKubeDomain,
}
})
FIt("has the correct resources", func() {
FIt("has the correct resources", func(ctx context.Context) {
By("testing the Solr StatefulSet")
statefulSet := expectStatefulSet(ctx, solrCloud, solrCloud.StatefulSetName())

Expand All @@ -536,7 +532,7 @@ var _ = FDescribe("SolrCloud controller - External DNS", func() {
// Env Variable Tests
expectedEnvVars := map[string]string{
"ZK_HOST": "host:7271/",
"SOLR_HOST": "$(POD_HOSTNAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_HOST": "$(POD_NAME)." + solrCloud.Namespace + "." + testDomain,
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)",
Expand Down
Loading

0 comments on commit 696faff

Please sign in to comment.