Merge pull request #18 from fluxcd/artifact-path

Change artifact path format
This commit is contained in:
Stefan Prodan 2020-04-13 20:23:24 +03:00 committed by GitHub
commit 0e4e3cd660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 13 deletions

View File

@ -16,7 +16,11 @@ limitations under the License.
package v1alpha1
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Artifact represents the output of a source synchronisation
type Artifact struct {
@ -39,3 +43,9 @@ type Artifact struct {
// +required
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
}
// ArtifactPath returns the artifact path in the form of
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
func ArtifactPath(kind, namespace, name, filename string) string {
return fmt.Sprintf("%s/%s/%s/%s", kind, namespace, name, filename)
}

View File

@ -24,7 +24,6 @@ import (
"time"
"github.com/go-logr/logr"
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/repo"
corev1 "k8s.io/api/core/v1"
@ -149,7 +148,7 @@ func (r *HelmChartReconciler) sync(repository sourcev1.HelmRepository, chart sou
ref := cv.URLs[0]
u, err := url.Parse(ref)
if err != nil {
err = errors.Errorf("invalid chart URL format '%s': %w", ref, err)
err = fmt.Errorf("invalid chart URL format '%s': %w", ref, err)
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
}

View File

@ -61,7 +61,7 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
// ArtifactFor returns an artifact for the given Kubernetes object
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
kind = strings.ToLower(kind)
path := fmt.Sprintf("%s/%s-%s/%s", kind, metadata.GetNamespace(), metadata.GetName(), fileName)
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
localPath := filepath.Join(s.BasePath, path)
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)