Reduce size of pgmconfig package

This commit is contained in:
Jeffrey Regan
2019-10-02 16:27:13 -07:00
committed by jregan
parent 14b0a65091
commit baa0296a12
53 changed files with 498 additions and 285 deletions

View File

@@ -6,6 +6,7 @@ package main
import (
"fmt"
"github.com/evanphx/json-patch"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
@@ -22,7 +23,7 @@ type plugin struct {
decodedPatch jsonpatch.Patch
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *types.Selector `json:"target,omitempty", yaml:"target,omitempty"`
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
}
//noinspection GoUnusedGlobalVariable
@@ -99,9 +100,9 @@ func (p *plugin) Transform(m resmap.ResMap) error {
if err != nil {
return err
}
for _, resource := range resources {
for _, res := range resources {
if p.decodedPatch != nil {
rawObj, err := resource.MarshalJSON()
rawObj, err := res.MarshalJSON()
if err != nil {
return err
}
@@ -110,17 +111,17 @@ func (p *plugin) Transform(m resmap.ResMap) error {
return errors.Wrapf(
err, "failed to apply json patch '%s'", p.Patch)
}
err = resource.UnmarshalJSON(modifiedObj)
err = res.UnmarshalJSON(modifiedObj)
if err != nil {
return err
}
}
if p.loadedPatch != nil {
patchCopy := p.loadedPatch.DeepCopy()
patchCopy.SetName(resource.GetName())
patchCopy.SetNamespace(resource.GetNamespace())
patchCopy.SetGvk(resource.GetGvk())
err = resource.Patch(patchCopy.Kunstructured)
patchCopy.SetName(res.GetName())
patchCopy.SetNamespace(res.GetNamespace())
patchCopy.SetGvk(res.GetGvk())
err = res.Patch(patchCopy.Kunstructured)
if err != nil {
return err
}

View File

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