apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: home-apps
  name: go-links-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nfs-client
  resources:
    requests:
      storage: 2Gi
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-links
  namespace: home-apps
  labels:
    app: go-links
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: go-links
  template:
    metadata:
      labels:
        app: go-links
        name: go-links
    spec:
      containers:
        - name: go-links
          # https://github.com/tailscale/golink/pkgs/container/golink
          image: ghcr.io/tailscale/golink:main@sha256:47eaa3af7dbfdc882b3c78e41d07e1449bb3df0dbda638a210afa4d7d9efb930
          imagePullPolicy: IfNotPresent
          args:
            - -dev-listen
            - :8080
            - -sqlitedb
            - /home/nonroot/go-links.db
          ports:
            - containerPort: 8080
              name: web
              protocol: TCP
          env:
            - name: TZ
              value: "Australia/Melbourne"
          volumeMounts:
            - name: data
              mountPath: /home/nonroot
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 300m
              memory: 512Mi
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: go-links-pvc

---

apiVersion: v1
kind: Service
metadata:
  name: go-links
  labels:
    name: go-links
spec:
  type: ClusterIP
  selector:
    app: go-links
  ports:
    - name: go-links
      targetPort: web
      port: 80
      protocol: TCP

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-links-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "false"
spec:
  rules:
    - host: go
      http:
        paths:
        - backend:
            service:
              name: go-links
              port:
                number: 80
          path: /
          pathType: Prefix

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-links-public-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://id.junv.cc/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://id.junv.cc/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
  tls:
    - hosts:
      - go.junv.cc
      secretName: go-links-webhook-tls
  rules:
    - host: go.junv.cc
      http:
        paths:
        - backend:
            service:
              name: go-links
              port:
                number: 80
          path: /
          pathType: Prefix
