#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you 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: Namespace
metadata:
  name: trafficserver-test

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: trafficserver-test
  name: trafficserver-test
  namespace: trafficserver-test
spec:
  minReadySeconds: 30

  selector:
    matchLabels:
      app: trafficserver-test

  replicas: 1

  template:
    metadata:
      labels:
        app: trafficserver-test
    spec:
      containers:
        - name: trafficserver-test
          image: ats-ingress:latest # Needs to be updated
# Optional privileged securityContext that can be handy when you need to do debugging 
#          securityContext:
#            privileged: true
          volumeMounts:
            - mountPath: "/etc/ats/ssl"
              name: ats-ssl
              readOnly: true
            - name: log-trafficserver
              mountPath: "/opt/ats/var/log/trafficserver"
            - name: log-ingress
              mountPath: "/opt/ats/var/log/ingress"
          imagePullPolicy: IfNotPresent
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
# Optional environment variables
#            - name: INGRESS_DEBUG
#              value: "true"
#            - name: INGRESS_CLASS
#              value: "ats"
#            - name: LOG_CONFIG_FNAME
#              value: "/opt/ats/etc/trafficserver/logging.yaml"
#            - name: SSL_SERVERNAME_FNAME
#              value: "/opt/ats/etc/trafficserver/ssl_server_name.yaml"
            - name: POD_TLS_PATH
              value: "/etc/ats/ssl"
          ports:
          - containerPort: 8080
            name: http
            protocol: TCP
          - containerPort: 8443
            name: https
            protocol: TCP
        - name: log-collector
          image: fluent/fluentd:v1.14-debian-1
          volumeMounts:
          - name: log-trafficserver
            mountPath: "/var/log/trafficserver"
          - name: log-ingress
            mountPath: "/var/log/ingress"
          - name: config-volume
            mountPath: "/fluentd/etc"
        - name: trafficserver-exporter
          image: ats-ingress-exporter:latest
          imagePullPolicy: IfNotPresent
          args: ["--endpoint=http://127.0.0.1:8080/_stats"]
          ports:
          - containerPort: 9122
      volumes:
        - name: ats-ssl
          secret:
            secretName: tls-secret
        - name: log-trafficserver
          emptyDir: {}
        - name: log-ingress
          emptyDir: {}
        - name: config-volume
          configMap:
            name: fluentd-config

---

apiVersion: v1
kind: Service
metadata:
  name: trafficserver-test
  namespace: trafficserver-test
spec:
  type: NodePort
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: 8080
    nodePort: 30080
  - name: https
    port: 8443
    protocol: TCP
    targetPort: 8443
    nodePort: 30443
  selector:
    app: trafficserver-test
