#! Copyright 2020-2023 the Pinniped contributors. All Rights Reserved.
#! SPDX-License-Identifier: Apache-2.0

#@ load("@ytt:data", "data")
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: proxy
  namespace: tools
  labels:
    app: proxy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: proxy
  template:
    metadata:
      labels:
        app: proxy
    spec:
      volumes:
        - name: log-dir
          emptyDir: {}
      containers:
        - name: proxy
          image: #@ data.values.proxy_image
          imagePullPolicy: IfNotPresent
          ports:
          - name: http
            containerPort: 3128
          volumeMounts:
            - name: log-dir
              mountPath: "/var/log/squid/"
          readinessProbe:
            tcpSocket:
              port: http
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 5
            failureThreshold: 2
        - name: accesslogs
          image: #@ data.values.proxy_image
          imagePullPolicy: IfNotPresent
          command:
            - "/bin/sh"
            - "-c"
          args:
            - tail -F /var/log/squid/access.log
          volumeMounts:
            - name: log-dir
              mountPath: "/var/log/squid/"
      tolerations:
        - key: kubernetes.io/arch
          effect: NoSchedule
          operator: Equal
          value: amd64 #! Allow running on amd64 nodes.
        - key: kubernetes.io/arch
          effect: NoSchedule
          operator: Equal
          value: arm64 #! Also allow running on arm64 nodes.
---
apiVersion: v1
kind: Service
metadata:
  name: proxy
  namespace: tools
  labels:
    app: proxy
spec:
  type: NodePort
  selector:
    app: proxy
  ports:
    - port: 3128
      nodePort: #@ data.values.ports.node
