Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use more common templates #1454

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
charts/*/charts/**
.cr-release-packages
.cr-release-packages/**
!charts/victoria-metrics-k8s-stack/charts/crds
!charts/victoria-metrics-k8s-stack/charts/crds/**
!charts/*/charts/crds
!charts/*/charts/crds/**
.cr-release-packages
.cr-release-packages/**
.helm/
.local/
tmp/
11 changes: 5 additions & 6 deletions charts/victoria-logs-single/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fluent-bit.config.outputs: |
[OUTPUT]
Name http
Match kube.*
Host '{{ include "victoria-logs.server.fullname" . }}'
Host '{{ include "vm.plain.fullname" (dict "helm" . "appKey" "server") }}'
port 9428
compress gzip
uri /insert/jsonline?_stream_fields=stream,kubernetes_pod_name,kubernetes_container_name,kubernetes_namespace_name&_msg_field=log&_time_field=date
Expand Down Expand Up @@ -337,7 +337,7 @@ auto
<td></td>
</tr>
<tr>
<td>global.victoriaLogs.server.fullnameOverride</td>
<td>global.victoria-logs-single.server.fullnameOverride</td>
<td>string</td>
<td><pre lang="">
null
Expand All @@ -347,14 +347,13 @@ null
</td>
</tr>
<tr>
<td>global.victoriaLogs.server.name</td>
<td>global.victoria-logs-single.server.name</td>
<td>string</td>
<td><pre lang="">
server
""
</pre>
</td>
<td><p>Server container name</p>
</td>
<td></td>
</tr>
<tr>
<td>podDisruptionBudget.enabled</td>
Expand Down
20 changes: 12 additions & 8 deletions charts/victoria-logs-single/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
{{- if .Values.printNotes }}
{{- if .Values.server.enabled }}
{{- $ctx := dict "helm" . "appKey" "server" "style" "plain" }}
{{- $fqdn := include "vm.fqdn" $ctx }}
{{- $url := include "vm.url" $ctx }}
{{- $fullname := (include "vm.plain.fullname" $ctx) }}
The VictoriaLogs write api can be accessed via port {{ .Values.server.service.servicePort }} on the following DNS name from within your cluster:
{{ include "victoria-logs.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local
{{ $fqdn }}


Logs Ingestion:
Get the Victoria Logs 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-logs.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-logs.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-logs.server.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export SERVICE_IP=$(kubectl get svc --namespace {{ include "vm.namespace" . }} {{ include $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.global.victoriaLogs.server.name }}" -o jsonpath="{.items[0].metadata.name}")
export POD_NAME=$(kubectl get pods --namespace {{ include "vm.namespace" . }} -l "app={{ include "vm.app.name" $ctx }}" -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-logs.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local:{{ .Values.server.service.servicePort }}/
{{ $url }}

Read Data:
The following url can be used to query data::
http://{{ include "victoria-logs.server.fullname" . }}.{{ include "vm.namespace" . }}.svc.cluster.local:{{ .Values.server.service.servicePort }}
The following url can be used to query data:
{{ $url }}
{{- end }}
{{- end }}
73 changes: 9 additions & 64 deletions charts/victoria-logs-single/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,51 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "victoria-logs.name" -}}
{{- default .Chart.Name .Values.global.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-logs.fullname" -}}
{{- if .Values.global.victoriaLogs.server.fullnameOverride -}}
{{- .Values.global.victoriaLogs.server.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.global.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-logs.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}

{{/*
Create unified labels for victoria-logs components
*/}}
{{- define "victoria-logs.common.matchLabels" -}}
app.kubernetes.io/name: {{ include "victoria-logs.name" . }}
app.kubernetes.io/instance: {{ .Release.Name | trunc 63 | trimSuffix "-" }}
{{- $Release := (.helm).Release | default .Release -}}
app.kubernetes.io/name: {{ include "vm.name" . }}
app.kubernetes.io/instance: {{ $Release.Name | trunc 63 | trimSuffix "-" }}
{{- end -}}

