Files
2026-08-26 03:39:42 +05:30

185 lines
5.3 KiB
Smarty

{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "telegraf-operator.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Maintainer - Akshay Gupta
Tolerations and nodeSelector via Resources Requests.
*/}}
{{- define "meesho.getCpu" -}}
{{- $cpu := toString .Values.resources.requests.cpu -}}
{{- if contains "m" $cpu -}}
{{- $cpu := trimAll "m" $cpu | float64 -}}
{{- $cpu := $cpu | float64 -}}
{{- printf "%f" $cpu -}}
{{- else -}}
{{- $cpu := mulf $cpu 1000.000 -}}
{{- printf "%f" $cpu -}}
{{- end -}}
{{- end -}}
{{- define "meesho.getMem" -}}
{{- $mem := toString .Values.resources.requests.memory -}}
{{- if contains "Mi" $mem -}}
{{- $mem := trimAll "Mi" $mem | float64 -}}
{{- printf "%f" $mem -}}
{{- else if contains "Gi" $mem -}}
{{- $mem := trimAll "Gi" $mem | float64 -}}
{{- $mem := mulf $mem 1024.000 -}}
{{- printf "%f" $mem -}}
{{- end -}}
{{- end -}}
{{- define "meesho.getRatio" -}}
{{- $cpu := (include "meesho.getCpu" .) -}}
{{- $mem := (include "meesho.getMem" .) -}}
{{- $ratio := divf $mem $cpu -}}
{{- if gt $ratio 4.00 -}}
{{- printf "1to8" -}}
{{- else if gt $ratio 2.00 -}}
{{- printf "1to4" -}}
{{- else -}}
{{- printf "1to2" -}}
{{- end -}}
{{- end -}}
{{- define "meesho.dedicatedValue" -}}
{{- if (index .Values.labels "arch") -}}
{{- if (index .Values.labels "runpod") -}}
{{- $cpu := (include "meesho.getCpu" .) -}}
{{- $mem := (include "meesho.getMem" .) -}}
{{- $ratio := (include "meesho.getRatio" .) -}}
{{- $arch := .Values.labels.arch -}}
{{- $runPod := .Values.labels.runpod -}}
{{- printf "%s-%s-%s" $ratio $arch $runPod -}}
{{- else -}}
{{- printf "missing-runpod-label" -}}
{{- end -}}
{{- else -}}
{{- printf "missing-arch-label" -}}
{{- end -}}
{{- 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 "telegraf-operator.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 -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "telegraf-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "telegraf-operator.labels" -}}
helm.sh/chart: {{ include "telegraf-operator.chart" . }}
{{ include "telegraf-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Selector labels
*/}}
{{- define "telegraf-operator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "telegraf-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "telegraf-operator.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "telegraf-operator.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{/*
Generate certificates for telegraf-operator mutating webhook
*/}}
{{- define "telegraf-operator.non_certmanager" -}}
{{- $altNames := list ( printf "%s.%s" (include "telegraf-operator.fullname" .) .Release.Namespace ) ( printf "%s.%s.svc" (include "telegraf-operator.fullname" .) .Release.Namespace ) -}}
{{- $ca := genCA "telegraf-operator-ca" 365 -}}
{{- $cert := genSignedCert ( include "telegraf-operator.fullname" . ) nil $altNames 365 $ca -}}
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
annotations:
cert-manager.io/inject-ca-from: "{{ .Values.namespace }}/{{ include "telegraf-operator.fullname" . }}"
labels:
{{- include "telegraf-operator.labels" . | nindent 4 }}
name: {{ include "telegraf-operator.fullname" . }}
webhooks:
- clientConfig:
service:
name: {{ include "telegraf-operator.fullname" . }}
namespace: {{ .Release.Namespace }}
path: /mutate-v1-pod
caBundle: {{ $ca.Cert | b64enc }}
failurePolicy: Ignore
sideEffects: None
admissionReviewVersions:
- 'v1'
name: telegraf.influxdata.com
{{- if .Values.webhook.excludeNamespaces }}
namespaceSelector:
matchExpressions:
- key: kubernetes.io/metadata.name
operator: NotIn
values:
{{- range .Values.webhook.excludeNamespaces }}
- {{ . | quote }}
{{- end }}
{{- end }}
rules:
- apiGroups:
- '*'
apiVersions:
- '*'
operations:
- CREATE
- DELETE
resources:
- pods
---
apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
name: telegraf-operator-tls
labels:
{{- include "telegraf-operator.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": "pre-install,pre-upgrade"
"helm.sh/hook-delete-policy": "before-hook-creation"
data:
tls.crt: {{ $cert.Cert | b64enc }}
tls.key: {{ $cert.Key | b64enc }}
{{- end -}}