Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Allow for name overrides of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jaumann committed Nov 21, 2019
1 parent f2c8815 commit e4f4cca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 3 additions & 1 deletion elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ helm install --name elasticsearch elastic/elasticsearch --set imageTag=7.4.1
| Parameter | Description | Default |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `clusterName` | This will be used as the Elasticsearch [cluster.name](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster.name.html) and should be unique per cluster in the namespace | `elasticsearch` |
| `nodeGroup` | This is the name that will be used for each group of nodes in the cluster. The name will be `clusterName-nodeGroup-X` | `master` |
| `nodeGroup` | This is the name that will be used for each group of nodes in the cluster. The name will be `clusterName-nodeGroup-X`, `nameOverride-nodeGroup-X` if a nameOverride is specified, and `fullnameOverride-X` if a fullnameOverride is specified | `master` |
| `masterService` | Optional. The service name used to connect to the masters. You only need to set this if your master `nodeGroup` is set to something other than `master`. See [Clustering and Node Discovery](#clustering-and-node-discovery) for more information. | `` |
| `roles` | A hash map with the [specific roles](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html) for the node group | `master: true`<br>`data: true`<br>`ingest: true` |
| `replicas` | Kubernetes replica count for the statefulset (i.e. how many pods) | `3` |
Expand Down Expand Up @@ -130,6 +130,8 @@ helm install --name elasticsearch elastic/elasticsearch --set imageTag=7.4.1
| `keystore` | Allows you map Kubernetes secrets into the keystore. See the [config example](/elasticsearch/examples/config/values.yaml) and [how to use the keystore](#how-to-use-the-keystore) | `[]` |
| `rbac` | Configuration for creating a role, role binding and service account as part of this helm chart with `create: true`. Also can be used to reference an external service account with `serviceAccountName: "externalServiceAccountName"`. | `create: false`<br>`serviceAccountName: ""` |
| `podSecurityPolicy` | Configuration for create a pod security policy with minimal permissions to run this Helm chart with `create: true`. Also can be used to reference an external pod security policy with `name: "externalPodSecurityPolicy"` | `create: false`<br>`name: ""` |
| `nameOverride` | Overrides the clusterName when used in the naming of resources | `""` |
| `fullnameOverride` | Overrides the clusterName and nodeGroup when used in the naming of resources. This should only be used when using a single nodeGroup, otherwise you will have name conflicts | `""` |

## Try it out

Expand Down
16 changes: 16 additions & 0 deletions elasticsearch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- end -}}

{{- define "uname" -}}
{{- if empty .Values.fullnameOverride -}}
{{- if empty .Values.nameOverride -}}
{{ .Values.clusterName }}-{{ .Values.nodeGroup }}
{{- else -}}
{{ .Values.nameOverride }}-{{ .Values.nodeGroup }}
{{- end -}}
{{- else -}}
{{ .Values.fullnameOverride }}
{{- end -}}
{{- end -}}

{{- define "masterService" -}}
{{- if empty .Values.masterService -}}
{{- if empty .Values.fullnameOverride -}}
{{- if empty .Values.nameOverride -}}
{{ .Values.clusterName }}-master
{{- else -}}
{{ .Values.nameOverride }}-master
{{- end -}}
{{- else -}}
{{ .Values.fullnameOverride }}
{{- end -}}
{{- else -}}
{{ .Values.masterService }}
{{- end -}}
{{- end -}}
Expand Down
8 changes: 8 additions & 0 deletions elasticsearch/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
kind: Service
apiVersion: v1
metadata:
{{- if eq .Values.nodeGroup "master" }}
name: {{ template "masterService" . }}
{{- else }}
name: {{ template "uname" . }}
{{- end }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
Expand Down Expand Up @@ -34,7 +38,11 @@ spec:
kind: Service
apiVersion: v1
metadata:
{{- if eq .Values.nodeGroup "master" }}
name: {{ template "masterService" . }}-headless
{{- else }}
name: {{ template "uname" . }}-headless
{{- end }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
Expand Down
24 changes: 22 additions & 2 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def test_adding_a_label_on_non_headless_service():
r = helm_template(config)

assert 'label1' not in r['service'][uname]['metadata']['labels']

config = '''
service:
labels:
Expand All @@ -699,7 +699,7 @@ def test_adding_a_label_on_headless_service():
r = helm_template(config)

assert 'label1' not in r['service'][uname + '-headless']['metadata']['labels']

config = '''
service:
labelsHeadless:
Expand Down Expand Up @@ -1033,3 +1033,23 @@ def test_external_service_account():
# When referencing an external service account we do not want any resources to be created.
for resource in resources:
assert resource not in r

def test_name_override():
## Make sure we can use a name override
config = '''
nameOverride: "customName"
'''
r = helm_template(config)

assert "customName-master" in r['statefulset']
assert "customName-master" in r['service']

def test_full_name_override():
## Make sure we can use a full name override
config = '''
fullnameOverride: "customfullName"
'''
r = helm_template(config)

assert "customfullName" in r['statefulset']
assert "customfullName" in r['service']

0 comments on commit e4f4cca

Please sign in to comment.