This is an automated email from the ASF dual-hosted git repository.
HoustonPutman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 2764dee8 Expose the node's zone label to Solr as availability_zone
(#892)
2764dee8 is described below
commit 2764dee8d6679eb1a6aee8ddd96a4e7a735f2b22
Author: Jan Høydahl <[email protected]>
AuthorDate: Mon Nov 16 20:40:25 2026 +0100
Expose the node's zone label to Solr as availability_zone (#892)
Set the spread_domain system property to the Kubernetes node each Solr pod
runs on. With spreadAcrossDomains enabled in the AffinityPlacementFactory,
Solr then puts replicas of a shard on different Kubernetes nodes within
a zone.
---------
Co-authored-by: Copilot Autofix powered by AI
<[email protected]>
Co-authored-by: Houston Putman <[email protected]>
---
controllers/solrcloud_controller_backup_test.go | 6 +--
.../solrcloud_controller_externaldns_test.go | 14 +++----
controllers/solrcloud_controller_ingress_test.go | 14 +++----
controllers/solrcloud_controller_test.go | 46 ++++++++++++++++++--
controllers/solrcloud_controller_zk_test.go | 10 ++---
controllers/util/solr_util.go | 25 ++++++++++-
docs/modules/solr-cloud/pages/solr-cloud-crd.adoc | 15 +++++++
.../modules/upgrade-notes/pages/upgrade-notes.adoc | 5 +++
helm/solr-operator/Chart.yaml | 7 ++++
tests/e2e/solrcloud_basic_test.go | 6 ++-
tests/e2e/test_utils_test.go | 49 ++++++++++++++++++++++
tests/scripts/e2e-kind-config.yaml | 6 +++
12 files changed, 175 insertions(+), 28 deletions(-)
diff --git a/controllers/solrcloud_controller_backup_test.go
b/controllers/solrcloud_controller_backup_test.go
index d7531c7d..f5924f92 100644
--- a/controllers/solrcloud_controller_backup_test.go
+++ b/controllers/solrcloud_controller_backup_test.go
@@ -108,7 +108,7 @@ var _ = FDescribe("SolrCloud controller - Backup
Repositories", func() {
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
foundEnv :=
statefulSet.Spec.Template.Spec.Containers[0].Env
@@ -158,7 +158,7 @@ var _ = FDescribe("SolrCloud controller - Backup
Repositories", func() {
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
"SOLR_LOG_LEVEL": "INFO",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
foundEnv :=
found.Spec.Template.Spec.Containers[0].Env
@@ -213,7 +213,7 @@ var _ = FDescribe("SolrCloud controller - Backup
Repositories", func() {
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
"SOLR_LOG_LEVEL": "INFO",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
foundEnv :=
found.Spec.Template.Spec.Containers[0].Env
diff --git a/controllers/solrcloud_controller_externaldns_test.go
b/controllers/solrcloud_controller_externaldns_test.go
index 0cd0bcc5..1ea2293b 100644
--- a/controllers/solrcloud_controller_externaldns_test.go
+++ b/controllers/solrcloud_controller_externaldns_test.go
@@ -102,7 +102,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_PORT_ADVERTISE": "3000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -181,7 +181,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_PORT_ADVERTISE": "2000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "2000"}), "Incorrect pre-stop command")
@@ -253,7 +253,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_PORT_ADVERTISE": "3000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -324,7 +324,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_PORT_ADVERTISE": "3000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -393,7 +393,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_PORT_ADVERTISE": "3000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -474,7 +474,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_PORT_ADVERTISE": "2000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "2000"}), "Incorrect pre-stop command")
@@ -540,7 +540,7 @@ var _ = FDescribe("SolrCloud controller - External DNS",
func() {
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_PORT_ADVERTISE": "2000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "2000"}), "Incorrect pre-stop command")
diff --git a/controllers/solrcloud_controller_ingress_test.go
b/controllers/solrcloud_controller_ingress_test.go
index 87fb57b6..07a62852 100644
--- a/controllers/solrcloud_controller_ingress_test.go
+++ b/controllers/solrcloud_controller_ingress_test.go
@@ -118,7 +118,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "100",
"SOLR_PORT_ADVERTISE": "100",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -306,7 +306,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "3000",
"SOLR_PORT_ADVERTISE": "3000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -384,7 +384,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "100",
"SOLR_PORT_ADVERTISE": "100",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -460,7 +460,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "100",
"SOLR_PORT_ADVERTISE": "100",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -538,7 +538,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "100",
"SOLR_PORT_ADVERTISE": "100",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -612,7 +612,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "100",
"SOLR_PORT_ADVERTISE": "100",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
@@ -689,7 +689,7 @@ var _ = FDescribe("SolrCloud controller - Ingress", func() {
"SOLR_PORT": "3000",
"SOLR_NODE_PORT": "100",
"SOLR_PORT_ADVERTISE": "100",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal([]string{"solr",
"stop", "-p", "3000"}), "Incorrect pre-stop command")
diff --git a/controllers/solrcloud_controller_test.go
b/controllers/solrcloud_controller_test.go
index abca59ae..a56a8206 100644
--- a/controllers/solrcloud_controller_test.go
+++ b/controllers/solrcloud_controller_test.go
@@ -127,7 +127,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
"SOLR_LOG_LEVEL": "DEBUG",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) extra-opts",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN) extra-opts",
}
foundEnv :=
statefulSet.Spec.Template.Spec.Containers[0].Env
// Note that this check changes the variable foundEnv,
so the values are no longer valid afterwards.
@@ -306,7 +306,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
"GC_TUNE": "gc Options",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
"SOLR_STOP_WAIT":
strconv.FormatInt(testTerminationGracePeriodSeconds-5, 10),
}
expectedStatefulSetLabels :=
util.MergeLabelsOrAnnotations(solrCloud.SharedLabelsWith(solrCloud.Labels),
map[string]string{"technology": util.SolrCloudPVCTechnology})
@@ -511,7 +511,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
"SOLR_PORT": "2000",
"SOLR_NODE_PORT": "2000",
"SOLR_PORT_ADVERTISE": "2000",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT)",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
By("testing the Solr Common Service")
@@ -542,6 +542,46 @@ var _ = FDescribe("SolrCloud controller - General", func()
{
})
})
+ FContext("Solr Cloud availability zone and spread domain", func() {
+ BeforeEach(func() {
+ solrCloud.Spec = solrv1beta1.SolrCloudSpec{
+ ZookeeperRef: &solrv1beta1.ZookeeperRef{
+ ConnectionInfo:
&solrv1beta1.ZookeeperConnectionInfo{
+ InternalConnectionString:
"host:7271",
+ },
+ },
+ }
+ })
+ FIt("has the correct resources", func(ctx context.Context) {
+ By("testing the Solr StatefulSet")
+ statefulSet := expectStatefulSet(ctx, solrCloud,
solrCloud.StatefulSetName())
+
+ testPodEnvVariables(map[string]string{
+ "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)
-Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN)",
+ }, statefulSet.Spec.Template.Spec.Containers[0].Env)
+
+ var zoneEnvVar *corev1.EnvVar
+ for _, envVar := range
statefulSet.Spec.Template.Spec.Containers[0].Env {
+ if envVar.Name == "SOLR_AVAILABILITY_ZONE" {
+ zoneEnvVar = &envVar
+ break
+ }
+ }
+ Expect(zoneEnvVar).To(Not(BeNil()),
"SOLR_AVAILABILITY_ZONE env var should be set")
+
Expect(zoneEnvVar.ValueFrom.FieldRef.FieldPath).To(Equal("metadata.labels['topology.kubernetes.io/zone']"),
"Wrong fieldRef for the availability zone env var")
+
+ var spreadDomainEnvVar *corev1.EnvVar
+ for _, envVar := range
statefulSet.Spec.Template.Spec.Containers[0].Env {
+ if envVar.Name == "SOLR_SPREAD_DOMAIN" {
+ spreadDomainEnvVar = &envVar
+ break
+ }
+ }
+ Expect(spreadDomainEnvVar).To(Not(BeNil()),
"SOLR_SPREAD_DOMAIN env var should be set")
+
Expect(spreadDomainEnvVar.ValueFrom.FieldRef.FieldPath).To(Equal("spec.nodeName"),
"Wrong fieldRef for the spread domain env var")
+ })
+ })
+
FContext("Solr Cloud with changing generated SolrXML", func() {
BeforeEach(func() {
solrCloud.Spec = solrv1beta1.SolrCloudSpec{
diff --git a/controllers/solrcloud_controller_zk_test.go
b/controllers/solrcloud_controller_zk_test.go
index 1619e766..db17a4a8 100644
--- a/controllers/solrcloud_controller_zk_test.go
+++ b/controllers/solrcloud_controller_zk_test.go
@@ -109,7 +109,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper",
func() {
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
}
insertExpectedAclEnvVars(expectedEnvVars, false)
for _, envVar := range extraVars {
@@ -175,7 +175,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper",
func() {
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
}
insertExpectedAclEnvVars(expectedEnvVars, true)
for _, envVar := range extraVars {
@@ -459,7 +459,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper",
func() {
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
"ZK_CHROOT": "/a-ch/root",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
}
insertExpectedAclEnvVars(expectedEnvVars, false)
for _, envVar := range extraVars {
@@ -535,7 +535,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper",
func() {
"SOLR_PORT": "8983",
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN) $(SOLR_ZK_CREDS_AND_ACLS) -Dextra -Dopts",
}
insertExpectedAclEnvVars(expectedEnvVars, true)
for _, envVar := range extraVars {
@@ -577,7 +577,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper",
func() {
"SOLR_NODE_PORT": "8983",
"SOLR_PORT_ADVERTISE": "8983",
"SOLR_ZK_OPTS": testSolrZKOpts,
- "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) $(SOLR_ZK_OPTS) " + testSolrOpts,
+ "SOLR_OPTS":
"-DhostPort=$(SOLR_NODE_PORT) -Davailability_zone=$(SOLR_AVAILABILITY_ZONE)
-Dspread_domain=$(SOLR_SPREAD_DOMAIN) $(SOLR_ZK_OPTS) " + testSolrOpts,
"SOLR_STOP_WAIT": strconv.FormatInt(60-5,
10),
}
testPodEnvVariables(expectedEnvVars,
statefulSet.Spec.Template.Spec.Containers[0].Env)
diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go
index 64c0b92d..89fddae1 100644
--- a/controllers/util/solr_util.go
+++ b/controllers/util/solr_util.go
@@ -153,7 +153,9 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud,
solrCloudStatus *solr.SolrCl
// Keep track of the SolrOpts that the Solr Operator needs to set
// These will be added to the SolrOpts given by the user.
- allSolrOpts := []string{"-DhostPort=$(SOLR_NODE_PORT)"}
+ // The "availability_zone" and "spread_domain" system properties are
used by Solr's AffinityPlacementFactory
+ // to spread replicas across zones, and across Kubernetes nodes within
a zone
+ allSolrOpts := []string{"-DhostPort=$(SOLR_NODE_PORT)",
"-Davailability_zone=$(SOLR_AVAILABILITY_ZONE)",
"-Dspread_domain=$(SOLR_SPREAD_DOMAIN)"}
// Volumes & Mounts
solrVolumes := []corev1.Volume{
@@ -389,6 +391,27 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud,
solrCloudStatus *solr.SolrCl
},
},
},
+ {
+ // The PodTopologyLabels admission plugin (beta and
enabled by default since Kubernetes v1.35) copies the
+ // node's zone label onto the pod. Without it the label
is missing, which resolves to an empty value.
+ Name: "SOLR_AVAILABILITY_ZONE",
+ ValueFrom: &corev1.EnvVarSource{
+ FieldRef: &corev1.ObjectFieldSelector{
+ FieldPath:
fmt.Sprintf("metadata.labels['%s']", corev1.LabelTopologyZone),
+ APIVersion: "v1",
+ },
+ },
+ },
+ {
+ // The Kubernetes node, so that replicas of a shard can
be spread across nodes within a zone
+ Name: "SOLR_SPREAD_DOMAIN",
+ ValueFrom: &corev1.EnvVarSource{
+ FieldRef: &corev1.ObjectFieldSelector{
+ FieldPath: "spec.nodeName",
+ APIVersion: "v1",
+ },
+ },
+ },
{
Name: "SOLR_HOST",
Value: solrHostName,
diff --git a/docs/modules/solr-cloud/pages/solr-cloud-crd.adoc
b/docs/modules/solr-cloud/pages/solr-cloud-crd.adoc
index d77dcc58..263b09f5 100644
--- a/docs/modules/solr-cloud/pages/solr-cloud-crd.adoc
+++ b/docs/modules/solr-cloud/pages/solr-cloud-crd.adoc
@@ -49,6 +49,21 @@ NOTE: Both properties work by adding a `sharedLib` element
to the `solr.xml` tha
If you provide your own `solr.xml` through `providedConfigMap`, they have no
effect, and you must list the library directories in your custom `solr.xml`
yourself.
See xref:custom-solr-config.adoc#solr-xml-managed-elements[Elements the
operator normally generates for you].
+=== Availability Zone Awareness
+
+Solr's
https://solr.apache.org/guide/solr/latest/configuration-guide/replica-placement-plugins.html#affinityplacementfactory[AffinityPlacementFactory]
spreads replicas across availability zones, using the `availability_zone`
system property of each Solr node.
+
+The operator always sets this system property, from the
`topology.kubernetes.io/zone` label of the Kubernetes node each Solr pod runs
on.
+There is nothing to configure in the SolrCloud resource, but the
`AffinityPlacementFactory` still has to be enabled in Solr to make use of it.
+
+Kubernetes only makes the node's zone label available to the pod through the
https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podtopologylabels[PodTopologyLabels]
admission plugin, which is enabled by default since `v1.35`.
+On older versions, or when the plugin is disabled or the node has no zone
label, the system property is empty.
+Solr then places replicas as if all nodes were in one zone, which is the same
as when no availability zones are used at all.
+
+The operator also sets the `spread_domain` system property to the name of the
Kubernetes node each Solr pod runs on.
+When `spreadAcrossDomains` is enabled in the `AffinityPlacementFactory`
configuration, Solr places the replicas of a shard on different Kubernetes
nodes within each zone, so that losing a single Kubernetes node does not take
down all replicas of a shard.
+Unlike the zone, the node name is always available, on every Kubernetes
version.
+
== Data Storage
The SolrCloud CRD gives the option for users to use either
diff --git a/docs/modules/upgrade-notes/pages/upgrade-notes.adoc
b/docs/modules/upgrade-notes/pages/upgrade-notes.adoc
index c4caa07e..b631f940 100644
--- a/docs/modules/upgrade-notes/pages/upgrade-notes.adoc
+++ b/docs/modules/upgrade-notes/pages/upgrade-notes.adoc
@@ -154,6 +154,11 @@ Mount the `solr.xml` ConfigMap into such a container if it
needs the current con
** The permission fixing that `cp-solr-xml` also did for `volume`
`backupRepositories` has moved to a new `volume-prep` initContainer, which is
only created for SolrClouds that have a `volume` `backupRepository`.
All other Solr pods now start without any volume prep initContainer.
+* Solr pods now get the `availability_zone` system property, set from the
`topology.kubernetes.io/zone` label of the node they run on, for Solr's
xref:solr-cloud:solr-cloud-crd.adoc#availability-zone-awareness[AffinityPlacementFactory].
+The label is only copied onto pods by Kubernetes `v1.35`+, and the property is
empty on older versions, which leaves replica placement unchanged.
+Solr pods also get the `spread_domain` system property, set to the name of
their Kubernetes node, which Solr only uses when `spreadAcrossDomains` is
enabled in the `AffinityPlacementFactory` configuration.
+These are part of the same pod spec change that restarts the Solr pods during
this upgrade, so they do not cause an additional restart.
+
=== v0.8.0
* *The minimum supported Solr version is now 8.11*
diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml
index 9b5e6ffc..25878ea8 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -167,6 +167,13 @@ annotations:
url: https://github.com/apache/solr-operator/issues/707
- name: Github PR
url: https://github.com/apache/solr-operator/pull/876
+ - kind: added
+ description: Solr pods now get the availability_zone system property,
used by Solr's AffinityPlacementFactory, from the topology.kubernetes.io/zone
label of their Kubernetes node. The label is copied onto pods by Kubernetes
v1.35+, and the property is empty on older versions. Solr pods also get the
spread_domain system property, set to the name of their Kubernetes node
+ links:
+ - name: Github Issue
+ url: https://github.com/apache/solr-operator/issues/556
+ - name: Github PR
+ url: https://github.com/apache/solr-operator/pull/892
artifacthub.io/images: |
- name: solr-operator
image: apache/solr-operator:v0.10.0-prerelease
diff --git a/tests/e2e/solrcloud_basic_test.go
b/tests/e2e/solrcloud_basic_test.go
index 5eb8ff72..b1a214f6 100644
--- a/tests/e2e/solrcloud_basic_test.go
+++ b/tests/e2e/solrcloud_basic_test.go
@@ -59,7 +59,9 @@ var _ = FDescribe("E2E - SolrCloud - Basic", func() {
}
})
- // All testing will be done in the "JustBeforeEach" logic, no
additional tests required here
- FIt("Starts correctly", func(ctx context.Context) {})
+ FIt("Starts correctly", func(ctx context.Context) {
+ By("checking that Solr was given its node and, if
Kubernetes supports it, its node's zone for replica placement")
+ expectPlacementSystemProperties(ctx, solrCloud)
+ })
})
})
diff --git a/tests/e2e/test_utils_test.go b/tests/e2e/test_utils_test.go
index 240ee4ce..6af44548 100644
--- a/tests/e2e/test_utils_test.go
+++ b/tests/e2e/test_utils_test.go
@@ -47,6 +47,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"
+ utilversion "k8s.io/apimachinery/pkg/util/version"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -513,6 +514,54 @@ func callSolrApiInPod(ctx context.Context, solrCloud
*solrv1beta1.SolrCloud, htt
return runExecForContainer(ctx, util.SolrNodeContainer,
solrCloud.GetRandomSolrPodName(), solrCloud.Namespace, command)
}
+// podTopologyLabelsMinVersion is the first Kubernetes version with the
PodTopologyLabels admission plugin enabled by
+// default (beta). It copies the node's topology labels, including the zone,
onto each pod when it is scheduled.
+var podTopologyLabelsMinVersion = utilversion.MajorMinor(1, 35)
+
+// expectPlacementSystemProperties checks the system properties that every
Solr node reports for Solr's
+// AffinityPlacementFactory. The "availability_zone" must match the Kubernetes
version under test: the zone label of the
+// node the pod runs on when the cluster copies node topology labels onto
pods, and an empty value otherwise.
+// The "spread_domain" is always the name of the node the pod runs on.
+func expectPlacementSystemProperties(ctx context.Context, solrCloud
*solrv1beta1.SolrCloud, additionalOffset ...int) {
+ offset := resolveOffset(additionalOffset)
+
+ serverVersion, err := rawK8sClient.Discovery().ServerVersion()
+ ExpectWithOffset(offset, err).ToNot(HaveOccurred(), "Could not fetch
the Kubernetes server version")
+ parsedVersion, err := utilversion.ParseGeneric(serverVersion.GitVersion)
+ ExpectWithOffset(offset, err).ToNot(HaveOccurred(), "Could not parse
the Kubernetes server version %s", serverVersion.GitVersion)
+ podTopologyLabelsEnabled :=
parsedVersion.AtLeast(podTopologyLabelsMinVersion)
+
+ for _, podName := range solrCloud.GetAllSolrPodNames() {
+ pod := expectPodNow(ctx, solrCloud, podName, offset)
+ node, err := rawK8sClient.CoreV1().Nodes().Get(ctx,
pod.Spec.NodeName, metav1.GetOptions{})
+ ExpectWithOffset(offset, err).ToNot(HaveOccurred(), "Could not
fetch node %s of pod %s", pod.Spec.NodeName, podName)
+
+ expectedZone := ""
+ if podTopologyLabelsEnabled {
+ expectedZone = node.Labels[corev1.LabelTopologyZone]
+ }
+ ExpectWithOffset(offset,
pod.Labels[corev1.LabelTopologyZone]).To(Equal(expectedZone),
+ "Pod %s has the wrong zone label for Kubernetes %s
(node %s is in zone %q)", podName, serverVersion.GitVersion, node.Name,
node.Labels[corev1.LabelTopologyZone])
+
+ EventuallyWithOffset(offset, func(g Gomega) {
+ response, err := runExecForContainer(ctx,
util.SolrNodeContainer, podName, solrCloud.Namespace, []string{
+ "curl", "-sSk",
+
fmt.Sprintf("\"%s://localhost:${SOLR_PORT}/solr/admin/info/properties?wt=json\"",
solrCloud.UrlScheme(false)),
+ })
+ g.Expect(err).ToNot(HaveOccurred(), "Could not fetch
the system properties of Solr pod %s", podName)
+
+ properties := &struct {
+ SystemProperties map[string]string
`json:"system.properties"`
+ }{}
+ g.Expect(json.Unmarshal([]byte(response),
properties)).To(Succeed(), "Could not parse the system properties response:
%s", response)
+
g.Expect(properties.SystemProperties).To(HaveKeyWithValue("availability_zone",
expectedZone),
+ "Solr pod %s has the wrong availability_zone
for Kubernetes %s", podName, serverVersion.GitVersion)
+
g.Expect(properties.SystemProperties).To(HaveKeyWithValue("spread_domain",
pod.Spec.NodeName),
+ "Solr pod %s should have its node as the
spread_domain", podName)
+ }).Should(Succeed())
+ }
+}
+
func runExecForContainer(ctx context.Context, container string, podName
string, namespace string, command []string) (response string, err error) {
req := rawK8sClient.CoreV1().RESTClient().Post().
Resource("pods").
diff --git a/tests/scripts/e2e-kind-config.yaml
b/tests/scripts/e2e-kind-config.yaml
index c55cfa98..137b4271 100644
--- a/tests/scripts/e2e-kind-config.yaml
+++ b/tests/scripts/e2e-kind-config.yaml
@@ -22,11 +22,17 @@ nodes:
- hostPath: /tmp/backup
containerPath: /tmp/backup
- role: worker
+ # Each worker is in its own zone, so tests can check that Solr is given
the zone of its node
+ labels:
+ topology.kubernetes.io/zone: e2e-zone-a
# add a mount from /path/to/my/files on the host to /files on the node
extraMounts:
- hostPath: /tmp/backup
containerPath: /tmp/backup
- role: worker
+ # Each worker is in its own zone, so tests can check that Solr is given
the zone of its node
+ labels:
+ topology.kubernetes.io/zone: e2e-zone-b
# add a mount from /path/to/my/files on the host to /files on the node
extraMounts:
- hostPath: /tmp/backup