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

Templatize ServiceMonitor #1130

Open
patila-hpe opened this issue Apr 16, 2024 · 0 comments
Open

Templatize ServiceMonitor #1130

patila-hpe opened this issue Apr 16, 2024 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@patila-hpe
Copy link

Is your feature request related to a problem? Please describe.

There's no provision to set custom values for Service Monitor when enabled. Looking at fluentbit-servicemonitor.yaml, the template is barebones without any placeholders to accept custom values for endpoints, selectors, labels etc.

metadata:
  name: fluent-bit
  labels:
    app.kubernetes.io/name: fluent-bit
spec:
  endpoints:
    - port: metrics
      path: /api/v2/metrics/prometheus
      interval: 30s
  selector:
    matchLabels:
      app.kubernetes.io/name: fluent-bit

We cannot specify namespace on resource and selectors, there's no ability to specify additional labels.

Describe the solution you'd like

This can be parameterized to accept custom values.

fluentbit-servicemonitor.yaml

{{- if .Values.Kubernetes -}}
{{- if .Values.fluentbit.enable -}}
{{- if .Values.fluentbit.serviceMonitor.enable -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: fluent-bit
  labels:
    app.kubernetes.io/name: fluent-bit
  namespace: {{ template "fluent-operator.namespace" . }}
spec:
  endpoints:
    - port: metrics
      path: {{ .Values.fluentbit.serviceMonitor.path }} 
      interval: {{ .Values.fluentbit.serviceMonitor.interval }}
      {{- if .Values.fluentbit.serviceMonitor.secure }}
      scheme: https
      tlsConfig:
        {{- toYaml .Values.fluentbit.serviceMonitor.tlsConfig }}
      {{- end }}
      scrapeTimeout: {{ .Values.fluentbit.serviceMonitor.scrapeTimeout }}
      {{- with .Values.fluentbit.serviceMonitor.relabelings }}
      relabelings:
        {{- toYaml . | nindent 6 }}
      {{- end }}
      {{- with .Values.fluentbit.serviceMonitor.metricRelabelings }}
      metricRelabelings:
        {{- toYaml . | nindent 6 }}
      {{- end }}
  selector:
    matchLabels:
      {{- include "fluent-operator.selectorLabels" . | nindent 6 }}
      {{- with .Values.fluentbit.labels }}
      {{- toYaml .Values.fluentbit.labels | nindent 6}}
      {{- end }}
  namespaceSelector:
    matchNames:
    - {{ template "fluent-operator.namespace" . }} 
{{- end }}
{{- end }}
{{- end }}

and modify default values.yaml -

fluentbit:
  # Installs a sub chart carrying the CRDs for the fluent-bit controller. The sub chart is enabled by default.
  crdsEnable: true
  enable: true
  serviceMonitor: 
    enable: false
    interval: 30s
    path: /api/v2/metrics/prometheus
    scrapeTimeout: 10s
    secure: false
    tlsConfig: {}
    relabelings: []
    metricRelabelings: []

Additional context

No response

@benjaminhuo benjaminhuo added help wanted Extra attention is needed good first issue Good for newcomers labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants