# Copyright 2017 Google Inc. All rights reserved.
#
# 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
#
#     http://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.

# This daemonset deploys the GPU partitioner on all GPU nodes and partitions
# the GPUs as defined in the GPU config file.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: partition-gpus
  namespace: kube-system
  labels:
    k8s-app: partition-gpus
spec:
  selector:
    matchLabels:
      k8s-app: partition-gpus
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: partition-gpus
        k8s-app: partition-gpus
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cloud.google.com/gke-accelerator
                operator: Exists
      tolerations:
      - operator: "Exists"
      hostNetwork: true
      hostPID: true
      volumes:
      - name: dev
        hostPath:
          path: /dev
      - name: nvidia
        hostPath:
          path: /home/kubernetes/bin/nvidia
      - name: nvidia-config
        hostPath:
          path: /etc/nvidia
      initContainers:
      - image: "gcr.io/gke-release/nvidia-partition-gpu@sha256:4238017c76b48ef82aa9e59f17469017f311a65945c3cd3aea6a96e0c3e143b4"
        name: partition-gpus
        env:
        - name: LD_LIBRARY_PATH
          value: /usr/local/nvidia/lib64    
        resources:
          requests:
            cpu: "0.15"
        securityContext:
          privileged: true
        volumeMounts:
        - name: nvidia
          mountPath: /usr/local/nvidia
        - name: dev
          mountPath: /dev
        - name: nvidia-config
          mountPath: /etc/nvidia
      containers:
      - image: "gcr.io/google-containers/pause:2.0"
        name: pause
