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

connectors: convert pod-monitor.yaml to go #1448

Merged
merged 1 commit into from
Jul 25, 2024
Merged
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
56 changes: 56 additions & 0 deletions charts/connectors/podmonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// +gotohelm:filename=_pod-monitor.go.tpl
package connectors

import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func PodMonitor(dot *helmette.Dot) *monitoringv1.PodMonitor {
values := helmette.Unwrap[Values](dot.Values)

// TODO Add check for .Capabilities.APIVersions.Has "monitoring.coreos.com/v1"
if !values.Monitoring.Enabled {
return nil
}

return &monitoringv1.PodMonitor{
TypeMeta: metav1.TypeMeta{
APIVersion: "monitoring.coreos.com/v1",
Kind: "PodMonitor",
},
ObjectMeta: metav1.ObjectMeta{
Name: Fullname(dot),
Labels: values.Monitoring.Labels,
Annotations: values.Monitoring.Annotations,
},
Spec: monitoringv1.PodMonitorSpec{
NamespaceSelector: values.Monitoring.NamespaceSelector,
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Path: "/",
Port: "prometheus",
},
},
Selector: metav1.LabelSelector{
MatchLabels: PodLabels(dot),
},
},
}
}
18 changes: 18 additions & 0 deletions charts/connectors/templates/_pod-monitor.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- /* Generated from "podmonitor.go" */ -}}

{{- define "connectors.PodMonitor" -}}
{{- $dot := (index .a 0) -}}
{{- range $_ := (list 1) -}}
{{- $_is_returning := false -}}
{{- $values := $dot.Values.AsMap -}}
{{- if (not $values.monitoring.enabled) -}}
{{- $_is_returning = true -}}
{{- (dict "r" (coalesce nil)) | toJson -}}
{{- break -}}
{{- end -}}
{{- $_is_returning = true -}}
{{- (dict "r" (mustMergeOverwrite (dict "metadata" (dict "creationTimestamp" (coalesce nil) ) "spec" (dict "podMetricsEndpoints" (coalesce nil) "selector" (dict ) "namespaceSelector" (dict ) ) ) (mustMergeOverwrite (dict ) (dict "apiVersion" "monitoring.coreos.com/v1" "kind" "PodMonitor" )) (dict "metadata" (mustMergeOverwrite (dict "creationTimestamp" (coalesce nil) ) (dict "name" (get (fromJson (include "connectors.Fullname" (dict "a" (list $dot) ))) "r") "labels" $values.monitoring.labels "annotations" $values.monitoring.annotations )) "spec" (mustMergeOverwrite (dict "podMetricsEndpoints" (coalesce nil) "selector" (dict ) "namespaceSelector" (dict ) ) (dict "namespaceSelector" $values.monitoring.namespaceSelector "podMetricsEndpoints" (list (mustMergeOverwrite (dict "bearerTokenSecret" (dict "key" "" ) ) (dict "path" "/" "port" "prometheus" ))) "selector" (mustMergeOverwrite (dict ) (dict "matchLabels" (get (fromJson (include "connectors.PodLabels" (dict "a" (list $dot) ))) "r") )) )) ))) | toJson -}}
{{- break -}}
{{- end -}}
{{- end -}}

28 changes: 5 additions & 23 deletions charts/connectors/templates/pod-monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{- if and (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") .Values.monitoring.enabled }}
{{/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
Expand All @@ -15,26 +14,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}

apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: {{ template "connectors.fullname" . }}
labels:
{{- with .Values.monitoring.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.monitoring.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.monitoring.namespaceSelector }}
namespaceSelector: {{- toYaml . | nindent 4}}
{{- end }}
podMetricsEndpoints:
- path: /
port: prometheus
selector:
matchLabels: {{ (include "connectors-pod-labels" .) | nindent 6 }}
{{ $pm := (get ((include "connectors.PodMonitor" (dict "a" (list .))) | fromJson) "r") }}
{{- if ne $pm nil -}}
---
{{ toYaml $pm }}
{{- end }}

Loading