Skip to content

Commit

Permalink
Merge pull request #63 from sebastien-prudhomme/prometheus-operator
Browse files Browse the repository at this point in the history
Support for Prometheus operator
  • Loading branch information
AjayTripathy authored Jun 11, 2019
2 parents 1f140dc + 267af36 commit 7de45d2
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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`
9 changes: 9 additions & 0 deletions cost-analyzer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ app.kubernetes.io/name: {{ include "cost-analyzer.name" . }}
helm.sh/chart: {{ include "cost-analyzer.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app: cost-analyzer
{{- end -}}

{{/*
Create the selector labels.
*/}}
{{- define "cost-analyzer.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cost-analyzer.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
template:
metadata:
labels:
app: cost-analyzer
{{ 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7de45d2

Please sign in to comment.