Skip to content

Commit d7c58a0

Browse files
committed
Prevent cyclical Kustomize calls
While Kustomize already has cycle detection and we don't enable our Policy Generator plugin in the internal Kustomize instance so it won't work anyway, I figured this message would be clearer than a "PolicyGenerator plugin isn't available" message. Signed-off-by: Dale Haiducek <[email protected]>
1 parent 6019cf5 commit d7c58a0

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

cmd/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"io/ioutil"
77
"os"
8-
"path"
98

109
"github.com/spf13/pflag"
1110
"open-cluster-management.io/ocm-kustomize-generator-plugins/internal"
@@ -67,7 +66,7 @@ func processGeneratorConfig(filePath string) []byte {
6766
errorAndExit("failed to read file '%s': %s", filePath, err)
6867
}
6968

70-
err = p.Config(fileData, path.Dir(cwd))
69+
err = p.Config(fileData, cwd)
7170
if err != nil {
7271
errorAndExit("error processing the PolicyGenerator file '%s': %s", filePath, err)
7372
}

internal/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ func verifyManifestPath(baseDirectory string, manifestPath string) error {
438438
)
439439
}
440440

441+
if relPath == "." {
442+
return fmt.Errorf(
443+
"the manifest path %s may not refer to the same directory as the kustomization.yaml file",
444+
manifestPath,
445+
)
446+
}
447+
441448
parDir := ".." + string(filepath.Separator)
442449
if strings.HasPrefix(relPath, parDir) || relPath == ".." {
443450
return fmt.Errorf(

internal/utils_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,20 @@ func TestVerifyManifestPath(t *testing.T) {
12641264
baseDirectory,
12651265
),
12661266
},
1267+
{
1268+
workingDir,
1269+
fmt.Sprintf(
1270+
"the manifest path %s may not refer to the same directory as the kustomization.yaml file",
1271+
workingDir,
1272+
),
1273+
},
1274+
{
1275+
".",
1276+
fmt.Sprintf(
1277+
"the manifest path %s may not refer to the same directory as the kustomization.yaml file",
1278+
".",
1279+
),
1280+
},
12671281
{
12681282
otherManifestPath,
12691283
fmt.Sprintf(

0 commit comments

Comments
 (0)