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.
This commit is contained in:
Hidde Beydals 2020-09-09 13:16:09 +02:00
parent 0b752178b1
commit 99b74da044
10 changed files with 65 additions and 31 deletions

View File

@ -23,9 +23,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Artifact represents the output of a source synchronisation
// Artifact represents the output of a source synchronisation.
type Artifact struct {
// Path is the local file path of this artifact.
// Path is the relative file path of this artifact.
// +required
Path string `json:"path"`
@ -33,12 +33,16 @@ type Artifact struct {
// +required
URL string `json:"url"`
// Revision is a human readable identifier traceable in the origin source system.
// It can be a commit sha, git tag, a helm index timestamp,
// a helm chart version, a checksum, etc.
// Revision is a human readable identifier traceable in the origin
// source system. It can be a Git commit sha, Git tag, a Helm index
// timestamp, a Helm chart version, etc.
// +optional
Revision string `json:"revision"`
// Checksum is the SHA1 checksum of the artifact.
// +optional
Checksum string `json:"checksum"`
// LastUpdateTime is the timestamp corresponding to the last
// update of this artifact.
// +required
@ -46,14 +50,14 @@ type Artifact struct {
}
// ArtifactDir returns the artifact dir path in the form of
// <source-kind>/<source-namespace>/<source-name>
// <source-kind>/<source-namespace>/<source-name>.
func ArtifactDir(kind, namespace, name string) string {
kind = strings.ToLower(kind)
return path.Join(kind, namespace, name)
}
// ArtifactPath returns the artifact path in the form of
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>.
func ArtifactPath(kind, namespace, name, filename string) string {
return path.Join(ArtifactDir(kind, namespace, name), filename)
}

View File

@ -129,18 +129,21 @@ spec:
description: Artifact represents the output of the last successful
repository sync.
properties:
checksum:
description: Checksum is the SHA1 checksum of the artifact.
type: string
lastUpdateTime:
description: LastUpdateTime is the timestamp corresponding to
the last update of this artifact.
format: date-time
type: string
path:
description: Path is the local file path of this artifact.
description: Path is the relative file path of this artifact.
type: string
revision:
description: Revision is a human readable identifier traceable
in the origin source system. It can be a commit sha, git tag,
a helm index timestamp, a helm chart version, a checksum, etc.
in the origin source system. It can be a Git commit sha, Git
tag, a Helm index timestamp, a Helm chart version, etc.
type: string
url:
description: URL is the HTTP address of this artifact.

View File

@ -101,18 +101,21 @@ spec:
description: Artifact represents the output of the last successful
chart sync.
properties:
checksum:
description: Checksum is the SHA1 checksum of the artifact.
type: string
lastUpdateTime:
description: LastUpdateTime is the timestamp corresponding to
the last update of this artifact.
format: date-time
type: string
path:
description: Path is the local file path of this artifact.
description: Path is the relative file path of this artifact.
type: string
revision:
description: Revision is a human readable identifier traceable
in the origin source system. It can be a commit sha, git tag,
a helm index timestamp, a helm chart version, a checksum, etc.
in the origin source system. It can be a Git commit sha, Git
tag, a Helm index timestamp, a Helm chart version, etc.
type: string
url:
description: URL is the HTTP address of this artifact.

View File

@ -81,18 +81,21 @@ spec:
description: Artifact represents the output of the last successful
repository sync.
properties:
checksum:
description: Checksum is the SHA1 checksum of the artifact.
type: string
lastUpdateTime:
description: LastUpdateTime is the timestamp corresponding to
the last update of this artifact.
format: date-time
type: string
path:
description: Path is the local file path of this artifact.
description: Path is the relative file path of this artifact.
type: string
revision:
description: Revision is a human readable identifier traceable
in the origin source system. It can be a commit sha, git tag,
a helm index timestamp, a helm chart version, a checksum, etc.
in the origin source system. It can be a Git commit sha, Git
tag, a Helm index timestamp, a Helm chart version, etc.
type: string
url:
description: URL is the HTTP address of this artifact.

View File

@ -212,8 +212,10 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
}
}
// TODO(hidde): implement checksum when https://github.com/fluxcd/source-controller/pull/133
// has been merged.
artifact := r.Storage.ArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(),
fmt.Sprintf("%s.tar.gz", commit.Hash.String()), revision)
fmt.Sprintf("%s.tar.gz", commit.Hash.String()), revision, "")
// create artifact dir
err = r.Storage.MkdirAll(artifact)

