Skip to content

Commit

Permalink
update the generic chart to add some capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
colearendt committed Jul 28, 2023
1 parent 89a2416 commit f90e606
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# charts to ignore
charts/nfs-subdir-external-provisioner
bin/
2 changes: 1 addition & 1 deletion charts/generic/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: generic
description: A generic Helm chart for Kubernetes

type: application
version: 0.2.6
version: 0.2.7
appVersion: latest
maintainers:
- name: colearendt
Expand Down
8 changes: 8 additions & 0 deletions charts/generic/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.2.7

- Add support for `pod.otherPorts` and `service.otherPorts` with verbatim spec exposed
- Add support for `service.portName` (which gets used by `pod.container.port` too)
- Beware that the `readinessProbe` does target port `http` by default. This does not change automatically
- Allow `image@sha256:12345` type image references dynamically by allowing `tag` to be a `sha256:` value
- Add support for `pod.initContainers` and `pod.otherContainers`

# 0.2.6

- Fix issue with `NOTES.txt` displaying ingress wrong
Expand Down
11 changes: 8 additions & 3 deletions charts/generic/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# generic

![Version: 0.2.6](https://img.shields.io/badge/Version-0.2.6-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)
![Version: 0.2.7](https://img.shields.io/badge/Version-0.2.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)

## Installing the Chart

To install the chart with the release name `my-release` at version 0.2.6:
To install the chart with the release name `my-release` at version 0.2.7:

```bash
helm repo add colearendt https://colearendt.github.io/helm
helm install my-release colearendt/generic --version=0.2.6
helm install my-release colearendt/generic --version=0.2.7
```

#### _A generic Helm chart for Kubernetes_
Expand Down Expand Up @@ -47,7 +47,10 @@ helm install my-release colearendt/generic --version=0.2.6
| nodeSelector | object | `{}` | |
| pod.annotations | object | `{}` | Additional annotations to add to the pods |
| pod.env | list | `[]` | |
| pod.initContainers | list | `[]` | |
| pod.labels | object | `{}` | Additional labels to add to the pods |
| pod.otherContainers | list | `[]` | |
| pod.otherPorts | list | `[]` | |
| pod.port | int | `80` | |
| pod.securityContext | object | `{}` | |
| pod.volumeMounts | list | `[]` | |
Expand All @@ -62,7 +65,9 @@ helm install my-release colearendt/generic --version=0.2.6
| resources | object | `{}` | |
| secretEnv | list | `[]` | an array of name, value keys that will be used to create secret entries and attach as environment variables. Values evaluated as a template |
| securityContext | object | `{}` | |
| service.otherPorts | list | `[]` | |
| service.port | int | `80` | |
| service.portName | string | `"http"` | The port.name for the default port. Also used as the container port.name as well. |
| service.type | string | `"ClusterIP"` | |
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account |
| serviceAccount.create | bool | `true` | Specifies whether a service account should be created |
Expand Down
20 changes: 18 additions & 2 deletions charts/generic/ci/all-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ image:
repository: nginx
pullPolicy: IfNotPresent
# -- Overrides the image tag whose default is the chart appVersion.
tag: ""
tag: "sha256:12345"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

pod:
port: 80
otherPorts:
- name: rpc
containerPort: 8090
protocol: TCP
env:
- name: "TEST_ENV"
value: "SOME_VALUE"
Expand All @@ -22,6 +26,12 @@ pod:
one: two
securityContext: {}
# fsGroup: 2000
initContainers:
- name: test-init
image: colearendt/netcat:bionic
otherContainers:
- name: sidecar
image: "nginx:latest"

command: []
args: []
Expand All @@ -46,6 +56,12 @@ securityContext: {}
service:
type: ClusterIP
port: 80
portName: testing
otherPorts:
- name: rpc
targetPort: rpc
protocol: TCP
port: 8090

ingress:
enabled: false
Expand Down Expand Up @@ -105,7 +121,7 @@ livenessProbe: null
startupProbe:
httpGet:
path: /
port: http
port: testing

mountConfig:
- name: test.sh
Expand Down
14 changes: 14 additions & 0 deletions charts/generic/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ Create the name of the service account to use
{{- end }}
{{- end }}

{{- /*
Define the image. This is helpful in case the tag has a sha in it
Should be passed values directly
*/ -}}
{{- define "generic.image" -}}
{{- $tag := .Values.image.tag | default .Chart.AppVersion }}
{{- if hasPrefix "sha256:" $tag -}}
"{{ .Values.image.repository }}@{{ $tag }}"
{{- else -}}
"{{ .Values.image.repository }}:{{ $tag }}"
{{- end }}
{{- end }}

{{/* thanks to https://github.com/bitnami/charts/blob/master/bitnami/common/templates/_tplvalues.tpl */}}
{{/*
Renders a value that contains template.
Expand Down
12 changes: 10 additions & 2 deletions charts/generic/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ spec:
serviceAccountName: {{ include "generic.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.pod.securityContext | nindent 8 }}
{{- with .Values.pod.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
image: {{- include "generic.image" . | nindent 12 }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- with .Values.pod.env }}
Expand All @@ -66,9 +70,10 @@ spec:
[]
{{- end }}
ports:
- name: http
- name: {{ .Values.service.portName }}
containerPort: {{ .Values.pod.port }}
protocol: TCP
{{- toYaml .Values.pod.otherPorts | nindent 12 }}
{{- with .Values.command }}
command:
{{- toYaml . | nindent 12 }}
Expand Down Expand Up @@ -108,6 +113,9 @@ spec:
{{- if not (or .Values.pod.volumeMounts .Values.storage.create .Values.mountConfig .Values.mountSecret) }}
[]
{{- end }}
{{- with .Values.pod.otherContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
5 changes: 3 additions & 2 deletions charts/generic/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
targetPort: {{ .Values.service.portName }}
protocol: TCP
name: http
name: {{ .Values.service.portName }}
{{- toYaml .Values.service.otherPorts | nindent 4 }}
selector:
{{- include "generic.selectorLabels" . | nindent 4 }}
6 changes: 6 additions & 0 deletions charts/generic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ secretEnv: []

pod:
port: 80
otherPorts: []
env: []
volumes: []
volumeMounts: []
Expand All @@ -55,6 +56,8 @@ pod:
labels: {}
securityContext: {}
# fsGroup: 2000
initContainers: []
otherContainers: []

# -- command for the pod's primary container. Default is the container's default entrypoint
command: []
Expand Down Expand Up @@ -105,6 +108,9 @@ securityContext: {}
service:
type: ClusterIP
port: 80
# -- The port.name for the default port. Also used as the container port.name as well.
portName: http
otherPorts: []

ingress:
enabled: false
Expand Down

0 comments on commit f90e606

Please sign in to comment.