Skip to content

Commit

Permalink
Add chart to provide a dedicated prometheus for one tsuru pool
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Apr 16, 2021
1 parent 3c3a346 commit f20afc8
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/tsuru-prometheus-pool/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions charts/tsuru-prometheus-pool/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: tsuru-prometheus-pool
description: Dedicated prometheus instance by tsuru pool

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0
62 changes: 62 additions & 0 deletions charts/tsuru-prometheus-pool/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "..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 "..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 "..chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "..labels" -}}
helm.sh/chart: {{ include "..chart" . }}
{{ include "..selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "..selectorLabels" -}}
app.kubernetes.io/name: {{ include "..name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "..serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "..fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
58 changes: 58 additions & 0 deletions charts/tsuru-prometheus-pool/templates/apps_monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: tsuru-apps
labels:
tsuru.io/pool: {{ .Values.tsuru.pool.name }}
{{- include "..labels" . | nindent 4 }}
spec:
selector:
matchLabels:
tsuru.io/is-tsuru: "true"
tsuru.io/is-build: "false"
tsuru.io/is-deploy: "false"
podMetricsEndpoints:
- relabelings:
- sourceLabels:
- '__meta_kubernetes_pod_annotation_prometheus_io_scrape'
regex: 'true'
action: 'keep'
- sourceLabels:
- '__meta_kubernetes_pod_annotation_prometheus_io_scheme'
regex: '(https?)'
targetLabel: '__scheme__'
- sourceLabels:
- '__meta_kubernetes_pod_annotation_prometheus_io_path'
regex: '(.+)'
targetLabel: '__metrics_path__'
action: replace
- sourceLabels:
- '__address__'
- '__meta_kubernetes_pod_annotation_prometheus_io_port'
regex: '([^:]+)(?::\d+)?;(\d+)'
targetLabel: '__address__'
replacement: '$1:$2'
action: 'replace'

- sourceLabels:
- '__meta_kubernetes_pod_label_tsuru_io_app_name'
targetLabel: 'tsuru_app'
- sourceLabels:
- '__meta_kubernetes_pod_label_tsuru_io_app_version'
targetLabel: 'tsuru_app_version'
- sourceLabels:
- '__meta_kubernetes_pod_label_tsuru_io_app_process'
targetLabel: 'tsuru_app_process'
- sourceLabels:
- '__meta_kubernetes_pod_label_tsuru_io_app_team'
targetLabel: 'tsuru_team'
- sourceLabels:
- '__meta_kubernetes_pod_label_tsuru_io_app_pool'
targetLabel: 'tsuru_pool'
- sourceLabels:
- '__meta_kubernetes_pod_label_tsuru_io_app_platform'
targetLabel: 'tsuru_platform'
- sourceLabels:
- 'pod'
targetLabel: 'tsuru_unit'
action: replace
36 changes: 36 additions & 0 deletions charts/tsuru-prometheus-pool/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "..fullname" . -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "..labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
- host: {{ .Values.ingress.host | quote }}
http:
paths:
- path: {{ .Values.ingress.path }}
backend:
serviceName: {{ $fullName }}
servicePort: 9090
{{- end }}
36 changes: 36 additions & 0 deletions charts/tsuru-prometheus-pool/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.networkPolicy.enabled -}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "..fullname" . }}
labels:
{{- include "..labels" . | nindent 4 }}
spec:
egress:
- to: # allow egress to same namespace
- namespaceSelector:
matchLabels:
name: tsuru-{{ .Values.tsuru.pool.name }}

- ports: # allow egress to k8s-apiserver
- port: 80
protocol: TCP
- port: 443
protocol: TCP
to:
- namespaceSelector:
matchLabels:
name: default

{{ range $_, $ip := .Values.networkPolicy.k8sAPIAddresses }}
- ipBlock:
cidr: {{ $ip }}/32
{{ end }}

podSelector:
matchLabels:
tsuru.io/pool: {{ .Values.tsuru.pool.name }}

policyTypes:
- Egress
{{- end }}
57 changes: 57 additions & 0 deletions charts/tsuru-prometheus-pool/templates/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: {{ include "..fullname" . }}
labels:
{{- include "..labels" . | nindent 4 }}
spec:
alerting:
alertmanagers: []
arbitraryFSAccessThroughSMs: {}
externalLabels:
prometheus_from: tsuru-pool-{{ .Values.tsuru.pool.name }}
{{- if .Values.ingress.enabled }}
externalUrl: http://{{ .Values.ingress.host }}
{{ end }}
image: {{ .Values.prometheus.image.repository }}:{{ .Values.prometheus.version }}
logFormat: logfmt
logLevel: info
podMetadata:
labels:
tsuru.io/pool: {{ .Values.tsuru.pool.name }}
{{- include "..labels" . | nindent 6 }}
podMonitorNamespaceSelector:
matchLabels:
name: tsuru-{{ .Values.tsuru.pool.name }}
podMonitorSelector:
matchLabels:
tsuru.io/pool: {{ .Values.tsuru.pool.name }}
portName: web
probeNamespaceSelector:
matchLabels:
name: tsuru-{{ .Values.tsuru.pool.name }}
replicas: {{ .Values.replicaCount }}
resources: {}
retention: 10d
routePrefix: /
ruleNamespaceSelector:
matchLabels:
name: tsuru-{{ .Values.tsuru.pool.name }}
rules:
alert: {}
securityContext:
{{- .Values.securityContext | toYaml | nindent 4 }}
fsGroup: 2000
runAsGroup: 2000
runAsNonRoot: true
runAsUser: 1000
serviceAccountName: {{ include "..serviceAccountName" . }}
serviceMonitorNamespaceSelector:
matchLabels:
name: tsuru-{{ .Values.tsuru.pool.name }}
serviceMonitorSelector: {}
shards: 1
version: {{ .Values.prometheus.version }}
storage:
volumeClaimTemplate:
{{- .Values.volumeClaimTemplate | toYaml |nindent 6}}
41 changes: 41 additions & 0 deletions charts/tsuru-prometheus-pool/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "..fullname" . }}-reader
labels:
{{- include "..labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
resources:
- nodes
- nodes/metrics
- services
- endpoints
- pods
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "..fullname" . }}
labels:
{{- include "..labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "..fullname" . }}-reader
subjects:
- kind: ServiceAccount
name: {{ include "..serviceAccountName" . }}
12 changes: 12 additions & 0 deletions charts/tsuru-prometheus-pool/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "..serviceAccountName" . }}
labels:
{{- include "..labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit f20afc8

Please sign in to comment.