Change advertised artifact URLs on hostname change
This commit is contained in:
parent
7a3a5938d3
commit
d03f4fa4c4
|
@ -199,6 +199,10 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
|
||||||
// return early on unchanged revision
|
// return early on unchanged revision
|
||||||
artifact := r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), revision, fmt.Sprintf("%s.tar.gz", commit.Hash.String()))
|
artifact := r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), revision, fmt.Sprintf("%s.tar.gz", commit.Hash.String()))
|
||||||
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == revision {
|
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == revision {
|
||||||
|
if artifact.URL != repository.GetArtifact().URL {
|
||||||
|
r.Storage.SetArtifactURL(repository.GetArtifact())
|
||||||
|
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)
|
||||||
|
}
|
||||||
return repository, nil
|
return repository, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,12 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
// return early on unchanged chart version
|
// return early on unchanged chart version
|
||||||
|
artifact := r.Storage.NewArtifactFor(chart.Kind, chart.GetObjectMeta(), cv.Version, fmt.Sprintf("%s-%s.tgz", cv.Name, cv.Version))
|
||||||
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == cv.Version {
|
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == cv.Version {
|
||||||
|
if artifact.URL != repository.GetArtifact().URL {
|
||||||
|
r.Storage.SetArtifactURL(repository.GetArtifact())
|
||||||
|
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)
|
||||||
|
}
|
||||||
return chart, nil
|
return chart, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,8 +265,6 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
|
||||||
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
|
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
|
||||||
}
|
}
|
||||||
|
|
||||||
artifact := r.Storage.NewArtifactFor(chart.Kind, chart.GetObjectMeta(), cv.Version, fmt.Sprintf("%s-%s.tgz", cv.Name, cv.Version))
|
|
||||||
|
|
||||||
// create artifact dir
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -359,12 +362,15 @@ func (r *HelmChartReconciler) reconcileFromGitRepository(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
// return early on unchanged chart version
|
// return early on unchanged chart version
|
||||||
|
artifact := r.Storage.NewArtifactFor(chart.Kind, chart.ObjectMeta.GetObjectMeta(), chartMetadata.Version, fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version))
|
||||||
if chart.GetArtifact() != nil && chart.GetArtifact().Revision == chartMetadata.Version {
|
if chart.GetArtifact() != nil && chart.GetArtifact().Revision == chartMetadata.Version {
|
||||||
|
if artifact.URL != repository.GetArtifact().URL {
|
||||||
|
r.Storage.SetArtifactURL(repository.GetArtifact())
|
||||||
|
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)
|
||||||
|
}
|
||||||
return chart, nil
|
return chart, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
artifact := r.Storage.NewArtifactFor(chart.Kind, chart.ObjectMeta.GetObjectMeta(), chartMetadata.Version, fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version))
|
|
||||||
|
|
||||||
// create artifact dir
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -217,7 +217,13 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
|
||||||
}
|
}
|
||||||
|
|
||||||
// return early on unchanged generation
|
// return early on unchanged generation
|
||||||
|
artifact := r.Storage.NewArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(), i.Generated.Format(time.RFC3339Nano),
|
||||||
|
fmt.Sprintf("index-%s.yaml", url.PathEscape(i.Generated.Format(time.RFC3339Nano))))
|
||||||
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == i.Generated.Format(time.RFC3339Nano) {
|
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == i.Generated.Format(time.RFC3339Nano) {
|
||||||
|
if artifact.URL != repository.GetArtifact().URL {
|
||||||
|
r.Storage.SetArtifactURL(repository.GetArtifact())
|
||||||
|
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)
|
||||||
|
}
|
||||||
return repository, nil
|
return repository, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,9 +233,6 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
|
||||||
return sourcev1.HelmRepositoryNotReady(repository, sourcev1.IndexationFailedReason, err.Error()), err
|
return sourcev1.HelmRepositoryNotReady(repository, sourcev1.IndexationFailedReason, err.Error()), err
|
||||||
}
|
}
|
||||||
|
|
||||||
artifact := r.Storage.NewArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(), i.Generated.Format(time.RFC3339Nano),
|
|
||||||
fmt.Sprintf("index-%s.yaml", url.PathEscape(i.Generated.Format(time.RFC3339Nano))))
|
|
||||||
|
|
||||||
// create artifact dir
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -89,6 +90,17 @@ func (s Storage) SetArtifactURL(artifact *sourcev1.Artifact) {
|
||||||
artifact.URL = fmt.Sprintf("http://%s/%s", s.Hostname, artifact.Path)
|
artifact.URL = fmt.Sprintf("http://%s/%s", s.Hostname, artifact.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetHostname sets the hostname of the given URL string to the current Storage.Hostname
|
||||||
|
// and returns the result.
|
||||||
|
func (s Storage) SetHostname(URL string) string {
|
||||||
|
u, err := url.Parse(URL)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
u.Host = s.Hostname
|
||||||
|
return u.String()
|
||||||
|
}
|
||||||
|
|
||||||
// MkdirAll calls os.MkdirAll for the given v1alpha1.Artifact base dir.
|
// MkdirAll calls os.MkdirAll for the given v1alpha1.Artifact base dir.
|
||||||
func (s *Storage) MkdirAll(artifact sourcev1.Artifact) error {
|
func (s *Storage) MkdirAll(artifact sourcev1.Artifact) error {
|
||||||
dir := filepath.Dir(s.LocalPath(artifact))
|
dir := filepath.Dir(s.LocalPath(artifact))
|
||||||
|
|
Loading…
Reference in New Issue