mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Put goplugins behind flag.
This commit is contained in:
@@ -14,6 +14,9 @@ limitations under the License.
|
||||
package target_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -69,3 +72,47 @@ metadata:
|
||||
name: shouldNotHaveHash
|
||||
`)
|
||||
}
|
||||
|
||||
func TestGoPluginNotEnabled(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app")
|
||||
th.writeK("/app", `
|
||||
secretGenerator:
|
||||
- name: attemptGoPlugin
|
||||
kvSources:
|
||||
- name: foo
|
||||
pluginType: go
|
||||
args:
|
||||
- someArg
|
||||
- someOtherArg
|
||||
`)
|
||||
_, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "enable go plugins by ") {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoPluginDoesNotExist(t *testing.T) {
|
||||
th := NewKustTestHarnessWithPluginConfig(
|
||||
t, "/app", types.PluginConfig{GoEnabled: true})
|
||||
th.writeK("/app", `
|
||||
secretGenerator:
|
||||
- name: attemptGoPlugin
|
||||
kvSources:
|
||||
- name: foo
|
||||
pluginType: go
|
||||
args:
|
||||
- someArg
|
||||
- someOtherArg
|
||||
`)
|
||||
_, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
if !strings.Contains(err.Error(),
|
||||
filepath.Join("kvSources", "foo.so")) {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import (
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
|
||||
interror "sigs.k8s.io/kustomize/pkg/internal/error"
|
||||
patchtransformer "sigs.k8s.io/kustomize/pkg/patch/transformer"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
@@ -89,7 +89,7 @@ func commaOr(q []string) string {
|
||||
func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
||||
var content []byte
|
||||
match := 0
|
||||
for _, kf := range constants.KustomizationFileNames {
|
||||
for _, kf := range pgmconfig.KustomizationFileNames {
|
||||
c, err := ldr.Load(kf)
|
||||
if err == nil {
|
||||
match += 1
|
||||
@@ -100,7 +100,7 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
||||
case 0:
|
||||
return nil, fmt.Errorf(
|
||||
"unable to find one of %v in directory '%s'",
|
||||
commaOr(quoted(constants.KustomizationFileNames)), ldr.Root())
|
||||
commaOr(quoted(pgmconfig.KustomizationFileNames)), ldr.Root())
|
||||
case 1:
|
||||
return content, nil
|
||||
default:
|
||||
|
||||
@@ -21,13 +21,14 @@ package target_test
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/internal/loadertest"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
. "sigs.k8s.io/kustomize/pkg/target"
|
||||
@@ -42,10 +43,18 @@ type KustTestHarness struct {
|
||||
}
|
||||
|
||||
func NewKustTestHarness(t *testing.T, path string) *KustTestHarness {
|
||||
return NewKustTestHarnessWithPluginConfig(
|
||||
t, path, plugin.DefaultPluginConfig())
|
||||
}
|
||||
|
||||
func NewKustTestHarnessWithPluginConfig(
|
||||
t *testing.T, path string,
|
||||
config types.PluginConfig) *KustTestHarness {
|
||||
return &KustTestHarness{
|
||||
t: t,
|
||||
rf: resmap.NewFactory(resource.NewFactory(
|
||||
kunstruct.NewKunstructuredFactoryImpl())),
|
||||
kunstruct.NewKunstructuredFactoryWithGeneratorArgs(
|
||||
&types.GeneratorMetaArgs{PluginConfig: config}))),
|
||||
ldr: loadertest.NewFakeLoader(path)}
|
||||
}
|
||||
|
||||
@@ -66,7 +75,7 @@ func (th *KustTestHarness) writeF(dir string, content string) {
|
||||
}
|
||||
|
||||
func (th *KustTestHarness) writeK(dir string, content string) {
|
||||
th.writeF(filepath.Join(dir, constants.KustomizationFileNames[0]), `
|
||||
th.writeF(filepath.Join(dir, pgmconfig.KustomizationFileNames[0]), `
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
`+content)
|
||||
|
||||
Reference in New Issue
Block a user