Skip to content

Commit

Permalink
Merge pull request #18 from pelotech/feat/extend-nodejs-chart
Browse files Browse the repository at this point in the history
feat(nodejs): Freshen up!
  • Loading branch information
emmanuel authored Dec 2, 2022
2 parents 550c5c3 + 8cfbe07 commit a778688
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion charts/nodejs/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
appVersion: "1.0"
description: A Helm chart for Deploying NoodeJS applications to Kubernetes
name: nodejs
version: 0.1.0
version: 0.2.0
41 changes: 40 additions & 1 deletion charts/nodejs/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,54 @@ Create chart name and version as used by the chart label.
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nodejs.appVersion" -}}
{{- if .Values.appVersion }}
{{- .Values.appVersion | quote -}}
{{- else if .Values.image.tag }}
{{- .Values.image.tag | quote -}}
{{- end -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "nodejs.labels" -}}
app.kubernetes.io/name: {{ include "nodejs.name" . }}
helm.sh/chart: {{ include "nodejs.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/name: {{ include "nodejs.name" . }}
{{- if (and false .Chart.AppVersion) }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- if include "nodejs.appVersion" . }}
app.kubernetes.io/version: {{ include "nodejs.appVersion" . }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Return the appropriate apiVersion for Ingress objects.
*/}}
{{- define "nodejs.ingress.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.Version -}}
{{- print "extensions/v1beta1" -}}
{{- else if semverCompare "<1.19-0" .Capabilities.KubeVersion.Version -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- else -}}
{{- print "networking.k8s.io/v1" -}}
{{- end -}}
{{- end -}}

{{/*
Return "true" if the API ingressClassName field is supported
*/}}
{{- define "nodejs.ingress.supportsIngressClassname" -}}
{{- if semverCompare "<1.18-0" .Capabilities.KubeVersion.Version -}}
{{- print "false" -}}
{{- else -}}
{{- print "true" -}}
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/nodejs/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.configuration }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -7,3 +8,4 @@ metadata:
data:
configuration: |
{{ toJson .Values.configuration | indent 4 }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/nodejs/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,25 @@ spec:
{{- if .Values.environment }}
{{- toYaml .Values.environment | nindent 12 }}
{{- end }}
{{- if .Values.envFrom }}
envFrom:
{{- toYaml .Values.envFrom | nindent 12 }}
{{- end }}
volumeMounts:
{{- if .Values.configuration }}
- name: config
mountPath: {{ .Values.applicationDirectory }}/config/production.json
subPath: configuration
{{- end }}
{{- if .Values.extraVolumeMounts }}
{{- toYaml .Values.extraVolumeMounts | nindent 12 }}
{{- end }}
volumes:
{{- if .Values.configuration }}
- name: config
configMap:
name: {{ include "nodejs.fullname" . }}
{{- end }}
{{- if .Values.extraVolumes }}
{{- toYaml .Values.extraVolumes | nindent 6 }}
{{- end }}
Expand Down
18 changes: 15 additions & 3 deletions charts/nodejs/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "nodejs.fullname" . -}}
apiVersion: extensions/v1beta1
apiVersion: {{ include "nodejs.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName }}
Expand All @@ -10,27 +10,39 @@ metadata:
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if and .Values.ingress.ingressClassName (eq "false" (include "nodejs.ingress.supportsIngressClassname" .)) }}
kubernetes.io/ingress.class: {{ .Values.ingress.ingressClassName | quote }}
{{- end }}
spec:
{{- if and .Values.ingress.ingressClassName (eq "true" (include "nodejs.ingress.supportsIngressClassname" .)) }}
ingressClassName: {{ .Values.ingress.ingressClassName | quote }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
{{- if .secretName }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- end }}
rules:
{{- $pathType := .Values.ingress.pathType -}}
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
pathType: {{ $pathType }}
backend:
serviceName: {{ $fullName }}
servicePort: http
service:
name: {{ $fullName }}
port:
name: http
{{- end }}
{{- end }}
{{- end }}
9 changes: 7 additions & 2 deletions charts/nodejs/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ tls:
ingress:
# ingress.enabled -- Whether to enable ingress to the application.
enabled: false
# ingress.ingressClassName -- Which ingressClass to assign this ingress to.
ingressClassName: nginx
# ingress.annotations -- Annotations to apply to the ingress.
annotations:
kubernetes.io/ingress.class: nginx
annotations: {}
# kubernetes.io/tls-acme: "true"
# ingress.pathType -- https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types
pathType: Prefix
# ingress.hosts -- Host and path configurations to route to the service
hosts:
# ingress.hosts[0].host -- An example hostname.
Expand All @@ -56,6 +59,8 @@ healthCheckUrl: /health-check
configuration: {}
# environment -- Environment variables to set inside the containers.
environment: []
# envFrom -- Environment variables from ConfigMaps/Secrets to import into the containers.
envFrom: []
# resources -- Resource requests/limits for the deployment.
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down

0 comments on commit a778688

Please sign in to comment.