From b7603f9fd320f14b3558645b4484aa0d8e9930b9 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 1 Sep 2020 16:01:19 +0200 Subject: [PATCH 1/2] storage: change logic of `ArtifactExist` method Given that: * The produced artifact as advertisted in the path should always be a regular file (including the exclusion of symlinks). * The produced artifact should be readable, so any type of error should count as "does not exist". We should use `os.Lstat` to not follow symlinks; return `false` on any error we run in to, or return if the file mode information reports a regular file. --- controllers/storage.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/storage.go b/controllers/storage.go index a0a51d29..56e4ea48 100644 --- a/controllers/storage.go +++ b/controllers/storage.go @@ -120,12 +120,14 @@ func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) error { return nil } -// ArtifactExist returns a boolean indicating whether the artifact file exists in storage +// ArtifactExist returns a boolean indicating whether the artifact exists in storage and is a +// regular file. func (s *Storage) ArtifactExist(artifact sourcev1.Artifact) bool { - if _, err := os.Stat(artifact.Path); os.IsNotExist(err) { + fi, err := os.Lstat(artifact.Path) + if err != nil { return false } - return true + return fi.Mode().IsRegular() } // Archive creates a tar.gz to the artifact path from the given dir excluding any VCS specific From 2c4dcfe72d1ff291d6a09f95d2f1b55170a823a9 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 1 Sep 2020 16:08:20 +0200 Subject: [PATCH 2/2] helmchart: use dir of artifact path on package run --- controllers/helmchart_controller.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 844cf63c..0eaca70b 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -23,6 +23,7 @@ import ( "net/url" "os" "path" + "path/filepath" "strings" "time" @@ -383,7 +384,7 @@ func (r *HelmChartReconciler) reconcileFromGitRepository(ctx context.Context, // package chart pkg := action.NewPackage() - pkg.Destination = artifact.Path + pkg.Destination = filepath.Dir(artifact.Path) _, err = pkg.Run(chartPath, nil) if err != nil { err = fmt.Errorf("chart package error: %w", err)