apiVersion: v1
kind: Service
metadata:
  name: url-shortener
  namespace: {{ .Release.Namespace }}
spec:
  type: ClusterIP
  selector:
    app: url-shortener
  ports:
    - name: http
      protocol: TCP
      port: {{ .Values.port }}
      targetPort: http
---
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: http
          containerPort: {{ .Values.port }}
          protocol: TCP
        command:
        - url-shortener
        - --port={{ .Values.port }}
        - --db-path=/data/urls.db
        - --require-auth={{ .Values.requireAuth }}
        volumeMounts:
        - name: url-shortener
          mountPath: /data
      volumes:
      - name: url-shortener
        persistentVolumeClaim:
          claimName: {{ .Values.persistentVolumeClaimName }}
