mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
kyaml: rename annotations and fix linting
This commit is contained in:
@@ -22,7 +22,7 @@ type TypeError = yaml.TypeError
|
||||
type Unmarshaler = yaml.Unmarshaler
|
||||
|
||||
var Marshal = yaml.Marshal
|
||||
var UnMarshal = yaml.Unmarshal
|
||||
var Unmarshal = yaml.Unmarshal
|
||||
var NewDecoder = yaml.NewDecoder
|
||||
var NewEncoder = func(w io.Writer) *yaml.Encoder {
|
||||
e := yaml.NewEncoder(w)
|
||||
|
||||
@@ -46,7 +46,8 @@ func (y *YFilter) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
if err := unmarshal(meta); err != nil {
|
||||
return err
|
||||
}
|
||||
if filter, found := Filters[meta.Kind]; !found {
|
||||
filter, found := Filters[meta.Kind]
|
||||
if !found {
|
||||
var knownFilters []string
|
||||
for k := range Filters {
|
||||
knownFilters = append(knownFilters, k)
|
||||
@@ -54,9 +55,9 @@ func (y *YFilter) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
sort.Strings(knownFilters)
|
||||
return fmt.Errorf("unsupported GrepFilter Kind %s: may be one of: [%s]",
|
||||
meta.Kind, strings.Join(knownFilters, ","))
|
||||
} else {
|
||||
y.Filter = filter()
|
||||
}
|
||||
y.Filter = filter()
|
||||
|
||||
if err := unmarshal(y.Filter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -82,10 +82,9 @@ func (p *PathMatcher) filter(rn *RNode) (*RNode, error) {
|
||||
if IsListIndex(p.Path[0]) {
|
||||
// match seq elements
|
||||
return p.doSeq(rn)
|
||||
} else {
|
||||
// match a field
|
||||
return p.doField(rn)
|
||||
}
|
||||
// match a field
|
||||
return p.doField(rn)
|
||||
}
|
||||
|
||||
func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
|
||||
|
||||
@@ -240,7 +240,7 @@ type ObjectMeta struct {
|
||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
var MissingMetaError = errors.New("missing Resource metadata")
|
||||
var ErrMissingMetadata = errors.New("missing Resource metadata")
|
||||
|
||||
// GetMeta returns the ResourceMeta for a RNode
|
||||
func (rn *RNode) GetMeta() (ResourceMeta, error) {
|
||||
@@ -259,7 +259,7 @@ func (rn *RNode) GetMeta() (ResourceMeta, error) {
|
||||
return m, err
|
||||
}
|
||||
if reflect.DeepEqual(m, ResourceMeta{}) {
|
||||
return m, MissingMetaError
|
||||
return m, ErrMissingMetadata
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -298,6 +298,13 @@ func (rn *RNode) Pipe(functions ...Filter) (*RNode, error) {
|
||||
return v, err
|
||||
}
|
||||
|
||||
// PipeE runs Pipe, dropping the *RNode return value.
|
||||
// Useful for directly returning the Pipe error value from functions.
|
||||
func (rn *RNode) PipeE(functions ...Filter) error {
|
||||
_, err := rn.Pipe(functions...)
|
||||
return err
|
||||
}
|
||||
|
||||
// Document returns the Node RNode for the value. Does not unwrap the node if it is a
|
||||
// DocumentNodes
|
||||
func (rn *RNode) Document() *yaml.Node {
|
||||
@@ -445,7 +452,7 @@ func (rn *RNode) Elements() ([]*RNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
var elements []*RNode
|
||||
for i := 0; i < len(rn.Content()); i += 1 {
|
||||
for i := 0; i < len(rn.Content()); i++ {
|
||||
elements = append(elements, NewRNode(rn.Content()[i]))
|
||||
}
|
||||
return elements, nil
|
||||
@@ -459,7 +466,7 @@ func (rn *RNode) ElementValues(key string) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
var elements []string
|
||||
for i := 0; i < len(rn.Content()); i += 1 {
|
||||
for i := 0; i < len(rn.Content()); i++ {
|
||||
field := NewRNode(rn.Content()[i]).Field(key)
|
||||
if !IsFieldEmpty(field) {
|
||||
elements = append(elements, field.Value.YNode().Value)
|
||||
@@ -497,8 +504,7 @@ func (rn *RNode) VisitElements(fn func(node *RNode) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AssociativeSequencePaths is a list of field names that may be used as associative keys
|
||||
// when merge Resources.
|
||||
// AssociativeSequenceKeys is a map of paths to sequences that have associative keys.
|
||||
// The order sets the precedence of the merge keys -- if multiple keys are present
|
||||
// in Resources in a list, then the FIRST key which ALL elements in the list have is used as the
|
||||
// associative key for merging that list.
|
||||
|
||||
@@ -24,10 +24,7 @@ func (l *Walker) walkAssociativeSequence() (*yaml.RNode, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values, err := l.elementValues(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values := l.elementValues(key)
|
||||
|
||||
// recursively set the elements in the list
|
||||
for _, value := range values {
|
||||
@@ -90,7 +87,7 @@ func (l Walker) elementKey() (string, error) {
|
||||
// from all sources.
|
||||
// Return value slice is ordered using the original ordering from the elements, where
|
||||
// elements missing from earlier sources appear later.
|
||||
func (l Walker) elementValues(key string) ([]string, error) {
|
||||
func (l Walker) elementValues(key string) []string {
|
||||
// use slice to to keep elements in the original order
|
||||
// dest node must be first
|
||||
var returnValues []string
|
||||
@@ -111,7 +108,7 @@ func (l Walker) elementValues(key string) ([]string, error) {
|
||||
seen.Insert(s)
|
||||
}
|
||||
}
|
||||
return returnValues, nil
|
||||
return returnValues
|
||||
}
|
||||
|
||||
// fieldValue returns a slice containing each source's value for fieldName
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// 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.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package walk
|
||||
|
||||
@@ -34,5 +23,5 @@ type Visitor interface {
|
||||
VisitList(nodes Sources, kind ListKind) (*yaml.RNode, error)
|
||||
}
|
||||
|
||||
// NoOp is returned if GrepFilter should do nothing after calling Set
|
||||
var ClearNode *yaml.RNode = nil
|
||||
// ClearNode is returned if GrepFilter should do nothing after calling Set
|
||||
var ClearNode *yaml.RNode
|
||||
|
||||
@@ -48,9 +48,9 @@ func (l Walker) Walk() (*yaml.RNode, error) {
|
||||
}
|
||||
if yaml.IsAssociative(l.Sources) {
|
||||
return l.walkAssociativeSequence()
|
||||
} else {
|
||||
return l.walkNonAssociativeSequence()
|
||||
}
|
||||
return l.walkNonAssociativeSequence()
|
||||
|
||||
case yaml.ScalarNode:
|
||||
if err := yaml.ErrorIfAnyInvalidAndNonNull(yaml.ScalarNode, l.Sources...); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user