diff --git a/util/webhook/webhook.go b/util/webhook/webhook.go index 2d4dcf39367e8..a4aefd4dc5796 100644 --- a/util/webhook/webhook.go +++ b/util/webhook/webhook.go @@ -337,8 +337,13 @@ func appFilesHaveChanged(app *v1alpha1.Application, changedFiles []string) bool f = ensureAbsPath(f) for _, item := range refreshPaths { item = ensureAbsPath(item) - - if _, err := security.EnforceToCurrentRoot(item, f); err == nil { + changed := false + if f == item { + changed = true + } else if _, err := security.EnforceToCurrentRoot(item, f); err == nil { + changed = true + } + if changed { log.WithField("application", app.Name).Debugf("Application uses files that have changed") return true } diff --git a/util/webhook/webhook_test.go b/util/webhook/webhook_test.go index 5ee3122b33e62..1f8c65fc50ceb 100644 --- a/util/webhook/webhook_test.go +++ b/util/webhook/webhook_test.go @@ -220,6 +220,12 @@ func Test_getAppRefreshPrefix(t *testing.T) { {"absolute path - not matching", getApp("/source/path1", "source/path"), []string{"source/path/my-deployment.yaml"}, false}, {"two relative paths - matching", getApp(".;../shared", "my-app"), []string{"shared/my-deployment.yaml"}, true}, {"two relative paths - not matching", getApp(".;../shared", "my-app"), []string{"README.md"}, false}, + {"file relative path - matching", getApp("./my-deployment.yaml", "source/path"), []string{"source/path/my-deployment.yaml"}, true}, + {"file relative path - not matching", getApp("./my-deployment.yaml", "source/path"), []string{"README.md"}, false}, + {"file absolute path - matching", getApp("/source/path/my-deployment.yaml", "source/path"), []string{"source/path/my-deployment.yaml"}, true}, + {"file absolute path - not matching", getApp("/source/path1/README.md", "source/path"), []string{"source/path/my-deployment.yaml"}, false}, + {"file two relative paths - matching", getApp("./README.md;../shared/my-deployment.yaml", "my-app"), []string{"shared/my-deployment.yaml"}, true}, + {"file two relative paths - not matching", getApp(".README.md;../shared/my-deployment.yaml", "my-app"), []string{"kustomization.yaml"}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {