Metric function helm chart changes
Change-Id: I0122c765e4bc664ae4c68f796ed6cf4d6db84b4a
diff --git a/5g-control-plane/templates/bin/_metrics-run.sh.tpl b/5g-control-plane/templates/bin/_metrics-run.sh.tpl
new file mode 100644
index 0000000..ccddaa4
--- /dev/null
+++ b/5g-control-plane/templates/bin/_metrics-run.sh.tpl
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Copyright 2022-present Open Networking Foundation
+#
+# SPDX-License-Identifier: Apache-2.0
+
+set -xe
+
+IMGPATH={{ .Values.config.imagePath }}
+{{- if .Values.config.coreDump.enabled }}
+cp /sdcore/metrics /tmp/coredump/
+{{- end }}
+
+cd /metricfunc
+cat config/metricscfg.conf
+
+echo $PWD
+
+GOTRACEBACK=crash /metricfunc/bin/metricfunc -metrics config/metricscfg.conf
diff --git a/5g-control-plane/templates/configmap-metrics.yaml b/5g-control-plane/templates/configmap-metrics.yaml
new file mode 100644
index 0000000..7705174
--- /dev/null
+++ b/5g-control-plane/templates/configmap-metrics.yaml
@@ -0,0 +1,30 @@
+{{/*
+# Copyright 2022-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.metrics.deploy }}
+
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- $metricscfg := index .Values.config.metrics.cfgFiles "metricscfg.conf" }}
+
+{{- end }}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: metrics
+ labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+data:
+ metrics-run.sh: |
+{{ tuple "bin/_metrics-run.sh.tpl" . | include "5g-control-plane.template" | indent 4 }}
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- range $key, $value := .Values.config.metrics.cfgFiles }}
+ {{ $key }}: |-
+{{ toYaml $value | indent 4 }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/deployment-metrics.yaml b/5g-control-plane/templates/deployment-metrics.yaml
new file mode 100644
index 0000000..b19f9c4
--- /dev/null
+++ b/5g-control-plane/templates/deployment-metrics.yaml
@@ -0,0 +1,82 @@
+{{/*
+# Copyright 2022-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+{{- if .Values.config.metrics.deploy }}
+{{ tuple "metrics" . | include "5g-control-plane.service_account" }}
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: metrics
+ labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+ replicas: 1
+ #serviceName: metrics-headless
+ selector:
+ matchLabels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 6 }}
+ template:
+ metadata:
+ labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 8 }}
+ {{- with .Values.config.metrics.podAnnotations }}
+ annotations:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ spec:
+ serviceAccountName: metrics
+ {{- if hasKey .Values.images "pullSecrets" }}
+ imagePullSecrets:
+{{ toYaml .Values.images.pullSecrets | indent 8 }}
+ {{- end }}
+ containers:
+ - name: metrics
+ image: {{ .Values.images.tags.metrics }}
+ imagePullPolicy: {{ .Values.images.pullPolicy }}
+ {{- if .Values.config.coreDump.enabled }}
+ securityContext:
+ runAsUser: 0
+ {{- end }}
+ stdin: true
+ tty: true
+ command: [ "/metricfunc/script/metrics-run.sh" ]
+ env:
+ - name: POD_IP
+ valueFrom:
+ fieldRef:
+ fieldPath: status.podIP
+ {{- if .Values.resources.enabled }}
+ resources:
+{{ toYaml .Values.resources.metrics | indent 10 }}
+ {{- end }}
+ volumeMounts:
+ - name: run-script
+ mountPath: /metricfunc/script/metrics-run.sh
+ subPath: metrics-run.sh
+ - name: metrics-config
+ mountPath: /metricfunc/config
+ {{- if .Values.config.coreDump.enabled }}
+ - name: coredump
+ mountPath: /tmp/coredump
+ {{- end }}
+ volumes:
+ - name: run-script
+ configMap:
+ name: metrics
+ defaultMode: 493
+ - name: metrics-config
+ configMap:
+ name: metrics
+ defaultMode: 493
+ {{- if .Values.config.coreDump.enabled }}
+ - name: host-rootfs
+ hostPath:
+ path: /
+ - name: coredump
+ hostPath:
+ path: {{ .Values.config.coreDump.path }}
+ {{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/service-metrics.yaml b/5g-control-plane/templates/service-metrics.yaml
new file mode 100644
index 0000000..7d8ec89
--- /dev/null
+++ b/5g-control-plane/templates/service-metrics.yaml
@@ -0,0 +1,28 @@
+{{/*
+# Copyright 2022-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.metrics.deploy }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: metrics
+ labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+ type: {{ .Values.config.metrics.serviceType }}
+ selector:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+ ports:
+ - name: prometheus-exporter
+ port: {{ .Values.config.metrics.prometheus.port }}
+ protocol: TCP
+{{- if eq .Values.config.metrics.serviceType "NodePort" }}
+{{- if .Values.config.metrics.prometheus.nodePort }}
+ nodePort: {{ .Values.config.metrics.prometheus.nodePort }}
+{{- end }}
+{{- end }}
+{{- end }}