Skip to content

Commit

Permalink
vmsingle: use common templates
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk committed Oct 22, 2024
1 parent 2f4f212 commit 5241fe8
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 188 deletions.
19 changes: 10 additions & 9 deletions charts/victoria-metrics-single/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
{{- if .Values.printNotes }}
{{- if .Values.server.enabled }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
The VictoriaMetrics write api can be accessed via port {{ .Values.server.service.servicePort }} on the following DNS name from within your cluster:
{{ include "victoria-metrics.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local

{{ include "vm.url" $ctx }}

Metrics Ingestion:
Get the Victoria Metrics service URL by running these commands in the same shell:

{{- if contains "NodePort" .Values.server.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ include "vm.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "victoria-metrics.server.fullname" . }})
export NODE_PORT=$(kubectl get --namespace {{ include "vm.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ $fullname }})
export NODE_IP=$(kubectl get nodes --namespace {{ include "vm.namespace" . }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.server.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc --namespace {{ include "vm.namespace" . }} -w {{ include "victoria-metrics.server.fullname" . }}'
You can watch the status of by running 'kubectl get svc --namespace {{ include "vm.namespace" . }} -w {{ $fullname }}'

export SERVICE_IP=$(kubectl get svc --namespace {{ include "vm.namespace" . }} {{ include "victoria-metrics.server.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export SERVICE_IP=$(kubectl get svc --namespace {{ include "vm.namespace" . }} {{ $fullname }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.server.service.servicePort }}
{{- else if contains "ClusterIP" .Values.server.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ include "vm.namespace" . }} -l "app={{ .Values.server.name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ include "vm.namespace" . }} port-forward $POD_NAME {{ .Values.server.service.servicePort }}
{{- end }}

Write url inside the kubernetes cluster:
http://{{ include "victoria-metrics.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local:{{ .Values.server.service.servicePort }}/api/v1/write
{{ include "vm.url" $ctx }}/api/v1/write

{{- if .Values.server.scrape.enabled }}

Metrics Scrape:
Pull-based scrapes are enabled
Scrape config can be displayed by running this command::
{{- if eq .Values.server.scrape.configMap "" }}
kubectl get cm {{ include "victoria-metrics.server.fullname" . }}-scrapeconfig -n {{ include "vm.namespace" . }}
kubectl get cm {{ $fullname }}-scrapeconfig -n {{ include "vm.namespace" . }}
{{- else }}
kubectl get cm .Values.server.scrape.configMap -n {{ include "vm.namespace" . }}
{{- end }}

The target’s information is accessible via api:
Inside cluster:
http://{{ include "victoria-metrics.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local:{{ .Values.server.service.servicePort }}/targets
{{ include "vm.url" $ctx }}/targets
Outside cluster:
You need to port-forward service (see instructions above) and call
http://<service-host-port>/targets
{{- end }}

Read Data:
The following url can be used as the datasource url in Grafana::
http://{{ include "victoria-metrics.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local:{{ .Values.server.service.servicePort }}
{{ include "vm.url" $ctx }}
{{- end }}
{{- end }}
109 changes: 0 additions & 109 deletions charts/victoria-metrics-single/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,112 +1,3 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "victoria-metrics.name" -}}
{{- 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 "victoria-metrics.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 "victoria-metrics.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "victoria-metrics.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "victoria-metrics.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create unified labels for victoria-metrics components
*/}}
{{- define "victoria-metrics.common.matchLabels" -}}
app.kubernetes.io/name: {{ include "victoria-metrics.name" . }}
app.kubernetes.io/instance: {{ .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end -}}

{{- define "victoria-metrics.common.metaLabels" -}}
helm.sh/chart: {{ include "victoria-metrics.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service | trunc 63 | trimSuffix "-" }}
{{- with .extraLabels }}
{{ toYaml .}}
{{- end }}
{{- end -}}

{{- define "victoria-metrics.server.labels" -}}
{{ include "victoria-metrics.server.matchLabels" . }}
{{ include "victoria-metrics.common.metaLabels" . }}
{{- end -}}

{{- define "victoria-metrics.server.matchLabels" -}}
app: {{ .Values.server.name }}
{{ include "victoria-metrics.common.matchLabels" . }}
{{- end -}}

{{/*
Create a fully qualified server name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "victoria-metrics.server.fullname" -}}
{{- if .Values.server.fullnameOverride -}}
{{- .Values.server.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- printf "%s-%s" .Release.Name .Values.server.name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.server.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Defines the name of scrape configuration map
*/}}
{{- define "victoria-metrics.server.scrape.configname" -}}
{{- if .Values.server.scrape.configMap -}}
{{- .Values.server.scrape.configMap -}}
{{- else -}}
{{- include "victoria-metrics.server.fullname" . -}}-scrapeconfig
{{- end -}}
{{- end -}}

{{/*
Defines the name of relabel configuration map
*/}}
{{- define "victoria-metrics.server.relabel.configname" -}}
{{- if .Values.server.relabel.configMap -}}
{{- .Values.server.relabel.configMap -}}
{{- else -}}
{{- include "victoria-metrics.server.fullname" . -}}-relabelconfig
{{- end -}}
{{- end -}}

{{- define "vmsingle.args" -}}
{{- $app := .Values.server -}}
{{- $args := default dict -}}
Expand Down
9 changes: 6 additions & 3 deletions charts/victoria-metrics-single/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{{- if and .Values.rbac.create (not .Values.rbac.namespaced) .Values.server.scrape.enabled }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "victoria-metrics.fullname" . }}-clusterrole
{{- $ctx := merge (deepCopy .) (dict "extraLabels" .Values.rbac.extraLabels) }}
labels: {{ include "victoria-metrics.common.metaLabels" $ctx | nindent 4 }}
name: {{ $fullname }}-clusterrole
{{- $_ := set $ctx "extraLabels" .Values.rbac.extraLabels }}
labels: {{ include "vm.metaLabels" $ctx | nindent 4 }}
{{- $_ := unset $ctx "extraLabels" }}
{{- with .Values.rbac.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
Expand Down
13 changes: 8 additions & 5 deletions charts/victoria-metrics-single/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{{- if and .Values.rbac.create (not .Values.rbac.namespaced) .Values.server.scrape.enabled }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "victoria-metrics.fullname" . }}-clusterrolebinding
{{- $ctx := merge (deepCopy .) (dict "extraLabels" .Values.rbac.extraLabels) }}
labels: {{ include "victoria-metrics.common.metaLabels" $ctx | nindent 4 }}
name: {{ $fullname }}-clusterrolebinding
{{- $_ := set $ctx "extraLabels" .Values.rbac.extraLabels }}
labels: {{ include "vm.metaLabels" $ctx | nindent 4 }}
{{- $_ := unset $ctx "extraLabels" }}
{{- with .Values.rbac.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
subjects:
- kind: ServiceAccount
name: {{ include "victoria-metrics.serviceAccountName" . }}
name: {{ .Values.serviceAccount.name | default $fullname }}
namespace: {{ include "vm.namespace" . }}
roleRef:
kind: ClusterRole
name: {{ include "victoria-metrics.fullname" . }}-clusterrole
name: {{ $fullname }}-clusterrole
apiGroup: rbac.authorization.k8s.io
{{- end -}}
11 changes: 7 additions & 4 deletions charts/victoria-metrics-single/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{{- if .Values.podDisruptionBudget.enabled }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "victoria-metrics.fullname" . }}
name: {{ $fullname }}
namespace: {{ include "vm.namespace" . }}
{{- $ctx := merge (deepCopy .) (dict "extraLabels" .Values.podDisruptionBudget.extraLabels) }}
labels: {{ include "victoria-metrics.common.metaLabels" $ctx | nindent 4 }}
{{- $_ := set $ctx "extraLabels" .Values.podDisruptionBudget.extraLabels }}
labels: {{ include "vm.metaLabels" $ctx | nindent 4 }}
{{- $_ := unset $ctx "extraLabels" }}
spec:
{{- with .Values.podDisruptionBudget.minAvailable }}
minAvailable: {{ . }}
Expand All @@ -14,5 +17,5 @@ spec:
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels: {{ include "victoria-metrics.server.matchLabels" . | nindent 6 }}
matchLabels: {{ include "vm.selectorLabels" $ctx | nindent 6 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{- if and .Values.server.relabel.enabled (eq .Values.server.relabel.configMap "") }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "victoria-metrics.server.fullname" . }}-relabelconfig
name: {{ $fullname }}-relabelconfig
namespace: {{ include "vm.namespace" . }}
labels: {{ include "victoria-metrics.server.labels" . | nindent 4 }}
labels: {{ include "vm.labels" $ctx | nindent 4 }}
data:
relabel.yml: |{{ toYaml .Values.server.relabel.config | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{- if and .Values.server.scrape.enabled (eq .Values.server.scrape.configMap "") }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "victoria-metrics.server.fullname" . }}-scrapeconfig
name: {{ $fullname }}-scrapeconfig
namespace: {{ include "vm.namespace" . }}
labels: {{ include "victoria-metrics.server.labels" . | nindent 4 }}
labels: {{ include "vm.labels" $ctx | nindent 4 }}
data:
scrape.yml: |
{{- range $k, $v := .Values.server.scrape.config }}
Expand Down
33 changes: 17 additions & 16 deletions charts/victoria-metrics-single/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{{- $global := (dict "Values" (deepCopy .Values) "Release" (deepCopy .Release) "Chart" (deepCopy .Chart) "Template" (deepCopy .Template)) -}}
{{- $app := .Values.server }}
{{- $fullname := (include "victoria-metrics.server.fullname" .) }}
{{- if and $app.enabled (not $app.statefulSet.enabled) -}}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
apiVersion: apps/v1
kind: Deployment
metadata:
{{- with $app.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
{{- $ctx := merge (deepCopy $global) (dict "extraLabels" $app.extraLabels) }}
labels: {{ include "victoria-metrics.server.labels" $ctx | nindent 4 }}
{{- $_ := set $ctx "extraLabels" $app.extraLabels }}
labels: {{ include "vm.labels" $ctx | nindent 4 }}
{{- $_ := unset $ctx "extraLabels" }}
name: {{ $fullname }}
namespace: {{ include "vm.namespace" . }}
spec:
selector:
matchLabels: {{ include "victoria-metrics.server.matchLabels" . | nindent 6 }}
matchLabels: {{ include "vm.selectorLabels" $ctx | nindent 6 }}
replicas: {{ $app.replicaCount }}
{{- if $app.persistentVolume.enabled }}
strategy:
Expand All @@ -26,8 +27,8 @@ spec:
{{- with $app.podAnnotations }}
annotations: {{ toYaml . | nindent 8 }}
{{- end }}
{{- $ctx := merge (deepCopy $global) (dict "extraLabels" $app.podLabels) }}
labels: {{ include "victoria-metrics.server.labels" $ctx | nindent 8 }}
{{- $_ := set $ctx "extraLabels" $app.podLabels }}
labels: {{ include "vm.labels" $ctx | nindent 8 }}
spec:
{{- with $app.priorityClassName }}
priorityClassName: {{ . }}
Expand All @@ -45,7 +46,8 @@ spec:
{{- if $manager.restore.onStart.enabled }}
{{- include "vm.enterprise.only" . }}
- name: vmbackupmanager-restore
image: {{ include "vm.image" (merge (deepCopy .) (dict "app" $manager)) }}
{{- $_ := set $ctx "app" "manager" }}
image: {{ include "vm.image" $ctx }}
imagePullPolicy: {{ $app.image.pullPolicy }}
{{- with $app.podSecurityContext }}
securityContext: {{ toYaml . | nindent 10 }}
Expand Down Expand Up @@ -84,7 +86,8 @@ spec:
{{- if $app.securityContext.enabled }}
securityContext: {{ include "vm.securityContext" (dict "securityContext" $app.securityContext "helm" .) | nindent 12 }}
{{- end }}
image: {{ include "vm.image" (merge (deepCopy $global) (dict "app" $app)) }}
{{- $_ := set $ctx "app" $app }}
image: {{ include "vm.image" $ctx }}
imagePullPolicy: {{ $app.image.pullPolicy }}
{{- if $app.containerWorkingDir }}
workingDir: {{ $app.containerWorkingDir }}
Expand Down Expand Up @@ -190,13 +193,11 @@ spec:
{{- with $app.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if hasKey $manager "enable" }}
{{- fail "`server.vmbackupmanager.enable` is deprecated. Use `server.vmbackupmanager.enabled` instead"}}
{{- end }}
{{- if $manager.enabled }}
{{- include "vm.enterprise.only" . }}
- name: vmbackupmanager
image: {{ include "vm.image" (merge (deepCopy $global) (dict "app" $manager)) }}
{{- $_ := set $ctx "app" $manager }}
image: {{ include "vm.image" $ctx }}
imagePullPolicy: {{ $app.image.pullPolicy }}
args: {{ include "vmbackupmanager.args" . | nindent 12 }}
{{- with (fromYaml (include "vm.probe" (dict "app" $manager "type" "readiness"))) }}
Expand Down Expand Up @@ -239,7 +240,7 @@ spec:
{{- if $app.podSecurityContext.enabled }}
securityContext: {{ include "vm.securityContext" (dict "securityContext" $app.podSecurityContext "helm" .) | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "victoria-metrics.serviceAccountName" . }}
serviceAccountName: {{ .Values.serviceAccount.name | default $fullname }}
{{- with $app.tolerations }}
tolerations: {{ toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -251,12 +252,12 @@ spec:
{{- if $app.scrape.enabled }}
- name: scrapeconfig
configMap:
name: {{ include "victoria-metrics.server.scrape.configname" . }}
name: {{ $fullname }}-scrapeconfig
{{- end }}
{{- if $app.relabel.enabled }}
- name: relabelconfig
configMap
name: {{ include "victoria-metrics.server.relabel.configname" . }}
name: {{ $fullname }}-relabelconfig
{{- end }}
{{- with $app.extraVolumes }}
{{- toYaml . | nindent 8 }}
Expand Down
Loading

0 comments on commit 5241fe8

Please sign in to comment.