Skip to content

Commit

Permalink
fix(csi): update csi hostpath operator to use go 18 (#12)
Browse files Browse the repository at this point in the history
fix(csi): update csi hostpath operator to use go 18
fix(csi): set go version from nomad variable in env
chore(csi): add explicit resource requirements to csi operator job
chore(csi): remove cached git clone if retry
refactor(csi): create prestart job for installing the controller
refactor(csi): fix path to plugin download
feat(csi): add an update strategy
chore(csi): add the build command
chore(csi): fix getter options for git repo
fix(csi): force plugin git getter to use dir mode
feat(csi): add restart strategy
fix(csi): use raw_exec driver since we need elevated privileges
chore(csi): add alternative build command

Signed-off-by: Bruce Becker <[email protected]>
  • Loading branch information
brucellino authored Nov 6, 2022
1 parent 4e354df commit c84e225
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 14 deletions.
49 changes: 43 additions & 6 deletions csi-hostpath-operator.nomad
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
variable "go_version" {
type = string
description = "Version of Go to use for compiling the plugin"
default = "1.18.8"
}
job "csi" {
datacenters = ["dc1"]
type = "sysbatch"

group "hostpath" {
task "go19" {
resources {
cpu = 100
memory = 100
}
driver = "exec"
lifecycle {
hook = "prestart"
}
env {
ARCH = attr.cpu.arch
GO_VERSION = var.go_version
PATH = "${NOMAD_ALLOC_DIR}/usr/local/go/bin:${PATH}"
}
config {
command = "local/script.sh"
}
template {
data = <<EOF
#!/bin/bash
set -eou pipefail
mkdir -vp ${NOMAD_ALLOC_DIR}/usr/local
echo "${ARCH}"
curl -fL https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz | tar xvz -C ${NOMAD_ALLOC_DIR}/usr/local
ls -lht ${NOMAD_ALLOC_DIR}/usr/local/go
EOF
destination = "local/script.sh"
perms = "0777"
}
}
task "install" {
driver = "raw_exec"

resources {
cpu = 100
memory = 100
}
config {
command = "local/script.sh"
}
Expand All @@ -14,13 +51,13 @@ job "csi" {
data = <<EOF
#!/bin/bash
set -eou pipefail
sudo apt-get install -y golang
go version
rm -rf csi-driver-host-path
git clone https://github.com/kubernetes-csi/csi-driver-host-path.git
cd csi-driver-host-path
sudo make
sudo install bin/hostpathplugin /usr/local/bin/
PATH=${NOMAD_ALLOC_DIR}/usr/local/go/bin:${PATH} make
sudo PATH=${NOMAD_ALLOC_DIR}/usr/local/go/bin:${PATH} install bin/hostpathplugin /usr/local/bin/
EOF

destination = "local/script.sh"
perms = "0777"
}
Expand Down
96 changes: 88 additions & 8 deletions csi-hostpath.nomad
Original file line number Diff line number Diff line change
@@ -1,30 +1,110 @@
# Add the csi host path plugin
variable "go_version" {
type = string
description = "Version of Go to use for compiling the plugin"
default = "1.18.8"
}

variable "plugin_version" {
type = string
description = "Version of Hostpath csi plugin to use"
default = "1.9.0"
}



job "plugin-csi-hostpath-controller" {
datacenters = ["dc1"]
type = "system"
update {
max_parallel = 1
// health_check = "checks"
// min_healthy_time = "10s"
// healthy_deadline = "5m"
// progress_deadline = "10m"
auto_revert = true
auto_promote = true
canary = 1
// stagger = "30s"
}

group "controller" {
restart {
interval = "1m"
attempts = 1
delay = "15s"
mode = "fail"
}
task "build" {
# Get the plugin source which we will build
artifact {
source = "git::https://github.com/kubernetes-csi/csi-driver-host-path"
destination = "local/plugin"
mode = "dir"
options {
ref = "v${var.plugin_version}"
depth = 1
}
}
artifact {
source = "https://go.dev/dl/go${var.go_version}.linux-${attr.cpu.arch}.tar.gz"
destination = "${NOMAD_ALLOC_DIR}/usr/local"
}
resources {
cpu = 100
memory = 100
}
# Need to use raw_exec because the artifact is downloaded as root and we run as
# nobody. This means that we can't create the "plugin/bin" directory
driver = "raw_exec"
lifecycle {
hook = "prestart"
}
env {
ARCH = attr.cpu.arch
GO_VERSION = var.go_version
PLUGIN_VERSION = var.plugin_version
PATH = "${NOMAD_ALLOC_DIR}/usr/local/go/bin:${PATH}"
}
config {
command = "local/script.sh"
}
template {
data = <<EOF
#!/bin/bash
set -eou pipefail
echo "I am $(whoami)"
echo "I am in ${PWD}"
cd local/plugin
make
# go build -a -ldflags ' -X main.version=v${PLUGIN_VERSION} -extldflags "-static"' -o ${NOMAD_ALLOC_DIR}/bin/hostpathplugin .
mkdir -p ${NOMAD_ALLOC_DIR}/bin
PATH=${NOMAD_ALLOC_DIR}/usr/local/go/bin:${PATH} install bin/hostpathplugin ${NOMAD_ALLOC_DIR}/bin
EOF
destination = "local/script.sh"
perms = "0777"
}
}

task "plugin" {
resources {
cpu = 10 # 10 MHz
memory = 25 # 25MB
}
// service {
// tags = ["csi"]
// port =
// }
driver = "raw_exec"
config {
command = "local/csi-hostpathplugin"
command = "${NOMAD_ALLOC_DIR}/bin/hostpathplugin"
args = [
"--drivername=csi-hostpath",
"--v=5",
"--endpoint=${CSI_ENDPOINT}",
"--nodeid=node-${NOMAD_ALLOC_INDEX}"
]
}
artifact {
source = "http://minio-api:9000/csi/csi-driver-host-path/bin/hostpathplugin"
destination = "local/csi-hostpathplugin"
mode = "file"
}


csi_plugin {
id = "csi-hostpath"
type = "monolith"
Expand Down

0 comments on commit c84e225

Please sign in to comment.