Skip to content

Commit ce78910

Browse files
pengzhoumlPeng Zhou
andauthored
MLE-13841: compatibility with hostname change (#214)
* MLE-13841: compatibility with hostname change * fix linting issue --------- Co-authored-by: Peng Zhou <[email protected]>
1 parent 9623907 commit ce78910

File tree

5 files changed

+74
-7
lines changed

5 files changed

+74
-7
lines changed

charts/templates/NOTES.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ WARNING
1616
FQDN is {{ include "marklogic.fqdn" . }}
1717
{{- if gt (len (include "marklogic.fqdn" .)) 64 }}
1818
WARNING: The hostname is greater than 64 characters
19-
There may be issues with certificates
20-
The certificates may shorten the name or use SANs for hostnames in the certificates
19+
There may be issues with certificates in MarkLogic App Server
2120
{{- end }}
2221

2322
Group {{ .Values.group.name }} is created on the MarkLogic cluster.

charts/templates/_helpers.tpl

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,46 @@ Expand the name of the chart.
55
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
66
{{- end }}
77

8+
{{/*
9+
newFullname is the name used after 1.1.x release, in an effort to make the release name shorter.
10+
*/}}
11+
{{- define "marklogic.newFullname" -}}
12+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
13+
{{- end }}
14+
15+
{{/*
16+
oldFullname is the name used before 1.1.x release
17+
*/}}
18+
{{- define "marklogic.oldFullname" -}}
19+
{{- $name := default .Chart.Name .Values.nameOverride }}
20+
{{- if contains $name .Release.Name }}
21+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
22+
{{- else }}
23+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
24+
{{- end }}
25+
{{- end }}
26+
27+
828
{{/*
929
Create a default fully qualified app name.
1030
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11-
The release name will be used as full name
31+
To surrport the upgrade from 1.0.x to 1.1.x, we keep the old name when doing upgrade from 1.0.x.
32+
For the new install, we use the new name, which is the release name.
1233
*/}}
1334
{{- define "marklogic.fullname" -}}
1435
{{- if .Values.fullnameOverride }}
1536
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
1637
{{- else }}
17-
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
38+
{{- if .Release.IsInstall -}}
39+
{{- include "marklogic.newFullname" . }}
40+
{{- else }}
41+
{{- $newCm := (lookup "apps/v1" "StatefulSet" .Release.Namespace (include "marklogic.newFullname" .)) }}
42+
{{- if $newCm }}
43+
{{- include "marklogic.newFullname" . }}
44+
{{- else }}
45+
{{- include "marklogic.oldFullname" . }}
46+
{{- end }}
47+
{{- end }}
1848
{{- end }}
1949
{{- end }}
2050

@@ -102,8 +132,8 @@ Validate values file
102132
*/}}
103133
{{- define "marklogic.checkInputError" -}}
104134
{{- $fqdn := include "marklogic.fqdn" . }}
105-
{{- if gt (len $fqdn) 64}}
106-
{{- $errorMessage := printf "%s%s%s" "The FQDN: " $fqdn " is longer than 64. Please use a shorter release name and try again." }}
135+
{{- if and (gt (len $fqdn) 64) (not .Values.allowLongHostname) }}
136+
{{- $errorMessage := printf "%s%s%s" "The FQDN: " $fqdn " is longer than 64. Please use a shorter release name and try again. MarkLogic App Server does not support turning on SSL with FQDN over 64 characters. If you still want to install with an FQDN longer than 64 characters, you can override this restriction by setting allowLongHostname: true in your Helm values file." }}
107137
{{- fail $errorMessage }}
108138
{{- end }}
109139
{{- end }}

charts/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ terminationGracePeriod: 120
1515
## Kubernetes cluster domain name
1616
clusterDomain: cluster.local
1717

18+
## To allow deployment with hostname over 64 characters
19+
## This is not remmended as it may cause issues when turning on TLS on MarkLogic Server
20+
## Because MarkLogic Server only supports using CN as hostname in the certificate
21+
## There is a limit of 64 characters for CN in the certificate
22+
allowLongHostname: false
23+
1824
## Group related settings
1925
group:
2026
## the group name of the current Marklogic Helm Deployment

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ prepare:
7070
.PHONY: lint
7171
lint:
7272
@echo "> Linting helm charts....."
73-
helm lint --with-subcharts charts/ $(if $(saveOutput),> helm-lint-output.txt,)
73+
helm lint --set allowLongHostname=true --with-subcharts charts/ $(if $(saveOutput),> helm-lint-output.txt,)
7474

7575
@echo "> Linting all tests....."
7676
golangci-lint run --timeout=5m $(if $(saveOutput),> test-lint-output.txt,)

test/template/template_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,35 @@ func TestTemplatePersistence(t *testing.T) {
137137
require.Equal(t, string(statefulset.Spec.VolumeClaimTemplates[1].Spec.AccessModes[0]), additionalVolumeClaimTemplatesAccessModes)
138138
require.Equal(t, statefulset.Spec.VolumeClaimTemplates[1].Spec.Resources.Requests.Storage().String(), additionalVolumeClaimTemplatesResourcesRequestsStorage)
139139
}
140+
141+
func TestAllowLongHostname(t *testing.T) {
142+
// Path to the helm chart we will test
143+
helmChartPath, err := filepath.Abs("../../charts")
144+
require.NoError(t, err)
145+
146+
// Set up the namespace; confirm that the template renders the expected value for the namespace.
147+
namespaceName := "ml-" + strings.ToLower(random.UniqueId())
148+
// Setup the args for helm install
149+
options := &helm.Options{
150+
SetValues: map[string]string{
151+
"allowLongHostname": "false",
152+
},
153+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
154+
}
155+
156+
longReleaseName := "very-long-hostname-test-that-should-fail"
157+
158+
_, err = helm.RenderTemplateE(t, options, helmChartPath, longReleaseName, []string{"templates/statefulset.yaml"})
159+
require.Error(t, err, "Expected error due to long release name")
160+
161+
shortReleaseName := "short-hostname"
162+
_, err = helm.RenderTemplateE(t, options, helmChartPath, shortReleaseName, []string{"templates/statefulset.yaml"})
163+
require.NoError(t, err, "Expected no error due to short release name")
164+
165+
options.SetValues = map[string]string{
166+
"allowLongHostname": "true",
167+
}
168+
_, err = helm.RenderTemplateE(t, options, helmChartPath, longReleaseName, []string{"templates/statefulset.yaml"})
169+
require.NoError(t, err, "Expected no error with longReleaseName due to set allowLongHostname to true")
170+
171+
}

0 commit comments

Comments
 (0)