Skip to content

Commit 270b6a5

Browse files
committed
api: add HasRevision method to Artifact
1 parent 41e8f21 commit 270b6a5

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

api/v1alpha1/artifact.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ type Artifact struct {
4949
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
5050
}
5151

52+
// HasRevision returns true if the given revision matches the current
53+
// Revision of the Artifact.
54+
func (in *Artifact) HasRevision(revision string) bool {
55+
if in == nil {
56+
return false
57+
}
58+
return in.Revision == revision
59+
}
60+
5261
// ArtifactDir returns the artifact dir path in the form of
5362
// <source-kind>/<source-namespace>/<source-name>.
5463
func ArtifactDir(kind, namespace, name string) string {

controllers/bucket_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
211211

212212
// return early on unchanged revision
213213
artifact := r.Storage.NewArtifactFor(bucket.Kind, bucket.GetObjectMeta(), revision, fmt.Sprintf("%s.tar.gz", revision))
214-
if bucket.GetArtifact() != nil && bucket.GetArtifact().Revision == revision {
214+
if bucket.GetArtifact().HasRevision(artifact.Revision) {
215215
if artifact.URL != bucket.GetArtifact().URL {
216216
r.Storage.SetArtifactURL(bucket.GetArtifact())
217217
bucket.Status.URL = r.Storage.SetHostname(bucket.Status.URL)

controllers/gitrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
198198

199199
// return early on unchanged revision
200200
artifact := r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), revision, fmt.Sprintf("%s.tar.gz", commit.Hash.String()))
201-
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == revision {
201+
if repository.GetArtifact().HasRevision(artifact.Revision) {
202202
if artifact.URL != repository.GetArtifact().URL {
203203
r.Storage.SetArtifactURL(repository.GetArtifact())
204204
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)

controllers/helmchart_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
240240
// Return early if the revision is still the same as the current artifact
241241
artifact := r.Storage.NewArtifactFor(chart.Kind, chart.GetObjectMeta(), cv.Version,
242242
fmt.Sprintf("%s-%s.tgz", cv.Name, cv.Version))
243-
if !force && repository.GetArtifact() != nil && repository.GetArtifact().Revision == cv.Version {
243+
if !force && repository.GetArtifact().HasRevision(artifact.Revision) {
244244
if artifact.URL != repository.GetArtifact().URL {
245245
r.Storage.SetArtifactURL(chart.GetArtifact())
246-
repository.Status.URL = r.Storage.SetHostname(chart.Status.URL)
246+
chart.Status.URL = r.Storage.SetHostname(chart.Status.URL)
247247
}
248248
return chart, nil
249249
}
@@ -434,7 +434,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
434434
// Return early if the revision is still the same as the current chart artifact
435435
chartArtifact := r.Storage.NewArtifactFor(chart.Kind, chart.ObjectMeta.GetObjectMeta(), chartMetadata.Version,
436436
fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version))
437-
if !force && chart.GetArtifact() != nil && chart.GetArtifact().Revision == chartMetadata.Version {
437+
if !force && chart.GetArtifact().HasRevision(chartArtifact.Revision) {
438438
if chartArtifact.URL != artifact.URL {
439439
r.Storage.SetArtifactURL(&chartArtifact)
440440
chart.Status.URL = r.Storage.SetHostname(chart.Status.URL)

controllers/helmrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
219219
// return early on unchanged generation
220220
artifact := r.Storage.NewArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(), i.Generated.Format(time.RFC3339Nano),
221221
fmt.Sprintf("index-%s.yaml", url.PathEscape(i.Generated.Format(time.RFC3339Nano))))
222-
if repository.GetArtifact() != nil && repository.GetArtifact().Revision == i.Generated.Format(time.RFC3339Nano) {
222+
if repository.GetArtifact().HasRevision(artifact.Revision) {
223223
if artifact.URL != repository.GetArtifact().URL {
224224
r.Storage.SetArtifactURL(repository.GetArtifact())
225225
repository.Status.URL = r.Storage.SetHostname(repository.Status.URL)

0 commit comments

Comments
 (0)