Merge pull request #2738 from phanimarupaka/ListSettersRecursively

List and set setters in folders recursively
This commit is contained in:
Jeff Regan
2020-07-22 13:14:13 -07:00
committed by GitHub
9 changed files with 153 additions and 60 deletions

View File

@@ -0,0 +1,35 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package pathutil
import (
"os"
"path/filepath"
"strings"
"sigs.k8s.io/kustomize/kyaml/errors"
)
// SubDirsWithFile takes the root directory path and returns all the paths of
// sub-directories which contain file with input fileName including itself
func SubDirsWithFile(root, fileName string) ([]string, error) {
var res []string
err := filepath.Walk(root,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if strings.HasSuffix(path, fileName) {
if root == "." {
path = root + "/" + path
}
res = append(res, path)
}
return nil
})
if err != nil {
return res, errors.Wrap(err)
}
return res, nil
}

View File

@@ -0,0 +1,23 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package printutil
import (
"fmt"
"io"
)
// GreenPrintf formats according to a format specifier and prints the resulting string
// in green color to the writer
func GreenPrintf(w io.Writer, format string, args ...string) {
msg := fmt.Sprintf(format, args)
fmt.Fprintf(w, "\033[1;32m%s\033[0m", msg)
}
// WarnPrintf formats according to a format specifier and prints the resulting string
// in yellow color to the writer
func WarnPrintf(w io.Writer, format string, args ...string) {
msg := fmt.Sprintf(format, args)
fmt.Fprintf(w, "\033[1;33m%s\033[0m", msg)
}

View File

@@ -34,6 +34,8 @@ type Set struct {
SetAll bool
}
const SetterNotFoundWarn = "unable to find setter with name "
// Filter implements Set as a yaml.Filter
func (s *Set) Filter(object *yaml.RNode) (*yaml.RNode, error) {
return object, accept(s, object)
@@ -328,14 +330,14 @@ func (s SetOpenAPI) Filter(object *yaml.RNode) (*yaml.RNode, error) {
return nil, err
}
if oa == nil {
return nil, errors.Errorf("no setter %s found", s.Name)
return nil, errors.Errorf(SetterNotFoundWarn + s.Name)
}
def, err := oa.Pipe(yaml.Lookup("x-k8s-cli", "setter"))
if err != nil {
return nil, err
}
if def == nil {
return nil, errors.Errorf("no setter %s found", s.Name)
return nil, errors.Errorf(SetterNotFoundWarn + s.Name)
}
// record the OpenAPI type for the setter

View File

@@ -1209,7 +1209,7 @@ openAPI:
{
name: "error",
setter: "replicas",
err: "no setter replicas found",
err: "unable to find setter with name replicas",
input: `
openAPI:
definitions: