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:
parent
0b752178b1
commit
99b74da044
|
@ -23,9 +23,9 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
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 {
|
type Artifact struct {
|
||||||
// Path is the local file path of this artifact.
|
// Path is the relative file path of this artifact.
|
||||||
// +required
|
// +required
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
|
|
||||||
|
@ -33,12 +33,16 @@ type Artifact struct {
|
||||||
// +required
|
// +required
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
|
||||||
// Revision is a human readable identifier traceable in the origin source system.
|
// Revision is a human readable identifier traceable in the origin
|
||||||
// It can be a commit sha, git tag, a helm index timestamp,
|
// source system. It can be a Git commit sha, Git tag, a Helm index
|
||||||
// a helm chart version, a checksum, etc.
|
// timestamp, a Helm chart version, etc.
|
||||||
// +optional
|
// +optional
|
||||||
Revision string `json:"revision"`
|
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
|
// LastUpdateTime is the timestamp corresponding to the last
|
||||||
// update of this artifact.
|
// update of this artifact.
|
||||||
// +required
|
// +required
|
||||||
|
@ -46,14 +50,14 @@ type Artifact struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArtifactDir returns the artifact dir path in the form of
|
// 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 {
|
func ArtifactDir(kind, namespace, name string) string {
|
||||||
kind = strings.ToLower(kind)
|
kind = strings.ToLower(kind)
|
||||||
return path.Join(kind, namespace, name)
|
return path.Join(kind, namespace, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArtifactPath returns the artifact path in the form of
|
// 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 {
|
func ArtifactPath(kind, namespace, name, filename string) string {
|
||||||
return path.Join(ArtifactDir(kind, namespace, name), filename)
|
return path.Join(ArtifactDir(kind, namespace, name), filename)
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,18 +129,21 @@ spec:
|
||||||
description: Artifact represents the output of the last successful
|
description: Artifact represents the output of the last successful
|
||||||
repository sync.
|
repository sync.
|
||||||
properties:
|
properties:
|
||||||
|
checksum:
|
||||||
|
description: Checksum is the SHA1 checksum of the artifact.
|
||||||
|
type: string
|
||||||
lastUpdateTime:
|
lastUpdateTime:
|
||||||
description: LastUpdateTime is the timestamp corresponding to
|
description: LastUpdateTime is the timestamp corresponding to
|
||||||
the last update of this artifact.
|
the last update of this artifact.
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
path:
|
path:
|
||||||
description: Path is the local file path of this artifact.
|
description: Path is the relative file path of this artifact.
|
||||||
type: string
|
type: string
|
||||||
revision:
|
revision:
|
||||||
description: Revision is a human readable identifier traceable
|
description: Revision is a human readable identifier traceable
|
||||||
in the origin source system. It can be a commit sha, git tag,
|
in the origin source system. It can be a Git commit sha, Git
|
||||||
a helm index timestamp, a helm chart version, a checksum, etc.
|
tag, a Helm index timestamp, a Helm chart version, etc.
|
||||||
type: string
|
type: string
|
||||||
url:
|
url:
|
||||||
description: URL is the HTTP address of this artifact.
|
description: URL is the HTTP address of this artifact.
|
||||||
|
|
|
@ -101,18 +101,21 @@ spec:
|
||||||
description: Artifact represents the output of the last successful
|
description: Artifact represents the output of the last successful
|
||||||
chart sync.
|
chart sync.
|
||||||
properties:
|
properties:
|
||||||
|
checksum:
|
||||||
|
description: Checksum is the SHA1 checksum of the artifact.
|
||||||
|
type: string
|
||||||
lastUpdateTime:
|
lastUpdateTime:
|
||||||
description: LastUpdateTime is the timestamp corresponding to
|
description: LastUpdateTime is the timestamp corresponding to
|
||||||
the last update of this artifact.
|
the last update of this artifact.
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
path:
|
path:
|
||||||
description: Path is the local file path of this artifact.
|
description: Path is the relative file path of this artifact.
|
||||||
type: string
|
type: string
|
||||||
revision:
|
revision:
|
||||||
description: Revision is a human readable identifier traceable
|
description: Revision is a human readable identifier traceable
|
||||||
in the origin source system. It can be a commit sha, git tag,
|
in the origin source system. It can be a Git commit sha, Git
|
||||||
a helm index timestamp, a helm chart version, a checksum, etc.
|
tag, a Helm index timestamp, a Helm chart version, etc.
|
||||||
type: string
|
type: string
|
||||||
url:
|
url:
|
||||||
description: URL is the HTTP address of this artifact.
|
description: URL is the HTTP address of this artifact.
|
||||||
|
|
|
@ -81,18 +81,21 @@ spec:
|
||||||
description: Artifact represents the output of the last successful
|
description: Artifact represents the output of the last successful
|
||||||
repository sync.
|
repository sync.
|
||||||
properties:
|
properties:
|
||||||
|
checksum:
|
||||||
|
description: Checksum is the SHA1 checksum of the artifact.
|
||||||
|
type: string
|
||||||
lastUpdateTime:
|
lastUpdateTime:
|
||||||
description: LastUpdateTime is the timestamp corresponding to
|
description: LastUpdateTime is the timestamp corresponding to
|
||||||
the last update of this artifact.
|
the last update of this artifact.
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
path:
|
path:
|
||||||
description: Path is the local file path of this artifact.
|
description: Path is the relative file path of this artifact.
|
||||||
type: string
|
type: string
|
||||||
revision:
|
revision:
|
||||||
description: Revision is a human readable identifier traceable
|
description: Revision is a human readable identifier traceable
|
||||||
in the origin source system. It can be a commit sha, git tag,
|
in the origin source system. It can be a Git commit sha, Git
|
||||||
a helm index timestamp, a helm chart version, a checksum, etc.
|
tag, a Helm index timestamp, a Helm chart version, etc.
|
||||||
type: string
|
type: string
|
||||||
url:
|
url:
|
||||||
description: URL is the HTTP address of this artifact.
|
description: URL is the HTTP address of this artifact.
|
||||||
|
|
|
@ -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(),
|
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
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
|
|
|
@ -261,7 +261,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
|
||||||
|
|
||||||
sum := r.Storage.Checksum(chartBytes)
|
sum := r.Storage.Checksum(chartBytes)
|
||||||
artifact := r.Storage.ArtifactFor(chart.Kind, chart.GetObjectMeta(),
|
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
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
|
@ -365,8 +365,10 @@ func (r *HelmChartReconciler) reconcileFromGitRepository(ctx context.Context,
|
||||||
return chart, nil
|
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(),
|
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
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
|
|
|
@ -229,7 +229,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
|
||||||
|
|
||||||
sum := r.Storage.Checksum(index)
|
sum := r.Storage.Checksum(index)
|
||||||
artifact := r.Storage.ArtifactFor(repository.Kind, repository.ObjectMeta.GetObjectMeta(),
|
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
|
// create artifact dir
|
||||||
err = r.Storage.MkdirAll(artifact)
|
err = r.Storage.MkdirAll(artifact)
|
||||||
|
|
|
@ -70,7 +70,7 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArtifactFor returns an artifact for the v1alpha1.Source.
|
// 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)
|
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
|
||||||
localPath := filepath.Join(s.BasePath, path)
|
localPath := filepath.Join(s.BasePath, path)
|
||||||
url := fmt.Sprintf("http://%s/%s", s.Hostname, 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,
|
Path: localPath,
|
||||||
URL: url,
|
URL: url,
|
||||||
Revision: revision,
|
Revision: revision,
|
||||||
|
Checksum: checksum,
|
||||||
LastUpdateTime: metav1.Now(),
|
LastUpdateTime: metav1.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,7 +458,7 @@ HelmRepositoryStatus
|
||||||
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmChartStatus">HelmChartStatus</a>,
|
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmChartStatus">HelmChartStatus</a>,
|
||||||
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmRepositoryStatus">HelmRepositoryStatus</a>)
|
<a href="#source.toolkit.fluxcd.io/v1alpha1.HelmRepositoryStatus">HelmRepositoryStatus</a>)
|
||||||
</p>
|
</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__scrollwrap">
|
||||||
<div class="md-typeset__table">
|
<div class="md-typeset__table">
|
||||||
<table>
|
<table>
|
||||||
|
@ -477,7 +477,7 @@ string
|
||||||
</em>
|
</em>
|
||||||
</td>
|
</td>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -500,9 +500,21 @@ string
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<em>(Optional)</em>
|
<em>(Optional)</em>
|
||||||
<p>Revision is a human readable identifier traceable in the origin source system.
|
<p>Revision is a human readable identifier traceable in the origin
|
||||||
It can be a commit sha, git tag, a helm index timestamp,
|
source system. It can be a Git commit sha, Git tag, a Helm index
|
||||||
a helm chart version, a checksum, etc.</p>
|
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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -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:
|
Source objects should contain a status sub-resource that embeds an artifact object:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Artifact represents the output of a source synchronisation
|
// Artifact represents the output of a source synchronisation.
|
||||||
type Artifact struct {
|
type Artifact struct {
|
||||||
// Path is the local file path of this artifact.
|
// Path is the relative file path of this artifact.
|
||||||
// +required
|
// +required
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
|
|
||||||
|
@ -64,12 +64,16 @@ type Artifact struct {
|
||||||
// +required
|
// +required
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
|
||||||
// Revision is a human readable identifier traceable in the origin source system.
|
// Revision is a human readable identifier traceable in the origin
|
||||||
// It can be a commit sha, git tag, a helm index timestamp,
|
// source system. It can be a Git commit sha, Git tag, a Helm index
|
||||||
// a helm chart version, a checksum, etc.
|
// timestamp, a Helm chart version, etc.
|
||||||
// +optional
|
// +optional
|
||||||
Revision string `json:"revision"`
|
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
|
// LastUpdateTime is the timestamp corresponding to the last
|
||||||
// update of this artifact.
|
// update of this artifact.
|
||||||
// +required
|
// +required
|
||||||
|
|
Loading…
Reference in New Issue