Skip to content

Commit 99b74da

Browse files
committed
api/artifact: add checksum field to artifact
This includes a change to how the revision for HelmRepository sources is recorded, as this will now equal to the generated timestamp from the index in RFC3339Nano format.
1 parent 0b75217 commit 99b74da

File tree

10 files changed

+65
-31
lines changed

10 files changed

+65
-31
lines changed

api/v1alpha1/artifact.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,41 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

26-
// Artifact represents the output of a source synchronisation
26+
// Artifact represents the output of a source synchronisation.
2727
type Artifact struct {
28-
// Path is the local file path of this artifact.
28+
// Path is the relative file path of this artifact.
2929
// +required
3030
Path string `json:"path"`
3131

3232
// URL is the HTTP address of this artifact.
3333
// +required
3434
URL string `json:"url"`
3535

36-
// Revision is a human readable identifier traceable in the origin source system.
37-
// It can be a commit sha, git tag, a helm index timestamp,
38-
// a helm chart version, a checksum, etc.
36+
// Revision is a human readable identifier traceable in the origin
37+
// source system. It can be a Git commit sha, Git tag, a Helm index
38+
// timestamp, a Helm chart version, etc.
3939
// +optional
4040
Revision string `json:"revision"`
4141

42+
// Checksum is the SHA1 checksum of the artifact.
43+
// +optional
44+
Checksum string `json:"checksum"`
45+
4246
// LastUpdateTime is the timestamp corresponding to the last
4347
// update of this artifact.
4448
// +required
4549
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
4650
}
4751

4852
// ArtifactDir returns the artifact dir path in the form of
49-
// <source-kind>/<source-namespace>/<source-name>
53+
// <source-kind>/<source-namespace>/<source-name>.
5054
func ArtifactDir(kind, namespace, name string) string {
5155
kind = strings.ToLower(kind)
5256
return path.Join(kind, namespace, name)
5357
}
5458

5559
// ArtifactPath returns the artifact path in the form of
56-
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
60+
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>.
5761
func ArtifactPath(kind, namespace, name, filename string) string {
5862
return path.Join(ArtifactDir(kind, namespace, name), filename)
5963
}

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,21 @@ spec:
129129
description: Artifact represents the output of the last successful
130130
repository sync.
131131
properties:
132+
checksum:
133+
description: Checksum is the SHA1 checksum of the artifact.
134+
type: string
132135
lastUpdateTime:
133136
description: LastUpdateTime is the timestamp corresponding to
134137
the last update of this artifact.
135138
format: date-time
136139
type: string
137140
path:
138-
description: Path is the local file path of this artifact.
141+
description: Path is the relative file path of this artifact.
139142
type: string
140143
revision:
141144
description: Revision is a human readable identifier traceable
142-
in the origin source system. It can be a commit sha, git tag,
143-
a helm index timestamp, a helm chart version, a checksum, etc.
145+
in the origin source system. It can be a Git commit sha, Git
146+
tag, a Helm index timestamp, a Helm chart version, etc.
144147
type: string
145148
url:
146149
description: URL is the HTTP address of this artifact.

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,21 @@ spec:
101101
description: Artifact represents the output of the last successful
102102
chart sync.
103103
properties:
104+
checksum:
105+
description: Checksum is the SHA1 checksum of the artifact.
106+
type: string
104107
lastUpdateTime:
105108
description: LastUpdateTime is the timestamp corresponding to
106109
the last update of this artifact.
107110
format: date-time
108111
type: string
109112
path:
110-
description: Path is the local file path of this artifact.
113+
description: Path is the relative file path of this artifact.
111114
type: string
112115
revision:
113116
description: Revision is a human readable identifier traceable
114-
in the origin source system. It can be a commit sha, git tag,
115-
a helm index timestamp, a helm chart version, a checksum, etc.
117+
in the origin source system. It can be a Git commit sha, Git
118+
tag, a Helm index timestamp, a Helm chart version, etc.
116119
type: string
117120
url:
118121
description: URL is the HTTP address of this artifact.

config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,21 @@ spec:
8181
description: Artifact represents the output of the last successful
8282
repository sync.
8383
properties:
84+
checksum:
85+
description: Checksum is the SHA1 checksum of the artifact.
86+
type: string
8487
lastUpdateTime:
8588
description: LastUpdateTime is the timestamp corresponding to
8689
the last update of this artifact.
8790
format: date-time
8891
type: string
8992
path:
90-
description: Path is the local file path of this artifact.
93+
description: Path is the relative file path of this artifact.
9194
type: string
9295
revision:
9396
description: Revision is a human readable identifier traceable
94-
in the origin source system. It can be a commit sha, git tag,
95-
a helm index timestamp, a helm chart version, a checksum, etc.
97+
in the origin source system. It can be a Git commit sha, Git
98+
tag, a Helm index timestamp, a Helm chart version, etc.
9699
type: string
97100
url:
98101
description: URL is the HTTP address of this artifact.

controllers/gitrepository_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
212212
}
213213
}
214214

215+
// TODO(hidde): implement checksum when https://github.com/fluxcd/source-controller/pull/133
216+
// has been merged.
215217
artifact := r.Storage.ArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(),
216-
fmt.Sprintf("%s.tar.gz", commit.Hash.String()), revision)
218+
fmt.Sprintf("%s.tar.gz", commit.Hash.String()), revision, "")
217219

