Skip to content

Commit bb9435a

Browse files
authored
Merge pull request #448 from Liujingfang1/decoder
remove decoder interface since it is only used inside k8sdeps
2 parents cf4a1ba + 96091df commit bb9435a

22 files changed

+35
-92
lines changed

internal/k8sdeps/decoder.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

internal/k8sdeps/kunstructuredfactory.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package k8sdeps
1818

1919
import (
20+
"bytes"
2021
"io"
22+
2123
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24+
"k8s.io/apimachinery/pkg/util/yaml"
2225
"sigs.k8s.io/kustomize/internal/k8sdeps/configmapandsecret"
2326
"sigs.k8s.io/kustomize/pkg/fs"
2427
"sigs.k8s.io/kustomize/pkg/ifc"
@@ -27,27 +30,26 @@ import (
2730

2831
// KunstructurerFactoryImpl hides construction using apimachinery types.
2932
type KunstructurerFactoryImpl struct {
30-
decoder ifc.Decoder
3133
cmfactory *configmapandsecret.ConfigMapFactory
3234
secfactory *configmapandsecret.SecretFactory
3335
}
3436

3537
var _ ifc.KunstructuredFactory = &KunstructurerFactoryImpl{}
3638

3739
// NewKunstructuredFactoryImpl returns a factory.
38-
func NewKunstructuredFactoryImpl(d ifc.Decoder) ifc.KunstructuredFactory {
39-
return &KunstructurerFactoryImpl{decoder: d}
40+
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
41+
return &KunstructurerFactoryImpl{}
4042
}
4143

4244
// SliceFromBytes returns a slice of Kunstructured.
4345
func (kf *KunstructurerFactoryImpl) SliceFromBytes(
4446
in []byte) ([]ifc.Kunstructured, error) {
45-
kf.decoder.SetInput(in)
47+
decoder := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(in), 1024)
4648
var result []ifc.Kunstructured
4749
var err error
4850
for err == nil || isEmptyYamlError(err) {
4951
var out unstructured.Unstructured
50-
err = kf.decoder.Decode(&out)
52+
err = decoder.Decode(&out)
5153
if err == nil {
5254
result = append(result, &UnstructAdapter{Unstructured: out})
5355
}

internal/k8sdeps/kunstructuredfactory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func TestSliceFromBytes(t *testing.T) {
27-
factory := NewKunstructuredFactoryImpl(NewKustDecoder())
27+
factory := NewKunstructuredFactoryImpl()
2828
testConfigMap := factory.FromMap(
2929
map[string]interface{}{
3030
"apiVersion": "v1",

internal/k8sdeps/patch/patch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
)
3030

3131
var rf = resource.NewFactory(
32-
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
32+
k8sdeps.NewKunstructuredFactoryImpl())
3333
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
3434
var foo = gvk.Gvk{Group: "example.com", Version: "v1", Kind: "Foo"}
3535

internal/k8sdeps/unstructadapter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
func TestGetFieldValue(t *testing.T) {
24-
factory := NewKunstructuredFactoryImpl(NewKustDecoder())
24+
factory := NewKunstructuredFactoryImpl()
2525
kunstructured := factory.FromMap(map[string]interface{}{
2626
"Kind": "Service",
2727
"metadata": map[string]interface{}{

kustomize.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ func main() {
2929
defer glog.Flush()
3030

3131
if err := commands.NewDefaultCommand(
32-
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()),
32+
k8sdeps.NewKunstructuredFactoryImpl(),
3333
patch.NewPatchTransformerFactory(),
34-
k8sdeps.NewKustDecoder(),
3534
k8sdeps.NewKustValidator(),
3635
k8sdeps.NewKustHash()).Execute(); err != nil {
3736
os.Exit(1)

pkg/commands/build/build.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func NewCmdBuild(
6565
out io.Writer, fs fs.FileSystem,
6666
kf ifc.KunstructuredFactory,
6767
ptf patch.TransformerFactory,
68-
decoder ifc.Decoder, hash ifc.Hash) *cobra.Command {
68+
hash ifc.Hash) *cobra.Command {
6969
var o buildOptions
7070
var p string
7171

@@ -79,7 +79,7 @@ func NewCmdBuild(
7979
if err != nil {
8080
return err
8181
}
82-
return o.RunBuild(out, fs, kf, ptf, decoder, hash)
82+
return o.RunBuild(out, fs, kf, ptf, hash)
8383
},
8484
}
8585
cmd.Flags().StringVarP(
@@ -126,7 +126,7 @@ func (o *buildOptions) RunBuild(
126126
out io.Writer, fSys fs.FileSystem,
127127
kf ifc.KunstructuredFactory,
128128
ptf patch.TransformerFactory,
129-
decoder ifc.Decoder, hash ifc.Hash) error {
129+
hash ifc.Hash) error {
130130
rootLoader, err := loader.NewLoader(o.kustomizationPath, "", fSys)
131131
if err != nil {
132132
return err
@@ -137,7 +137,7 @@ func (o *buildOptions) RunBuild(
137137
resmap.NewFactory(resource.NewFactory(kf)),
138138
ptf,
139139
makeTransformerconfig(fSys, o.transformerconfigPaths),
140-
decoder, hash)
140+
hash)
141141
if err != nil {
142142
return err
143143
}

pkg/commands/build/build_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
131131
buf := bytes.NewBuffer([]byte{})
132132
err = ops.RunBuild(
133133
buf, fSys,
134-
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()),
134+
k8sdeps.NewKunstructuredFactoryImpl(),
135135
patch.NewPatchTransformerFactory(),
136-
k8sdeps.NewKustDecoder(), k8sdeps.NewKustHash())
136+
k8sdeps.NewKustHash())
137137
switch {
138138
case err != nil && len(testcase.ExpectedError) == 0:
139139
t.Errorf("unexpected error: %v", err)

pkg/commands/commands.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
// NewDefaultCommand returns the default (aka root) command for kustomize command.
3434
func NewDefaultCommand(
3535
kf ifc.KunstructuredFactory, ptf patch.TransformerFactory,
36-
decoder ifc.Decoder,
3736
validator ifc.Validator, hash ifc.Hash) *cobra.Command {
3837
fsys := fs.MakeRealFS()
3938
stdOut := os.Stdout
@@ -50,7 +49,7 @@ See https://sigs.k8s.io/kustomize
5049

5150
c.AddCommand(
5251
// TODO: Make consistent API for newCmd* functions.
53-
build.NewCmdBuild(stdOut, fsys, kf, ptf, decoder, hash),
52+
build.NewCmdBuild(stdOut, fsys, kf, ptf, hash),
5453
edit.NewCmdEdit(fsys, validator, kf),
5554
misc.NewCmdConfig(fsys),
5655
misc.NewCmdVersion(stdOut),

pkg/ifc/ifc.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ import (
2323
"sigs.k8s.io/kustomize/pkg/types"
2424
)
2525

26-
// Decoder unmarshalls byte input into an object.
27-
type Decoder interface {
28-
// SetInput accepts new input.
29-
SetInput([]byte)
30-
// Decode yields the next object from the input, else io.EOF
31-
Decode(interface{}) error
32-
}
33-
3426
// Validator provides functions to validate annotations and labels
3527
type Validator interface {
3628
MakeAnnotationValidator() func(map[string]string) error

0 commit comments

Comments
 (0)