Skip to content

Instantly share code, notes, and snippets.

@tgross
Created March 25, 2020 14:33
Show Gist options
  • Save tgross/c268cd176c469467865e0fe461159a21 to your computer and use it in GitHub Desktop.
Save tgross/c268cd176c469467865e0fe461159a21 to your computer and use it in GitHub Desktop.
CSI hostpath quick test
job "csi-plugin" {
datacenters = ["dc1"]
group "csi" {
task "plugin" {
driver = "docker"
config {
image = "quay.io/k8scsi/hostpathplugin:v1.2.0"
args = [
"--drivername=csi-hostpath",
"--v=5",
"--endpoint=unix://csi/csi.sock",
"--nodeid=foo",
]
privileged = true
}
csi_plugin {
id = "hostpath-plugin0"
type = "monolith"
mount_dir = "/csi"
}
resources {
cpu = 500
memory = 256
network {
mbits = 10
port "plugin"{}
}
}
}
}
}
#!/bin/bash
# create the volume in the "external provider"
PLUGIN_ID=hostpath-plugin0
VOLUME_NAME=test-volume0
# non-dev mode
# CSI_ENDPOINT="/var/nomad/client/csi/monolith/$PLUGIN_ID/csi.sock"
# dev mode path is going to be in a tempdir
PLUGIN_DOCKER_ID=$(docker ps | grep hostpath | awk -F' +' '{print $1}')
CSI_ENDPOINT=$(docker inspect $PLUGIN_DOCKER_ID | jq -r '.[0].Mounts[] | select(.Destination == "/csi") | .Source')/csi.sock
echo "creating volume..."
UUID=$(sudo csc --endpoint $CSI_ENDPOINT controller create-volume $VOLUME_NAME --cap 1,2,ext4 | grep -o '".*"' | tr -d '"')
echo "registering volume $UUID..."
echo $(printf 'id = "%s"
name = "%s"
type = "csi"
external_id = "%s"
plugin_id = "%s"
access_mode = "single-node-writer"
attachment_mode = "file-system"' $VOLUME_NAME $VOLUME_NAME $UUID $PLUGIN_ID) > volume.hcl
nomad volume register volume.hcl
echo "querying volume $UUID..."
nomad volume status $UUID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment