Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same portName as targetPort in service and fix Status bugs. #145

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Please visit the following pages for documentation on using and developing the S

## Version Compatibility & Upgrade Notes

#### v0.2.7
- The `SolrCloud` and `SolrPrometheusExporter` services' portNames have changed to `"solr-client"` and `"solr-metrics"` from `"ext-solr-client"` and `"ext-solr-metrics"`, respectively.
This is due to a bug in Kubernetes where `portName` and `targetPort` must match for services.

#### v0.2.6
- The solr-operator argument `--ingressBaseDomain` has been **DEPRECATED**.
In order to set the external baseDomain of your clouds, please begin to use `SolrCloud.spec.solrAddressability.external.domainName` instead.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/solrcloud_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func (sc *SolrCloud) InternalNodeUrl(nodeName string, withPort bool) string {
func (sc *SolrCloud) InternalCommonUrl(withPort bool) (url string) {
url = fmt.Sprintf("%s.%s", sc.CommonServiceName(), sc.Namespace) + sc.customKubeDomain()
if withPort {
url += sc.NodePortSuffix()
url += sc.CommonPortSuffix()
}
return url
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/solrcloud_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ func reconcileCloudStatus(r *SolrCloudReconciler, solrCloud *solr.SolrCloud, new
nodeStatus := solr.SolrNodeStatus{}
nodeStatus.Name = p.Name
nodeStatus.NodeName = p.Spec.NodeName
nodeStatus.InternalAddress = "http://" + solrCloud.InternalNodeUrl(nodeStatus.NodeName, true)
if solrCloud.Spec.SolrAddressability.External != nil {
nodeStatus.InternalAddress = "http://" + solrCloud.InternalNodeUrl(nodeStatus.Name, true)
if solrCloud.Spec.SolrAddressability.External != nil && !solrCloud.Spec.SolrAddressability.External.HideNodes {
nodeStatus.ExternalAddress = "http://" + solrCloud.ExternalNodeUrl(nodeStatus.Name, solrCloud.Spec.SolrAddressability.External.DomainName, true)
}
ready := false
Expand Down Expand Up @@ -376,7 +376,7 @@ func reconcileCloudStatus(r *SolrCloudReconciler, solrCloud *solr.SolrCloud, new
}

newStatus.InternalCommonAddress = "http://" + solrCloud.InternalCommonUrl(true)
if solrCloud.Spec.SolrAddressability.External != nil {
if solrCloud.Spec.SolrAddressability.External != nil && !solrCloud.Spec.SolrAddressability.External.HideCommon {
extAddress := "http://" + solrCloud.ExternalCommonUrl(solrCloud.Spec.SolrAddressability.External.DomainName, true)
newStatus.ExternalCommonAddress = &extAddress
}
Expand Down
47 changes: 47 additions & 0 deletions controllers/solrcloud_controller_externaldns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestEDSCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "common service annotations", expectedCommonServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 4000, service.Spec.Ports[0].Port, "Wrong port on common Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on common Service")

Expand All @@ -131,6 +132,7 @@ func TestEDSCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "headless service annotations", expectedHeadlessServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 3000, service.Spec.Ports[0].Port, "Wrong port on headless Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on headless Service")

Expand All @@ -143,6 +145,12 @@ func TestEDSCloudReconcile(t *testing.T) {

// Check the ingress
expectNoIngress(g, cloudIKey)

// Check that the Addresses in the status are correct
g.Eventually(func() error { return testClient.Get(context.TODO(), expectedCloudRequest.NamespacedName, instance) }, timeout).Should(gomega.Succeed())
assert.Equal(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+":4000", instance.Status.InternalCommonAddress, "Wrong internal common address in status")
assert.NotNil(t, instance.Status.ExternalCommonAddress, "External common address in Status should not be nil.")
assert.EqualValues(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+"."+testDomain+":4000", *instance.Status.ExternalCommonAddress, "Wrong external common address in status")
}

func TestEDSNoNodesCloudReconcile(t *testing.T) {
Expand Down Expand Up @@ -234,12 +242,14 @@ func TestEDSNoNodesCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "common service annotations", expectedCommonServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 5000, service.Spec.Ports[0].Port, "Wrong port on common Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on common Service")

// Check the headless Service
service = expectService(t, g, requests, expectedCloudRequest, cloudHsKey, statefulSet.Spec.Template.Labels)
testMapsEqual(t, "headless service annotations", testHeadlessServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 2000, service.Spec.Ports[0].Port, "Wrong port on headless Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on headless Service")

Expand All @@ -252,6 +262,12 @@ func TestEDSNoNodesCloudReconcile(t *testing.T) {

// Check the ingress
expectNoIngress(g, cloudIKey)

// Check that the Addresses in the status are correct
g.Eventually(func() error { return testClient.Get(context.TODO(), expectedCloudRequest.NamespacedName, instance) }, timeout).Should(gomega.Succeed())
assert.Equal(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+":5000", instance.Status.InternalCommonAddress, "Wrong internal common address in status")
assert.NotNil(t, instance.Status.ExternalCommonAddress, "External common address in Status should not be nil.")
assert.EqualValues(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+"."+testDomain+":5000", *instance.Status.ExternalCommonAddress, "Wrong external common address in status")
}

func TestEDSNoCommonCloudReconcile(t *testing.T) {
Expand Down Expand Up @@ -340,6 +356,7 @@ func TestEDSNoCommonCloudReconcile(t *testing.T) {
// Check the client Service
service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels)
testMapsEqual(t, "common service annotations", testCommonServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 2000, service.Spec.Ports[0].Port, "Wrong port on common Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on common Service")

Expand All @@ -349,6 +366,7 @@ func TestEDSNoCommonCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "headless service annotations", expectedHeadlessServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 3000, service.Spec.Ports[0].Port, "Wrong port on headless Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on headless Service")

Expand All @@ -361,6 +379,11 @@ func TestEDSNoCommonCloudReconcile(t *testing.T) {

// Check the ingress
expectNoIngress(g, cloudIKey)

// Check that the Addresses in the status are correct
g.Eventually(func() error { return testClient.Get(context.TODO(), expectedCloudRequest.NamespacedName, instance) }, timeout).Should(gomega.Succeed())
assert.Equal(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+":2000", instance.Status.InternalCommonAddress, "Wrong internal common address in status")
assert.Nil(t, instance.Status.ExternalCommonAddress, "External common address in status should be nil")
}

func TestEDSUseInternalAddressCloudReconcile(t *testing.T) {
Expand Down Expand Up @@ -452,6 +475,7 @@ func TestEDSUseInternalAddressCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "common service annotations", expectedCommonServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 4000, service.Spec.Ports[0].Port, "Wrong port on common Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on common Service")

Expand All @@ -461,6 +485,7 @@ func TestEDSUseInternalAddressCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "headless service annotations", expectedHeadlessServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 3000, service.Spec.Ports[0].Port, "Wrong port on headless Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on headless Service")

Expand All @@ -473,6 +498,12 @@ func TestEDSUseInternalAddressCloudReconcile(t *testing.T) {

// Check the ingress
expectNoIngress(g, cloudIKey)

// Check that the Addresses in the status are correct
g.Eventually(func() error { return testClient.Get(context.TODO(), expectedCloudRequest.NamespacedName, instance) }, timeout).Should(gomega.Succeed())
assert.Equal(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+":4000", instance.Status.InternalCommonAddress, "Wrong internal common address in status")
assert.NotNil(t, instance.Status.ExternalCommonAddress, "External common address in Status should not be nil.")
assert.EqualValues(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+"."+testDomain+":4000", *instance.Status.ExternalCommonAddress, "Wrong external common address in status")
}

func TestEDSExtraDomainsCloudReconcile(t *testing.T) {
Expand Down Expand Up @@ -569,6 +600,7 @@ func TestEDSExtraDomainsCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": hostnameAnnotation,
})
testMapsEqual(t, "common service annotations", expectedCommonServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 4000, service.Spec.Ports[0].Port, "Wrong port on common Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on common Service")

Expand All @@ -578,6 +610,7 @@ func TestEDSExtraDomainsCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": hostnameAnnotation,
})
testMapsEqual(t, "headless service annotations", expectedHeadlessServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 3000, service.Spec.Ports[0].Port, "Wrong port on headless Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on headless Service")

