mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Merge pull request #1893 from artmello/enable_linters
kyaml: Enable Go linters (lll, stylecheck, unparam, whitespace)
This commit is contained in:
@@ -126,7 +126,7 @@ func (r *CatRunner) runE(c *cobra.Command, args []string) error {
|
|||||||
Writer: out,
|
Writer: out,
|
||||||
KeepReaderAnnotations: r.KeepAnnotations,
|
KeepReaderAnnotations: r.KeepAnnotations,
|
||||||
WrappingKind: r.WrapKind,
|
WrappingKind: r.WrapKind,
|
||||||
WrappingApiVersion: r.WrapApiVersion,
|
WrappingAPIVersion: r.WrapApiVersion,
|
||||||
FunctionConfig: functionConfig,
|
FunctionConfig: functionConfig,
|
||||||
Style: yaml.GetStyle(r.Styles...),
|
Style: yaml.GetStyle(r.Styles...),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func (r *WrapRunner) runE(c *cobra.Command, args []string) error {
|
|||||||
KeepReaderAnnotations: true,
|
KeepReaderAnnotations: true,
|
||||||
Writer: c.OutOrStdout(),
|
Writer: c.OutOrStdout(),
|
||||||
WrappingKind: kio.ResourceListKind,
|
WrappingKind: kio.ResourceListKind,
|
||||||
WrappingApiVersion: kio.ResourceListApiVersion}}}.Execute()
|
WrappingAPIVersion: kio.ResourceListAPIVersion}}}.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ func (r *XArgsRunner) runE(c *cobra.Command, _ []string) error {
|
|||||||
if version := rw.FunctionConfig.Field("apiVersion"); !yaml.IsFieldEmpty(version) {
|
if version := rw.FunctionConfig.Field("apiVersion"); !yaml.IsFieldEmpty(version) {
|
||||||
version.Value.YNode().Value = r.WrapVersion
|
version.Value.YNode().Value = r.WrapVersion
|
||||||
}
|
}
|
||||||
rw.WrappingApiVersion = r.WrapVersion
|
rw.WrappingAPIVersion = r.WrapVersion
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}(); err != nil {
|
}(); err != nil {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ linters:
|
|||||||
- dupl
|
- dupl
|
||||||
- errcheck
|
- errcheck
|
||||||
# - funlen
|
# - funlen
|
||||||
# - gochecknoinits
|
- gochecknoinits
|
||||||
# - goconst
|
# - goconst
|
||||||
# - gocritic
|
# - gocritic
|
||||||
- gocyclo
|
- gocyclo
|
||||||
@@ -28,19 +28,19 @@ linters:
|
|||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- interfacer
|
- interfacer
|
||||||
# - lll
|
- lll
|
||||||
- misspell
|
- misspell
|
||||||
- nakedret
|
- nakedret
|
||||||
- scopelint
|
- scopelint
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- structcheck
|
- structcheck
|
||||||
# - stylecheck
|
- stylecheck
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
# - unparam
|
- unparam
|
||||||
- unused
|
- unused
|
||||||
- varcheck
|
- varcheck
|
||||||
# - whitespace
|
- whitespace
|
||||||
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ func TestDiff_additionalDestFiles(t *testing.T) {
|
|||||||
diff, err := Diff(s, d)
|
diff, err := Diff(s, d)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.ElementsMatch(t, diff.List(), []string{"a2"})
|
assert.ElementsMatch(t, diff.List(), []string{"a2"})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDiff_srcDestContentsDiffer verifies if the file contents
|
// TestDiff_srcDestContentsDiffer verifies if the file contents
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ResourceListKind = "ResourceList"
|
ResourceListKind = "ResourceList"
|
||||||
ResourceListApiVersion = "config.kubernetes.io/v1alpha1"
|
ResourceListAPIVersion = "config.kubernetes.io/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ByteReadWriter reads from an input and writes to an output.
|
// ByteReadWriter reads from an input and writes to an output.
|
||||||
@@ -41,7 +41,7 @@ type ByteReadWriter struct {
|
|||||||
|
|
||||||
FunctionConfig *yaml.RNode
|
FunctionConfig *yaml.RNode
|
||||||
|
|
||||||
WrappingApiVersion string
|
WrappingAPIVersion string
|
||||||
WrappingKind string
|
WrappingKind string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ func (rw *ByteReadWriter) Read() ([]*yaml.RNode, error) {
|
|||||||
}
|
}
|
||||||
val, err := b.Read()
|
val, err := b.Read()
|
||||||
rw.FunctionConfig = b.FunctionConfig
|
rw.FunctionConfig = b.FunctionConfig
|
||||||
rw.WrappingApiVersion = b.WrappingApiVersion
|
rw.WrappingAPIVersion = b.WrappingAPIVersion
|
||||||
rw.WrappingKind = b.WrappingKind
|
rw.WrappingKind = b.WrappingKind
|
||||||
return val, errors.Wrap(err)
|
return val, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func (rw *ByteReadWriter) Write(nodes []*yaml.RNode) error {
|
|||||||
KeepReaderAnnotations: rw.KeepReaderAnnotations,
|
KeepReaderAnnotations: rw.KeepReaderAnnotations,
|
||||||
Style: rw.Style,
|
Style: rw.Style,
|
||||||
FunctionConfig: rw.FunctionConfig,
|
FunctionConfig: rw.FunctionConfig,
|
||||||
WrappingApiVersion: rw.WrappingApiVersion,
|
WrappingAPIVersion: rw.WrappingAPIVersion,
|
||||||
WrappingKind: rw.WrappingKind,
|
WrappingKind: rw.WrappingKind,
|
||||||
}.Write(nodes)
|
}.Write(nodes)
|
||||||
}
|
}
|
||||||
@@ -88,9 +88,9 @@ type ByteReader struct {
|
|||||||
// DisableUnwrapping prevents Resources in Lists and ResourceLists from being unwrapped
|
// DisableUnwrapping prevents Resources in Lists and ResourceLists from being unwrapped
|
||||||
DisableUnwrapping bool
|
DisableUnwrapping bool
|
||||||
|
|
||||||
// WrappingApiVersion is set by Read(), and is the apiVersion of the object that
|
// WrappingAPIVersion is set by Read(), and is the apiVersion of the object that
|
||||||
// the read objects were originally wrapped in.
|
// the read objects were originally wrapped in.
|
||||||
WrappingApiVersion string
|
WrappingAPIVersion string
|
||||||
|
|
||||||
// WrappingKind is set by Read(), and is the kind of the object that
|
// WrappingKind is set by Read(), and is the kind of the object that
|
||||||
// the read objects were originally wrapped in.
|
// the read objects were originally wrapped in.
|
||||||
@@ -138,9 +138,8 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) {
|
|||||||
len(values) == 1 && // Only unwrap if there is only 1 value
|
len(values) == 1 && // Only unwrap if there is only 1 value
|
||||||
(meta.Kind == ResourceListKind || meta.Kind == "List") &&
|
(meta.Kind == ResourceListKind || meta.Kind == "List") &&
|
||||||
node.Field("items") != nil {
|
node.Field("items") != nil {
|
||||||
|
|
||||||
r.WrappingKind = meta.Kind
|
r.WrappingKind = meta.Kind
|
||||||
r.WrappingApiVersion = meta.ApiVersion
|
r.WrappingAPIVersion = meta.APIVersion
|
||||||
|
|
||||||
// unwrap the list
|
// unwrap the list
|
||||||
fc := node.Field("functionConfig")
|
fc := node.Field("functionConfig")
|
||||||
@@ -154,7 +153,6 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) {
|
|||||||
// add items
|
// add items
|
||||||
output = append(output, yaml.NewRNode(items.Value.Content()[i]))
|
output = append(output, yaml.NewRNode(items.Value.Content()[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ elems:
|
|||||||
`, r.FunctionConfig.MustString())
|
`, r.FunctionConfig.MustString())
|
||||||
|
|
||||||
assert.Equal(t, ResourceListKind, r.WrappingKind)
|
assert.Equal(t, ResourceListKind, r.WrappingKind)
|
||||||
assert.Equal(t, ResourceListApiVersion, r.WrappingApiVersion)
|
assert.Equal(t, ResourceListAPIVersion, r.WrappingAPIVersion)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestByteReader_Read_wrappedList(t *testing.T) {
|
func TestByteReader_Read_wrappedList(t *testing.T) {
|
||||||
@@ -131,7 +130,7 @@ spec:
|
|||||||
// verify the function config
|
// verify the function config
|
||||||
assert.Nil(t, r.FunctionConfig)
|
assert.Nil(t, r.FunctionConfig)
|
||||||
assert.Equal(t, "List", r.WrappingKind)
|
assert.Equal(t, "List", r.WrappingKind)
|
||||||
assert.Equal(t, "v1", r.WrappingApiVersion)
|
assert.Equal(t, "v1", r.WrappingAPIVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestByteReader_Read tests the default Read behavior
|
// TestByteReader_Read tests the default Read behavior
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ type ByteWriter struct {
|
|||||||
// ByteWriter will wrap the Resources in a List .items field.
|
// ByteWriter will wrap the Resources in a List .items field.
|
||||||
WrappingKind string
|
WrappingKind string
|
||||||
|
|
||||||
// WrappingApiVersion is the apiVersion for WrappingKind
|
// WrappingAPIVersion is the apiVersion for WrappingKind
|
||||||
WrappingApiVersion string
|
WrappingAPIVersion string
|
||||||
|
|
||||||
// Sort if set, will cause ByteWriter to sort the the nodes before writing them.
|
// Sort if set, will cause ByteWriter to sort the the nodes before writing them.
|
||||||
Sort bool
|
Sort bool
|
||||||
@@ -54,7 +54,6 @@ func (w ByteWriter) Write(nodes []*yaml.RNode) error {
|
|||||||
encoder := yaml.NewEncoder(w.Writer)
|
encoder := yaml.NewEncoder(w.Writer)
|
||||||
defer encoder.Close()
|
defer encoder.Close()
|
||||||
for i := range nodes {
|
for i := range nodes {
|
||||||
|
|
||||||
// clean resources by removing annotations set by the Reader
|
// clean resources by removing annotations set by the Reader
|
||||||
if !w.KeepReaderAnnotations {
|
if !w.KeepReaderAnnotations {
|
||||||
_, err := nodes[i].Pipe(yaml.ClearAnnotation(kioutil.IndexAnnotation))
|
_, err := nodes[i].Pipe(yaml.ClearAnnotation(kioutil.IndexAnnotation))
|
||||||
@@ -102,7 +101,7 @@ func (w ByteWriter) Write(nodes []*yaml.RNode) error {
|
|||||||
Style: w.Style,
|
Style: w.Style,
|
||||||
Content: []*yaml.Node{
|
Content: []*yaml.Node{
|
||||||
{Kind: yaml.ScalarNode, Value: "apiVersion"},
|
{Kind: yaml.ScalarNode, Value: "apiVersion"},
|
||||||
{Kind: yaml.ScalarNode, Value: w.WrappingApiVersion},
|
{Kind: yaml.ScalarNode, Value: w.WrappingAPIVersion},
|
||||||
{Kind: yaml.ScalarNode, Value: "kind"},
|
{Kind: yaml.ScalarNode, Value: "kind"},
|
||||||
{Kind: yaml.ScalarNode, Value: w.WrappingKind},
|
{Kind: yaml.ScalarNode, Value: w.WrappingKind},
|
||||||
{Kind: yaml.ScalarNode, Value: "items"}, items,
|
{Kind: yaml.ScalarNode, Value: "items"}, items,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ g:
|
|||||||
Writer: buff,
|
Writer: buff,
|
||||||
FunctionConfig: node3,
|
FunctionConfig: node3,
|
||||||
WrappingKind: ResourceListKind,
|
WrappingKind: ResourceListKind,
|
||||||
WrappingApiVersion: ResourceListApiVersion}.
|
WrappingAPIVersion: ResourceListAPIVersion}.
|
||||||
Write([]*yaml.RNode{node2, node1})
|
Write([]*yaml.RNode{node2, node1})
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func (c *ContainerFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
|
|
||||||
// write the input
|
// write the input
|
||||||
err = kio.ByteWriter{
|
err = kio.ByteWriter{
|
||||||
WrappingApiVersion: kio.ResourceListApiVersion,
|
WrappingAPIVersion: kio.ResourceListAPIVersion,
|
||||||
WrappingKind: kio.ResourceListKind,
|
WrappingKind: kio.ResourceListKind,
|
||||||
Writer: in, KeepReaderAnnotations: true, FunctionConfig: c.Config}.Write(input)
|
Writer: in, KeepReaderAnnotations: true, FunctionConfig: c.Config}.Write(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -133,7 +133,6 @@ func (c *ContainerFilter) getArgs() []string {
|
|||||||
args = append(args, "-e", strings.Split(pair, "=")[0])
|
args = append(args, "-e", strings.Split(pair, "=")[0])
|
||||||
}
|
}
|
||||||
return append(args, c.Image)
|
return append(args, c.Image)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getCommand returns a command which will apply the GrepFilter using the container image
|
// getCommand returns a command which will apply the GrepFilter using the container image
|
||||||
|
|||||||
@@ -145,7 +145,6 @@ spec:
|
|||||||
|
|
||||||
// TestFormatInput_service verifies a Service yaml is formatted correctly
|
// TestFormatInput_service verifies a Service yaml is formatted correctly
|
||||||
func TestFormatInput_service(t *testing.T) {
|
func TestFormatInput_service(t *testing.T) {
|
||||||
|
|
||||||
y := `
|
y := `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
@@ -178,7 +177,6 @@ spec:
|
|||||||
|
|
||||||
// TestFormatInput_service verifies a Service yaml is formatted correctly
|
// TestFormatInput_service verifies a Service yaml is formatted correctly
|
||||||
func TestFormatInput_validatingWebhookConfiguration(t *testing.T) {
|
func TestFormatInput_validatingWebhookConfiguration(t *testing.T) {
|
||||||
|
|
||||||
y := `
|
y := `
|
||||||
apiVersion: admissionregistration.k8s.io/v1beta1
|
apiVersion: admissionregistration.k8s.io/v1beta1
|
||||||
kind: ValidatingWebhookConfiguration
|
kind: ValidatingWebhookConfiguration
|
||||||
@@ -459,7 +457,7 @@ func TestFormatFileOrDirectory_YamlExtFileWithJson(t *testing.T) {
|
|||||||
f, err := ioutil.TempFile("", "yamlfmt*.yaml")
|
f, err := ioutil.TempFile("", "yamlfmt*.yaml")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
err = ioutil.WriteFile(f.Name(), testyaml.UnformattedJson1, 0600)
|
err = ioutil.WriteFile(f.Name(), testyaml.UnformattedJSON1, 0600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// format the file
|
// format the file
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (c MergeFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
key := mergeKey{
|
key := mergeKey{
|
||||||
apiVersion: meta.ApiVersion,
|
apiVersion: meta.APIVersion,
|
||||||
kind: meta.Kind,
|
kind: meta.Kind,
|
||||||
namespace: meta.Namespace,
|
namespace: meta.Namespace,
|
||||||
name: meta.Name,
|
name: meta.Name,
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ func (ts *tuples) add(node *yaml.RNode) error {
|
|||||||
for i := range ts.list {
|
for i := range ts.list {
|
||||||
t := ts.list[i]
|
t := ts.list[i]
|
||||||
if t.meta.Name == nodeMeta.Name && t.meta.Namespace == nodeMeta.Namespace &&
|
if t.meta.Name == nodeMeta.Name && t.meta.Namespace == nodeMeta.Namespace &&
|
||||||
t.meta.ApiVersion == nodeMeta.ApiVersion && t.meta.Kind == nodeMeta.Kind {
|
t.meta.APIVersion == nodeMeta.APIVersion && t.meta.Kind == nodeMeta.Kind {
|
||||||
return t.add(node)
|
return t.add(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ apiVersion: example.com/v1beta1
|
|||||||
kind: MyType2
|
kind: MyType2
|
||||||
`)
|
`)
|
||||||
|
|
||||||
var UnformattedJson1 = []byte(`
|
var UnformattedJSON1 = []byte(`
|
||||||
{
|
{
|
||||||
"spec": "a",
|
"spec": "a",
|
||||||
"status": {"conditions": [3, 1, 2]},
|
"status": {"conditions": [3, 1, 2]},
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ func (r LocalPackageReader) Read() ([]*yaml.RNode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// readFile reads the ResourceNodes from a file
|
// readFile reads the ResourceNodes from a file
|
||||||
func (r *LocalPackageReader) readFile(path string, info os.FileInfo) ([]*yaml.RNode, error) {
|
func (r *LocalPackageReader) readFile(path string, _ os.FileInfo) ([]*yaml.RNode, error) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -258,7 +258,7 @@ func (r *LocalPackageReader) shouldSkipFile(info os.FileInfo) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initReaderAnnotations adds the LocalPackageReader Annotations to r.SetAnnotations
|
// initReaderAnnotations adds the LocalPackageReader Annotations to r.SetAnnotations
|
||||||
func (r *LocalPackageReader) initReaderAnnotations(path string, info os.FileInfo) {
|
func (r *LocalPackageReader) initReaderAnnotations(path string, _ os.FileInfo) {
|
||||||
if r.SetAnnotations == nil {
|
if r.SetAnnotations == nil {
|
||||||
r.SetAnnotations = map[string]string{}
|
r.SetAnnotations = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ func TestLocalPackageReader_Read_empty(t *testing.T) {
|
|||||||
assert.Contains(t, err.Error(), "must specify package path")
|
assert.Contains(t, err.Error(), "must specify package path")
|
||||||
}
|
}
|
||||||
assert.Nil(t, nodes)
|
assert.Nil(t, nodes)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalPackageReader_Read_pkg(t *testing.T) {
|
func TestLocalPackageReader_Read_pkg(t *testing.T) {
|
||||||
@@ -207,7 +206,6 @@ func TestLocalPackageReader_Read_pkgOmitAnnotations(t *testing.T) {
|
|||||||
{path: s.root},
|
{path: s.root},
|
||||||
}
|
}
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
|
|
||||||
// empty path
|
// empty path
|
||||||
rfr := LocalPackageReader{PackagePath: p.path, OmitReaderAnnotations: true}
|
rfr := LocalPackageReader{PackagePath: p.path, OmitReaderAnnotations: true}
|
||||||
nodes, err := rfr.Read()
|
nodes, err := rfr.Read()
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ func (r LocalPackageWriter) errorIfMissingRequiredAnnotation(nodes []*yaml.RNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r LocalPackageWriter) indexByFilePath(nodes []*yaml.RNode) (map[string][]*yaml.RNode, error) {
|
func (r LocalPackageWriter) indexByFilePath(nodes []*yaml.RNode) (map[string][]*yaml.RNode, error) {
|
||||||
|
|
||||||
outputFiles := map[string][]*yaml.RNode{}
|
outputFiles := map[string][]*yaml.RNode{}
|
||||||
for i := range nodes {
|
for i := range nodes {
|
||||||
// parse the file write path
|
// parse the file write path
|
||||||
|
|||||||
@@ -285,8 +285,8 @@ func compareNodes(i, j *yaml.RNode) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compare apiVersion
|
// compare apiVersion
|
||||||
if metai.ApiVersion != metaj.ApiVersion {
|
if metai.APIVersion != metaj.APIVersion {
|
||||||
return metai.ApiVersion < metaj.ApiVersion
|
return metai.APIVersion < metaj.APIVersion
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -872,7 +872,6 @@ func ExampleRNode_Elements() {
|
|||||||
// Element: 2
|
// Element: 2
|
||||||
// name: baz
|
// name: baz
|
||||||
// args: ['run.sh']
|
// args: ['run.sh']
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleRNode_ElementValues() {
|
func ExampleRNode_ElementValues() {
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ func (c FieldClearer) Filter(rn *RNode) (*RNode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(rn.Content()); i += 2 {
|
for i := 0; i < len(rn.Content()); i += 2 {
|
||||||
|
|
||||||
// if name matches, remove these 2 elements from the list because
|
// if name matches, remove these 2 elements from the list because
|
||||||
// they are treated as a fieldName/fieldValue pair.
|
// they are treated as a fieldName/fieldValue pair.
|
||||||
if rn.Content()[i].Value == c.Name {
|
if rn.Content()[i].Value == c.Name {
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ r: s
|
|||||||
`
|
`
|
||||||
|
|
||||||
func TestLookup_Fn_create(t *testing.T) {
|
func TestLookup_Fn_create(t *testing.T) {
|
||||||
|
|
||||||
// primitive
|
// primitive
|
||||||
node, err := Parse(s)
|
node, err := Parse(s)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -167,7 +166,6 @@ r: s
|
|||||||
`, assertNoErrorString(t)(node.String()))
|
`, assertNoErrorString(t)(node.String()))
|
||||||
assert.Equal(t, `h
|
assert.Equal(t, `h
|
||||||
`, assertNoErrorString(t)(rn.String()))
|
`, assertNoErrorString(t)(rn.String()))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookup_Fn_create2(t *testing.T) {
|
func TestLookup_Fn_create2(t *testing.T) {
|
||||||
@@ -442,7 +440,6 @@ foo: baz
|
|||||||
assert.Contains(t, err.Error(), "wrong Node Kind")
|
assert.Contains(t, err.Error(), "wrong Node Kind")
|
||||||
assert.Equal(t, `foo: baz
|
assert.Equal(t, `foo: baz
|
||||||
`, assertNoErrorString(t)(node.String()))
|
`, assertNoErrorString(t)(node.String()))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestErrorIfInvalid(t *testing.T) {
|
func TestErrorIfInvalid(t *testing.T) {
|
||||||
@@ -675,7 +672,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
assert.Equal(t, ResourceMeta{
|
assert.Equal(t, ResourceMeta{
|
||||||
Kind: "Deployment",
|
Kind: "Deployment",
|
||||||
ApiVersion: "v1/apps",
|
APIVersion: "v1/apps",
|
||||||
ObjectMeta: ObjectMeta{
|
ObjectMeta: ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Namespace: "bar",
|
Namespace: "bar",
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
|
|||||||
|
|
||||||
// doSeq iterates over a sequence and appends elements matching the path regex to p.Val
|
// doSeq iterates over a sequence and appends elements matching the path regex to p.Val
|
||||||
func (p *PathMatcher) doSeq(rn *RNode) (*RNode, error) {
|
func (p *PathMatcher) doSeq(rn *RNode) (*RNode, error) {
|
||||||
|
|
||||||
// parse the field + match pair
|
// parse the field + match pair
|
||||||
var err error
|
var err error
|
||||||
p.field, p.matchRegex, err = SplitIndexNameValue(p.Path[0])
|
p.field, p.matchRegex, err = SplitIndexNameValue(p.Path[0])
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ func (m Visitor) getStrValues(nodes walk.Sources) (strValues, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return strValues{}, err
|
return strValues{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if nodes.Dest() != nil && nodes.Dest().YNode() != nil {
|
if nodes.Dest() != nil && nodes.Dest().YNode() != nil {
|
||||||
s := nodes.Dest().YNode().Style
|
s := nodes.Dest().YNode().Style
|
||||||
|
|||||||
@@ -97,12 +97,11 @@ var WhitelistedListSortFields = map[string]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FieldOrder indexes fields and maps them to relative precedence
|
// FieldOrder indexes fields and maps them to relative precedence
|
||||||
var FieldOrder map[string]int
|
var FieldOrder = func() map[string]int {
|
||||||
|
|
||||||
func init() {
|
|
||||||
// create an index of field orderings
|
// create an index of field orderings
|
||||||
FieldOrder = map[string]int{}
|
fo := map[string]int{}
|
||||||
for i, f := range fieldSortOrder {
|
for i, f := range fieldSortOrder {
|
||||||
FieldOrder[f] = i + 1
|
fo[f] = i + 1
|
||||||
}
|
}
|
||||||
}
|
return fo
|
||||||
|
}()
|
||||||
|
|||||||
@@ -221,8 +221,8 @@ func (m MapNodeSlice) Values() []*RNode {
|
|||||||
|
|
||||||
// ResourceMeta contains the metadata for a both Resource Type and Resource.
|
// ResourceMeta contains the metadata for a both Resource Type and Resource.
|
||||||
type ResourceMeta struct {
|
type ResourceMeta struct {
|
||||||
// ApiVersion is the apiVersion field of a Resource
|
// APIVersion is the apiVersion field of a Resource
|
||||||
ApiVersion string `yaml:"apiVersion,omitempty"`
|
APIVersion string `yaml:"apiVersion,omitempty"`
|
||||||
// Kind is the kind field of a Resource
|
// Kind is the kind field of a Resource
|
||||||
Kind string `yaml:"kind,omitempty"`
|
Kind string `yaml:"kind,omitempty"`
|
||||||
// ObjectMeta is the metadata field of a Resource
|
// ObjectMeta is the metadata field of a Resource
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (l *Walker) walkAssociativeSequence() (*yaml.RNode, error) {
|
func (l *Walker) walkAssociativeSequence() (*yaml.RNode, error) {
|
||||||
|
|
||||||
// may require initializing the dest node
|
// may require initializing the dest node
|
||||||
dest, err := l.Sources.setDestNode(l.VisitList(l.Sources, AssociativeList))
|
dest, err := l.Sources.setDestNode(l.VisitList(l.Sources, AssociativeList))
|
||||||
if dest == nil || err != nil {
|
if dest == nil || err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user