Skip to content

Commit

Permalink
[charts/nri-prometheus] imported (#36)
Browse files Browse the repository at this point in the history
* [charts/nri-prometheus] imported chart

* [charts/nri-prometheus] added maintainers & home

* [charts/nri-prometheus] added test licenseKey
  • Loading branch information
jorikvdwerf authored May 21, 2020
1 parent 6b47d58 commit e1ae3a0
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 0 deletions.
22 changes: 22 additions & 0 deletions charts/nri-prometheus/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
15 changes: 15 additions & 0 deletions charts/nri-prometheus/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
appVersion: 1.3.0
description: A Helm chart to deploy the New Relic Prometheus OpenMetrics integration
name: nri-prometheus
version: 1.0.1
engine: gotpl
home: https://github.com/newrelic/nri-prometheus
icon: https://newrelic.com/assets/newrelic/source/NewRelic-logo-square.svg
keywords:
- prometheus
- newrelic
- monitoring
maintainers:
- name: douglascamata
- name: jorikvdwerf
38 changes: 38 additions & 0 deletions charts/nri-prometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# New Relic's Prometheus OpenMetrics Integration

## Chart Details

This chart will deploy the New Relic's Prometheus OpenMetrics Integration.

## Configuration

| Parameter | Description | Default |
|------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `global.cluster` - `cluster` | The cluster name for the Kubernetes cluster. | |
| `global.licenseKey` - `licenseKey` | The [license key](https://docs.newrelic.com/docs/accounts/install-new-relic/account-setup/license-key) for your New Relic Account. This will be preferred configuration option if both `licenseKey` and `customSecret` are specified. | |
| `global.customSecretName` - `customSecretName` | Name of the Secret object where the license key is stored | |
| `global.customSecretLicenseKey` - `customSecretLicenseKey` | Key in the Secret object where the license key is stored. | |
| `nameOverride` | The name that should be used for the deployment. | |
| `image.repository` | The prometheus openmetrics integration image name. | `newrelic/nri-prometheus` |
| `image.tag` | The prometheus openmetrics integration image tag. | `1.3.0` |
| `resources` | A yaml defining the resources for the events-router container. | {} |
| `rbac.create` | Enable Role-based authentication | `true` |
| `serviveAccount.create` | If true, a service account would be created and assigned to the deployment | true |
| `serviveAccount.name` | The service account to assign to the deployment. If `serviveAccount.create` is true then this name will be used when creating the service account | |
| `nodeSelector` | Node label to use for scheduling | `{}` |
| `tolerations` | List of node taints to tolerate (requires Kubernetes >= 1.6) | `[]` |
| `affinity` | Node affinity to use for scheduling | `{}` |
| `prometheusScrape` | true | Value for `prometheus.io/scrape` label |

## Example


Make sure you have [added the New Relic chart repository.](../../README.md#installing-charts)

Then, to install this chart, run the following command:

```sh
helm install newrelic/nri-prometheus \
--set licenseKey=<enter_new_relic_license_key> \
--set cluster=my-k8s-cluster
```
3 changes: 3 additions & 0 deletions charts/nri-prometheus/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global:
licenseKey: 1234567890abcdef1234567890abcdef12345678
cluster: test-cluster
7 changes: 7 additions & 0 deletions charts/nri-prometheus/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- if (include "nri-prometheus.areValuesValid" .) }}
Your deployment of the New Relic Prometheus scraper is complete.
{{- else -}}
##############################################################################
#### ERROR: You did not set a licenseKey and/or cluster name. ####
##############################################################################
{{- end -}}
128 changes: 128 additions & 0 deletions charts/nri-prometheus/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "nri-prometheus.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 "nri-prometheus.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 "nri-prometheus.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

{{/*
Create the name of the service account to use
*/}}
{{- define "nri-prometheus.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "nri-prometheus.name" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Return the licenseKey
*/}}
{{- define "nri-prometheus.licenseKey" -}}
{{- if .Values.global}}
{{- if .Values.global.licenseKey }}
{{- .Values.global.licenseKey -}}
{{- else -}}
{{- .Values.licenseKey | default "" -}}
{{- end -}}
{{- else -}}
{{- .Values.licenseKey | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Return the cluster
*/}}
{{- define "nri-prometheus.cluster" -}}
{{- if .Values.global -}}
{{- if .Values.global.cluster -}}
{{- .Values.global.cluster -}}
{{- else -}}
{{- .Values.cluster | default "" -}}
{{- end -}}
{{- else -}}
{{- .Values.cluster | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Return the customSecretName
*/}}
{{- define "nri-prometheus.customSecretName" -}}
{{- if .Values.global }}
{{- if .Values.global.customSecretName }}
{{- .Values.global.customSecretName -}}
{{- else -}}
{{- .Values.customSecretName | default "" -}}
{{- end -}}
{{- else -}}
{{- .Values.customSecretName | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Return the customSecretLicenseKey
*/}}
{{- define "nri-prometheus.customSecretLicenseKey" -}}
{{- if .Values.global }}
{{- if .Values.global.customSecretLicenseKey }}
{{- .Values.global.customSecretLicenseKey -}}
{{- else -}}
{{- .Values.customSecretLicenseKey | default "" -}}
{{- end -}}
{{- else -}}
{{- .Values.customSecretLicenseKey | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Returns if the template should render, it checks if the required values
licenseKey and cluster are set.
*/}}
{{- define "nri-prometheus.areValuesValid" -}}
{{- $cluster := include "nri-prometheus.cluster" . -}}
{{- $licenseKey := include "nri-prometheus.licenseKey" . -}}
{{- $customSecretName := include "nri-prometheus.customSecretName" . -}}
{{- $customSecretLicenseKey := include "nri-prometheus.customSecretLicenseKey" . -}}
{{- and (or $licenseKey (and $customSecretName $customSecretLicenseKey)) $cluster}}
{{- end -}}
22 changes: 22 additions & 0 deletions charts/nri-prometheus/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ template "nri-prometheus.fullname" . }}
labels:
{{ include "nri-prometheus.labels" . | indent 4 }}
rules:
- apiGroups: [""]
resources:
- "nodes"
- "nodes/metrics"
- "nodes/stats"
- "nodes/proxy"
- "pods"
- "services"
verbs: ["get", "list", "watch"]
- nonResourceURLs:
- /metrics
verbs:
- get
{{- end -}}
16 changes: 16 additions & 0 deletions charts/nri-prometheus/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ template "nri-prometheus.fullname" . }}
labels:
{{ include "nri-prometheus.labels" . | indent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "nri-prometheus.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "nri-prometheus.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
13 changes: 13 additions & 0 deletions charts/nri-prometheus/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: ConfigMap
metadata:
name: {{ template "nri-prometheus.fullname" . }}-config
namespace: {{ .Release.Namespace }}
labels:
{{ include "nri-prometheus.labels" . | indent 4 }}
apiVersion: v1
data:
config.yaml: |
cluster_name: {{ include "nri-prometheus.cluster" . }}
{{- if .Values.config }}
{{ toYaml .Values.config | indent 4 -}}
{{ end }}
65 changes: 65 additions & 0 deletions charts/nri-prometheus/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{- if (include "nri-prometheus.areValuesValid" .) }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "nri-prometheus.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "nri-prometheus.labels" . | indent 4 }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "nri-prometheus.name" . }}
template:
metadata:
labels:
{{ include "nri-prometheus.labels" . | indent 8 }}
spec:
serviceAccountName: {{ template "nri-prometheus.serviceAccountName" . }}
containers:
- name: nri-prometheus
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
args:
- "--configfile=/etc/nri-prometheus/config.yaml"
ports:
- containerPort: 8080
volumeMounts:
- name: config-volume
mountPath: /etc/nri-prometheus/
env:
- name: "LICENSE_KEY"
valueFrom:
secretKeyRef:
{{- if (include "nri-prometheus.licenseKey" .) }}
name: {{ template "nri-prometheus.fullname" . }}-config
key: licenseKey
{{- else }}
name: {{ include "nri-prometheus.customSecretName" . }}
key: {{ include "nri-prometheus.customSecretLicenseKey" . }}
{{- end }}
- name: "BEARER_TOKEN_FILE"
value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
- name: "CA_FILE"
value: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
{{- if .Values.resources }}
resources:
{{ toYaml .Values.resources | indent 10 }}
{{- end }}
volumes:
- name: config-volume
configMap:
name: {{ template "nri-prometheus.fullname" . }}-config
{{- if $.Values.nodeSelector }}
nodeSelector:
{{ toYaml $.Values.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
{{- if .Values.affinity }}
affinity:
{{ toYaml .Values.affinity | indent 8 }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/nri-prometheus/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- $licenseKey := include "nri-prometheus.licenseKey" . -}}
{{- if $licenseKey }}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "nri-prometheus.fullname" . }}-config
namespace: {{ .Release.Namespace }}
labels:
{{ include "nri-prometheus.labels" . | indent 4 }}
type: Opaque
data:
licenseKey: {{ $licenseKey | b64enc }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/nri-prometheus/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "nri-prometheus.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "nri-prometheus.labels" . | indent 4 }}
{{- end -}}
Loading

0 comments on commit e1ae3a0

Please sign in to comment.