diff --git a/util/webhook/webhook.go b/util/webhook/webhook.go index e6d8c6fa1880b..205c5cfa2d047 100644 --- a/util/webhook/webhook.go +++ b/util/webhook/webhook.go @@ -331,8 +331,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 f5161d7e9f561..962b321b478fb 100644 --- a/util/webhook/webhook_test.go +++ b/util/webhook/webhook_test.go @@ -219,6 +219,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) {