mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-23 15:27:01 +00:00
remove decoder interface since it is only used inside k8sdeps
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package k8sdeps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
)
|
||||
|
||||
// KustDecoder unmarshalls bytes to objects.
|
||||
type KustDecoder struct {
|
||||
d *yaml.YAMLOrJSONDecoder
|
||||
}
|
||||
|
||||
// NewKustDecoder returns a new KustDecoder.
|
||||
func NewKustDecoder() *KustDecoder {
|
||||
return &KustDecoder{}
|
||||
}
|
||||
|
||||
// SetInput initializes an apimachinery decoder.
|
||||
func (k *KustDecoder) SetInput(in []byte) {
|
||||
k.d = yaml.NewYAMLOrJSONDecoder(
|
||||
bytes.NewReader(in), 1024)
|
||||
}
|
||||
|
||||
// Decode delegates to the apimachinery decoder.
|
||||
func (k *KustDecoder) Decode(into interface{}) error {
|
||||
if k.d == nil {
|
||||
return errors.New("no decoder")
|
||||
}
|
||||
return k.d.Decode(into)
|
||||
}
|
||||
@@ -17,8 +17,11 @@ limitations under the License.
|
||||
package k8sdeps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
"sigs.k8s.io/kustomize/internal/k8sdeps/configmapandsecret"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
@@ -27,7 +30,6 @@ import (
|
||||
|
||||
// KunstructurerFactoryImpl hides construction using apimachinery types.
|
||||
type KunstructurerFactoryImpl struct {
|
||||
decoder ifc.Decoder
|
||||
cmfactory *configmapandsecret.ConfigMapFactory
|
||||
secfactory *configmapandsecret.SecretFactory
|
||||
}
|
||||
@@ -35,19 +37,19 @@ type KunstructurerFactoryImpl struct {
|
||||
var _ ifc.KunstructuredFactory = &KunstructurerFactoryImpl{}
|
||||
|
||||
// NewKunstructuredFactoryImpl returns a factory.
|
||||
func NewKunstructuredFactoryImpl(d ifc.Decoder) ifc.KunstructuredFactory {
|
||||
return &KunstructurerFactoryImpl{decoder: d}
|
||||
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
|
||||
return &KunstructurerFactoryImpl{}
|
||||
}
|
||||
|
||||
// SliceFromBytes returns a slice of Kunstructured.
|
||||
func (kf *KunstructurerFactoryImpl) SliceFromBytes(
|
||||
in []byte) ([]ifc.Kunstructured, error) {
|
||||
kf.decoder.SetInput(in)
|
||||
decoder := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(in), 1024)
|
||||
var result []ifc.Kunstructured
|
||||
var err error
|
||||
for err == nil || isEmptyYamlError(err) {
|
||||
var out unstructured.Unstructured
|
||||
err = kf.decoder.Decode(&out)
|
||||
err = decoder.Decode(&out)
|
||||
if err == nil {
|
||||
result = append(result, &UnstructAdapter{Unstructured: out})
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSliceFromBytes(t *testing.T) {
|
||||
factory := NewKunstructuredFactoryImpl(NewKustDecoder())
|
||||
factory := NewKunstructuredFactoryImpl()
|
||||
testConfigMap := factory.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
var rf = resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
|
||||
var foo = gvk.Gvk{Group: "example.com", Version: "v1", Kind: "Foo"}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetFieldValue(t *testing.T) {
|
||||
factory := NewKunstructuredFactoryImpl(NewKustDecoder())
|
||||
factory := NewKunstructuredFactoryImpl()
|
||||
kunstructured := factory.FromMap(map[string]interface{}{
|
||||
"Kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
|
||||
@@ -29,9 +29,8 @@ func main() {
|
||||
defer glog.Flush()
|
||||
|
||||
if err := commands.NewDefaultCommand(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()),
|
||||
k8sdeps.NewKunstructuredFactoryImpl(),
|
||||
patch.NewPatchTransformerFactory(),
|
||||
k8sdeps.NewKustDecoder(),
|
||||
k8sdeps.NewKustValidator(),
|
||||
k8sdeps.NewKustHash()).Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
|
||||
@@ -65,7 +65,7 @@ func NewCmdBuild(
|
||||
out io.Writer, fs fs.FileSystem,
|
||||
kf ifc.KunstructuredFactory,
|
||||
ptf patch.TransformerFactory,
|
||||
decoder ifc.Decoder, hash ifc.Hash) *cobra.Command {
|
||||
hash ifc.Hash) *cobra.Command {
|
||||
var o buildOptions
|
||||
var p string
|
||||
|
||||
@@ -79,7 +79,7 @@ func NewCmdBuild(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.RunBuild(out, fs, kf, ptf, decoder, hash)
|
||||
return o.RunBuild(out, fs, kf, ptf, hash)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVarP(
|
||||
@@ -126,7 +126,7 @@ func (o *buildOptions) RunBuild(
|
||||
out io.Writer, fSys fs.FileSystem,
|
||||
kf ifc.KunstructuredFactory,
|
||||
ptf patch.TransformerFactory,
|
||||
decoder ifc.Decoder, hash ifc.Hash) error {
|
||||
hash ifc.Hash) error {
|
||||
rootLoader, err := loader.NewLoader(o.kustomizationPath, "", fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -137,7 +137,7 @@ func (o *buildOptions) RunBuild(
|
||||
resmap.NewFactory(resource.NewFactory(kf)),
|
||||
ptf,
|
||||
makeTransformerconfig(fSys, o.transformerconfigPaths),
|
||||
decoder, hash)
|
||||
hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -131,9 +131,9 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
err = ops.RunBuild(
|
||||
buf, fSys,
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()),
|
||||
k8sdeps.NewKunstructuredFactoryImpl(),
|
||||
patch.NewPatchTransformerFactory(),
|
||||
k8sdeps.NewKustDecoder(), k8sdeps.NewKustHash())
|
||||
k8sdeps.NewKustHash())
|
||||
switch {
|
||||
case err != nil && len(testcase.ExpectedError) == 0:
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
|
||||
@@ -33,7 +33,6 @@ import (
|
||||
// NewDefaultCommand returns the default (aka root) command for kustomize command.
|
||||
func NewDefaultCommand(
|
||||
kf ifc.KunstructuredFactory, ptf patch.TransformerFactory,
|
||||
decoder ifc.Decoder,
|
||||
validator ifc.Validator, hash ifc.Hash) *cobra.Command {
|
||||
fsys := fs.MakeRealFS()
|
||||
stdOut := os.Stdout
|
||||
@@ -50,7 +49,7 @@ See https://sigs.k8s.io/kustomize
|
||||
|
||||
c.AddCommand(
|
||||
// TODO: Make consistent API for newCmd* functions.
|
||||
build.NewCmdBuild(stdOut, fsys, kf, ptf, decoder, hash),
|
||||
build.NewCmdBuild(stdOut, fsys, kf, ptf, hash),
|
||||
edit.NewCmdEdit(fsys, validator, kf),
|
||||
misc.NewCmdConfig(fsys),
|
||||
misc.NewCmdVersion(stdOut),
|
||||
|
||||
@@ -23,14 +23,6 @@ import (
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// Decoder unmarshalls byte input into an object.
|
||||
type Decoder interface {
|
||||
// SetInput accepts new input.
|
||||
SetInput([]byte)
|
||||
// Decode yields the next object from the input, else io.EOF
|
||||
Decode(interface{}) error
|
||||
}
|
||||
|
||||
// Validator provides functions to validate annotations and labels
|
||||
type Validator interface {
|
||||
MakeAnnotationValidator() func(map[string]string) error
|
||||
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
var rf = resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
|
||||
func TestNewPatchJson6902FactoryNoTarget(t *testing.T) {
|
||||
p := patch.Json6902{}
|
||||
|
||||
@@ -32,7 +32,7 @@ var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
|
||||
|
||||
func TestJsonPatchJSONTransformer_Transform(t *testing.T) {
|
||||
rf := resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
id := resid.NewResId(deploy, "deploy1")
|
||||
base := resmap.ResMap{
|
||||
id: rf.FromMap(
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
|
||||
var statefulset = gvk.Gvk{Group: "apps", Version: "v1", Kind: "StatefulSet"}
|
||||
var rf = resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
var rmF = NewFactory(rf)
|
||||
|
||||
func TestEncodeAsYaml(t *testing.T) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
var factory = NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
|
||||
var testConfigMap = factory.FromMap(
|
||||
map[string]interface{}{
|
||||
|
||||
@@ -43,7 +43,6 @@ import (
|
||||
// KustTarget encapsulates the entirety of a kustomization build.
|
||||
type KustTarget struct {
|
||||
kustomization *types.Kustomization
|
||||
decoder ifc.Decoder
|
||||
hash ifc.Hash
|
||||
ldr ifc.Loader
|
||||
fSys fs.FileSystem
|
||||
@@ -58,7 +57,7 @@ func NewKustTarget(
|
||||
rf *resmap.Factory,
|
||||
ptf patch.TransformerFactory,
|
||||
tcfg *transformerconfig.TransformerConfig,
|
||||
d ifc.Decoder, h ifc.Hash) (*KustTarget, error) {
|
||||
h ifc.Hash) (*KustTarget, error) {
|
||||
content, err := ldr.Load(constants.KustomizationFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -76,7 +75,6 @@ func NewKustTarget(
|
||||
fSys: fSys,
|
||||
rf: rf,
|
||||
tcfg: tcfg,
|
||||
decoder: d,
|
||||
hash: h,
|
||||
ptf: ptf,
|
||||
}, nil
|
||||
@@ -227,7 +225,7 @@ func (kt *KustTarget) loadCustomizedBases() (resmap.ResMap, *interror.Kustomizat
|
||||
continue
|
||||
}
|
||||
target, err := NewKustTarget(
|
||||
ldr, kt.fSys, kt.rf, kt.ptf, kt.tcfg, kt.decoder, kt.hash)
|
||||
ldr, kt.fSys, kt.rf, kt.ptf, kt.tcfg, kt.hash)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "couldn't make target for "+path))
|
||||
continue
|
||||
@@ -257,7 +255,7 @@ func (kt *KustTarget) loadBasesAsFlatList() ([]*KustTarget, error) {
|
||||
continue
|
||||
}
|
||||
target, err := NewKustTarget(
|
||||
ldr, kt.fSys, kt.rf, kt.ptf, kt.tcfg, kt.decoder, kt.hash)
|
||||
ldr, kt.fSys, kt.rf, kt.ptf, kt.tcfg, kt.hash)
|
||||
if err != nil {
|
||||
errs.Append(err)
|
||||
continue
|
||||
|
||||
@@ -89,7 +89,7 @@ metadata:
|
||||
)
|
||||
|
||||
var rf = resmap.NewFactory(resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder())))
|
||||
k8sdeps.NewKunstructuredFactoryImpl()))
|
||||
|
||||
func makeLoader1(t *testing.T) ifc.Loader {
|
||||
ldr := loadertest.NewFakeLoader("/testpath")
|
||||
@@ -212,7 +212,7 @@ func TestResources1(t *testing.T) {
|
||||
kt, err := NewKustTarget(
|
||||
l, fakeFs, rf, patch.NewPatchTransformerFactory(),
|
||||
transformerconfig.MakeDefaultTransformerConfig(),
|
||||
k8sdeps.NewKustDecoder(), k8sdeps.NewKustHash())
|
||||
k8sdeps.NewKustHash())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected construction error %v", err)
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func TestResourceNotFound(t *testing.T) {
|
||||
kt, err := NewKustTarget(
|
||||
l, fakeFs, rf, patch.NewPatchTransformerFactory(),
|
||||
transformerconfig.MakeDefaultTransformerConfig(),
|
||||
k8sdeps.NewKustDecoder(), k8sdeps.NewKustHash())
|
||||
k8sdeps.NewKustHash())
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected construction error %v", err)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func TestSecretTimeout(t *testing.T) {
|
||||
kt, err := NewKustTarget(
|
||||
l, fakeFs, rf, patch.NewPatchTransformerFactory(),
|
||||
transformerconfig.MakeDefaultTransformerConfig(),
|
||||
k8sdeps.NewKustDecoder(), k8sdeps.NewKustHash())
|
||||
k8sdeps.NewKustHash())
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected construction error %v", err)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
func TestImageTagTransformer(t *testing.T) {
|
||||
var rf = resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
|
||||
m := resmap.ResMap{
|
||||
resid.NewResId(deploy, "deploy1"): rf.FromMap(
|
||||
|
||||
@@ -42,7 +42,7 @@ var crb = gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Clus
|
||||
var sa = gvk.Gvk{Version: "v1", Kind: "ServiceAccount"}
|
||||
var ingress = gvk.Gvk{Kind: "Ingress"}
|
||||
var rf = resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
|
||||
func TestLabelsRun(t *testing.T) {
|
||||
m := resmap.ResMap{
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
func TestNameHashTransformer(t *testing.T) {
|
||||
rf := resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
objs := resmap.ResMap{
|
||||
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
func TestNameReferenceRun(t *testing.T) {
|
||||
rf := resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
m := resmap.ResMap{
|
||||
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
func TestNamespaceRun(t *testing.T) {
|
||||
rf := resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
m := resmap.ResMap{
|
||||
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
func TestPrefixNameRun(t *testing.T) {
|
||||
rf := resource.NewFactory(
|
||||
k8sdeps.NewKunstructuredFactoryImpl(k8sdeps.NewKustDecoder()))
|
||||
k8sdeps.NewKunstructuredFactoryImpl())
|
||||
m := resmap.ResMap{
|
||||
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user