Expand All @@ -590,6 +623,12 @@ func TestEDSExtraDomainsCloudReconcile(t *testing.T) {

// Check the ingress
expectNoIngress(g, cloudIKey)

// Check that the Addresses in the status are correct
g.Eventually(func() error { return testClient.Get(context.TODO(), expectedCloudRequest.NamespacedName, instance) }, timeout).Should(gomega.Succeed())
assert.Equal(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+":4000", instance.Status.InternalCommonAddress, "Wrong internal common address in status")
assert.NotNil(t, instance.Status.ExternalCommonAddress, "External common address in Status should not be nil.")
assert.EqualValues(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+"."+testDomain+":4000", *instance.Status.ExternalCommonAddress, "Wrong external common address in status")
}

func TestEDSKubeDomainCloudReconcile(t *testing.T) {
Expand Down Expand Up @@ -682,12 +721,14 @@ func TestEDSKubeDomainCloudReconcile(t *testing.T) {
"external-dns.alpha.kubernetes.io/hostname": instance.Namespace + "." + testDomain,
})
testMapsEqual(t, "common service annotations", expectedCommonServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 5000, service.Spec.Ports[0].Port, "Wrong port on common Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on common Service")

// Check the headless Service
service = expectService(t, g, requests, expectedCloudRequest, cloudHsKey, statefulSet.Spec.Template.Labels)
testMapsEqual(t, "headless service annotations", testHeadlessServiceAnnotations, service.Annotations)
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].Name, "Wrong port name on common Service")
assert.EqualValues(t, 2000, service.Spec.Ports[0].Port, "Wrong port on headless Service")
assert.EqualValues(t, "solr-client", service.Spec.Ports[0].TargetPort.StrVal, "Wrong podPort name on headless Service")

Expand All @@ -700,4 +741,10 @@ func TestEDSKubeDomainCloudReconcile(t *testing.T) {

// Check the ingress
expectNoIngress(g, cloudIKey)

// Check that the Addresses in the status are correct
g.Eventually(func() error { return testClient.Get(context.TODO(), expectedCloudRequest.NamespacedName, instance) }, timeout).Should(gomega.Succeed())
assert.Equal(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+".svc."+testKubeDomain+":5000", instance.Status.InternalCommonAddress, "Wrong internal common address in status")
assert.NotNil(t, instance.Status.ExternalCommonAddress, "External common address in Status should not be nil.")
assert.EqualValues(t, "http://"+cloudCsKey.Name+"."+instance.Namespace+"."+testDomain+":5000", *instance.Status.ExternalCommonAddress, "Wrong external common address in status")
}
Loading