{{- define "victoria-logs.common.metaLabels" -}}
helm.sh/chart: {{ include "victoria-logs.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service | trunc 63 | trimSuffix "-" }}
{{- $Release := (.helm).Release | default .Release -}}
helm.sh/chart: {{ include "vm.chart" . }}
app.kubernetes.io/managed-by: {{ $Release.Service | trunc 63 | trimSuffix "-" }}
{{- with .extraLabels }}
{{ toYaml . }}
{{- end }}
Expand All @@ -57,33 +22,13 @@ app.kubernetes.io/managed-by: {{ .Release.Service | trunc 63 | trimSuffix "-" }}
{{- end -}}

{{- define "victoria-logs.server.matchLabels" -}}
app: {{ .Values.global.victoriaLogs.server.name }}
app: {{ include "vm.app.name" . }}
{{ include "victoria-logs.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).

Use hardcoded default value as this template will be used in Fluent Bit chart
and .Chart.Name will be "fluent-bit" in sub-chart context.
*/}}
{{- define "victoria-logs.server.fullname" -}}
{{- if .Values.global.victoriaLogs.server.fullnameOverride -}}
{{- .Values.global.victoriaLogs.server.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}

{{- $name := default "victoria-logs-single" .Values.global.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- printf "%s-%s" .Release.Name .Values.global.victoriaLogs.server.name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.global.victoriaLogs.server.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "vlogs.args" -}}
{{- $app := .Values.server -}}
{{- $Values := (.helm).Values | default .Values }}
{{- $app := $Values.server -}}
{{- $args := default dict -}}
{{- $_ := set $args "retentionPeriod" $app.retentionPeriod -}}
{{- $_ := set $args "storageDataPath" $app.persistentVolume.mountPath -}}
Expand Down
13 changes: 7 additions & 6 deletions charts/victoria-logs-single/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{{- if .Values.podDisruptionBudget.enabled }}
{{- $pdb := .Values.podDisruptionBudget }}
{{- if $pdb.enabled }}
{{- $ctx := (dict "helm" . "extraLabels" $pdb.labels) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "victoria-logs.fullname" . }}
name: {{ include "vm.fullname" . }}
namespace: {{ include "vm.namespace" . }}
{{- $ctx := merge (deepCopy .) (dict "extraLabels" .Values.podDisruptionBudget.labels) }}
labels: {{ include "victoria-logs.common.metaLabels" $ctx | nindent 4 }}
spec:
{{- with .Values.podDisruptionBudget.minAvailable }}
{{- with $pdb.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.podDisruptionBudget.maxUnavailable }}
{{- with $pdb.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels: {{ include "victoria-logs.server.matchLabels" . | nindent 6 }}
matchLabels: {{ include "victoria-logs.server.matchLabels" (omit $ctx "extraLabels") | nindent 6 }}
{{- end }}
11 changes: 5 additions & 6 deletions charts/victoria-logs-single/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $global := (dict "Values" (deepCopy .Values) "Release" (deepCopy .Release) "Chart" (deepCopy .Chart) "Template" (deepCopy .Template)) -}}
{{- $app := .Values.server }}
{{- $fullname := (include "victoria-logs.server.fullname" .) }}
{{- $ctx := (dict "helm" . "extraLabels" $app.extraLabels "appKey" "server") }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- if and $app.enabled (not $app.statefulSet.enabled) -}}
apiVersion: apps/v1
kind: Deployment
Expand All @@ -10,11 +10,10 @@ metadata:
{{- with $app.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
{{- $ctx := merge (deepCopy $global) (dict "extraLabels" $app.extraLabels) }}
labels: {{ include "victoria-logs.server.labels" $ctx | nindent 4 }}
spec:
selector:
matchLabels: {{ include "victoria-logs.server.matchLabels" . | nindent 6 }}
matchLabels: {{ include "victoria-logs.server.matchLabels" (omit $ctx "extraLabels") | nindent 6 }}
replicas: {{ $app.replicaCount }}
{{- if $app.persistentVolume.enabled }}
strategy:
Expand All @@ -26,7 +25,7 @@ spec:
{{- with $app.podAnnotations }}
annotations: {{ toYaml . | nindent 8 }}
{{- end }}
{{- $ctx := merge (deepCopy $global) (dict "extraLabels" $app.podLabels) }}
{{- $_ := set $ctx "extraLabels" $app.podLabels }}
labels: {{ include "victoria-logs.server.labels" $ctx | nindent 8 }}
spec:
{{- with $app.priorityClassName }}
Expand All @@ -46,7 +45,7 @@ spec:
{{- if $app.securityContext.enabled }}
securityContext: {{- include "vm.compatibility.renderSecurityContext" (dict "secContext" $app.securityContext "context" .) | nindent 12 }}
{{- end }}
image: {{ include "vm.image" (merge (deepCopy $global) (dict "app" $app)) }}
image: {{ include "vm.image" (dict "helm" . "app" $app) }}
imagePullPolicy: {{ $app.image.pullPolicy }}
{{- if $app.containerWorkingDir }}
workingDir: {{ $app.containerWorkingDir }}
Expand Down
17 changes: 9 additions & 8 deletions charts/victoria-logs-single/templates/server-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{{- $app := .Values.server }}
{{- if and $app.enabled $app.ingress.enabled }}
{{- $serviceName := include "victoria-logs.server.fullname" . }}
{{- $ingress := $app.ingress }}
{{- if and $app.enabled $ingress.enabled }}
{{- $ctx := dict "helm" . "extraLabels" $ingress.extraLabels "appKey" "server" }}
{{- $serviceName := include "vm.plain.fullname" $ctx }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
{{- with $app.ingress.annotations }}
{{- with $ingress.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
{{- $ctx := merge (deepCopy .) (dict "extraLabels" $app.ingress.extraLabels) }}
labels: {{ include "victoria-logs.server.labels" $ctx | nindent 4 }}
name: {{ $serviceName }}
namespace: {{ include "vm.namespace" . }}
spec:
{{- with $app.ingress.ingressClassName }}
{{- with $ingress.ingressClassName }}
ingressClassName: {{ . }}
{{- end }}
{{- with $app.ingress.tls }}
{{- with $ingress.tls }}
tls: {{ tpl (toYaml .) $ | nindent 4 }}
{{- end }}
rules:
{{- range $app.ingress.hosts }}
{{- range $ingress.hosts }}
- host: {{ tpl .name $ }}
http:
paths:
- path: {{ .path }}
{{- with $app.ingress.pathType }}
{{- with $ingress.pathType }}
pathType: {{ . }}
{{- end }}
backend:
Expand Down
20 changes: 11 additions & 9 deletions charts/victoria-logs-single/templates/server-pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{{- if .Values.server.persistentVolume.enabled -}}
{{- if not .Values.server.statefulSet.enabled -}}
{{- if not .Values.server.persistentVolume.existingClaim -}}
{{- $app := .Values.server }}
{{- if $app.persistentVolume.enabled -}}
{{- if not $app.statefulSet.enabled -}}
{{- if not $app.persistentVolume.existingClaim -}}
{{- $ctx := dict "helm" . "appKey" "server" }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "victoria-logs.server.fullname" . }}
name: {{ include "vm.plain.fullname" $ctx }}
namespace: {{ include "vm.namespace" . }}
{{- with .Values.server.persistentVolume.annotations }}
{{- with $app.persistentVolume.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels: {{ include "victoria-logs.server.labels" . | nindent 4 }}
spec:
{{- with .Values.server.persistentVolume.accessModes }}
{{- with $app.persistentVolume.accessModes }}
accessModes: {{ toYaml . | nindent 4 }}
{{- end }}
resources:
requests:
storage: {{ .Values.server.persistentVolume.size }}
{{- with .Values.server.persistentVolume.storageClassName }}
storage: {{ $app.persistentVolume.size }}
{{- with $app.persistentVolume.storageClassName }}
storageClassName: {{ . }}
{{- end }}
{{- with .Values.server.persistentVolume.matchLabels }}
{{- with $app.persistentVolume.matchLabels }}
selector:
matchLabels: {{ toYaml . | nindent 6 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{- if and .Values.server.enabled .Values.server.serviceMonitor.enabled -}}
{{- $serviceMonitor := .Values.server.serviceMonitor -}}
{{- $ctx := dict "helm" . "extraLabels" $serviceMonitor.extraLabels "appKey" "server" }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
{{- with $serviceMonitor.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
{{- $ctx := merge (deepCopy .) (dict "extraLabels" $serviceMonitor.extraLabels) }}
labels: {{ include "victoria-logs.server.labels" $ctx | nindent 4 }}
name: {{ include "victoria-logs.server.fullname" . }}
name: {{ include "vm.plain.fullname" $ctx }}
{{- with $serviceMonitor.namespace }}
namespace: {{ . }}
{{- end }}
Expand All @@ -17,7 +17,7 @@ spec:
matchNames:
- {{ include "vm.namespace" . }}
selector:
matchLabels: {{ include "victoria-logs.server.matchLabels" . | nindent 6 }}
matchLabels: {{ include "victoria-logs.server.matchLabels" (omit $ctx "extraLabels") | nindent 6 }}
endpoints:
- port: http
{{- with $serviceMonitor.basicAuth }}
Expand Down
Loading