# Copyright 2020 Google LLC
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     https://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: ctf-daemon-gcsfuse
  namespace: kube-system
  labels:
    k8s-app: ctf-daemon-gcsfuse
spec:
  selector:
    matchLabels:
      name: ctf-daemon-gcsfuse
  template:
    metadata:
      labels:
        name: ctf-daemon-gcsfuse
    spec:
      serviceAccountName: gcsfuse-sa
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: ctf-daemon
        image: ubuntu:19.10
        securityContext:
          privileged: true
        command: ["sh", "-c", "apt-get update && apt-get install -y wget fuse && wget -q https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v0.29.0/gcsfuse_0.29.0_amd64.deb && dpkg -i gcsfuse_0.29.0_amd64.deb && mkdir -p /mnt/disks/gcs && ((test -f /config/gcs_bucket && gcsfuse --foreground --debug_fuse --debug_gcs --stat-cache-ttl 0 -type-cache-ttl 0 -o allow_other -o nonempty --file-mode 0777 --dir-mode 0777 --uid 1000 --gid 1000 $(cat /config/gcs_bucket) /mnt/disks/gcs))"]
        volumeMounts:
        - name: mnt-disks-gcs
          mountPath: /mnt/disks/gcs
          mountPropagation: Bidirectional
        - name: config
          mountPath: /config
        lifecycle:
          preStop:
            exec:
               command: ["sh", "-c", "fusermount -u /mnt/disks/gcs"]
      volumes:
      - name: mnt-disks-gcs
        hostPath:
          path: /mnt/disks/gcs
      - name: config
        configMap:
          name: gcsfuse-config
