Make scan.Filter more ammenable to change
Just allow kubectl and kustomize to be more functional
@@ -29,8 +29,11 @@ import (
// FilterOptions allow the behavior of the Konjure filter to be customized.
type FilterOptions struct {
+ // Default input (i.e. stdin).
DefaultReader io.Reader
+ // An alternate executor for kubectl commands.
KubectlExecutor func(cmd *exec.Cmd) ([]byte, error)
+ // An alternate executor for kustomize commands.
KustomizeExecutor func(cmd *exec.Cmd) ([]byte, error)
}
@@ -46,17 +49,18 @@ func (o *FilterOptions) NewFilter(workingDirectory string) *konjure.Filter {
}
if f.KubectlExecutor == nil {
- f.KubectlExecutor = kubectl
+ f.KubectlExecutor = kubectl()
}
if f.KustomizeExecutor == nil {
- f.KustomizeExecutor = kustomize
+ f.KustomizeExecutor = kustomize()
}
return f
}
-func kubectl(cmd *exec.Cmd) ([]byte, error) {
+func kubectl() func(cmd *exec.Cmd) ([]byte, error) {
+ return func(cmd *exec.Cmd) ([]byte, error) {
// If LookPath found the kubectl binary, it is safer to just use it. That
// way the cluster version doesn't need to be in the compatibility range of
// whatever client-go we were compiled with.
@@ -85,8 +89,10 @@ func kubectl(cmd *exec.Cmd) ([]byte, error) {
// Run minikubectl with the remaining arguments
return k.Run(flags.Args())
}
+}
-func kustomize(cmd *exec.Cmd) ([]byte, error) {
+func kustomize() func(cmd *exec.Cmd) ([]byte, error) {
+ return func(cmd *exec.Cmd) ([]byte, error) {
// If the command path is absolute, it was found by LookPath. In this
// case we will just fork so the embedded version of Kustomize does not
// becoming a limiting factor.
@@ -113,3 +119,4 @@ func kustomize(cmd *exec.Cmd) ([]byte, error) {
return rm.AsYaml()
}
+}
