mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Setters with subpackages
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/kyaml/ext"
|
||||
)
|
||||
|
||||
// ignoreFilesMatcher handles `.krmignore` files, which allows for ignoring
|
||||
// IgnoreFilesMatcher handles `.krmignore` files, which allows for ignoring
|
||||
// files or folders in a package. The format of this file is a subset of the
|
||||
// gitignore format, with recursive patterns (like a/**/c) not supported. If a
|
||||
// file or folder matches any of the patterns in the .krmignore file for the
|
||||
@@ -30,14 +30,14 @@ import (
|
||||
// package contains a pattern that ignores the directory foo, if foo is a
|
||||
// subpackage, it will still be included if the IncludeSubpackages property
|
||||
// is set to true
|
||||
type ignoreFilesMatcher struct {
|
||||
type IgnoreFilesMatcher struct {
|
||||
matchers []matcher
|
||||
}
|
||||
|
||||
// readIgnoreFile checks whether there is a .krmignore file in the path, and
|
||||
// if it is, reads it in and turns it into a matcher. If we can't find a file,
|
||||
// we just add a matcher that match nothing.
|
||||
func (i *ignoreFilesMatcher) readIgnoreFile(path string) error {
|
||||
func (i *IgnoreFilesMatcher) readIgnoreFile(path string) error {
|
||||
m, err := gitignore.NewGitIgnore(filepath.Join(path, ext.GetIgnoreFileName()))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -60,7 +60,7 @@ func (i *ignoreFilesMatcher) readIgnoreFile(path string) error {
|
||||
// is correct for the provided filepath. Matchers are removed once
|
||||
// we encounter a filepath that is not a subpath of the basepath for
|
||||
// the matcher.
|
||||
func (i *ignoreFilesMatcher) verifyPath(path string) {
|
||||
func (i *IgnoreFilesMatcher) verifyPath(path string) {
|
||||
for j := len(i.matchers) - 1; j >= 0; j-- {
|
||||
matcher := i.matchers[j]
|
||||
if !strings.HasPrefix(path, matcher.basePath) {
|
||||
@@ -72,7 +72,7 @@ func (i *ignoreFilesMatcher) verifyPath(path string) {
|
||||
|
||||
// matchFile checks whether the file given by the provided path matches
|
||||
// any of the patterns in the .krmignore file for the package.
|
||||
func (i *ignoreFilesMatcher) matchFile(path string) bool {
|
||||
func (i *IgnoreFilesMatcher) matchFile(path string) bool {
|
||||
if len(i.matchers) == 0 {
|
||||
return false
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func (i *ignoreFilesMatcher) matchFile(path string) bool {
|
||||
|
||||
// matchFile checks whether the directory given by the provided path matches
|
||||
// any of the patterns in the .krmignore file for the package.
|
||||
func (i *ignoreFilesMatcher) matchDir(path string) bool {
|
||||
func (i *IgnoreFilesMatcher) matchDir(path string) bool {
|
||||
if len(i.matchers) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ testfile.yaml
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
|
||||
ignoreFilesMatcher := ignoreFilesMatcher{}
|
||||
ignoreFilesMatcher := IgnoreFilesMatcher{}
|
||||
err = ignoreFilesMatcher.readIgnoreFile(dir)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
|
||||
@@ -80,6 +80,7 @@ func (r *LocalPackageReadWriter) Read() ([]*yaml.RNode, error) {
|
||||
IncludeSubpackages: r.IncludeSubpackages,
|
||||
ErrorIfNonResources: r.ErrorIfNonResources,
|
||||
SetAnnotations: r.SetAnnotations,
|
||||
PackageFileName: r.PackageFileName,
|
||||
}.Read()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
@@ -185,7 +186,7 @@ func (r LocalPackageReader) Read() ([]*yaml.RNode, error) {
|
||||
var operand ResourceNodeSlice
|
||||
var pathRelativeTo string
|
||||
var err error
|
||||
ignoreFilesMatcher := &ignoreFilesMatcher{}
|
||||
ignoreFilesMatcher := &IgnoreFilesMatcher{}
|
||||
r.PackagePath, err = filepath.Abs(r.PackagePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
@@ -257,7 +258,7 @@ func (r *LocalPackageReader) readFile(path string, _ os.FileInfo) ([]*yaml.RNode
|
||||
}
|
||||
|
||||
// ShouldSkipFile returns true if the file should be skipped
|
||||
func (r *LocalPackageReader) ShouldSkipFile(path string, matcher *ignoreFilesMatcher) (bool, error) {
|
||||
func (r *LocalPackageReader) ShouldSkipFile(path string, matcher *IgnoreFilesMatcher) (bool, error) {
|
||||
// check if the file is covered by a .krmignore file.
|
||||
if matcher.matchFile(path) {
|
||||
return false, nil
|
||||
@@ -285,7 +286,7 @@ func (r *LocalPackageReader) initReaderAnnotations(path string, _ os.FileInfo) {
|
||||
}
|
||||
|
||||
// ShouldSkipDir returns a filepath.SkipDir if the directory should be skipped
|
||||
func (r *LocalPackageReader) ShouldSkipDir(path string, matcher *ignoreFilesMatcher) error {
|
||||
func (r *LocalPackageReader) ShouldSkipDir(path string, matcher *IgnoreFilesMatcher) error {
|
||||
if r.PackageFileName == "" {
|
||||
// If the folder is not a package, but covered by the .krmignore file,
|
||||
// we skip it.
|
||||
|
||||
Reference in New Issue
Block a user