Skip to content

Commit 8968879

Browse files
Removing port mapping from headless service. (#87)
Note: This will change the hostname and port of all SolrClouds utilizing headlessServices
1 parent 48f6329 commit 8968879

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ service/example-solrcloud-1 ClusterIP ##.###.##.# <none>
127127
service/example-solrcloud-2 ClusterIP ##.###.###.## <none> 80/TCP 47h
128128
service/example-solrcloud-3 ClusterIP ##.###.##.### <none> 80/TCP 47h
129129
service/example-solrcloud-common ClusterIP ##.###.###.### <none> 80/TCP 47h
130-
service/example-solrcloud-headless ClusterIP None <none> 80/TCP 47h
130+
service/example-solrcloud-headless ClusterIP None <none> 8983/TCP 47h
131131
service/example-solrcloud-zk-client ClusterIP ##.###.###.### <none> 21210/TCP 49d
132132
service/example-solrcloud-zk-headless ClusterIP None <none> 22210/TCP,23210/TCP 49d
133133

@@ -407,6 +407,9 @@ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/mast
407407

408408
## Version Compatibility & Upgrade Notes
409409

410+
#### v0.2.3
411+
- If you do not use an ingress with the Solr Operator, the Solr Hostname and Port will change when upgrading to this version. This is to fix an outstanding bug. Because of the headless service port change, you will likely see an outage for inter-node communication until all pods have been restarted.
412+
410413
#### v0.2.2
411414
- `SolrCloud.spec.solrPodPolicy` has been **DEPRECATED** in favor of the `SolrCloud.spec.customSolrKubeOptions.podOptions` option.
412415
This option is backwards compatible, but will be removed in a future version (`v0.3.0`).

api/v1beta1/solrcloud_types.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,34 @@ func (sc *SolrCloud) NodeIngressUrl(nodeName string, ingressBaseUrl string) stri
699699
return fmt.Sprintf("%s.%s", sc.NodeIngressPrefix(nodeName), ingressBaseUrl)
700700
}
701701

702+
func (sc *SolrCloud) NodeHeadlessUrl(nodeName string, withPort bool) string {
703+
url := fmt.Sprintf("%s.%s.%s", nodeName, sc.HeadlessServiceName(), sc.Namespace)
704+
if withPort {
705+
url += ":8983"
706+
}
707+
return url
708+
}
709+
710+
func (sc *SolrCloud) NodeServiceUrl(nodeName string) string {
711+
return fmt.Sprintf("%s.%s", nodeName, sc.Namespace)
712+
}
713+
714+
func (sc *SolrCloud) InternalNodeUrl(nodeName string, useHeadlessService bool, withPort bool) string {
715+
if useHeadlessService {
716+
return sc.NodeHeadlessUrl(nodeName, withPort)
717+
} else {
718+
return sc.NodeServiceUrl(nodeName)
719+
}
720+
}
721+
722+
func (sc *SolrCloud) ExternalNodeUrl(nodeName string, ingressBaseDomain string, withPort bool) string {
723+
if ingressBaseDomain == "" {
724+
return sc.NodeHeadlessUrl(nodeName, withPort)
725+
} else {
726+
return sc.NodeIngressUrl(nodeName, ingressBaseDomain)
727+
}
728+
}
729+
702730
func (sc *SolrCloud) SharedLabels() map[string]string {
703731
return sc.SharedLabelsWith(map[string]string{})
704732
}

controllers/solrcloud_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func reconcileCloudStatus(r *SolrCloudReconciler, solrCloud *solr.SolrCloud, new
322322
nodeNames[idx] = p.Name
323323
nodeStatus := solr.SolrNodeStatus{}
324324
nodeStatus.NodeName = p.Name
325-
nodeStatus.InternalAddress = fmt.Sprintf("http://%s.%s.svc.cluster.local", p.Name, p.Namespace)
325+
nodeStatus.InternalAddress = "http://" + solrCloud.InternalNodeUrl(nodeStatus.NodeName, IngressBaseUrl == "", true)
326326
if IngressBaseUrl != "" {
327327
nodeStatus.ExternalAddress = "http://" + solrCloud.NodeIngressUrl(nodeStatus.NodeName, IngressBaseUrl)
328328
}

controllers/solrcloud_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestCloudReconcile(t *testing.T) {
115115
// Env Variable Tests
116116
expectedEnvVars := map[string]string{
117117
"ZK_HOST": "host:7271/",
118-
"SOLR_HOST": "$(POD_HOSTNAME)." + instance.HeadlessServiceName(),
118+
"SOLR_HOST": "$(POD_HOSTNAME)." + instance.HeadlessServiceName() + "." + instance.Namespace,
119119
"SOLR_JAVA_MEM": "-Xmx4G",
120120
"SOLR_PORT": "8983",
121121
"SOLR_LOG_LEVEL": "DEBUG",

controllers/util/solr_util.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
164164
}
165165

166166
// if an ingressBaseDomain is provided, the node should be addressable outside of the cluster
167-
solrHostName := "$(POD_HOSTNAME)." + solrCloud.HeadlessServiceName()
167+
solrHostName := solrCloud.ExternalNodeUrl("$(POD_HOSTNAME)", ingressBaseDomain, false)
168+
solrAdressingPort := 8983
168169
if ingressBaseDomain != "" {
169-
solrHostName = solrCloud.NodeIngressUrl("$(POD_HOSTNAME)", ingressBaseDomain)
170+
solrAdressingPort = 80
170171
}
171172

172173
// Environment Variables
@@ -279,6 +280,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
279280
},
280281
},
281282
VolumeMounts: volumeMounts,
283+
Args: []string{"-DhostPort=" + strconv.Itoa(solrAdressingPort)},
282284
Env: envVars,
283285
LivenessProbe: &corev1.Probe{
284286
InitialDelaySeconds: 20,
@@ -471,7 +473,7 @@ func GenerateConfigMap(solrCloud *solr.SolrCloud) *corev1.ConfigMap {
471473
<solr>
472474
<solrcloud>
473475
<str name="host">${host:}</str>
474-
<int name="hostPort">80</int>
476+
<int name="hostPort">${hostPort:80}</int>
475477
<str name="hostContext">${hostContext:solr}</str>
476478
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
477479
<int name="zkClientTimeout">${zkClientTimeout:30000}</int>
@@ -569,7 +571,7 @@ func GenerateHeadlessService(solrCloud *solr.SolrCloud) *corev1.Service {
569571
},
570572
Spec: corev1.ServiceSpec{
571573
Ports: []corev1.ServicePort{
572-
{Name: ExtSolrClientPortName, Port: ExtSolrClientPort, Protocol: corev1.ProtocolTCP, TargetPort: intstr.FromInt(SolrClientPort)},
574+
{Name: SolrClientPortName, Port: SolrClientPort, Protocol: corev1.ProtocolTCP, TargetPort: intstr.FromInt(SolrClientPort)},
573575
},
574576
Selector: selectorLabels,
575577
ClusterIP: corev1.ClusterIPNone,

0 commit comments

Comments
 (0)