# 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.

apiVersion: v1
kind: Service
metadata:
   name: freeradius
   namespace: {{ .Values.global.namespace }}
   serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
   labels:
     name: freeradius
spec:
  clusterIP: None
  ports:
    - name: radius-auth
      protocol: UDP
      port: 1812
      targetPort: 1812
    - name: radius-acc
      protocol: UDP
      port: 1813
      targetPort: 1813
    - name: radius
      port: 18120
      targetPort: 18120
  selector:
    app: freeradius
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: freeradius
  namespace: {{ .Values.global.namespace }}
  serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: freeradius
      annotations:
        cni: "weave"
    spec:
      serviceAccountName: {{ .Values.global.namespace }}-serviceaccount
      containers:
        - name: freeradius
          image: {{ .Values.freeradiusImage }}
          imagePullPolicy: {{ .Values.imagePullPolicy }}
          env:
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: RADIUS_LISTEN_IP
              value: "*"
            - name: USERS_FILE
              value: "/etc/raddb/users"
            - name: RADIUS_CLIENTS
              value: "SECRET@10.233.0.0/16"
          ports:
            - containerPort: 1812
              name: radauth-port
            - containerPort: 1813
              name: radacc-port
            - containerPort: 18120
              name: radius-port
          volumeMounts:
            - name: freeradius-config
              mountPath: /etc/raddb/clients.conf
              subPath: clients.conf
            - name: freeradius-config
              mountPath: /etc/raddb/users
              subPath: users
      volumes:
        - name: freeradius-config
          configMap:
            name: freeradius-config
