apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app.kubernetes.io/component: docker-cleanup
    app.kubernetes.io/instance: jenkins
  name: docker-cleanup
  namespace: jenkins
spec:
  selector:
    matchLabels:
      app.kubernetes.io/component: docker-cleanup
      app.kubernetes.io/instance: jenkins
  template:
    metadata:
      labels:
        app.kubernetes.io/component: docker-cleanup
        app.kubernetes.io/instance: jenkins
    spec:
      containers:
      - command:
        - /bin/sh
        - -c
        - --
        args:
        - "while true; do (docker system prune -f --volumes && echo 'Cleanup complete, see you tomorrow...\n' && sleep 86400); done;"
        image: docker:18.09
        imagePullPolicy: IfNotPresent
        name: cleaner
        resources:
          limits:
            cpu: 50m
            memory: 32Mi
          requests:
            cpu: 10m
            memory: 32Mi
        volumeMounts:
        - name: dockersock
          mountPath: "/var/run/docker.sock"
      securityContext:
        runAsUser: 999
        runAsGroup: 999
      volumes:
      - name: dockersock
        hostPath:
          path: /var/run/docker.sock
  updateStrategy:
    rollingUpdate:
      maxUnavailable: 1
    type: RollingUpdate
