From 44ddbc6ae50bc709f3081800301be50ab880e08a Mon Sep 17 00:00:00 2001 From: Mehdi Moussaif Date: Fri, 24 Nov 2023 23:42:17 +0100 Subject: [PATCH] Bug fix IsKustomizeDirectory returning parent dir Signed-off-by: Mehdi Moussaif --- core/cautils/kustomizedirectory.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/cautils/kustomizedirectory.go b/core/cautils/kustomizedirectory.go index cbbff13c..b9cdea7d 100644 --- a/core/cautils/kustomizedirectory.go +++ b/core/cautils/kustomizedirectory.go @@ -25,9 +25,7 @@ func IsKustomizeDirectory(path string) bool { return false } - if lastChar := path[len(path)-1:]; lastChar != "/" { - path += "/" - } + path = cleanPathDir(path) matches := 0 for _, kustomizationFileMatcher := range kustomizationFileMatchers { @@ -71,9 +69,20 @@ func GetKustomizeDirectoryName(path string) string { if isKustomizeDirectory := IsKustomizeDirectory(path); !isKustomizeDirectory { return "" } + + path = cleanPathDir(path) + return filepath.Dir(path) } +func cleanPathDir(path string) string { + if lastChar := path[len(path)-1:]; lastChar != "/" { + path += "/" + } + + return path +} + // Get Workloads, creates the yaml files(K8s resources) using Kustomize and // renders the workloads from the yaml files (k8s resources) func (kd *KustomizeDirectory) GetWorkloads(kustomizeDirectoryPath string) (map[string][]workloadinterface.IMetadata, []error) {