Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#919 from monopole/accumulatorPkg
Browse files Browse the repository at this point in the history
Move accumulator code to its own package.
  • Loading branch information
monopole authored Mar 26, 2019
2 parents f8cffef + 9a12b55 commit 9764eb2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package target
package accumulator

import (
"fmt"
Expand All @@ -30,10 +30,6 @@ import (

// ResAccumulator accumulates resources and the rules
// 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 {
resMap resmap.ResMap
tConfig *config.TransformerConfig
Expand Down Expand Up @@ -82,6 +78,10 @@ func (ra *ResAccumulator) MergeConfig(
return err
}

func (ra *ResAccumulator) GetTransformerConfig() *config.TransformerConfig {
return ra.tConfig
}

func (ra *ResAccumulator) MergeVars(incoming []types.Var) error {
return ra.varSet.MergeSlice(incoming)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package target_test
package accumulator_test

import (
"bytes"
Expand All @@ -24,11 +24,11 @@ import (
"testing"

"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
. "sigs.k8s.io/kustomize/pkg/accumulator"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
. "sigs.k8s.io/kustomize/pkg/target"
"sigs.k8s.io/kustomize/pkg/transformers/config"
"sigs.k8s.io/kustomize/pkg/types"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/edit/add/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMakeConfigMapArgs(t *testing.T) {
}

func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) {
kv := []types.KVSource{}
var kv []types.KVSource

mergeFlagsIntoCmArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}})

Expand All @@ -81,7 +81,7 @@ func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) {
}

func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) {
kv := []types.KVSource{}
var kv []types.KVSource

mergeFlagsIntoCmArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}})

Expand All @@ -99,7 +99,7 @@ func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) {
func TestMergeFlagsIntoCmArgs_EnvSource(t *testing.T) {
envFileName := "env1"
envFileName2 := "env2"
kv := []types.KVSource{}
var kv []types.KVSource

mergeFlagsIntoCmArgs(&kv, flagsAndArgs{EnvFileSource: envFileName})

Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/edit/add/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestMakeSecretArgs(t *testing.T) {
}

func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
kv := []types.KVSource{}
var kv []types.KVSource

mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}})

Expand All @@ -83,7 +83,7 @@ func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
}

func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
kv := []types.KVSource{}
var kv []types.KVSource

mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}})

Expand All @@ -101,7 +101,7 @@ func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) {
envFileName := "env1"
envFileName2 := "env2"
kv := []types.KVSource{}
var kv []types.KVSource

mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{EnvFileSource: envFileName})

Expand Down
9 changes: 5 additions & 4 deletions pkg/target/kusttarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

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

for _, path := range kt.kustomization.Bases {
ldr, err := kt.ldr.New(path)
Expand Down

0 comments on commit 9764eb2

Please sign in to comment.