mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Merge pull request #2738 from phanimarupaka/ListSettersRecursively
List and set setters in folders recursively
This commit is contained in:
35
kyaml/pathutil/pathutil.go
Normal file
35
kyaml/pathutil/pathutil.go
Normal 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
|
||||
}
|
||||
23
kyaml/printutil/printutil.go
Normal file
23
kyaml/printutil/printutil.go
Normal 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)
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user