From 0db762a62b3c072f0560b16b990333054cb0c88f Mon Sep 17 00:00:00 2001 From: wrider Date: Wed, 4 Sep 2019 17:05:29 -0400 Subject: [PATCH] Add chart for MR subscriber Signed-off-by: wrider Change-Id: I233435bc465f45af61fe14428dce82cc92724a2d --- ric-aux/80-Auxiliary-Functions/bin/install | 2 +- ric-aux/80-Auxiliary-Functions/bin/uninstall | 2 +- .../80-Auxiliary-Functions/helm/mrsub/.helmignore | 22 +++++++++ .../80-Auxiliary-Functions/helm/mrsub/Chart.yaml | 5 +++ .../helm/mrsub/resources/mrsub.sh | 43 ++++++++++++++++++ .../helm/mrsub/templates/_helpers.tpl | 37 +++++++++++++++ .../helm/mrsub/templates/configmap-bin.yaml | 24 ++++++++++ .../helm/mrsub/templates/configmap-env.yaml | 29 ++++++++++++ .../helm/mrsub/templates/deployment.yaml | 52 ++++++++++++++++++++++ .../80-Auxiliary-Functions/helm/mrsub/values.yaml | 17 +++++++ 10 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml create mode 100644 ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml diff --git a/ric-aux/80-Auxiliary-Functions/bin/install b/ric-aux/80-Auxiliary-Functions/bin/install index 52bf88d7..63ed6d1e 100755 --- a/ric-aux/80-Auxiliary-Functions/bin/install +++ b/ric-aux/80-Auxiliary-Functions/bin/install @@ -122,7 +122,7 @@ fi -RICAUX_COMPONENTS="dashboard ves message-router" +RICAUX_COMPONENTS="dashboard ves message-router mrsub" echo "Deploying RIC AUX components [$RICAUX_COMPONENTS]" echo "Helm Release Name: $RELEASE_NAME" diff --git a/ric-aux/80-Auxiliary-Functions/bin/uninstall b/ric-aux/80-Auxiliary-Functions/bin/uninstall index c86e42b3..85d3b5c3 100755 --- a/ric-aux/80-Auxiliary-Functions/bin/uninstall +++ b/ric-aux/80-Auxiliary-Functions/bin/uninstall @@ -30,7 +30,7 @@ else RELEASE_NAME=$RICAUX_RELEASE_NAME fi -RICAUX_COMPONENTS="dashboard message-router ves" +RICAUX_COMPONENTS="dashboard message-router ves mrsub" echo "Undeploying RIC AUX components [$RICAUX_COMPONENTS]" echo "Helm Release Name: $RELEASE_NAME" diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore b/ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore new file mode 100644 index 00000000..50af0317 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore @@ -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/ diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml new file mode 100644 index 00000000..fb316eb0 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: mrsub +version: 0.1.0 diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh b/ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh new file mode 100644 index 00000000..27439512 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +MR_HOSTPORT="$_MR_HOSTPORT" +MR_TOPIC="$_MR_TOPIC" +LOGSTASH_URL="$_LOGSTASH_URL" + +if ! jq --version > /dev/null 2&>1 ; then + apt-get update + apt-get install -y jq curl +fi + +echo "IN SCRIPT" +echo "$MR_HOSTPORT $MR_TOPIC $LOGSTASH_URL" + +while true; do + # if dmaap returns single JSON structure + DATA=$(curl -s -H "Accept: application/json" -X GET http://${MR_HOSTPORT}/events/${MR_TOPIC}/elk-plotter/elk-plotter?timeout=60000) + DATA=$(echo $DATA| sed -e 's/\\"/"/g' -e 's/"{/{/g' -e 's/}"/}/g') + echo "Getting data: $DATA" + + #VESEVENT=$(echo $DATA |jq -r '((.event.commonEventHeader.lastEpochMicrosec)|tostring) + "," + ((.event.measurementsForVfScalingFields.vNicUsageArray[0].receivedTotalPacketsDelta) | tostring)') + #curl -i -XPUT 'http://127.0.0.1:8080/onenumber/onenumebr' -d "${VESEVENT}" + + # dmaap returns json array + # echo "Reading source: $.event.commonEventHeader.reportingEntityName" + source=$(echo $DATA |jq -r '.[] | ((.event.commonEventHeader.reportingEntityName) | tostring)') + echo "Source name: $source" + if [ "$source" == "GS_LITE MC" ] + then + DATA=$(echo $DATA |jq -r --arg source "$source" '.[] | $source+","+((.event.measurementsForVfScalingFields.additionalFields[1].value) | tostring)+ ","+ ((.event.measurementsForVfScalingFields.additionalFields[2].value) | tostring)') + #EVENTS=$(echo $DATA |jq -r '.event.measurementFields.additionalFields.SgNBRequestRate') + #for EVENT in $EVENTS; do + elif [ "$source" == "AC xAPP" ] + then + DATA=$(echo $DATA |jq -r --arg source "$source" '.[] | $source+","+((.event.measurementsForVfScalingFields.additionalFields[0].value) | tostring)') + else + DATA="No supportive reporting entity provided" + fi + echo "Injecting VES event: $DATA" + curl -i -XPUT "${LOGSTASH_URL}" -d "${DATA}" + #done +done + diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl new file mode 100644 index 00000000..34157e23 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl @@ -0,0 +1,37 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "mrsub.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 "mrsub.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 "mrsub.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "mrsub.configmapname" -}} + {{- $name := ( include "mrsub.fullname" . ) -}} + {{- printf "configmap-%s" $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml new file mode 100644 index 00000000..b511a9e1 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml @@ -0,0 +1,24 @@ +################################################################################ +# Copyright (c) 2019 AT&T Intellectual Property. # +# Copyright (c) 2019 Nokia. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "mrsub.configmapname" . }}-bin +data: + {{- (.Files.Glob "resources/mrsub.sh").AsConfig |nindent 2 }} + diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml new file mode 100644 index 00000000..8f1d4de8 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml @@ -0,0 +1,29 @@ +################################################################################ +# Copyright (c) 2019 AT&T Intellectual Property. # +# Copyright (c) 2019 Nokia. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "mrsub.configmapname" . }}-env +data: + {{- if .Values.mrsub.appenv }} + {{- toYaml .Values.mrsub.appenv | nindent 2 }} + {{- end }} + _MR_HOSTPORT: "{{ .Values.mrsub.mrhostport }}" + _MR_TOPIC: "{{ .Values.mrsub.mrtopic }}" + _LOGSTASH_URL: "{{ .Values.mrsub.logstashurl }}" + diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml new file mode 100644 index 00000000..022350d8 --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mrsub.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "mrsub.name" . }} + helm.sh/chart: {{ include "mrsub.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "mrsub.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "mrsub.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["/scripts/mrsub.sh"] + #command: ["sleep"] + #args: ["3600"] + volumeMounts: + - mountPath: /scripts + name: script + envFrom: + - configMapRef: + name: {{ include "mrsub.configmapname" . }}-env + volumes: + - name: script + configMap: + name: {{ include "mrsub.configmapname" . }}-bin + defaultMode: 0744 + + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml new file mode 100644 index 00000000..cb05a5cb --- /dev/null +++ b/ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml @@ -0,0 +1,17 @@ +# Default values for mrsub. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ubuntu + tag: 16.04 + pullPolicy: IfNotPresent + + +mrsub: + mrhostport: "10.1.0.26:30227" + mrtopic: "unauthenticated.SEC_MEASUREMENT_OUTPUT" + logstashurl: "http://192.168.130.77:8081/ves/ves" + -- 2.16.6