# Copyright 2017-present Open Networking Foundation
#
# 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.

#
# The grafana service
#
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: {{ .Values.global.namespace }}
  serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
spec:
  clusterIP: None
  selector:
    app: grafana
  ports:
  - name: ui-port
    protocol: TCP
    port: 8883
    targetPort: 80
  - name: port-2003
    protocol: TCP
    port: 2003
    targetPort: 2003
  - name: port-2004
    protocol: TCP
    port: 2004
    targetPort: 2004
  - name: port-8126
    protocol: TCP
    port: 8126
    targetPort: 8126
  - name: port-8125
    protocol: TCP
    port: 8125
    targetPort: 8125
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: grafana
  namespace: {{ .Values.global.namespace }}
  serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: grafana
    spec:
      serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
      containers:
      - name: grafana
        image: {{ .Values.grafanaImage }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        ports:
        - containerPort: 80
        - containerPort: 2003
        - containerPort: 2004
        - containerPort: 8126
        - containerPort: 8125
        env:
        - name: GR_SERVER_ROOT_URL
          value: "http://localhost:80/grafana/"
