api: add HasRevision method to Artifact
This commit is contained in:
parent
41e8f215ba
commit
270b6a5c0c
|
@ -49,6 +49,15 @@ type Artifact struct {
|
|||
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
|
||||
}
|
||||
|
||||
// HasRevision returns true if the given revision matches the current
|
||||
// Revision of the Artifact.
|
||||
func (in *Artifact) HasRevision(revision string) bool {
|
||||
if in == nil {
|
||||
return false
|
||||
}
|
||||
return in.Revision == revision
|
||||
}
|
||||
|
||||
// ArtifactDir returns the artifact dir path in the form of
|
||||
// <source-kind>/<source-namespace>/<source-name>.
|
||||
func ArtifactDir(kind, namespace, name string) string {
|
||||
|
|
|
@ -211,7 +211,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
|
|||
|
||||
// return early on unchanged revision
|
||||
artifact := r.Storage.NewArtifactFor(bucket.Kind, bucket.GetObjectMeta(), revision, fmt.Sprintf("%s.tar.gz", revision))
|
||||
if bucket.GetArtifact() != nil && bucket.GetArtifact().Revision == revision {
|
||||
if bucket.GetArtifact().HasRevision(artifact.Revision) {
|
||||
if artifact.URL != bucket.GetArtifact().URL {
|
||||
r.Storage.SetArtifactURL(bucket.GetArtifact())
|
||||
bucket.Status.URL = r.Storage.SetHostname(bucket.Status.URL)
|
||||
|
|
|
@ -198,7 +198,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
|
|||
|
||||
// return early on unchanged revision
|
||||
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().HasRevision(artifact.Revision) {
|
||||
if artifact.URL != repository.GetArtifact().URL {
|
||||
r.Storage.SetArtifactURL(repository.GetArtifact())
|
||||
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)
|
||||
|
|
|
@ -240,10 +240,10 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
|
|||
// Return early if the revision is still the same as the current artifact
|
||||
artifact := r.Storage.NewArtifactFor(chart.Kind, chart.GetObjectMeta(), cv.Version,
|
||||
fmt.Sprintf("%s-%s.tgz", cv.Name, cv.Version))
|
||||
if !force && repository.GetArtifact() != nil && repository.GetArtifact().Revision == cv.Version {
|
||||
if !force && repository.GetArtifact().HasRevision(artifact.Revision) {
|
||||
if artifact.URL != repository.GetArtifact().URL {
|
||||
r.Storage.SetArtifactURL(chart.GetArtifact())
|
||||
repository.Status.URL = r.Storage.SetHostname(chart.Status.URL)
|
||||
chart.Status.URL = r.Storage.SetHostname(chart.Status.URL)
|
||||
}
|
||||
return chart, nil
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
|
|||
// Return early if the revision is still the same as the current chart artifact
|
||||
chartArtifact := r.Storage.NewArtifactFor(chart.Kind, chart.ObjectMeta.GetObjectMeta(), chartMetadata.Version,
|
||||
fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version))
|
||||
if !force && chart.GetArtifact() != nil && chart.GetArtifact().Revision == chartMetadata.Version {
|
||||
if !force && chart.GetArtifact().HasRevision(chartArtifact.Revision) {
|
||||
if chartArtifact.URL != artifact.URL {
|
||||
r.Storage.SetArtifactURL(&chartArtifact)
|
||||
chart.Status.URL = r.Storage.SetHostname(chart.Status.URL)
|
||||
|
|
|
@ -219,7 +219,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
|
|||
// 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().HasRevision(artifact.Revision) {
|
||||
if artifact.URL != repository.GetArtifact().URL {
|
||||
r.Storage.SetArtifactURL(repository.GetArtifact())
|
||||
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)
|
||||
|
|
Loading…
Reference in New Issue