From 2cee3776d9ff3c06bb9a142808dc523f0d6b0ab3 Mon Sep 17 00:00:00 2001 From: kamal-devtron Date: Thu, 29 May 2025 18:32:23 +0530 Subject: [PATCH 1/4] modified the chart 4.21 and added support for the vmservice scrape and vmrule --- .../deployment-chart_4-21-0/app-values.yaml | 4 +- .../templates/_helpers.tpl | 39 +++++- .../templates/app-metrics.yaml | 40 ++++++ .../templates/deployment.yaml | 36 ++++- .../templates/flagger.yaml | 23 +++- .../templates/istio-authorizationpolicy.yaml | 4 + .../templates/istio-destinationrule.yaml | 4 + .../templates/istio-gateway.yaml | 9 +- .../templates/istio-peerauthentication.yaml | 4 + .../istio-requestauthentication.yaml | 6 +- .../templates/istio-virtualservice.yaml | 7 + .../templates/metrics-service-monitor.yaml | 2 +- .../templates/podmonitor.yaml | 32 +++++ .../templates/servicemonitor.yaml | 11 +- .../templates/vmrule.yaml | 29 ++++ .../templates/vmservice-scraper.yaml | 127 ++++++++++++++++++ .../deployment-chart_4-21-0/test_values.yaml | 59 +++++++- .../deployment-chart_4-21-0/values.yaml | 18 ++- 18 files changed, 437 insertions(+), 17 deletions(-) create mode 100644 scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/app-metrics.yaml create mode 100644 scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/podmonitor.yaml create mode 100644 scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmrule.yaml create mode 100644 scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/app-values.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/app-values.yaml index 5f8216c0a7..629b8482d5 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/app-values.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/app-values.yaml @@ -527,4 +527,6 @@ hostAliases: [] # - "bar.remote" verticalPodScaling: - enabled: false \ No newline at end of file + enabled: false + +MetricsScraper: Prometheus \ No newline at end of file diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl index 10de322e2a..07465d79f1 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl @@ -164,4 +164,41 @@ Create chart name and version as used by the chart label. {{- $LabelsContain = true -}} {{- end }} {{- $LabelsContain -}} -{{- end -}} \ No newline at end of file +{{- end -}} + +{{- define "vmserviceScrapeEnabled" -}} + {{- $SMenabled := false -}} + {{- range .Values.ContainerPort }} + {{- if .vmservicescrape }} + {{- if and .vmservicescrape.enabled }} + {{- $SMenabled = true -}} + {{- end }} + {{- end }} + {{- end }} + {{- $SMenabled -}} +{{- end -}} + + +{{- define "podMonitorEnabled" -}} + {{- $SMenabled := false -}} + {{- if .Values.podmonitor.enabled }} + {{- $SMenabled = true -}} + {{- end }} + {{- $SMenabled -}} +{{- end -}} + + +{{- define "scrapeType" -}} + {{- $ServiceMonitorEnabled := include "serviceMonitorEnabled" . -}} + {{- $VmServiceScrapeEnabled := include "vmserviceScrapeEnabled" . -}} + {{- $val1 := "vmservicescrape"}} + {{- $val2 := "servicemonitor"}} + {{- if and (eq $VmServiceScrapeEnabled "true") (eq $ServiceMonitorEnabled "true")}} + {{- $val1 }} + {{- else if eq $ServiceMonitorEnabled "true" }} + {{- $val2 }} + {{- else if eq $VmServiceScrapeEnabled "true" }} + {{- $val1 }} + {{- end }} + +{{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/app-metrics.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/app-metrics.yaml new file mode 100644 index 0000000000..5c8d17f98d --- /dev/null +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/app-metrics.yaml @@ -0,0 +1,40 @@ +{{- if $.Values.appMetrics -}} +{{- if eq .Values.MetricsScraper "Victoria" }} +apiVersion: operator.victoriametrics.com/v1beta1 +kind: VMServiceScrape +{{- else if eq .Values.MetricsScraper "Prometheus" }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +{{- end }} +metadata: + name: {{ template ".Chart.Name .fullname" $ }} + labels: + app: {{ template ".Chart.Name .name" . }} + appId: {{ $.Values.app | quote }} + envId: {{ $.Values.env | quote }} + chart: {{ template ".Chart.Name .chart" . }} + release: {{ .Values.prometheus.release }} +spec: + jobLabel: {{ template ".Chart.Name .name" $ }} + endpoints: + - port: envoy-admin + interval: 30s + path: /stats/prometheus + relabelings: + - action: replace + sourceLabels: + - __meta_kubernetes_pod_label_pod_template_hash + targetLabel: devtron_app_hash + selector: + matchLabels: + app: {{ template ".Chart.Name .name" $ }} + appId: {{ $.Values.app | quote }} + envId: {{ $.Values.env | quote }} + namespaceSelector: + matchNames: + - {{.Release.Namespace}} + podTargetLabels: + - appId + - envId + - devtron_app_hash +{{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/deployment.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/deployment.yaml index 811ff84df5..8cae02d3c0 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/deployment.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/deployment.yaml @@ -259,9 +259,9 @@ spec: {{- end }} env: - name: CONFIG_HASH - value: {{ include (print $.Chart.Name "/templates/configmap.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.ConfigHash) }}{{ .Values.devtronInternal.containerSpecs.ConfigHash }}{{ end }} + value: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.ConfigHash) }}{{ .Values.devtronInternal.containerSpecs.ConfigHash }}{{ end }} - name: SECRET_HASH - value: {{ include (print $.Chart.Name "/templates/secret.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.SecretHash) }}{{ .Values.devtronInternal.containerSpecs.SecretHash }}{{ end }} + value: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.SecretHash) }}{{ .Values.devtronInternal.containerSpecs.SecretHash }}{{ end }} - name: DEVTRON_APP_NAME value: {{ template ".Chart.Name .name" $ }} - name: POD_NAME @@ -571,8 +571,20 @@ spec: {{ toYaml .volumeMounts | indent 12 -}} {{- end}} {{- else}} +{{- $cCopy := deepCopy . }} +{{- if hasKey $cCopy "ports" }} +{{- $newPorts := list }} +{{- range $port := $cCopy.ports }} + {{- $newPorts = append $newPorts (dict + "name" (get $port "name") + "containerPort" (get $port "containerPort") + "protocol" (get $port "protocol") + ) }} +{{- end }} +{{- $_ := set $cCopy "ports" $newPorts }} +{{- end }} - -{{ toYaml . | indent 10 }} +{{ toYaml $cCopy | indent 10 }} {{- end}} {{- end}} {{- end}} @@ -874,9 +886,9 @@ spec: {{- end }} env: - name: CONFIG_HASH - value: {{ include (print $.Chart.Name "/templates/configmap.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.ConfigHash) }}{{ .Values.devtronInternal.containerSpecs.ConfigHash }}{{ end }} + value: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.ConfigHash) }}{{ .Values.devtronInternal.containerSpecs.ConfigHash }}{{ end }} - name: SECRET_HASH - value: {{ include (print $.Chart.Name "/templates/secret.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.SecretHash) }}{{ .Values.devtronInternal.containerSpecs.SecretHash }}{{ end }} + value: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}{{ if and (.Values.devtronInternal) (.Values.devtronInternal.containerSpecs.SecretHash) }}{{ .Values.devtronInternal.containerSpecs.SecretHash }}{{ end }} - name: DEVTRON_APP_NAME value: {{ template ".Chart.Name .name" $ }} - name: POD_NAME @@ -1186,8 +1198,20 @@ spec: {{ toYaml .volumeMounts | indent 12 -}} {{- end}} {{- else}} +{{- $cCopy := deepCopy . }} +{{- if hasKey $cCopy "ports" }} +{{- $newPorts := list }} +{{- range $port := $cCopy.ports }} + {{- $newPorts = append $newPorts (dict + "name" (get $port "name") + "containerPort" (get $port "containerPort") + "protocol" (get $port "protocol") + ) }} +{{- end }} +{{- $_ := set $cCopy "ports" $newPorts }} +{{- end }} - -{{ toYaml . | indent 10 }} +{{ toYaml $cCopy | indent 10 }} {{- end}} {{- end}} {{- end}} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/flagger.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/flagger.yaml index 766098fb61..a0fb8b4032 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/flagger.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/flagger.yaml @@ -71,6 +71,9 @@ metadata: {{ toYaml .annotations | indent 4 }} {{- end }} spec: +{{- if .provider }} + provider: {{ .provider }} +{{- end }} targetRef: apiVersion: apps/v1 kind: Deployment @@ -146,13 +149,31 @@ spec: maxWeight: {{ .analysis.maxWeight }} stepWeight: {{ .analysis.stepWeight }} metrics: +{{- if $.Values.flaggerCanary.analysis.metrics }} +{{- range $.Values.flaggerCanary.analysis.metrics }} + - name: {{ .name }} + threshold: {{ .successRate }} + interval: {{.interval }} +{{- end }} +{{- end }} - name: request-success-rate threshold: {{ .thresholds.successRate }} interval: 1m - name: request-duration threshold: {{ .thresholds.latency }} - interval: 1m + interval: 1m webhooks: +{{- if $.Values.flaggerCanary.analysis.webhooks }} +{{- range $.Values.flaggerCanary.analysis.webhooks }} + - name: {{ .name }} + url: {{ .url }} + timeout: {{ .timeout }} + metadata: + {{- range $key, $val := .metadata }} + {{ $key }}: {{ $val | quote }} + {{- end }} + {{- end }} +{{- end }} {{- if .loadtest.enabled }} - name: load-test url: {{ .loadtest.url }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-authorizationpolicy.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-authorizationpolicy.yaml index 8340555ff3..df063920a7 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-authorizationpolicy.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-authorizationpolicy.yaml @@ -1,6 +1,10 @@ {{- with .Values.istio }} {{- if and .enable .authorizationPolicy.enabled }} +{{ if semverCompare ">=1.22-0" $.Capabilities.KubeVersion.GitVersion -}} +apiVersion: security.istio.io/v1 +{{- else -}} apiVersion: security.istio.io/v1beta1 +{{- end }} kind: AuthorizationPolicy metadata: {{- if .authorizationPolicy.name }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-destinationrule.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-destinationrule.yaml index 4d06deb0b8..bc665e6ec0 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-destinationrule.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-destinationrule.yaml @@ -1,6 +1,10 @@ {{- with .Values.istio }} {{- if and .enable .destinationRule.enabled }} +{{ if semverCompare ">=1.22-0" $.Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.istio.io/v1 +{{ else }} apiVersion: networking.istio.io/v1beta1 +{{- end }} kind: DestinationRule metadata: {{- if .destinationRule.name }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-gateway.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-gateway.yaml index b145d6c569..e4c6750af6 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-gateway.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-gateway.yaml @@ -1,5 +1,9 @@ {{- if and .Values.istio.enable .Values.istio.gateway.enabled -}} +{{ if semverCompare ">=1.22-0" $.Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.istio.io/v1 +{{ else }} apiVersion: networking.istio.io/v1beta1 +{{- end }} kind: Gateway metadata: {{- if .Values.istio.gateway.name }} @@ -24,6 +28,9 @@ metadata: {{ toYaml $.Values.istio.gateway.annotations | indent 4 }} {{- end }} spec: +{{- if .Values.istio.gateway.gatewayExtraSpec }} +{{ toYaml $.Values.istio.gateway.gatewayExtraSpec | indent 2}} +{{- end }} {{ with $.Values.istio.gateway }} selector: {{- if .selector }} @@ -68,4 +75,4 @@ spec: {{ end }} {{ end }} {{ end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-peerauthentication.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-peerauthentication.yaml index dedd971c6d..5e143c8530 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-peerauthentication.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-peerauthentication.yaml @@ -1,6 +1,10 @@ {{- with .Values.istio }} {{- if and .enable .peerAuthentication.enabled }} +{{ if semverCompare ">=1.22-0" $.Capabilities.KubeVersion.GitVersion -}} +apiVersion: security.istio.io/v1 +{{- else -}} apiVersion: security.istio.io/v1beta1 +{{- end }} kind: PeerAuthentication metadata: {{- if .peerAuthentication.name }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-requestauthentication.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-requestauthentication.yaml index 49bb89552d..d8082bd34d 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-requestauthentication.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-requestauthentication.yaml @@ -1,10 +1,14 @@ {{- with .Values.istio }} {{- if and .enable .requestAuthentication.enabled }} +{{ if semverCompare ">=1.22-0" $.Capabilities.KubeVersion.GitVersion -}} +apiVersion: security.istio.io/v1 +{{- else -}} apiVersion: security.istio.io/v1beta1 +{{- end }} kind: RequestAuthentication metadata: {{- if .requestAuthentication.name }} - name: {{.requestAuthentication.name }} + name: {{ .requestAuthentication.name }} {{- else }} name: {{ template ".Chart.Name .fullname" $ }} {{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-virtualservice.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-virtualservice.yaml index 32a3380228..bc0ff136ba 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-virtualservice.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/istio-virtualservice.yaml @@ -1,6 +1,10 @@ {{- with .Values.istio }} {{- if and .enable .virtualService.enabled }} +{{ if semverCompare ">=1.22-0" $.Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.istio.io/v1 +{{ else }} apiVersion: networking.istio.io/v1beta1 +{{- end }} kind: VirtualService metadata: {{- if .virtualService.name }} @@ -25,6 +29,9 @@ metadata: {{ toYaml .virtualService.annotations | indent 4 }} {{- end }} spec: +{{- if .virtualService.virtualServiceExtraSpec }} +{{ toYaml .virtualService.virtualServiceExtraSpec | indent 2}} +{{- end }} {{- if or .gateway.enabled .virtualService.gateways }} gateways: {{- if .gateway.enabled }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml index fa5321d303..d1b80f2194 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml @@ -1,4 +1,4 @@ -{{- if $.Values.appMetrics -}} +{{- if and ($.Values.appMetrics) (eq .Values.MetricsScraper "Prometheus") -}} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/podmonitor.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/podmonitor.yaml new file mode 100644 index 0000000000..2f22219191 --- /dev/null +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/podmonitor.yaml @@ -0,0 +1,32 @@ +{{ $podMonitorEnabled := include "podMonitorEnabled" . }} +{{- if eq "true" $podMonitorEnabled -}} +--- +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + {{- if .Values.podmonitor.name }} + name: {{ .Values.podmonitor.name }} + {{- else }} + name: {{ template ".Chart.Name .fullname" . }}-pm + {{- end }} +spec: + jobLabel: {{ .Values.podmonitor.jobLabel }} + namespaceSelector: + matchNames: + - devtron-demo +{{- if .Values.podmonitor.podMetricsEndpoints }} + podMetricsEndpoints: + {{- toYaml .Values.podmonitor.podMetricsEndpoints | nindent 4}} +{{- end }} + podTargetLabels: + - appId + - envId + - devtron_app_hash + selector: + matchLabels: + {{- if .Values.podmonitor.matchLabels }} + {{- toYaml .Values.pod.matchLabels | nindent 6 }} + {{- else }} + app: {{ template ".Chart.Name .name" $ }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml index 9b920388d2..466cd987af 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml @@ -1,5 +1,6 @@ {{ $serviceMonitorEnabled := include "serviceMonitorEnabled" . }} -{{- if eq "true" $serviceMonitorEnabled -}} +{{- if and (eq $serviceMonitorEnabled "true") (eq .Values.MetricsScraper "Prometheus") -}} + --- apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor @@ -59,6 +60,10 @@ spec: metricRelabelings: {{toYaml .servicemonitor.metricRelabelings | indent 8 }} {{- end }} +{{- if .servicemonitor.relabelings }} + relabelings: +{{ toYaml .servicemonitor.relabelings | indent 8 }} + {{- end }} {{- end }} {{- end }} {{- end }} @@ -98,6 +103,10 @@ spec: metricRelabelings: {{toYaml .servicemonitor.metricRelabelings | indent 8 }} {{- end }} +{{- if .servicemonitor.relabelings }} + relabelings: +{{ toYaml .servicemonitor.relabelings | indent 8 }} + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmrule.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmrule.yaml new file mode 100644 index 0000000000..8e3b162f8c --- /dev/null +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmrule.yaml @@ -0,0 +1,29 @@ +{{- if .Values.vmrule.enabled -}} +apiVersion: operator.victoriametrics.com/v1beta1 +kind: VMRule +metadata: + {{- if .Values.vmrule.name }} + name: {{ .Values.vmrule.name }} + {{- else }} + name: {{ template ".Chart.Name .fullname" . }}-vmr + {{- end }} + namespace: + labels: + kind: Victoria + app: {{ template ".Chart.Name .name" . }} + appId: {{ $.Values.app | quote }} + envId: {{ $.Values.env | quote }} + chart: {{ template ".Chart.Name .chart" . }} + release: {{ .Values.prometheus.release }} + {{- if .Values.vmrule.additionalLabels }} +{{ toYaml .Values.vmrule.additionalLabels | indent 4 }} + {{- end }} + {{- if .Values.appLabels }} +{{ toYaml .Values.appLabels | indent 4 }} + {{- end }} +spec: +{{- if .Values.vmrule.rules }} + groups: +{{ toYaml .Values.vmrule.rules | indent 4}} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml new file mode 100644 index 0000000000..cc60c79630 --- /dev/null +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml @@ -0,0 +1,127 @@ +{{ $scrapetype := include "scrapeType" . }} +{{- if and ($scrapetype) (eq .Values.MetricsScraper "Victoria") -}} +{{ $scraper := get (dict "servicemonitor" .Values.servicemonitor "vmservicescrape" .Values.vmservicescrape) $scrapetype }} +apiVersion: operator.victoriametrics.com/v1beta1 +kind: VMServiceScrape +metadata: + {{- if .Values.vmservicescrape.name }} + name: {{ .Values.vmservicescrape.name }} + {{- else }} + name: {{ template ".Chart.Name .fullname" . }}-vm + {{- end }} + labels: + kind: Victoria + app: {{ template ".Chart.Name .name" . }} + appId: {{ $.Values.app | quote }} + envId: {{ $.Values.env | quote }} + chart: {{ template ".Chart.Name .chart" . }} + release: {{ .Values.prometheus.release }} + {{- if .Values.vmservicescrape.additionalLabels }} +{{ toYaml .Values.vmservicescrape.additionalLabels | indent 4 }} + {{- end }} + {{- if .Values.appLabels }} +{{ toYaml .Values.appLabels | indent 4 }} + {{- end }} +spec: + endpoints: + {{- range .Values.ContainerPort }} + {{ $scraper := get (dict "servicemonitor" .servicemonitor "vmservicescrape" .vmservicescrape) $scrapetype }} + {{- if $scraper }} + {{- if $scraper.enabled}} + {{- if $scraper.targetPort }} + - targetPort: {{ $scraper.targetPort }} + {{- else if .servicePort }} + - port: {{ .name }} + {{- end }} + {{- if $scraper.path }} + path: {{ $scraper.path}} + {{- end }} + {{- if $scraper.scheme }} + scheme: {{ $scraper.scheme}} + {{- end }} + {{- if $scraper.interval }} + interval: {{ $scraper.interval}} + {{- end }} + {{- if $scraper.scrapeTimeout }} + scrapeTimeout: {{ $scraper.scrapeTimeout | quote }} + {{- end }} + {{- if $scraper.basicAuth }} + basicAuth: + {{- toYaml $scraper.basicAuth | nindent 8 }} + {{- end }} + {{- if $scraper.insecureTLS }} + tlsConfig: + insecureSkipVerify: true + {{- else if $scraper.tlsConfig }} + tlsConfig: + {{- toYaml $scraper.tlsConfig | nindent 8 }} + {{- end }} + {{- if $scraper.metricRelabelings}} + metricRelabelings: +{{toYaml $scraper.metricRelabelings | indent 8 }} + {{- end }} +{{- if $scraper.relabelings }} + relabelings: +{{ toYaml $scraper.relabelings | indent 8 }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- range .Values.containers }} + {{- range .ports }} + {{ $scraper := get (dict "servicemonitor" .servicemonitor "vmservicescrape" .vmservicescrape) $scrapetype }} + {{- if $scraper }} + {{- if $scraper.enabled}} + {{- if $scraper.targetPort }} + - targetPort: {{ $scraper.targetPort }} + {{- else if .servicePort }} + - port: {{ .name }} + {{- end }} + {{- if $scraper.path }} + path: {{ $scraper.path}} + {{- end }} + {{- if $scraper.scheme }} + scheme: {{ $scraper.scheme}} + {{- end }} + {{- if $scraper.interval }} + interval: {{ $scraper.interval}} + {{- end }} + {{- if $scraper.scrapeTimeout }} + scrapeTimeout: {{ $scraper.scrapeTimeout}} + {{- end }} + {{- if $scraper.basicAuth }} + basicAuth: + {{- toYaml $scraper.basicAuth | nindent 8 }} + {{- end }} + {{- if $scraper.insecureTLS }} + tlsConfig: + insecureSkipVerify: true + {{- else if $scraper.tlsConfig }} + tlsConfig: + {{- toYaml $scraper.tlsConfig | nindent 8 }} + {{- end }} + {{- if $scraper.metricRelabelings}} + metricRelabelings: +{{toYaml $scraper.metricRelabelings | indent 8 }} + {{- end }} +{{- if $scraper.relabelings }} + relabelings: +{{ toYaml $scraper.relabelings | indent 8 }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- if $scraper.namespaceSelector }} + namespaceSelector: + matchNames: + {{- toYaml $scraper.namespaceSelector | nindent 6 }} + {{- end }} + selector: + matchLabels: + {{- if $scraper.matchLabels }} + {{- toYaml $scraper.matchLabels | nindent 6 }} + {{- end }} + app: {{ template ".Chart.Name .name" $ }} +{{- end }} + diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/test_values.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/test_values.yaml index 48e62037f6..5008e2c6b3 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/test_values.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/test_values.yaml @@ -79,9 +79,20 @@ ContainerPort: useHTTP2: false supportStreaming: false idleTimeout: 1800s + # vmservicescrape: + # enabled: true + # path: /abcde + # scheme: 'http' + # interval: 30s + # scrapeTimeout: 20s + # metricRelabelings: + # - sourceLabels: [namespace] + # regex: '(.*)' + # replacement: myapp + # targetLabel: target_namespace servicemonitor: enabled: true - path: /abc + path: /abcd scheme: 'http' interval: 30s scrapeTimeout: 20s @@ -91,6 +102,7 @@ ContainerPort: replacement: myapp targetLabel: target_namespace + - name: app1 port: 8090 targetPort: 1234 @@ -204,7 +216,7 @@ istio: # host: service2 flaggerCanary: - enabled: false + enabled: true labels: {} annotations: {} createIstioGateway: @@ -259,6 +271,7 @@ flaggerCanary: # allowHeaders: # - x-some-header # maxAge: 24h + analysis: # schedule interval (default 60s) interval: 5s @@ -270,6 +283,11 @@ flaggerCanary: # canary increment step # percentage (0-100) stepWeight: 5 + metrics: + - name: test + interval: 10s + threshold: 10 + webhooks: [] thresholds: # minimum req success rate (non 5xx responses) # percentage (0-100) @@ -659,6 +677,27 @@ containers: volumeMounts: - mountPath: /usr/local/airflow/logs name: logs-data + ports: + - name: test + port: 8080 + servicePort: 80 + envoyTimeout: 15 + targetPort: 8080 + envoyPort: 8799 + useHTTP2: false + supportStreaming: false + idleTimeout: 1800s + vmservicescrape: + enabled: true + path: /abcde + scheme: 'http' + interval: 30s + scrapeTimeout: 20s + metricRelabelings: + - sourceLabels: [namespace] + regex: '(.*)' + replacement: myapp + targetLabel: target_namespace rawYaml: @@ -779,4 +818,18 @@ secondaryWorkload: MinReplicas: 1 MaxReplicas: 2 TargetCPUUtilizationPercentage: 90 - TargetMemoryUtilizationPercentage: 80 \ No newline at end of file + TargetMemoryUtilizationPercentage: 80 + + +vmservicescrape: + name: test + +vmrule: + name: test-vmr + rules: + - name: kubelet.rules + record: dksjndksnd + - name: kznjdk + record: kdjskjdnks + +MetricsScraper: Victoria \ No newline at end of file diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/values.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/values.yaml index d67a0b2560..aebe4a920c 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/values.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/values.yaml @@ -383,6 +383,8 @@ prometheus: servicemonitor: additionalLabels: {} +vmservicescrape: + additionalLabels: {} prometheusRule: enabled: false @@ -715,4 +717,18 @@ secondaryWorkload: autoscaling: enabled: false containerResource: - enabled: false \ No newline at end of file + enabled: false + + + +vmrule: + enabled: false + name: test-vmr + rules: [] + +podmonitor: + enabled: false + name: "" + jobLabel: test + +MetricsScraper: Prometheus From b8770c3f60b4ce66e9f4e46a13650dd9564dd8df Mon Sep 17 00:00:00 2001 From: kamal-devtron Date: Tue, 10 Jun 2025 11:52:58 +0530 Subject: [PATCH 2/4] changes in service scraper and helpers tpl --- .../templates/_helpers.tpl | 5 +- .../templates/metrics-service-monitor.yaml | 35 ----- ...vice-scraper.yaml => service-scraper.yaml} | 16 ++- .../templates/servicemonitor.yaml | 126 ------------------ 4 files changed, 14 insertions(+), 168 deletions(-) delete mode 100644 scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml rename scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/{vmservice-scraper.yaml => service-scraper.yaml} (94%) delete mode 100644 scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl index 07465d79f1..98f7ac04e0 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/_helpers.tpl @@ -193,12 +193,15 @@ Create chart name and version as used by the chart label. {{- $VmServiceScrapeEnabled := include "vmserviceScrapeEnabled" . -}} {{- $val1 := "vmservicescrape"}} {{- $val2 := "servicemonitor"}} + {{- $val3 := "" }} {{- if and (eq $VmServiceScrapeEnabled "true") (eq $ServiceMonitorEnabled "true")}} {{- $val1 }} {{- else if eq $ServiceMonitorEnabled "true" }} {{- $val2 }} {{- else if eq $VmServiceScrapeEnabled "true" }} - {{- $val1 }} + {{- $val1 }} + {{- else }} + {{- $val3 }} {{- end }} {{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml deleted file mode 100644 index d1b80f2194..0000000000 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/metrics-service-monitor.yaml +++ /dev/null @@ -1,35 +0,0 @@ -{{- if and ($.Values.appMetrics) (eq .Values.MetricsScraper "Prometheus") -}} -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - name: {{ template ".Chart.Name .fullname" $ }} - labels: - app: {{ template ".Chart.Name .name" . }} - appId: {{ $.Values.app | quote }} - envId: {{ $.Values.env | quote }} - chart: {{ template ".Chart.Name .chart" . }} - release: {{ .Values.prometheus.release }} -spec: - jobLabel: {{ template ".Chart.Name .name" $ }} - endpoints: - - port: envoy-admin - interval: 30s - path: /stats/prometheus - relabelings: - - action: replace - sourceLabels: - - __meta_kubernetes_pod_label_pod_template_hash - targetLabel: devtron_app_hash - selector: - matchLabels: - app: {{ template ".Chart.Name .name" $ }} - appId: {{ $.Values.app | quote }} - envId: {{ $.Values.env | quote }} - namespaceSelector: - matchNames: - - {{.Release.Namespace}} - podTargetLabels: - - appId - - envId - - devtron_app_hash -{{- end }} diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/service-scraper.yaml similarity index 94% rename from scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml rename to scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/service-scraper.yaml index cc60c79630..1b50719db4 100644 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/vmservice-scraper.yaml +++ b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/service-scraper.yaml @@ -1,16 +1,21 @@ {{ $scrapetype := include "scrapeType" . }} -{{- if and ($scrapetype) (eq .Values.MetricsScraper "Victoria") -}} {{ $scraper := get (dict "servicemonitor" .Values.servicemonitor "vmservicescrape" .Values.vmservicescrape) $scrapetype }} +{{- if ($scrapetype) }} +{{- if and ($scrapetype) (eq .Values.MetricsScraper "Victoria") -}} apiVersion: operator.victoriametrics.com/v1beta1 kind: VMServiceScrape +{{- else }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +{{- end }} metadata: - {{- if .Values.vmservicescrape.name }} - name: {{ .Values.vmservicescrape.name }} + {{- if $scraper.name }} + name: {{ $scraper.name }} {{- else }} name: {{ template ".Chart.Name .fullname" . }}-vm {{- end }} labels: - kind: Victoria + kind: {{ $scrapetype }} app: {{ template ".Chart.Name .name" . }} appId: {{ $.Values.app | quote }} envId: {{ $.Values.env | quote }} @@ -119,9 +124,8 @@ spec: {{- end }} selector: matchLabels: - {{- if $scraper.matchLabels }} + {{- if .Values.servicemonitor.matchLabels }} {{- toYaml $scraper.matchLabels | nindent 6 }} {{- end }} app: {{ template ".Chart.Name .name" $ }} {{- end }} - diff --git a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml b/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml deleted file mode 100644 index 466cd987af..0000000000 --- a/scripts/devtron-reference-helm-charts/deployment-chart_4-21-0/templates/servicemonitor.yaml +++ /dev/null @@ -1,126 +0,0 @@ -{{ $serviceMonitorEnabled := include "serviceMonitorEnabled" . }} -{{- if and (eq $serviceMonitorEnabled "true") (eq .Values.MetricsScraper "Prometheus") -}} - ---- -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - {{- if .Values.servicemonitor.name }} - name: {{ .Values.servicemonitor.name }} - {{- else }} - name: {{ template ".Chart.Name .fullname" . }}-sm - {{- end }} - labels: - kind: Prometheus - app: {{ template ".Chart.Name .name" . }} - appId: {{ $.Values.app | quote }} - envId: {{ $.Values.env | quote }} - chart: {{ template ".Chart.Name .chart" . }} - release: {{ .Values.prometheus.release }} - {{- if .Values.servicemonitor.additionalLabels }} -{{ toYaml .Values.servicemonitor.additionalLabels | indent 4 }} - {{- end }} - {{- if .Values.appLabels }} -{{ toYaml .Values.appLabels | indent 4 }} - {{- end }} -spec: - endpoints: - {{- range .Values.ContainerPort }} - {{- if .servicemonitor }} - {{- if .servicemonitor.enabled}} - {{- if .servicemonitor.targetPort }} - - targetPort: {{ .servicemonitor.targetPort }} - {{- else if .servicePort }} - - port: {{ .name }} - {{- end }} - {{- if .servicemonitor.path }} - path: {{ .servicemonitor.path}} - {{- end }} - {{- if .servicemonitor.scheme }} - scheme: {{ .servicemonitor.scheme}} - {{- end }} - {{- if .servicemonitor.interval }} - interval: {{ .servicemonitor.interval}} - {{- end }} - {{- if .servicemonitor.scrapeTimeout }} - scrapeTimeout: {{ .servicemonitor.scrapeTimeout | quote }} - {{- end }} - {{- if .servicemonitor.basicAuth }} - basicAuth: - {{- toYaml .servicemonitor.basicAuth | nindent 8 }} - {{- end }} - {{- if .servicemonitor.insecureTLS }} - tlsConfig: - insecureSkipVerify: true - {{- else if .servicemonitor.tlsConfig }} - tlsConfig: - {{- toYaml .servicemonitor.tlsConfig | nindent 8 }} - {{- end }} - {{- if .servicemonitor.metricRelabelings}} - metricRelabelings: -{{toYaml .servicemonitor.metricRelabelings | indent 8 }} - {{- end }} -{{- if .servicemonitor.relabelings }} - relabelings: -{{ toYaml .servicemonitor.relabelings | indent 8 }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} - {{- range .Values.containers }} - {{- range .ports }} - {{- if .servicemonitor }} - {{- if .servicemonitor.enabled}} - {{- if .servicemonitor.targetPort }} - - targetPort: {{ .servicemonitor.targetPort }} - {{- else if .servicePort }} - - port: {{ .name }} - {{- end }} - {{- if .servicemonitor.path }} - path: {{ .servicemonitor.path}} - {{- end }} - {{- if .servicemonitor.scheme }} - scheme: {{ .servicemonitor.scheme}} - {{- end }} - {{- if .servicemonitor.interval }} - interval: {{ .servicemonitor.interval}} - {{- end }} - {{- if .servicemonitor.scrapeTimeout }} - scrapeTimeout: {{ .servicemonitor.scrapeTimeout}} - {{- end }} - {{- if .servicemonitor.basicAuth }} - basicAuth: - {{- toYaml .servicemonitor.basicAuth | nindent 8 }} - {{- end }} - {{- if .servicemonitor.insecureTLS }} - tlsConfig: - insecureSkipVerify: true - {{- else if .servicemonitor.tlsConfig }} - tlsConfig: - {{- toYaml .servicemonitor.tlsConfig | nindent 8 }} - {{- end }} - {{- if .servicemonitor.metricRelabelings}} - metricRelabelings: -{{toYaml .servicemonitor.metricRelabelings | indent 8 }} - {{- end }} -{{- if .servicemonitor.relabelings }} - relabelings: -{{ toYaml .servicemonitor.relabelings | indent 8 }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} - {{- if .Values.servicemonitor.namespaceSelector }} - namespaceSelector: - matchNames: - {{- toYaml .Values.servicemonitor.namespaceSelector | nindent 6 }} - {{- end }} - selector: - matchLabels: - {{- if .Values.servicemonitor.matchLabels }} - {{- toYaml .Values.servicemonitor.matchLabels | nindent 6 }} - {{- else }} - app: {{ template ".Chart.Name .name" $ }} -{{- end }} -{{- end }} From fdffc0ccc58c7a8fce6622cf810f5608483ee2f9 Mon Sep 17 00:00:00 2001 From: kamal-devtron Date: Tue, 10 Jun 2025 15:41:43 +0530 Subject: [PATCH 3/4] added sql file for deployment 4.21 --- ...3603701_deployment-chart-ref_4-21-0.up.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql diff --git a/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql b/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql new file mode 100644 index 0000000000..639ec825b9 --- /dev/null +++ b/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql @@ -0,0 +1,30 @@ +INSERT INTO "public"."chart_ref" ("location", "version", "is_default", "active", "created_on", "created_by", "updated_on", "updated_by", "name", "deployment_strategy_path") +SELECT 'deployment-chart_4-21-0', '4.21.0', 'f', 't', 'now()', 1, 'now()', 1, 'Deployment', 'pipeline-values.yaml' +WHERE NOT EXISTS ( + SELECT 1 FROM "public"."chart_ref" WHERE "location" = 'deployment-chart_4-21-0' +); + +-- Next, safely insert the mapping if it doesn't already exist. +INSERT INTO "public"."global_strategy_metadata_chart_ref_mapping" ("global_strategy_metadata_id", "chart_ref_id", "active", "default", "created_on", "created_by", "updated_on", "updated_by") +SELECT + (SELECT "id" FROM "public"."global_strategy_metadata" WHERE "name" = 'ROLLING'), + (SELECT "id" FROM "public"."chart_ref" WHERE "location" = 'deployment-chart_4-21-0'), + true, true, 'now()', 1, 'now()', 1 +WHERE NOT EXISTS ( + SELECT 1 + FROM "public"."global_strategy_metadata_chart_ref_mapping" + WHERE "global_strategy_metadata_id" = (SELECT "id" FROM "public"."global_strategy_metadata" WHERE "name" = 'ROLLING') + AND "chart_ref_id" = (SELECT "id" FROM "public"."chart_ref" WHERE "location" = 'deployment-chart_4-21-0') +); + +INSERT INTO "public"."global_strategy_metadata_chart_ref_mapping" ("global_strategy_metadata_id", "chart_ref_id", "active", "default", "created_on", "created_by", "updated_on", "updated_by") +SELECT + (SELECT "id" FROM "public"."global_strategy_metadata" WHERE "name" = 'RECREATE'), + (SELECT "id" FROM "public"."chart_ref" WHERE "location" = 'deployment-chart_4-21-0'), + true, true, 'now()', 1, 'now()', 1 +WHERE NOT EXISTS ( + SELECT 1 + FROM "public"."global_strategy_metadata_chart_ref_mapping" + WHERE "global_strategy_metadata_id" = (SELECT "id" FROM "public"."global_strategy_metadata" WHERE "name" = 'RECREATE') + AND "chart_ref_id" = (SELECT "id" FROM "public"."chart_ref" WHERE "location" = 'deployment-chart_4-21-0') +); \ No newline at end of file From d7d47ee437f2c11d40a2f08a9848b7f1cb5d596f Mon Sep 17 00:00:00 2001 From: kamal-devtron Date: Wed, 11 Jun 2025 11:38:52 +0530 Subject: [PATCH 4/4] changes in sql script --- scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql b/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql index 639ec825b9..2c04f71aa8 100644 --- a/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql +++ b/scripts/sql/33603701_deployment-chart-ref_4-21-0.up.sql @@ -1,5 +1,7 @@ +UPDATE chart_ref SET is_default=false; + INSERT INTO "public"."chart_ref" ("location", "version", "is_default", "active", "created_on", "created_by", "updated_on", "updated_by", "name", "deployment_strategy_path") -SELECT 'deployment-chart_4-21-0', '4.21.0', 'f', 't', 'now()', 1, 'now()', 1, 'Deployment', 'pipeline-values.yaml' +SELECT 'deployment-chart_4-21-0', '4.21.0', 't', 't', 'now()', 1, 'now()', 1, 'Deployment', 'pipeline-values.yaml' WHERE NOT EXISTS ( SELECT 1 FROM "public"."chart_ref" WHERE "location" = 'deployment-chart_4-21-0' );