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

Support for Prometheus operator #63

Merged
merged 3 commits into from Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -19,3 +19,8 @@ Parameter | Description | Default
`ingress.hosts` | Ingress hostnames | `[cost-analyzer.local]`
`ingress.tls` | Ingress TLS configuration (YAML) | `[]`
`networkPolicy.enabled` | If true, create a NetworkPolicy to deny egress | `false`
`serviceMonitor.enabled` | Set this to `true` to create ServiceMonitor for Prometheus operator | `false`
`serviceMonitor.additionalLabels` | Additional labels that can be used so ServiceMonitor will be discovered by Prometheus | `{}`
`prometheusRule.enabled` | Set this to `true` to create PrometheusRule for Prometheus operator | `false`
`prometheusRule.additionalLabels` | Additional labels that can be used so PrometheusRule will be discovered by Prometheus | `{}`
`grafana.sidecar.datasources.defaultDatasourceEnabled` | Set this to `false` to disable creation of Prometheus datasource in Grafana | `true`
8 changes: 8 additions & 0 deletions cost-analyzer/templates/_helpers.tpl
Expand Up @@ -51,3 +51,11 @@ helm.sh/chart: {{ include "cost-analyzer.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Create the selector labels.
*/}}
{{- define "cost-analyzer.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cost-analyzer.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
Expand Up @@ -13,7 +13,7 @@ spec:
template:
metadata:
labels:
app: cost-analyzer
sebastien-prudhomme marked this conversation as resolved.
Show resolved Hide resolved
{{ include "cost-analyzer.selectorLabels" . | nindent 8 }}
{{- if .Values.global.podAnnotations}}
annotations:
{{- with .Values.global.podAnnotations }}
Expand Down
2 changes: 1 addition & 1 deletion cost-analyzer/templates/cost-analyzer-network-policy.yaml
Expand Up @@ -9,7 +9,7 @@ metadata:
spec:
podSelector:
matchLabels:
app: cost-analyzer
{{ include "cost-analyzer.selectorLabels" . | nindent 6 }}
policyTypes:
- Egress
egress:
Expand Down
21 changes: 21 additions & 0 deletions cost-analyzer/templates/cost-analyzer-prometheusrule-template.yaml
@@ -0,0 +1,21 @@
{{- if .Values.prometheus }}
{{- if .Values.prometheus.serverFiles }}
{{- if .Values.prometheus.serverFiles.rules }}
{{- if .Values.prometheusRule }}
{{- if .Values.prometheusRule.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ include "cost-analyzer.fullname" . }}
labels:
{{ include "cost-analyzer.commonLabels" . | nindent 4 }}
{{- if .Values.prometheusRule.additionalLabels }}
{{ toYaml .Values.prometheusRule.additionalLabels | nindent 4 }}
{{- end }}
spec:
{{ toYaml .Values.prometheus.serverFiles.rules | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Up @@ -6,7 +6,7 @@ metadata:
{{ include "cost-analyzer.commonLabels" . | nindent 4 }}
spec:
selector:
app: cost-analyzer
{{ include "cost-analyzer.selectorLabels" . | nindent 4 }}
{{- if .Values.service -}}
{{- if .Values.service.type }}
type: "{{ .Values.service.type }}"
Expand Down
27 changes: 27 additions & 0 deletions cost-analyzer/templates/cost-analyzer-servicemonitor-template.yaml
@@ -0,0 +1,27 @@
{{- if .Values.serviceMonitor }}
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "cost-analyzer.fullname" . }}
labels:
{{ include "cost-analyzer.commonLabels" . | nindent 4 }}
{{- if .Values.serviceMonitor.additionalLabels }}
{{ toYaml .Values.serviceMonitor.additionalLabels | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: model
honorLabels: true
interval: 1m
scrapeTimeout: 10s
path: /metrics
scheme: http
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
{{ include "cost-analyzer.selectorLabels" . | nindent 6 }}
{{- end }}
{{- end }}
5 changes: 4 additions & 1 deletion cost-analyzer/templates/grafana-datasource-template.yaml
Expand Up @@ -2,12 +2,14 @@
{{- if .Values.grafana.sidecar -}}
{{- if .Values.grafana.sidecar.datasources -}}
{{- if .Values.grafana.sidecar.datasources.enabled -}}
{{- if .Values.grafana.sidecar.datasources.defaultDatasourceEnabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-datasource
labels:
grafana_datasource: "1"
{{ include "cost-analyzer.commonLabels" . | nindent 4 }}
grafana_datasource: "1"
data:
datasource.yaml: |-
# config file version
Expand All @@ -25,4 +27,5 @@ data:
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
10 changes: 10 additions & 0 deletions cost-analyzer/values.yaml
Expand Up @@ -94,9 +94,19 @@ prometheus:
record: cluster:cpu_usage:rate5m
- expr: rate(container_cpu_usage_seconds_total{container_name!=""}[5m])
record: cluster:cpu_usage_nosum:rate5m

serviceMonitor:
enabled: false
additionalLabels: {}

prometheusRule:
enabled: false
additionalLabels: {}

grafana:
sidecar:
dashboards:
enabled: true
datasources:
enabled: true
defaultDatasourceEnabled: true