218220
// create artifact dir
219221
err = r.Storage.MkdirAll(artifact)

controllers/helmchart_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
261261

262262
sum := r.Storage.Checksum(chartBytes)
263263
artifact := r.Storage.ArtifactFor(chart.Kind, chart.GetObjectMeta(),
264-
fmt.Sprintf("%s-%s-%s.tgz", cv.Name, cv.Version, sum), cv.Version)
264+
fmt.Sprintf("%s-%s-%s.tgz", cv.Name, cv.Version, sum), cv.Version, sum)
265265

266266
// create artifact dir
267267
err = r.Storage.MkdirAll(artifact)
@@ -365,8 +365,10 @@ func (r *HelmChartReconciler) reconcileFromGitRepository(ctx context.Context,
365365
return chart, nil
366366
}
367367

368+
// TODO(hidde): implement checksum when https://github.com/fluxcd/source-controller/pull/133
369+
// has been merged.
368370
artifact := r.Storage.ArtifactFor(chart.Kind, chart.ObjectMeta.GetObjectMeta(),
369-
fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version), chartMetadata.Version)
371+
fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version), chartMetadata.Version, "")
370372

371373
// create artifact dir
372374
err = r.Storage.MkdirAll(artifact)

controllers/helmrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
229229

230230
sum := r.Storage.Checksum(index)
231231
artifact := r.Storage.ArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(),
232-
fmt.Sprintf("index-%s.yaml", sum), sum)
232+
fmt.Sprintf("index-%s.yaml", sum), i.Generated.Format(time.RFC3339Nano), sum)
233233

234234
// create artifact dir
235235
err = r.Storage.MkdirAll(artifact)

controllers/storage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
7070
}
7171

7272
// ArtifactFor returns an artifact for the v1alpha1.Source.
73-
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
73+
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision, checksum string) sourcev1.Artifact {
7474
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
7575
localPath := filepath.Join(s.BasePath, path)
7676
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)
@@ -79,6 +79,7 @@ func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, rev
7979
Path: localPath,
8080
URL: url,
8181
Revision: revision,
82+
Checksum: checksum,
8283
LastUpdateTime: metav1.Now(),
8384
}
8485
}

docs/api/source.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ HelmRepositoryStatus
458458
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmChartStatus">HelmChartStatus</a>,
459459
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmRepositoryStatus">HelmRepositoryStatus</a>)
460460
</p>
461-
<p>Artifact represents the output of a source synchronisation</p>
461+
<p>Artifact represents the output of a source synchronisation.</p>
462462
<div class="md-typeset__scrollwrap">
463463
<div class="md-typeset__table">
464464
<table>
@@ -477,7 +477,7 @@ string
477477
</em>
478478
</td>
479479
<td>
480-
<p>Path is the local file path of this artifact.</p>
480+
<p>Path is the relative file path of this artifact.</p>
481481
</td>
482482
</tr>
483483
<tr>
@@ -500,9 +500,21 @@ string
500500
</td>
501501
<td>
502502
<em>(Optional)</em>
503-
<p>Revision is a human readable identifier traceable in the origin source system.
504-
It can be a commit sha, git tag, a helm index timestamp,
505-
a helm chart version, a checksum, etc.</p>
503+
<p>Revision is a human readable identifier traceable in the origin
504+
source system. It can be a Git commit sha, Git tag, a Helm index
505+
timestamp, a Helm chart version, etc.</p>
506+
</td>
507+
</tr>
508+
<tr>
509+
<td>
510+
<code>checksum</code><br>
511+
<em>
512+
string
513+
</em>
514+
</td>
515+
<td>
516+
<em>(Optional)</em>
517+
<p>Checksum is the SHA1 checksum of the artifact.</p>
506518
</td>
507519
</tr>
508520
<tr>

docs/spec/v1alpha1/common.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,26 @@ kubectl annotate --overwrite gitrepository/podinfo fluxcd.io/reconcileAt="$(date
5454
Source objects should contain a status sub-resource that embeds an artifact object:
5555

5656
```go
57-
// Artifact represents the output of a source synchronisation
57+
// Artifact represents the output of a source synchronisation.
5858
type Artifact struct {
59-
// Path is the local file path of this artifact.
59+
// Path is the relative file path of this artifact.
6060
// +required
6161
Path string `json:"path"`
6262

6363
// URL is the HTTP address of this artifact.
6464
// +required
6565
URL string `json:"url"`
6666

67-
// Revision is a human readable identifier traceable in the origin source system.
68-
// It can be a commit sha, git tag, a helm index timestamp,
69-
// a helm chart version, a checksum, etc.
67+
// Revision is a human readable identifier traceable in the origin
68+
// source system. It can be a Git commit sha, Git tag, a Helm index
69+
// timestamp, a Helm chart version, etc.
7070
// +optional
7171
Revision string `json:"revision"`
7272

73+
// Checksum is the SHA1 checksum of the artifact.
74+
// +optional
75+
Checksum string `json:"checksum"`
76+
7377
// LastUpdateTime is the timestamp corresponding to the last
7478
// update of this artifact.
7579
// +required

0 commit comments

Comments
 (0)