Skip to content

Commit

Permalink
Merge pull request #32 from FNNDSC/util-0.2.1
Browse files Browse the repository at this point in the history
fnndsc/util version 0.2.1
  • Loading branch information
jennydaman authored Nov 27, 2024
2 parents 7a0b861 + 60a1b52 commit fd7a394
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
2 changes: 1 addition & 1 deletion charts/util/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: util
description: Library chart providing helper functions for FNNDSC Helm charts
type: library
version: 0.2.0
version: 0.2.1

7 changes: 2 additions & 5 deletions charts/util/templates/_deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ metadata:
name: {{ include "util.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "util.labels" . | nindent 4 }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "util.topLabels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand All @@ -33,6 +30,6 @@ spec:
{{- end }}
spec:
containers:
{{- include "util.container" (mustMerge (dict "containerName" (include "util.name" .) "portName" "http") .) | nindent 8 }}
{{- include "util.container" (mustMerge (dict "containerName" (default (include "util.name" .) .containerName) "portName" "http") .) | nindent 8 }}
{{- include "util.podSpec" . | nindent 6 }}
{{- end }}
25 changes: 18 additions & 7 deletions charts/util/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ app.kubernetes.io/name: {{ include "util.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "util.topLabels" -}}
{{- mustMergeOverwrite (include "util.labels" . | fromYaml) .Values.labels | toYaml }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "util.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- if ((.Values).serviceAccount).create }}
{{- default (include "util.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
Expand All @@ -69,26 +72,30 @@ Create the name of the service account to use
{{- define "util.podSpec" -}}
{{- with (concat (.Values.imagePullSecrets | default (list)) ((.Values.global).imagePullSecrets | default (list)) | mustUniq) }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- if (or .Values.serviceAccount.name .Values.serviceAccount.create) }}
{{- if (or ((.Values).serviceAccount).name ((.Values).serviceAccount).create) }}
serviceAccountName: {{ include "util.util.serviceAccountName" . }}
{{- end }}
{{- with (.Values.podSecurityContext | deepCopy | mustMergeOverwrite (deepCopy ((.Values.global).podSecurityContext | default (dict)))) }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end -}}

Expand Down Expand Up @@ -116,6 +123,10 @@ tolerations:
value: {{ $v | quote }}
{{- end }}
{{- end }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 4 }}
Expand Down
5 changes: 1 addition & 4 deletions charts/util/templates/_knative.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ metadata:
name: {{ include "util.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "util.labels" . | nindent 4 }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "util.topLabels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
11 changes: 6 additions & 5 deletions charts/util/templates/_knative_or_deployment.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{{- define "util.knativeOrDeployment" -}}
{{- include "util.serviceAccountTpl" . }}
---
{{- include "util.testServiceConnectionTpl" . }}
---
{{- if (eq .Values.kind "Service") }}
{{- include "util.knativeServiceTpl" . }}
{{- include "util.knativeServiceTpl" . }}
{{- else if (eq .Values.kind "Deployment") }}
{{- include "util.deploymentEverythingTpl" . }}
{{- include "util.deploymentEverythingTpl" . }}
{{- else }}
{{- fail (printf "Unsupported kind: %s" .kind) }}
{{- fail (printf "Unsupported kind: %s" .kind) }}
{{- end -}}
{{- end -}}

Expand All @@ -18,7 +21,5 @@
---
{{- include "util.serviceTpl" . }}
---
{{- include "util.testServiceConnectionTpl" . }}
---
{{- include "util.openshiftRouteTpl" . }}
{{- end }}
4 changes: 1 addition & 3 deletions charts/util/templates/_serviceaccount.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{{- define "util.serviceAccountTpl" }}
{{- if .Values.serviceAccount.create }}
{{- if ((.Values).serviceAccount).create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "util.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- with .labels }}
labels:
{{- .Value.serviceAccount.labels | deepCopy | default (dict) | mustMergeOverwrite (include "util.labels" . | fromYaml) | toYaml | nindent 4 }}
{{- end }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
27 changes: 26 additions & 1 deletion charts/util/templates/_test_connection.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
{{- define "util.testConnectionHost" -}}
{{- if .Values.route.enabled -}}
{{- .Values.route.host | required "route.host is required because route.enabled=true" -}}
{{- else if .Values.ingress.enabled -}}
{{- (first .Values.ingress.hosts).host | required "ingress.hosts[0].host is required because ingress.enabled=true" -}}
{{- else if (eq .Values.kind "Service") }}
{{- include "util.fullname" . }}.{{ .Release.Namespace }}.svc {{- /* knative service */}}
{{- else -}}
{{- include "util.fullname" . }}:{{ .Values.service.port }}
{{- end -}}
{{- end -}}
{{- define "util.testConnectionScheme" -}}
{{- if (or (and .Values.ingress.enabled .Values.ingress.tls)
(and .Values.route.enabled .Values.route.tls)) -}}
https
{{- else -}}
http
{{- end -}}
{{- end -}}

{{- define "util.testServiceConnectionTpl" }}
apiVersion: v1
kind: Pod
Expand All @@ -14,6 +34,11 @@ spec:
command: ['wget']
args:
- --spider
- http://{{ include "util.fullname" . }}:{{ .Values.service.port }}{{ (.Values.test).path }}
- {{ include "util.testConnectionScheme" . }}://{{ include "util.testConnectionHost" . }}{{ (.Values.test).path }}
resources:
requests: &REQUESTS
cpu: 100m
memory: 128Mi
limits: *REQUESTS
restartPolicy: Never
{{- end }}

0 comments on commit fd7a394

Please sign in to comment.