---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: flux
spec:
  replicas: 1
  selector:
    matchLabels:
      name: flux
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        prometheus.io.port: "3031" # tell prometheus to scrape /metrics endpoint's port.
      labels:
        name: flux
    spec:
      serviceAccount: flux
      volumes:
      - name: git-key
        secret:
          secretName: flux-git-deploy
          defaultMode: 0400 # when mounted read-only, we won't be able to chmod

      # This is a tmpfs used for generating SSH keys. In K8s >= 1.10,
      # mounted secrets are read-only, so we need a separate volume we
      # can write to.
      - name: git-keygen
        emptyDir:
          medium: Memory

      containers:
      - name: flux
        # There are no ":latest" images for flux. Find the most recent
        # release or image version at https://quay.io/weaveworks/flux
        # and replace the tag here.
        image: quay.io/weaveworks/flux:1.8.1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3030 # informational
        volumeMounts:
        - name: git-key
          mountPath: /etc/fluxd/ssh # to match image's ~/.ssh/config
          readOnly: true # this will be the case perforce in K8s >=1.10
        - name: git-keygen
          mountPath: /var/fluxd/keygen # to match image's ~/.ssh/config
        args:

        # if you deployed memcached in a different namespace to flux,
        # or with a different service name, you can supply these
        # following two arguments to tell fluxd how to connect to it.
        # - --memcached-hostname=memcached.default.svc.cluster.local
        # - --memcached-service=memcached

        # this must be supplied, and be in the tmpfs (emptyDir)
        # mounted above, for K8s >= 1.10
        - --ssh-keygen-dir=/var/fluxd/keygen
        # replace (at least) the following URL
        - --git-url=git@github.com:weaveworks/flux-example
        - --git-branch=master
        - --listen-metrics=:3031
        - --connect=ws://127.0.0.1:3032
      - name: fluxcloud
        image: justinbarrick/fluxcloud:v0.3.8
        imagePullPolicy: Always
        ports:
        - containerPort: 3032
        env:
        # Set these environment variables:
        - name: SLACK_URL
          value: "https://hooks.slack.com/services/WEBHOOK_DATA"
        - name: SLACK_CHANNEL
          value: "#kubernetes"
        # Or configure multiple channels
        # (comma separated <channel>=<namespace>) string:
        #  value: "#kubernetes=*,#team=team"
        # Optional: legacy Slack API token
        # - name: SLACK_TOKEN
        #   valueFrom:
        #     secretKeyRef:
        #       key: token
        #       name: slack-token
        - name: SLACK_USERNAME
          value: Flux Deployer
        - name: SLACK_ICON_EMOJI
          value: ":heart:"
        - name: GITHUB_URL
          value: "https://github.com/justinbarrick/fluxcloud/"
        - name: LISTEN_ADDRESS
          value: ":3032"
