Commit 8663c100 authored by lavado's avatar lavado
Browse files

Revert "Merge branch 'feat/magma_snmp' into 'master'"

This reverts merge request !83
parent 085374dd
# 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/
apiVersion: v1
appVersion: "1.0"
description: OSM EE helm chart
name: eechart
version: 0.1.0
dependencies:
- name: snmpexporter
condition: snmpexporter.enabled
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
\ No newline at end of file
apiVersion: v1
name: snmpexporter
description: SNMP Exporter for OSM VNF
type: application
version: 1.0.0
appVersion: 1.0.0
dependencies:
- name: snmp-exporter
version: "0.17.0"
repository: "https://hub.docker.com/r/prom/snmp-exporter"
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "snmpexporter.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 "snmpexporter.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 "snmpexporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "snmpexporter.labels" -}}
helm.sh/chart: {{ include "snmpexporter.chart" . }}
{{ include "snmpexporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "snmpexporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "snmpexporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "snmpexporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "snmpexporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "snmpexporter.fullname" . }}
labels:
{{- include "snmpexporter.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "snmpexporter.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "snmpexporter.selectorLabels" . | nindent 8 }}
spec:
securityContext:
runAsUser: 0
initContainers:
- name: init-config
image: busybox:1.28
command: ['sh', '-c', 'if [ ! -f "/etc/snmp_exporter/snmp.yml" ]; then cp /etc/snmp_exporter_init/snmp.yml /etc/snmp_exporter; fi']
volumeMounts:
- name: config-volume
mountPath: /etc/snmp_exporter
- name: init-config-volume
mountPath: /etc/snmp_exporter_init
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.version }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 9116
protocol: TCP
volumeMounts:
- name: config-volume
mountPath: /etc/snmp_exporter
livenessProbe:
exec:
command:
- /bin/sh
- -c
- if [ ! -f "/etc/snmp_exporter/generator.yml" ]; then exit 0; else rm -f /etc/snmp_exporter/generator.yml && exit 1; fi
failureThreshold: 1
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: config-volume
hostPath:
path: "/var/lib/osm/snmp_exporter/{{ .Values.global.osm.vnf_id | lower }}/"
- name: init-config-volume
configMap:
name: "snmp-init-config-{{ .Values.global.osm.vnf_id | lower }}"
apiVersion: v1
kind: Service
metadata:
name: {{ include "snmpexporter.fullname" . }}
labels:
{{- include "snmpexporter.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: 9116
protocol: TCP
name: snmp
selector:
{{- include "snmpexporter.selectorLabels" . | nindent 4 }}
\ No newline at end of file
# Default values for snmpexporter.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: prom/snmp-exporter
version: v0.17.0
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
\ No newline at end of file
- job_name: '{{ JOB_NAME }}'
static_configs:
- targets:
- {{ TARGET_IP }}
metrics_path: /snmp
params:
module: [ osm-snmp ]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: {{ EXPORTER_POD_IP }}:{{ EXPORTER_POD_PORT }} # The SNMP exporter's real hostname:port.
#!/bin/bash
##
# 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.
##
echo "installing libraries for snmp generator"
#apt-get install -y ...
apt-get update
apt-get install -y python3-pip unzip build-essential libsnmp-dev wget curl
curl -s https://storage.googleapis.com/golang/go1.11.8.linux-amd64.tar.gz | tar -v -C /usr/local -xz
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/go
go get github.com/go-logfmt/logfmt && go get github.com/go-kit/kit/log
wget -q https://github.com/prometheus/snmp_exporter/archive/v0.17.0.tar.gz -P /tmp/ \
&& tar -C /tmp -xf /tmp/v0.17.0.tar.gz \
&& (cd /tmp/snmp_exporter-0.17.0/generator && go build) \
&& cp /tmp/snmp_exporter-0.17.0/generator/generator /usr/local/bin/snmp_generator
##
# All Rights Reserved.
#
# 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.
##
import asyncio
import logging
import os
from osm_ee.exceptions import VnfException
import osm_ee.util.util_ee as util_ee
class VnfEE:
def __init__(self, config_params):
self.logger = logging.getLogger('osm_ee.vnf')
self.config_params = config_params
async def config(self, id, params):
self.logger.debug("Execute action config params: {}".format(params))
# Config action is special, params are merged with previous config calls
self.config_params.update(params)
required_params = ["ssh-hostname"]
self._check_required_params(self.config_params, required_params)
yield "OK", "Configured"
async def sleep(self, id, params):
self.logger.debug("Execute action sleep, params: {}".format(params))
for i in range(3):
await asyncio.sleep(5)
self.logger.debug("Temporal result return, params: {}".format(params))
yield "PROCESSING", f"Processing {i} action id {id}"
yield "OK", f"Processed action id {id}"
async def generate_snmp(self, id, params):
self.logger.debug("Executing SNMP exporter configuration generation\nWith params: {}".format(params))
commands = ("cp /app/vnf/generator/generator.yml ./",
"snmp_generator generate --output-path=/etc/snmp_exporter/snmp.yml",
"touch /etc/snmp_exporter/generator.yml")
for command in commands:
return_code, stdout, stderr = await util_ee.local_async_exec(command)
if return_code != 0:
yield "ERROR", "return code {}: {}".format(return_code, stderr.decode())
break
else:
yield "OK", stdout.decode()
@staticmethod
def _check_required_params(params, required_params):
for required_param in required_params:
if required_param not in params:
raise VnfException("Missing required param: {}".format(required_param))
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "eechart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].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 "eechart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "eechart.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 "eechart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "eechart.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 "eechart.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 "eechart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "eechart.labels" -}}
app.kubernetes.io/name: {{ include "eechart.name" . }}
helm.sh/chart: {{ include "eechart.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 "eechart.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "eechart.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "eechart.fullname" . }}
data:
{{ (.Files.Glob "source/*").AsConfig | indent 2 }}
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "eechart.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{ include "eechart.labels" . | indent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "eechart.fullname" . }}
labels:
{{ include "eechart.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: grpc
protocol: TCP
name: grpc
selector:
app.kubernetes.io/name: {{ include "eechart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "eechart.serviceAccountName" . }}
labels:
{{ include "eechart.labels" . | indent 4 }}
{{- end -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "eechart.fullname" . }}
labels:
{{ include "eechart.labels" . | indent 4 }}
spec:
serviceName: {{ include "eechart.fullname" . }}
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "eechart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "eechart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
imagePullSecrets:
- name: regcred
serviceAccountName: {{ template "eechart.serviceAccountName" . }}
securityContext:
runAsUser: 0
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: grpc
containerPort: 50051
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: osm-ee
mountPath: /app/storage
- name: osm-ee-source
mountPath: /app/EE/osm_ee/vnf
{{- if .Values.snmpexporter.enabled }}
- name: snmp-config-volume
mountPath: /etc/snmp_exporter
- name: vnf-mibs
mountPath: /root/.snmp/mibs
- name: vnf-generator
mountPath: /app/vnf/generator
{{- end }}
volumes:
- name: osm-ee-source
configMap:
name: {{ include "eechart.fullname" . }}
- name: osm-ee
hostPath:
path: /var/lib/osm/osm/osm_osm_packages/_data
{{- if .Values.snmpexporter.enabled }}
- name: snmp-config-volume
hostPath:
path: "/var/lib/osm/snmp_exporter/{{ .Values.global.osm.vnf_id | lower }}/"
- name: vnf-mibs
configMap:
name: "vnf-snmp-mibs-{{ .Values.global.osm.vnf_id | lower}}"
- name: vnf-generator
configMap:
name: "vnf-snmp-generator-{{ .Values.global.osm.vnf_id | lower}}"
{{- end }}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "eechart.fullname" . }}-test-connection"
labels:
{{ include "eechart.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "eechart.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment