Skip to content

Commit

Permalink
[prometheus-json-exporter] feat: allow namespace override (#4067)
Browse files Browse the repository at this point in the history
Signed-off-by: t3mi <[email protected]>
Co-authored-by: MH <[email protected]>
  • Loading branch information
t3mi and zanhsieh authored Dec 12, 2023
1 parent a355182 commit ac48110
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion charts/prometheus-json-exporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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.8.0
version: 0.9.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
Expand Down
14 changes: 7 additions & 7 deletions charts/prometheus-json-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[].nodePort}" services {{ include "prometheus-json-exporter.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[].status.addresses[].address}")
export NODE_PORT=$(kubectl get --namespace {{ include "prometheus-json-exporter.namespace" . }} -o jsonpath="{.spec.ports[].nodePort}" services {{ include "prometheus-json-exporter.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ include "prometheus-json-exporter.namespace" . }} -o jsonpath="{.items[].status.addresses[].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "prometheus-json-exporter.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "prometheus-json-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{[]}{{ end }}"}}")
You can watch the status of by running 'kubectl get --namespace {{ include "prometheus-json-exporter.namespace" . }} svc -w {{ include "prometheus-json-exporter.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ include "prometheus-json-exporter.namespace" . }} {{ include "prometheus-json-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{[]}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "prometheus-json-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[].ports[].containerPort}")
export POD_NAME=$(kubectl get pods --namespace {{ include "prometheus-json-exporter.namespace" . }} -l "app.kubernetes.io/name={{ include "prometheus-json-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ include "prometheus-json-exporter.namespace" . }} $POD_NAME -o jsonpath="{.spec.containers[].ports[].containerPort}")
echo "Visit http://127.0.0.1:{{ .Values.service.port }} to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME {{ .Values.service.port }}:$CONTAINER_PORT
kubectl --namespace {{ include "prometheus-json-exporter.namespace" . }} port-forward $POD_NAME {{ .Values.service.port }}:$CONTAINER_PORT
{{- end }}
7 changes: 7 additions & 0 deletions charts/prometheus-json-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Allow overriding namespace
*/}}
{{- define "prometheus-json-exporter.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride -}}
{{- end }}
3 changes: 3 additions & 0 deletions charts/prometheus-json-exporter/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "prometheus-json-exporter.fullname" . }}
namespace: {{ include "prometheus-json-exporter.namespace" . }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
data:
allow-snippet-annotations: "false"
config.yml: |
Expand Down
1 change: 1 addition & 0 deletions charts/prometheus-json-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "prometheus-json-exporter.fullname" . }}
namespace: {{ include "prometheus-json-exporter.namespace" . }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
spec:
Expand Down
1 change: 1 addition & 0 deletions charts/prometheus-json-exporter/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "prometheus-json-exporter.fullname" . }}
namespace: {{ include "prometheus-json-exporter.namespace" . }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
spec:
Expand Down
1 change: 1 addition & 0 deletions charts/prometheus-json-exporter/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ include "prometheus-json-exporter.namespace" . }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
{{- with .Values.ingress.labels }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ template "prometheus-json-exporter.fullname" . }}
{{- with .Values.prometheusRule.namespace }}
namespace: {{ . }}
{{- end }}
namespace: {{ default (include "prometheus-json-exporter.namespace" .) .Values.prometheusRule.namespace }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
{{- with .Values.prometheusRule.additionalLabels -}}
Expand Down
1 change: 1 addition & 0 deletions charts/prometheus-json-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "prometheus-json-exporter.fullname" . }}
namespace: {{ include "prometheus-json-exporter.namespace" . }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
{{- with .Values.service.labels }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "prometheus-json-exporter.serviceAccountName" . }}
namespace: {{ include "prometheus-json-exporter.namespace" . }}
labels:
{{- include "prometheus-json-exporter.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
Expand Down
6 changes: 2 additions & 4 deletions charts/prometheus-json-exporter/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "prometheus-json-exporter.fullname" $ }}-{{ .name }}
{{- if $.Values.serviceMonitor.namespace }}
namespace: {{ $.Values.serviceMonitor.namespace }}
{{- end }}
namespace: {{ default (include "prometheus-json-exporter.namespace" $) $.Values.serviceMonitor.namespace }}
labels:
{{- include "prometheus-json-exporter.labels" $ | nindent 4 }}
{{- if or $.Values.serviceMonitor.defaults.labels .labels }}
Expand Down Expand Up @@ -46,6 +44,6 @@ spec:
{{- include "prometheus-json-exporter.selectorLabels" $ | nindent 6 }}
namespaceSelector:
matchNames:
- {{ $.Release.Namespace }}
- {{ include "prometheus-json-exporter.namespace" $ }}
{{- end }}
{{- end }}

0 comments on commit ac48110

Please sign in to comment.