misc: order imports and align digest aliases
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
eb4a38e421
commit
d62f4dc0c6
|
@ -21,12 +21,11 @@ import (
|
|||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fluxcd/source-controller/internal/digest"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/docker/go-units"
|
||||
digestlib "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/go-digest"
|
||||
helmgetter "helm.sh/helm/v3/pkg/getter"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -49,6 +48,7 @@ import (
|
|||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||
"github.com/fluxcd/source-controller/internal/cache"
|
||||
intdigest "github.com/fluxcd/source-controller/internal/digest"
|
||||
serror "github.com/fluxcd/source-controller/internal/error"
|
||||
"github.com/fluxcd/source-controller/internal/helm/getter"
|
||||
"github.com/fluxcd/source-controller/internal/helm/repository"
|
||||
|
@ -469,9 +469,9 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
|
|||
|
||||
// Early comparison to current Artifact.
|
||||
if curArtifact := obj.GetArtifact(); curArtifact != nil {
|
||||
curDig := digestlib.Digest(curArtifact.Digest)
|
||||
curDig := digest.Digest(curArtifact.Digest)
|
||||
if curDig == "" {
|
||||
curDig = digestlib.Digest(sourcev1.TransformLegacyRevision(curArtifact.Checksum))
|
||||
curDig = digest.Digest(sourcev1.TransformLegacyRevision(curArtifact.Checksum))
|
||||
}
|
||||
if curDig.Validate() == nil {
|
||||
// Short-circuit based on the fetched index being an exact match to the
|
||||
|
@ -500,12 +500,12 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
|
|||
// Check if index has changed compared to current Artifact revision.
|
||||
var changed bool
|
||||
if artifact := obj.Status.Artifact; artifact != nil {
|
||||
curRev := digestlib.Digest(sourcev1.TransformLegacyRevision(artifact.Revision))
|
||||
curRev := digest.Digest(sourcev1.TransformLegacyRevision(artifact.Revision))
|
||||
changed = curRev.Validate() != nil || curRev != chartRepo.Revision(curRev.Algorithm())
|
||||
}
|
||||
|
||||
// Calculate revision.
|
||||
revision := chartRepo.Revision(digest.Canonical)
|
||||
revision := chartRepo.Revision(intdigest.Canonical)
|
||||
if revision.Validate() != nil {
|
||||
e := &serror.Event{
|
||||
Err: fmt.Errorf("failed to calculate revision: %w", err),
|
||||
|
|
|
@ -21,10 +21,6 @@ import (
|
|||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fluxcd/source-controller/internal/cache"
|
||||
"github.com/fluxcd/source-controller/internal/digest"
|
||||
digestlib "github.com/opencontainers/go-digest"
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -33,7 +29,9 @@ import (
|
|||
"time"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/opencontainers/go-digest"
|
||||
helmgetter "helm.sh/helm/v3/pkg/getter"
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -50,6 +48,8 @@ import (
|
|||
"github.com/fluxcd/pkg/runtime/patch"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||
"github.com/fluxcd/source-controller/internal/cache"
|
||||
intdigest "github.com/fluxcd/source-controller/internal/digest"
|
||||
"github.com/fluxcd/source-controller/internal/helm/getter"
|
||||
"github.com/fluxcd/source-controller/internal/helm/repository"
|
||||
sreconcile "github.com/fluxcd/source-controller/internal/reconcile"
|
||||
|
@ -316,7 +316,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
server options
|
||||
url string
|
||||
secret *corev1.Secret
|
||||
beforeFunc func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digestlib.Digest)
|
||||
beforeFunc func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digest.Digest)
|
||||
afterFunc func(t *WithT, obj *sourcev1.HelmRepository, artifact sourcev1.Artifact, chartRepo *repository.ChartRepository)
|
||||
want sreconcile.Result
|
||||
wantErr bool
|
||||
|
@ -371,7 +371,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
"password": []byte("1234"),
|
||||
},
|
||||
},
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "basic-auth"}
|
||||
},
|
||||
want: sreconcile.ResultSuccess,
|
||||
|
@ -402,7 +402,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
"caFile": tlsCA,
|
||||
},
|
||||
},
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "ca-file"}
|
||||
},
|
||||
want: sreconcile.ResultSuccess,
|
||||
|
@ -433,7 +433,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
"caFile": []byte("invalid"),
|
||||
},
|
||||
},
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "invalid-ca"}
|
||||
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
|
||||
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
|
||||
|
@ -455,7 +455,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Invalid URL makes FetchFailed=True and returns stalling error",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.URL = strings.ReplaceAll(obj.Spec.URL, "http://", "")
|
||||
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
|
||||
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
|
||||
|
@ -478,7 +478,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Unsupported scheme makes FetchFailed=True and returns stalling error",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.URL = strings.ReplaceAll(obj.Spec.URL, "http://", "ftp://")
|
||||
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
|
||||
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
|
||||
|
@ -501,7 +501,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Missing secret returns FetchFailed=True and returns error",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "non-existing"}
|
||||
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
|
||||
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
|
||||
|
@ -531,7 +531,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
"username": []byte("git"),
|
||||
},
|
||||
},
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "malformed-basic-auth"}
|
||||
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
|
||||
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
|
||||
|
@ -553,7 +553,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Stored index with same digest and revision",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digest.Digest) {
|
||||
obj.Status.Artifact = &sourcev1.Artifact{
|
||||
Revision: revision.String(),
|
||||
Digest: digest.String(),
|
||||
|
@ -579,7 +579,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Stored index with same checksum and (legacy) revision",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digest.Digest) {
|
||||
obj.Status.Artifact = &sourcev1.Artifact{
|
||||
Revision: revision.Hex(),
|
||||
Checksum: digest.Hex(),
|
||||
|
@ -604,7 +604,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Stored index with different digest and same revision",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, digest digest.Digest) {
|
||||
obj.Status.Artifact = &sourcev1.Artifact{
|
||||
Revision: revision.String(),
|
||||
Digest: "sha256:80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86",
|
||||
|
@ -632,7 +632,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Stored index with different revision and digest",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Status.Artifact = &sourcev1.Artifact{
|
||||
Revision: "80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86",
|
||||
Checksum: "80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86",
|
||||
|
@ -660,7 +660,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
{
|
||||
name: "Existing artifact makes ArtifactOutdated=True",
|
||||
protocol: "http",
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digestlib.Digest) {
|
||||
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository, revision, checksum digest.Digest) {
|
||||
obj.Status.Artifact = &sourcev1.Artifact{
|
||||
Path: "some-path",
|
||||
Revision: "some-rev",
|
||||
|
@ -769,13 +769,13 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
|||
|
||||
// NOTE: checksum will be empty in beforeFunc for invalid repo
|
||||
// configurations as the client can't get the repo.
|
||||
var revision, checksum digestlib.Digest
|
||||
var revision, checksum digest.Digest
|
||||
if validSecret {
|
||||
g.Expect(newChartRepo.CacheIndex()).To(Succeed())
|
||||
checksum = newChartRepo.Digest(digest.Canonical)
|
||||
checksum = newChartRepo.Digest(intdigest.Canonical)
|
||||
|
||||
g.Expect(newChartRepo.LoadFromPath()).To(Succeed())
|
||||
revision = newChartRepo.Revision(digest.Canonical)
|
||||
revision = newChartRepo.Revision(intdigest.Canonical)
|
||||
}
|
||||
if tt.beforeFunc != nil {
|
||||
tt.beforeFunc(g, obj, revision, checksum)
|
||||
|
|
|
@ -34,7 +34,7 @@ import (
|
|||
|
||||
securejoin "github.com/cyphar/filepath-securejoin"
|
||||
"github.com/fluxcd/go-git/v5/plumbing/format/gitignore"
|
||||
digestlib "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/go-digest"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
|
||||
|
@ -43,7 +43,7 @@ import (
|
|||
"github.com/fluxcd/pkg/untar"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||
"github.com/fluxcd/source-controller/internal/digest"
|
||||
intdigest "github.com/fluxcd/source-controller/internal/digest"
|
||||
sourcefs "github.com/fluxcd/source-controller/internal/fs"
|
||||
)
|
||||
|
||||
|
@ -360,7 +360,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
|
|||
}
|
||||
}()
|
||||
|
||||
md, err := digest.NewMultiDigester(digest.Canonical, digestlib.SHA256)
|
||||
md, err := intdigest.NewMultiDigester(intdigest.Canonical, digest.SHA256)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create digester: %w", err)
|
||||
}
|
||||
|
@ -455,8 +455,8 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
|
|||
return err
|
||||
}
|
||||
|
||||
artifact.Digest = md.Digest(digest.Canonical).String()
|
||||
artifact.Checksum = md.Digest(digestlib.SHA256).Encoded()
|
||||
artifact.Digest = md.Digest(intdigest.Canonical).String()
|
||||
artifact.Checksum = md.Digest(digest.SHA256).Encoded()
|
||||
artifact.LastUpdateTime = metav1.Now()
|
||||
artifact.Size = &sz.written
|
||||
|
||||
|
@ -478,7 +478,7 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
|
|||
}
|
||||
}()
|
||||
|
||||
md, err := digest.NewMultiDigester(digest.Canonical, digestlib.SHA256)
|
||||
md, err := intdigest.NewMultiDigester(intdigest.Canonical, digest.SHA256)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create digester: %w", err)
|
||||
}
|
||||
|
@ -501,8 +501,8 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
|
|||
return err
|
||||
}
|
||||
|
||||
artifact.Digest = md.Digest(digest.Canonical).String()
|
||||
artifact.Checksum = md.Digest(digestlib.SHA256).Encoded()
|
||||
artifact.Digest = md.Digest(intdigest.Canonical).String()
|
||||
artifact.Checksum = md.Digest(digest.SHA256).Encoded()
|
||||
artifact.LastUpdateTime = metav1.Now()
|
||||
artifact.Size = &sz.written
|
||||
|
||||
|
@ -524,7 +524,7 @@ func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error
|
|||
}
|
||||
}()
|
||||
|
||||
md, err := digest.NewMultiDigester(digest.Canonical, digestlib.SHA256)
|
||||
md, err := intdigest.NewMultiDigester(intdigest.Canonical, digest.SHA256)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create digester: %w", err)
|
||||
}
|
||||
|
@ -543,8 +543,8 @@ func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error
|
|||
return err
|
||||
}
|
||||
|
||||
artifact.Digest = md.Digest(digest.Canonical).String()
|
||||
artifact.Checksum = md.Digest(digestlib.SHA256).Encoded()
|
||||
artifact.Digest = md.Digest(intdigest.Canonical).String()
|
||||
artifact.Checksum = md.Digest(digest.SHA256).Encoded()
|
||||
artifact.LastUpdateTime = metav1.Now()
|
||||
artifact.Size = &sz.written
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
"time"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
digestlib "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
helmgetter "helm.sh/helm/v3/pkg/getter"
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
|
@ -512,7 +512,7 @@ func TestChartRepository_Revision(t *testing.T) {
|
|||
r := newChartRepository()
|
||||
r.Index = repo.NewIndexFile()
|
||||
|
||||
for _, algo := range []digestlib.Algorithm{digestlib.SHA256, digestlib.SHA512} {
|
||||
for _, algo := range []digest.Algorithm{digest.SHA256, digest.SHA512} {
|
||||
t.Run(algo.String(), func(t *testing.T) {
|
||||
g := NewWithT(t)
|
||||
|
||||
|
@ -528,14 +528,14 @@ func TestChartRepository_Revision(t *testing.T) {
|
|||
g := NewWithT(t)
|
||||
|
||||
r := newChartRepository()
|
||||
g.Expect(r.Revision(digestlib.SHA256)).To(BeEmpty())
|
||||
g.Expect(r.Revision(digest.SHA256)).To(BeEmpty())
|
||||
})
|
||||
|
||||
t.Run("from cache", func(t *testing.T) {
|
||||
g := NewWithT(t)
|
||||
|
||||
algo := digestlib.SHA256
|
||||
expect := digestlib.Digest("sha256:fake")
|
||||
algo := digest.SHA256
|
||||
expect := digest.Digest("sha256:fake")
|
||||
|
||||
r := newChartRepository()
|
||||
r.Index = repo.NewIndexFile()
|
||||
|
@ -555,7 +555,7 @@ func TestChartRepository_Digest(t *testing.T) {
|
|||
r := newChartRepository()
|
||||
r.Path = p
|
||||
|
||||
for _, algo := range []digestlib.Algorithm{digestlib.SHA256, digestlib.SHA512} {
|
||||
for _, algo := range []digest.Algorithm{digest.SHA256, digest.SHA512} {
|
||||
t.Run(algo.String(), func(t *testing.T) {
|
||||
g := NewWithT(t)
|
||||
|
||||
|
@ -571,14 +571,14 @@ func TestChartRepository_Digest(t *testing.T) {
|
|||
g := NewWithT(t)
|
||||
|
||||
r := newChartRepository()
|
||||
g.Expect(r.Digest(digestlib.SHA256)).To(BeEmpty())
|
||||
g.Expect(r.Digest(digest.SHA256)).To(BeEmpty())
|
||||
})
|
||||
|
||||
t.Run("from cache", func(t *testing.T) {
|
||||
g := NewWithT(t)
|
||||
|
||||
algo := digestlib.SHA256
|
||||
expect := digestlib.Digest("sha256:fake")
|
||||
algo := digest.SHA256
|
||||
expect := digest.Digest("sha256:fake")
|
||||
|
||||
i := filepath.Join(t.TempDir(), "index.yaml")
|
||||
g.Expect(os.WriteFile(i, []byte(`apiVersion: v1`), 0o644)).To(Succeed())
|
||||
|
|
Loading…
Reference in New Issue