apiVersion: v1
kind: Service
metadata:
  name: url-shortener
  namespace: {{ .Release.Namespace }}
spec:
  type: ClusterIP
  selector:
    app: url-shortener
  ports:
    - name: {{ .Values.portName }}
      protocol: TCP
      port: 80
      targetPort: {{ .Values.portName }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: url-shortener
  namespace: {{ .Release.Namespace }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: url-shortener
  template:
    metadata:
      labels:
        app: url-shortener
    spec:
      containers:
      - name: url-shortener
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        ports:
        - name: {{ .Values.portName }}
          containerPort: 8080
          protocol: TCP
        command:
        - url-shortener
        - --port=8080
        - --db-path=/data/urls.db
        - --require-auth={{ .Values.requireAuth }}
        volumeMounts:
        - name: url-shortener
          mountPath: /data
      volumes:
      - name: url-shortener
        persistentVolumeClaim:
          claimName: url-shortener
