Start pluglib, a set of public, plugin specific functions.

This commit is contained in:
Jeffrey Regan
2019-10-14 17:52:40 -07:00
committed by jregan
parent 2fadb4dd59
commit 41a008e9a3
78 changed files with 280 additions and 329 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/evanphx/json-patch"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/types"
@@ -17,8 +16,6 @@ import (
)
type plugin struct {
ldr ifc.Loader
rf *resmap.Factory
loadedPatch *resource.Resource
decodedPatch jsonpatch.Patch
Path string `json:"path,omitempty" yaml:"path,omitempty"`
@@ -30,9 +27,7 @@ type plugin struct {
var KustomizePlugin plugin
func (p *plugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.ldr = ldr
p.rf = rf
h *resmap.PluginHelpers, c []byte) (err error) {
err = yaml.Unmarshal(c, p)
if err != nil {
return err
@@ -49,7 +44,7 @@ func (p *plugin) Config(
}
var in []byte
if p.Path != "" {
in, err = ldr.Load(p.Path)
in, err = h.Loader().Load(p.Path)
if err != nil {
return
}
@@ -58,7 +53,7 @@ func (p *plugin) Config(
in = []byte(p.Patch)
}
patchSM, errSM := p.rf.RF().FromBytes(in)
patchSM, errSM := h.ResmapFactory().RF().FromBytes(in)
patchJson, errJson := jsonPatchFromBytes(in)
if errSM != nil && errJson != nil {
err = fmt.Errorf(

View File

@@ -7,8 +7,9 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pluglib"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pkg/plugins/testenv"
)
const (
@@ -66,7 +67,7 @@ spec:
)
func TestPatchTransformerMissingFile(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -90,7 +91,7 @@ path: patch.yaml
}
func TestPatchTransformerBadPatch(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -114,7 +115,7 @@ patch: "thisIsNotAPatch"
}
func TestPatchTransformerMissingSelector(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -138,7 +139,7 @@ patch: '[{"op": "add", "path": "/spec/template/spec/dnsPolicy", "value": "Cluste
}
func TestPatchTransformerBothEmptyPathAndPatch(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -161,7 +162,7 @@ metadata:
}
func TestPatchTransformerBothNonEmptyPathAndPatch(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -186,7 +187,7 @@ Patch: "something"
}
func TestPatchTransformerFromFiles(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -268,7 +269,7 @@ spec:
}
func TestPatchTransformerWithInline(t *testing.T) {
tc := testenv.NewEnvForTest(t).Set()
tc := pluglib.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(