Skip to content

Commit

Permalink
feature: update goldpinger chart (#47)
Browse files Browse the repository at this point in the history
Use actual Ingress api version
Template labels and selectors
  • Loading branch information
okgolove authored Nov 11, 2021
1 parent 3340c60 commit 68ab86f
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 108 deletions.
2 changes: 1 addition & 1 deletion charts/goldpinger/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ name: goldpinger
sources:
- https://github.com/bloomberg/goldpinger
- https://github.com/okgolove/helm-charts
version: 4.3.1
version: 5.0.0
66 changes: 43 additions & 23 deletions charts/goldpinger/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "goldpinger.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "goldpinger.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "goldpinger.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create the name of the service account
Common labels
*/}}
{{- define "goldpinger.labels" -}}
helm.sh/chart: {{ include "goldpinger.chart" . }}
{{ include "goldpinger.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "goldpinger.selectorLabels" -}}
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "goldpinger.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "goldpinger.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "goldpinger.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
9 changes: 3 additions & 6 deletions charts/goldpinger/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "goldpinger.fullname" . }}-clusterrole
name: {{ include "goldpinger.fullname" . }}-clusterrole
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "goldpinger.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["list"]
{{- end }}
{{- end }}
11 changes: 4 additions & 7 deletions charts/goldpinger/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "goldpinger.fullname" . }}-clusterrolebinding
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "goldpinger.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: {{ template "goldpinger.serviceAccountName" . }}
name: {{ include "goldpinger.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ template "goldpinger.fullname" . }}-clusterrole
name: {{ include "goldpinger.fullname" . }}-clusterrole
apiGroup: rbac.authorization.k8s.io
{{- end }}
{{- end }}
27 changes: 11 additions & 16 deletions charts/goldpinger/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,29 @@ kind: DaemonSet
metadata:
name: {{ include "goldpinger.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "goldpinger.labels" . | nindent 4 }}
spec:
{{- with .Values.updateStrategy }}
updateStrategy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- include "goldpinger.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- with .Values.podLabels }}
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- with .Values.podAnnotations }}
annotations:
{{ toYaml . | nindent 8 }}
{{- end }}
{{ toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "goldpinger.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{ toYaml . | nindent 8 }}
{{- end }}
spec:
priorityClassName: {{ .Values.priorityClassName }}
serviceAccountName: {{ template "goldpinger.serviceAccountName" . }}
serviceAccountName: {{ include "goldpinger.serviceAccountName" . }}
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
Expand Down
65 changes: 42 additions & 23 deletions charts/goldpinger/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,61 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "goldpinger.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.labels }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.ingress.annotations }}
{{- include "goldpinger.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . }}
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
- path: {{ $ingressPath }}
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
13 changes: 5 additions & 8 deletions charts/goldpinger/templates/podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "goldpinger.fullname" . }}-pod-security-policy
name: {{ include "goldpinger.fullname" . }}-pod-security-policy
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "goldpinger.labels" . | nindent 4 }}
rules:
- apiGroups: ["extensions"]
resources: ["podsecuritypolicies"]
Expand All @@ -18,18 +15,18 @@ rules:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "goldpinger.fullname" . }}-pod-security-policy
name: {{ include "goldpinger.fullname" . }}-pod-security-policy
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
roleRef:
kind: Role
name: {{ template "goldpinger.fullname" . }}-pod-security-policy
name: {{ include "goldpinger.fullname" . }}-pod-security-policy
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: {{ template "goldpinger.serviceAccountName" . }}
name: {{ include "goldpinger.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
8 changes: 2 additions & 6 deletions charts/goldpinger/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ kind: Service
metadata:
name: {{ include "goldpinger.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "goldpinger.labels" . | nindent 4 }}
{{- with .Values.service.labels }}
{{ toYaml . | indent 4 }}
{{- end }}
Expand All @@ -22,5 +19,4 @@ spec:
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- include "goldpinger.selectorLabels" . | nindent 4 }}
9 changes: 3 additions & 6 deletions charts/goldpinger/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "goldpinger.serviceAccountName" . }}
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ template "goldpinger.serviceAccountName" . }}
{{- end }}
{{- include "goldpinger.labels" . | nindent 4 }}
{{- end }}
12 changes: 4 additions & 8 deletions charts/goldpinger/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "goldpinger.fullname" . }}
name: {{ include "goldpinger.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ .Values.serviceMonitor.namespace }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "goldpinger.name" . }}
helm.sh/chart: {{ include "goldpinger.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- include "goldpinger.labels" . | nindent 4 }}
{{- range $key, $value := .Values.serviceMonitor.selector }}
{{ $key }}: {{ $value | quote }}
{{- end }}
Expand All @@ -27,6 +24,5 @@ spec:
- {{ .Release.Namespace }}
selector:
matchLabels:
app.kubernetes.io/name: {{ template "goldpinger.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{- include "goldpinger.selectorLabels" . | nindent 6 }}
{{- end -}}
11 changes: 7 additions & 4 deletions charts/goldpinger/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ service:
annotations: {}
labels: {}


ingress:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- goldpinger.local
labels: {}
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.test
# - chart-example.local

## Set a priorityClassName for the pod. If left blank a default priority will be set.
priorityClassName:
Expand Down

0 comments on commit 68ab86f

Please sign in to comment.