Skip to content

Commit

Permalink
dynamic host volumes: expand demo
Browse files Browse the repository at this point in the history
  • Loading branch information
gulducat committed Dec 6, 2024
1 parent 3196880 commit 6046ef2
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 8 deletions.
14 changes: 14 additions & 0 deletions demo/hostvolume/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

set -xeuo pipefail

nomad volume status -type=host -verbose
nomad operator api /v1/nodes | jq '.[].HostVolumes'

addr="$(nomad service info -json job | jq -r '.[0].Address'):8000"
curl -sS "$addr/external/" | grep hi
curl -sS "$addr/internal/" | grep hi

echo '💚 looks good! 💚'
9 changes: 9 additions & 0 deletions demo/hostvolume/e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

set -xeuo pipefail

./setup.sh
./check.sh
./teardown.sh
File renamed without changes.
22 changes: 22 additions & 0 deletions demo/hostvolume/external-plugin.volume.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

name = "external-plugin"
type = "host"
# the executable named `example-plugin-mkfs` must be placed in the
# -host-volume-plugin-dir (config: client.host_volume_plugin_dir)
# or you will get an error creating the volume:
# * could not place volume "external-plugin": no node meets constraints
# The default location is <data-dir>/host_volume_plugins
plugin_id = "example-plugin-mkfs"
capacity_min = "50mb"
capacity_max = "50mb"

capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}

parameters {
a = "ayy"
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
name = "test"
type = "host"
plugin_id = "example-host-volume"
capacity_min = "50mb"
capacity_max = "50mb"

name = "internal-plugin"
type = "host"
# this plugin is built into Nomad;
# it simply creates a directory.
plugin_id = "mkdir"

capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}

parameters {
a = "ayy"
}
48 changes: 48 additions & 0 deletions demo/hostvolume/job.nomad.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

job "job" {
group "g" {
task "t" {
driver = "docker"
config {
image = "python:slim"
command = "bash"
args = ["-xc", <<-EOF
for dir in internal external; do
touch ${NOMAD_TASK_DIR}/$dir/hiii
done
python -m http.server -d ${NOMAD_TASK_DIR} --bind=::
EOF
]
ports = ["http"]
}
volume_mount {
volume = "int"
destination = "${NOMAD_TASK_DIR}/internal"
}
volume_mount {
volume = "ext"
destination = "${NOMAD_TASK_DIR}/external"
}
}
volume "int" {
type = "host"
source = "internal-plugin"
}
volume "ext" {
type = "host"
source = "external-plugin"
}
network {
port "http" {
static = 8000
}
}
service {
name = "job"
port = "http"
provider = "nomad"
}
}
}
14 changes: 14 additions & 0 deletions demo/hostvolume/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

set -xeuo pipefail

nomad volume create external-plugin.volume.hcl
nomad volume create internal-plugin.volume.hcl

nomad job run job.nomad.hcl

nomad volume status -type=host -verbose
nomad operator api /v1/nodes | jq '.[].HostVolumes'

17 changes: 17 additions & 0 deletions demo/hostvolume/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

set -xeuo pipefail

nomad job stop job || true

for _ in {1..5}; do
sleep 3
ids="$(nomad volume status -type=host -verbose | awk '/ternal-plugin/ {print$1}')"
test -z "$ids" && break
for id in $ids; do
nomad volume delete -type=host "$id" || continue
done
done

0 comments on commit 6046ef2

Please sign in to comment.