Merge pull request #3027 from gochist/windows-exec

Support exec plugin on Windows
This commit is contained in:
Jeff Regan
2020-10-07 14:18:14 -07:00
committed by GitHub
2 changed files with 41 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"runtime"
"strings"
"github.com/google/shlex"
@@ -50,7 +51,14 @@ func (p *ExecPlugin) ErrIfNotExecutable() error {
if err != nil {
return err
}
if f.Mode()&0111 == 0000 {
// In Windows, it is not possible to determine whether a
// file is executable through file mode.
// TODO: provide for setting the executable FileMode bit on Windows
// The (fs *fileStat) Mode() (m FileMode) {} function in
// https://golang.org/src/os/types_windows.go
// lacks the ability to set the FileMode executable bit in response
// to file data on Windows.
if f.Mode()&0111 == 0000 && runtime.GOOS != "windows" {
return fmt.Errorf("unexecutable plugin at: %s", p.path)
}
return nil

View File

@@ -4,12 +4,15 @@
package execplugin_test
import (
"path/filepath"
"runtime"
"strings"
"testing"
"sigs.k8s.io/kustomize/api/filesys"
. "sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/api/konfig"
fLdr "sigs.k8s.io/kustomize/api/loader"
@@ -89,3 +92,32 @@ metadata:
t.Fatalf("unexpected arg array: %#v", p.Args())
}
}
func TestExecPlugin_ErrIfNotExecutable(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skipf("always returns nil on Windows")
}
srcRoot, err := utils.DeterminePluginSrcRoot(filesys.MakeFsOnDisk())
if err != nil {
t.Error(err)
}
// Test unexecutable plugin
unexecutablePlugin := filepath.Join(
srcRoot, "builtin", "", "secretgenerator", "SecretGenerator.so")
p := NewExecPlugin(unexecutablePlugin)
err = p.ErrIfNotExecutable()
if err == nil {
t.Fatalf("unexpected err: %v", err)
}
// Test executable plugin
executablePlugin := filepath.Join(
srcRoot, "someteam.example.com", "v1", "bashedconfigmap", "BashedConfigMap")
p = NewExecPlugin(executablePlugin)
err = p.ErrIfNotExecutable()
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
}