From cec5799d97a796ca8db7997302b3bbe723980978 Mon Sep 17 00:00:00 2001 From: Jim Wright Date: Fri, 8 Jul 2022 13:53:45 +0100 Subject: [PATCH] Support files in argocd.argoproj.io/manifest-generate-paths annotation (#9908) Signed-off-by: Jim Wright --- util/webhook/webhook.go | 9 +++++++-- util/webhook/webhook_test.go | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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) {