Move accumulator code to its own package.

This commit is contained in:
Jeffrey Regan
2019-03-26 09:43:50 -07:00
parent f8cffef977
commit 9a12b55139
5 changed files with 18 additions and 17 deletions

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package target package accumulator
import ( import (
"fmt" "fmt"
@@ -30,10 +30,6 @@ import (
// ResAccumulator accumulates resources and the rules // ResAccumulator accumulates resources and the rules
// used to customize those resources. // used to customize those resources.
// TODO(monopole): Move to "accumulator" package and make members private.
// This will make a better separation between KustTarget, which should
// be mainly concerned with data loading, and this class, which could
// become the home of all transformation data and logic.
type ResAccumulator struct { type ResAccumulator struct {
resMap resmap.ResMap resMap resmap.ResMap
tConfig *config.TransformerConfig tConfig *config.TransformerConfig
@@ -82,6 +78,10 @@ func (ra *ResAccumulator) MergeConfig(
return err return err
} }
func (ra *ResAccumulator) GetTransformerConfig() *config.TransformerConfig {
return ra.tConfig
}
func (ra *ResAccumulator) MergeVars(incoming []types.Var) error { func (ra *ResAccumulator) MergeVars(incoming []types.Var) error {
return ra.varSet.MergeSlice(incoming) return ra.varSet.MergeSlice(incoming)
} }

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package target_test package accumulator_test
import ( import (
"bytes" "bytes"
@@ -24,11 +24,11 @@ import (
"testing" "testing"
"sigs.k8s.io/kustomize/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/k8sdeps/kunstruct"
. "sigs.k8s.io/kustomize/pkg/accumulator"
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
. "sigs.k8s.io/kustomize/pkg/target"
"sigs.k8s.io/kustomize/pkg/transformers/config" "sigs.k8s.io/kustomize/pkg/transformers/config"
"sigs.k8s.io/kustomize/pkg/types" "sigs.k8s.io/kustomize/pkg/types"
) )

View File

@@ -65,7 +65,7 @@ func TestMakeConfigMapArgs(t *testing.T) {
} }
func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) { func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) {
kv := []types.KVSource{} var kv []types.KVSource
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}}) mergeFlagsIntoCmArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}})
@@ -81,7 +81,7 @@ func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) {
} }
func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) { func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) {
kv := []types.KVSource{} var kv []types.KVSource
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}}) mergeFlagsIntoCmArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}})
@@ -99,7 +99,7 @@ func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) {
func TestMergeFlagsIntoCmArgs_EnvSource(t *testing.T) { func TestMergeFlagsIntoCmArgs_EnvSource(t *testing.T) {
envFileName := "env1" envFileName := "env1"
envFileName2 := "env2" envFileName2 := "env2"
kv := []types.KVSource{} var kv []types.KVSource
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{EnvFileSource: envFileName}) mergeFlagsIntoCmArgs(&kv, flagsAndArgs{EnvFileSource: envFileName})

View File

@@ -67,7 +67,7 @@ func TestMakeSecretArgs(t *testing.T) {
} }
func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) { func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
kv := []types.KVSource{} var kv []types.KVSource
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}}) mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}})
@@ -83,7 +83,7 @@ func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
} }
func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) { func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
kv := []types.KVSource{} var kv []types.KVSource
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}}) mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}})
@@ -101,7 +101,7 @@ func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) { func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) {
envFileName := "env1" envFileName := "env1"
envFileName2 := "env2" envFileName2 := "env2"
kv := []types.KVSource{} var kv []types.KVSource
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{EnvFileSource: envFileName}) mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{EnvFileSource: envFileName})

View File

@@ -25,6 +25,7 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/pkg/accumulator"
"sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/ifc/transformer" "sigs.k8s.io/kustomize/pkg/ifc/transformer"
interror "sigs.k8s.io/kustomize/pkg/internal/error" interror "sigs.k8s.io/kustomize/pkg/internal/error"
@@ -151,7 +152,7 @@ func (kt *KustTarget) shouldAddHashSuffixesToGeneratedResources() bool {
// to do so. The name back references and vars are // to do so. The name back references and vars are
// not yet fixed. // not yet fixed.
func (kt *KustTarget) AccumulateTarget() ( func (kt *KustTarget) AccumulateTarget() (
ra *ResAccumulator, err error) { ra *accumulator.ResAccumulator, err error) {
// TODO(monopole): Get rid of the KustomizationErrors accumulator. // TODO(monopole): Get rid of the KustomizationErrors accumulator.
// It's not consistently used, and complicates tests. // It's not consistently used, and complicates tests.
errs := &interror.KustomizationErrors{} errs := &interror.KustomizationErrors{}
@@ -205,7 +206,7 @@ func (kt *KustTarget) AccumulateTarget() (
if len(errs.Get()) > 0 { if len(errs.Get()) > 0 {
return nil, errs return nil, errs
} }
t, err := kt.newTransformer(patches, ra.tConfig) t, err := kt.newTransformer(patches, ra.GetTransformerConfig())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -240,9 +241,9 @@ func (kt *KustTarget) generateConfigMapsAndSecrets(
// used to customized them from only the _bases_ // used to customized them from only the _bases_
// of this KustTarget. // of this KustTarget.
func (kt *KustTarget) accumulateBases() ( func (kt *KustTarget) accumulateBases() (
ra *ResAccumulator, errs *interror.KustomizationErrors) { ra *accumulator.ResAccumulator, errs *interror.KustomizationErrors) {
errs = &interror.KustomizationErrors{} errs = &interror.KustomizationErrors{}
ra = MakeEmptyAccumulator() ra = accumulator.MakeEmptyAccumulator()
for _, path := range kt.kustomization.Bases { for _, path := range kt.kustomization.Bases {
ldr, err := kt.ldr.New(path) ldr, err := kt.ldr.New(path)