# 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:e226275da6c45816959fe43cde907ee9a85c6a2aa8a429418a4cadef8ecdb86a"
        name: partition-gpus
        env:
        - name: LD_LIBRARY_PATH
          value: /usr/local/nvidia/lib64
        resources:
          requests:
            cpu: 150m
        securityContext:
          privileged: true
        volumeMounts:
        - name: nvidia
          mountPath: /usr/local/nvidia
        - name: dev
          mountPath: /dev
        - name: nvidia-config
          mountPath: /etc/nvidia
      containers:
      - image: "gke.gcr.io/pause:3.8@sha256:880e63f94b145e46f1b1082bb71b85e21f16b99b180b9996407d61240ceb9830"
        name: pause
