Skip to content

Commit

Permalink
Add ability to run the provisioner directly on the ZFS host.
Browse files Browse the repository at this point in the history
The default is to run kubernetes-zfs-provisioner in a container and
create datasets via SSH on a remote host.
To do that, the docker image is created with the zfs and
update-permissions stubs that will both call commands on the remote host
using SSH.

Allows running kubernetes-zfs-provisioner directly on the ZFS host by
making the update-permissions script presence optional. The zfs stub is
already optional because it merely replaces the command of the same name
on the remote host. The provisionner now uses the update-permissions
executable if it's present in the current PATH, otherwise it falls back
to executing chmod g+w directly.

Fixes #130.
  • Loading branch information
jp39 committed Sep 10, 2024
1 parent 5884d5b commit 313eef9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docker/update-permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set -eo pipefail
zfs_mod="${ZFS_MOD:-g+w}"
chmod_bin=${ZFS_CHOWN_BIN:-sudo -H chmod}

zfs_host="${1}"
zfs_mountpoint="${2}"
zfs_mountpoint="${1}"

# Do not try to manually modify these Env vars, they will be updated by the provisioner just before invoking the script.
zfs_host="${ZFS_HOST}"

ssh "${zfs_host}" "${chmod_bin} ${zfs_mod} ${zfs_mountpoint}"
14 changes: 13 additions & 1 deletion pkg/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"

gozfs "github.com/mistifyio/go-zfs/v3"
Expand Down Expand Up @@ -114,7 +115,18 @@ func (z *zfsImpl) SetPermissions(dataset *Dataset) error {
if dataset.Mountpoint == "" {
return fmt.Errorf("undefined mountpoint for dataset: %s", dataset.Name)
}
cmd := exec.Command("update-permissions", dataset.Hostname, dataset.Mountpoint)

globalLock.Lock()
defer globalLock.Unlock()
if err := setEnvironmentVars(dataset.Hostname); err != nil {
return err
}
cmd := exec.Command("update-permissions", dataset.Mountpoint)
if !filepath.IsAbs(cmd.Path) {
// update-permissions not found in PATH
cmd = exec.Command("chmod", "g+w", dataset.Mountpoint)
}

out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
Expand Down
2 changes: 1 addition & 1 deletion test/update-permissions
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -eo pipefail
zfs_mod="${ZFS_MOD:-g+w}"
chmod_bin=${ZFS_CHOWN_BIN:-chmod}

zfs_mountpoint="${2}"
zfs_mountpoint="${1}"

${chmod_bin} ${zfs_mod} ${zfs_mountpoint}

0 comments on commit 313eef9

Please sign in to comment.