AETHER-527 Chart for installing edge-monitoring-server

Change-Id: Ib54732f503c7f958cc86c432ad0a74510dd40c55
diff --git a/monitoring/edge-monitoring-server/.helmignore b/monitoring/edge-monitoring-server/.helmignore
new file mode 100644
index 0000000..17fdbc0
--- /dev/null
+++ b/monitoring/edge-monitoring-server/.helmignore
@@ -0,0 +1,26 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# 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/
diff --git a/monitoring/edge-monitoring-server/Chart.yaml b/monitoring/edge-monitoring-server/Chart.yaml
new file mode 100644
index 0000000..999bb9e
--- /dev/null
+++ b/monitoring/edge-monitoring-server/Chart.yaml
@@ -0,0 +1,16 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: v1
+name: edge-monitoring-server
+description: A Helm chart for deploying Aether's edge monitoring server
+
+# 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.1.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
+# follow Semantic Versioning. They should reflect the version the application is using.
+appVersion: 0.3.0
diff --git a/monitoring/edge-monitoring-server/templates/NOTES.txt b/monitoring/edge-monitoring-server/templates/NOTES.txt
new file mode 100644
index 0000000..e944ec6
--- /dev/null
+++ b/monitoring/edge-monitoring-server/templates/NOTES.txt
@@ -0,0 +1,26 @@
+{{/*
+Copyright 2020-present Open Networking Foundation
+SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+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 "edge-monitoring-server.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 "edge-monitoring-server.fullname" . }}'
+  export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "edge-monitoring-server.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 "edge-monitoring-server.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 --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
+{{- end }}
diff --git a/monitoring/edge-monitoring-server/templates/_helpers.tpl b/monitoring/edge-monitoring-server/templates/_helpers.tpl
new file mode 100644
index 0000000..942e60a
--- /dev/null
+++ b/monitoring/edge-monitoring-server/templates/_helpers.tpl
@@ -0,0 +1,57 @@
+{{/*
+Copyright 2020-present Open Networking Foundation
+SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+{{/* vim: set filetype=mustache: */}}
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "edge-monitoring-server.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 "edge-monitoring-server.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 "edge-monitoring-server.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "edge-monitoring-server.labels" -}}
+helm.sh/chart: {{ include "edge-monitoring-server.chart" . }}
+{{ include "edge-monitoring-server.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "edge-monitoring-server.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "edge-monitoring-server.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
diff --git a/monitoring/edge-monitoring-server/templates/deployment.yaml b/monitoring/edge-monitoring-server/templates/deployment.yaml
new file mode 100644
index 0000000..65895ca
--- /dev/null
+++ b/monitoring/edge-monitoring-server/templates/deployment.yaml
@@ -0,0 +1,72 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ include "edge-monitoring-server.fullname" . }}
+  labels:
+    {{- include "edge-monitoring-server.labels" . | nindent 4 }}
+spec:
+{{- if not .Values.autoscaling.enabled }}
+  replicas: {{ .Values.replicaCount }}
+{{- end }}
+  selector:
+    matchLabels:
+      {{- include "edge-monitoring-server.selectorLabels" . | nindent 6 }}
+  template:
+    metadata:
+    {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+      labels:
+        {{- include "edge-monitoring-server.selectorLabels" . | nindent 8 }}
+    spec:
+      {{- with .Values.imagePullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      securityContext:
+        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+      containers:
+        - name: {{ .Chart.Name }}
+          securityContext:
+            {{- toYaml .Values.securityContext | nindent 12 }}
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+          imagePullPolicy: {{ .Values.image.pullPolicy }}
+          ports:
+            - name: http
+              containerPort: 80
+              protocol: TCP
+          command: ["python", "edge_monitoring_server.py"]
+          env:
+            - name: SECRET_ICAL_URL
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "edge-monitoring-server.fullname" . }}-calendar-secret
+                  key: iCalUrl
+          livenessProbe:
+            httpGet:
+              path: /edges/healthz
+              port: 80
+            initialDelaySeconds: 3
+            periodSeconds: 3
+          readinessProbe:
+            httpGet:
+              path: /edges
+              port: http
+          resources:
+            {{- toYaml .Values.resources | nindent 12 }}
+      {{- 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/monitoring/edge-monitoring-server/templates/ingress.yaml b/monitoring/edge-monitoring-server/templates/ingress.yaml
new file mode 100644
index 0000000..5288186
--- /dev/null
+++ b/monitoring/edge-monitoring-server/templates/ingress.yaml
@@ -0,0 +1,44 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+{{- if .Values.ingress.enabled -}}
+{{- $fullName := include "edge-monitoring-server.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 "edge-monitoring-server.labels" . | nindent 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 }}
diff --git a/monitoring/edge-monitoring-server/templates/secret.yaml b/monitoring/edge-monitoring-server/templates/secret.yaml
new file mode 100644
index 0000000..046807d
--- /dev/null
+++ b/monitoring/edge-monitoring-server/templates/secret.yaml
@@ -0,0 +1,13 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: v1
+kind: Secret
+metadata:
+  name: {{ include "edge-monitoring-server.fullname" . }}-calendar-secret
+  labels:
+    {{- include "edge-monitoring-server.labels" . | nindent 4 }}
+type: Opaque
+data:
+  iCalUrl: |-
+    {{ .Values.iCalUrl | b64enc }}
\ No newline at end of file
diff --git a/monitoring/edge-monitoring-server/templates/service.yaml b/monitoring/edge-monitoring-server/templates/service.yaml
new file mode 100644
index 0000000..00a2540
--- /dev/null
+++ b/monitoring/edge-monitoring-server/templates/service.yaml
@@ -0,0 +1,18 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "edge-monitoring-server.fullname" . }}
+  labels:
+    {{- include "edge-monitoring-server.labels" . | nindent 4 }}
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+    - port: {{ .Values.service.port }}
+      targetPort: http
+      protocol: TCP
+      name: http
+  selector:
+    {{- include "edge-monitoring-server.selectorLabels" . | nindent 4 }}
diff --git a/monitoring/edge-monitoring-server/values.yaml b/monitoring/edge-monitoring-server/values.yaml
new file mode 100644
index 0000000..e244c19
--- /dev/null
+++ b/monitoring/edge-monitoring-server/values.yaml
@@ -0,0 +1,76 @@
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# Default values for edge-monitoring-server.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+replicaCount: 1
+
+image:
+  repository: docker.io/omecproject/edge-monitoring-server
+  pullPolicy: Always
+  # Overrides the image tag whose default is the chart appVersion.
+  tag: ""
+
+# URL of calendar containing scheduled downtimes, in iCal format
+iCalUrl: ""
+
+imagePullSecrets: []
+nameOverride: ""
+fullnameOverride: ""
+
+podAnnotations: {}
+
+podSecurityContext: {}
+  # fsGroup: 2000
+
+securityContext: {}
+  # capabilities:
+  #   drop:
+  #   - ALL
+  # readOnlyRootFilesystem: true
+  # runAsNonRoot: true
+  # runAsUser: 1000
+
+service:
+  type: ClusterIP
+  port: 80
+
+ingress:
+  enabled: false
+  annotations: {}
+    # kubernetes.io/ingress.class: nginx
+    # kubernetes.io/tls-acme: "true"
+  hosts:
+    - host: chart-example.local
+      paths: []
+  tls: []
+  #  - secretName: chart-example-tls
+  #    hosts:
+  #      - chart-example.local
+
+resources: {}
+  # We usually recommend not to specify default resources and to leave this as a conscious
+  # choice for the user. This also increases chances charts run on environments with little
+  # resources, such as Minikube. If you do want to specify resources, uncomment the following
+  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
+  # limits:
+  #   cpu: 100m
+  #   memory: 128Mi
+  # requests:
+  #   cpu: 100m
+  #   memory: 128Mi
+
+autoscaling:
+  enabled: false
+  minReplicas: 1
+  maxReplicas: 100
+  targetCPUUtilizationPercentage: 80
+  # targetMemoryUtilizationPercentage: 80
+
+nodeSelector: {}
+
+tolerations: []
+
+affinity: {}