From 551841b7898e05013622b3b8feef59c047601afa Mon Sep 17 00:00:00 2001 From: June Yi Date: Tue, 22 Sep 2020 22:42:18 +0900 Subject: [PATCH 1/3] Support exec plugin on Windows --- api/internal/plugins/execplugin/execplugin.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/internal/plugins/execplugin/execplugin.go b/api/internal/plugins/execplugin/execplugin.go index 22b379eb5..eff0209f9 100644 --- a/api/internal/plugins/execplugin/execplugin.go +++ b/api/internal/plugins/execplugin/execplugin.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "os" "os/exec" + "runtime" "strings" "github.com/google/shlex" @@ -50,7 +51,9 @@ 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. + if f.Mode()&0111 == 0000 && runtime.GOOS != "windows" { return fmt.Errorf("unexecutable plugin at: %s", p.path) } return nil From 85f79edc97ec9dbfe7316e27b509ee35a538cd38 Mon Sep 17 00:00:00 2001 From: June Yi Date: Sat, 26 Sep 2020 17:45:15 +0900 Subject: [PATCH 2/3] Add testcase for `ErrIfNotExecutable` --- .../plugins/execplugin/execplugin_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/api/internal/plugins/execplugin/execplugin_test.go b/api/internal/plugins/execplugin/execplugin_test.go index d6b9021cf..95cf6257e 100644 --- a/api/internal/plugins/execplugin/execplugin_test.go +++ b/api/internal/plugins/execplugin/execplugin_test.go @@ -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) + } +} From 51ecca8f2fb1194f63643c7198c2b10323bce9f4 Mon Sep 17 00:00:00 2001 From: June Yi Date: Sat, 3 Oct 2020 09:46:28 +0900 Subject: [PATCH 3/3] Add a comment about the behavior in Windows --- api/internal/plugins/execplugin/execplugin.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/internal/plugins/execplugin/execplugin.go b/api/internal/plugins/execplugin/execplugin.go index eff0209f9..a6f801ebb 100644 --- a/api/internal/plugins/execplugin/execplugin.go +++ b/api/internal/plugins/execplugin/execplugin.go @@ -53,6 +53,11 @@ func (p *ExecPlugin) ErrIfNotExecutable() error { } // 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) }