View File

@ -261,7 +261,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
sum := r.Storage.Checksum(chartBytes)
artifact := r.Storage.ArtifactFor(chart.Kind, chart.GetObjectMeta(),
fmt.Sprintf("%s-%s-%s.tgz", cv.Name, cv.Version, sum), cv.Version)
fmt.Sprintf("%s-%s-%s.tgz", cv.Name, cv.Version, sum), cv.Version, sum)
// create artifact dir
err = r.Storage.MkdirAll(artifact)
@ -365,8 +365,10 @@ func (r *HelmChartReconciler) reconcileFromGitRepository(ctx context.Context,
return chart, nil
}
// TODO(hidde): implement checksum when https://github.com/fluxcd/source-controller/pull/133
// has been merged.
artifact := r.Storage.ArtifactFor(chart.Kind, chart.ObjectMeta.GetObjectMeta(),
fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version), chartMetadata.Version)
fmt.Sprintf("%s-%s.tgz", chartMetadata.Name, chartMetadata.Version), chartMetadata.Version, "")
// create artifact dir
err = r.Storage.MkdirAll(artifact)

View File

@ -229,7 +229,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
sum := r.Storage.Checksum(index)
artifact := r.Storage.ArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(),
fmt.Sprintf("index-%s.yaml", sum), sum)
fmt.Sprintf("index-%s.yaml", sum), i.Generated.Format(time.RFC3339Nano), sum)
// create artifact dir
err = r.Storage.MkdirAll(artifact)

View File

@ -70,7 +70,7 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
}
// ArtifactFor returns an artifact for the v1alpha1.Source.
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision, checksum string) sourcev1.Artifact {
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
localPath := filepath.Join(s.BasePath, path)
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)
@ -79,6 +79,7 @@ func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, rev
Path: localPath,
URL: url,
Revision: revision,
Checksum: checksum,
LastUpdateTime: metav1.Now(),
}
}

View File

@ -458,7 +458,7 @@ HelmRepositoryStatus
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmChartStatus">HelmChartStatus</a>,
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmRepositoryStatus">HelmRepositoryStatus</a>)
</p>
<p>Artifact represents the output of a source synchronisation</p>
<p>Artifact represents the output of a source synchronisation.</p>
<div class="md-typeset__scrollwrap">
<div class="md-typeset__table">
<table>
@ -477,7 +477,7 @@ string
</em>
</td>
<td>
<p>Path is the local file path of this artifact.</p>
<p>Path is the relative file path of this artifact.</p>
</td>
</tr>
<tr>
@ -500,9 +500,21 @@ string
</td>
<td>
<em>(Optional)</em>
<p>Revision is a human readable identifier traceable in the origin source system.
It can be a commit sha, git tag, a helm index timestamp,
a helm chart version, a checksum, etc.</p>
<p>Revision is a human readable identifier traceable in the origin
source system. It can be a Git commit sha, Git tag, a Helm index
timestamp, a Helm chart version, etc.</p>
</td>
</tr>
<tr>
<td>
<code>checksum</code><br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Checksum is the SHA1 checksum of the artifact.</p>
</td>
</tr>
<tr>

View File

@ -54,9 +54,9 @@ kubectl annotate --overwrite gitrepository/podinfo fluxcd.io/reconcileAt="$(date
Source objects should contain a status sub-resource that embeds an artifact object:
```go
// Artifact represents the output of a source synchronisation
// Artifact represents the output of a source synchronisation.
type Artifact struct {
// Path is the local file path of this artifact.
// Path is the relative file path of this artifact.
// +required
Path string `json:"path"`
@ -64,12 +64,16 @@ type Artifact struct {
// +required
URL string `json:"url"`
// Revision is a human readable identifier traceable in the origin source system.
// It can be a commit sha, git tag, a helm index timestamp,
// a helm chart version, a checksum, etc.
// Revision is a human readable identifier traceable in the origin
// source system. It can be a Git commit sha, Git tag, a Helm index
// timestamp, a Helm chart version, etc.
// +optional
Revision string `json:"revision"`
// Checksum is the SHA1 checksum of the artifact.
// +optional
Checksum string `json:"checksum"`
// LastUpdateTime is the timestamp corresponding to the last
// update of this artifact.
// +required