#!/bin/bash

# Setup kubernetes cluster
sudo kubeadm reset   # Delete existing master
rm $HOME/.kube/config
sudo rm -rf /etc/cni/net.d
sudo swapoff -a     # Swapoff
sudo kubeadm init --pod-network-cidr=10.244.0.0/16  # Initialize cluster
mkdir -p $HOME/.kube    
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml     # Use flannel for networking
kubectl taint nodes ub-10 node-role.kubernetes.io/master-   # Allow device plugins and pods to run on master

# Deploy nvidia daemonset
# kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.14.0/nvidia-device-plugin.yml

# helm install oci://ghcr.io/nebuly-ai/helm-charts/nvidia-device-plugin --version 0.13.0 --generate-name -n nebuly-nvidia --create-namespace
kubectl label node ub-10 nos.nebuly.com/gpu-partitioning=mps

helm install oci://ghcr.io/nebuly-ai/helm-charts/nvidia-device-plugin --version 0.13.0 --generate-name -n nebuly-nvidia --create-namespace --values mps-config.yaml
# helm upgrade -i nvdp nvdp/nvidia-device-plugin --version=0.14.0 --namespace nvidia-device-plugin --create-namespace --set-file config.map.config=./config.yaml
# helm upgrade -i nvdp nvdp/nvidia-device-plugin --version=0.14.0 --namespace nvidia-device-plugin --create-namespace --set-file config.map.config=./config_map.yaml
# helm upgrade -i nvdp nvdp/nvidia-device-plugin --version=0.14.0 --namespace nvidia-device-plugin --create-namespace