From 5e4aca729b609cdfeef1521c507b186e004951e7 Mon Sep 17 00:00:00 2001 From: Manabu McCloskey Date: Tue, 11 Jun 2024 10:30:39 -0700 Subject: [PATCH] ensure only yaml files are processed (#288) Signed-off-by: Manabu McCloskey --- pkg/controllers/localbuild/controller.go | 2 +- pkg/util/git_repository.go | 2 +- pkg/util/util.go | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index 3d70d632..0a399308 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -454,7 +454,7 @@ func (r *LocalbuildReconciler) reconcileCustomPkgDir(ctx context.Context, resour for i := range files { file := files[i] - if !file.Type().IsRegular() { + if !file.Type().IsRegular() || !util.IsYamlFile(file.Name()) { continue } diff --git a/pkg/util/git_repository.go b/pkg/util/git_repository.go index a5949938..f5282ccf 100644 --- a/pkg/util/git_repository.go +++ b/pkg/util/git_repository.go @@ -85,7 +85,7 @@ func GetWorktreeYamlFiles(parent string, wt billy.Filesystem, recurse bool) ([]s } paths = append(paths, rPaths...) } - if ent.Mode().IsRegular() && (strings.HasSuffix(ent.Name(), "yaml") || strings.HasSuffix(ent.Name(), "yml")) { + if ent.Mode().IsRegular() && IsYamlFile(ent.Name()) { paths = append(paths, fmt.Sprintf("%s/%s", parent, ent.Name())) } } diff --git a/pkg/util/util.go b/pkg/util/util.go index 952fc709..beb04a1f 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -7,6 +7,7 @@ import ( "math" "math/big" mathrand "math/rand" + "path/filepath" "strings" "github.com/cnoe-io/idpbuilder/api/v1alpha1" @@ -123,3 +124,8 @@ func getRandElement(input string) (string, error) { return string(input[position.Int64()]), nil } + +func IsYamlFile(input string) bool { + extension := filepath.Ext(input) + return extension == ".yaml" || extension == ".yml" +}