1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Add the possibility to ignore files with build and diff ks

If implemented, user will be able to ignore files when using `build
kustomization` and `diff kustomization` both with .sourceignore and
`ignore-paths` flag.

Signed-off-by: Soule BA <bah.soule@gmail.com>
This commit is contained in:
Soule BA
2023-04-04 18:04:55 +02:00
parent f00fee5328
commit b74638c25c
11 changed files with 107 additions and 9 deletions

View File

@@ -25,6 +25,7 @@ import (
"fmt"
"io"
"os"
"strings"
"sync"
"time"
@@ -71,6 +72,7 @@ type Builder struct {
namespace string
resourcesPath string
kustomizationFile string
ignore []string
// mu is used to synchronize access to the kustomization file
mu sync.Mutex
action kustomize.Action
@@ -156,6 +158,14 @@ func WithDryRun(dryRun bool) BuilderOptionFunc {
}
}
// WithIgnore sets ignore field
func WithIgnore(ignore []string) BuilderOptionFunc {
return func(b *Builder) error {
b.ignore = ignore
return nil
}
}
// NewBuilder returns a new Builder
// It takes a kustomization name and a path to the resources
// It also takes a list of BuilderOptionFunc to configure the builder
@@ -326,9 +336,13 @@ func (b *Builder) generate(kustomization kustomizev1.Kustomization, dirPath stri
if err != nil {
return "", err
}
gen := kustomize.NewGeneratorWithIgnore("", "", unstructured.Unstructured{Object: data})
// acuire the lock
// a scanner will be used down the line to parse the list
// so we have to make sure to unclude newlines
ignoreList := strings.Join(b.ignore, "\n")
gen := kustomize.NewGeneratorWithIgnore("", ignoreList, unstructured.Unstructured{Object: data})
// acquire the lock
b.mu.Lock()
defer b.mu.Unlock()