---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: $DEPLOYMENT_NAME
  name: $DEPLOYMENT_NAME
  namespace: blackdice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: $DEPLOYMENT_NAME
  template:
    metadata:
      labels:
        app: $DEPLOYMENT_NAME
    spec:
      containers:
      - image: $IMAGE_NAME
        imagePullPolicy: Always
        name: $DEPLOYMENT_NAME
        ports:
        - containerPort: 3000
          protocol: UDP
      restartPolicy: Always


---
apiVersion: v1
kind: Service
metadata:
  name: $DEPLOYMENT_NAME
  namespace: blackdice
spec:
  ports:
  - name: $DEPLOYMENT_NAME
    port: 3000
    protocol: UDP
    targetPort: 3000
  selector:
    app: $DEPLOYMENT_NAME
  type: ClusterIP


---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: $DEPLOYMENT_NAME
  namespace: blackdice
spec:
  schedule: "0 0 * * *" 
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: $DEPLOYMENT_NAME
            image: $IMAGE_NAME
            command: ["/bin/bash", "-c"]
            args: [
              "/usr/local/gcf1/bin/gcf1dbmng.sh etc urldb_download && \
              /usr/local/gcf1/bin/gcf1dbmng.sh etc urldb_update"
            ]
          restartPolicy: OnFailure
      backoffLimit: 4