Skip to content

Commit 19ba61a

Browse files
committed
Remove TransformLegacyRevision from v1
Consumers still relying on this should make use of `v1beta2` to facilitate any transition. In addition, remove the `*Implementation` constants for now removed Git implemenations. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent 861343d commit 19ba61a

9 files changed

+8
-225
lines changed

api/v1/artifact_types.go

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1
1818

1919
import (
2020
"path"
21-
"regexp"
2221
"strings"
2322

2423
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -68,7 +67,7 @@ func (in *Artifact) HasRevision(revision string) bool {
6867
if in == nil {
6968
return false
7069
}
71-
return TransformLegacyRevision(in.Revision) == TransformLegacyRevision(revision)
70+
return in.Revision == revision
7271
}
7372

7473
// HasDigest returns if the given digest matches the current Digest of the
@@ -92,60 +91,3 @@ func ArtifactDir(kind, namespace, name string) string {
9291
func ArtifactPath(kind, namespace, name, filename string) string {
9392
return path.Join(ArtifactDir(kind, namespace, name), filename)
9493
}
95-
96-
// TransformLegacyRevision transforms a "legacy" revision string into a "new"
97-
// revision string. It accepts the following formats:
98-
//
99-
// - main/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
100-
// - feature/branch/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
101-
// - HEAD/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
102-
// - tag/55609ff9d959589ed917ce32e6bc0f0a36809565f308602c15c3668965979edc
103-
// - d52bde83c5b2bd0fa7910264e0afc3ac9cfe9b6636ca29c05c09742f01d5a4bd
104-
//
105-
// Which are transformed into the following formats respectively:
106-
//
107-
// - main@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
108-
// - feature/branch@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
109-
// - sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
110-
// - tag@sha256:55609ff9d959589ed917ce32e6bc0f0a36809565f308602c15c3668965979edc
111-
// - sha256:d52bde83c5b2bd0fa7910264e0afc3ac9cfe9b6636ca29c05c09742f01d5a4bd
112-
//
113-
// Deprecated, this function exists for backwards compatibility with existing
114-
// resources, and to provide a transition period. Will be removed in a future
115-
// release.
116-
func TransformLegacyRevision(rev string) string {
117-
if rev != "" && strings.LastIndex(rev, ":") == -1 {
118-
if i := strings.LastIndex(rev, "/"); i >= 0 {
119-
sha := rev[i+1:]
120-
if algo := determineSHAType(sha); algo != "" {
121-
if name := rev[:i]; name != "HEAD" {
122-
return name + "@" + algo + ":" + sha
123-
}
124-
return algo + ":" + sha
125-
}
126-
}
127-
if algo := determineSHAType(rev); algo != "" {
128-
return algo + ":" + rev
129-
}
130-
}
131-
return rev
132-
}
133-
134-
// isAlphaNumHex returns true if the given string only contains 0-9 and a-f
135-
// characters.
136-
var isAlphaNumHex = regexp.MustCompile(`^[0-9a-f]+$`).MatchString
137-
138-
// determineSHAType returns the SHA algorithm used to compute the provided hex.
139-
// The determination is heuristic and based on the length of the hex string. If
140-
// the size is not recognized, an empty string is returned.
141-
func determineSHAType(hex string) string {
142-
if isAlphaNumHex(hex) {
143-
switch len(hex) {
144-
case 40:
145-
return "sha1"
146-
case 64:
147-
return "sha256"
148-
}
149-
}
150-
return ""
151-
}

api/v1/artifact_types_test.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

api/v1/gitrepository_types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ import (
2727
const (
2828
// GitRepositoryKind is the string representation of a GitRepository.
2929
GitRepositoryKind = "GitRepository"
30-
31-
// GoGitImplementation for performing Git operations using go-git.
32-
GoGitImplementation = "go-git"
33-
// LibGit2Implementation for performing Git operations using libgit2.
34-
LibGit2Implementation = "libgit2"
3530
)
3631

3732
const (

controllers/bucket_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
459459
// Check if index has changed compared to current Artifact revision.
460460
var changed bool
461461
if artifact := obj.Status.Artifact; artifact != nil && artifact.Revision != "" {
462-
curRev := digest.Digest(sourcev1.TransformLegacyRevision(artifact.Revision))
462+
curRev := digest.Digest(artifact.Revision)
463463
changed = curRev.Validate() != nil || curRev != index.Digest(curRev.Algorithm())
464464
}
465465

@@ -512,7 +512,7 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
512512
// Set the ArtifactInStorageCondition if there's no drift.
513513
defer func() {
514514
if curArtifact := obj.GetArtifact(); curArtifact != nil && curArtifact.Revision != "" {
515-
curRev := digest.Digest(sourcev1.TransformLegacyRevision(curArtifact.Revision))
515+
curRev := digest.Digest(curArtifact.Revision)
516516
if curRev.Validate() == nil && index.Digest(curRev.Algorithm()) == curRev {
517517
conditions.Delete(obj, sourcev1.ArtifactOutdatedCondition)
518518
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason,
@@ -523,7 +523,7 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
523523

524524
// The artifact is up-to-date
525525
if curArtifact := obj.GetArtifact(); curArtifact != nil && curArtifact.Revision != "" {
526-
curRev := digest.Digest(sourcev1.TransformLegacyRevision(curArtifact.Revision))
526+
curRev := digest.Digest(curArtifact.Revision)
527527
if curRev.Validate() == nil && index.Digest(curRev.Algorithm()) == curRev {
528528
r.eventLogf(ctx, obj, eventv1.EventTypeTrace, sourcev1.ArtifactUpToDateReason, "artifact up-to-date with remote revision: '%s'", artifact.Revision)
529529
return sreconcile.ResultSuccess, nil

controllers/bucket_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func TestBucketReconciler_reconcileSource_generic(t *testing.T) {
514514
bucketName: "dummy",
515515
beforeFunc: func(obj *bucketv1.Bucket) {
516516
obj.Status.Artifact = &sourcev1.Artifact{
517-
Revision: "b4c2a60ce44b67f5b659a95ce4e4cc9e2a86baf13afb72bd397c5384cbc0e479",
517+
Revision: "sha256:b4c2a60ce44b67f5b659a95ce4e4cc9e2a86baf13afb72bd397c5384cbc0e479",
518518
}
519519
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
520520
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
@@ -856,7 +856,7 @@ func TestBucketReconciler_reconcileSource_gcs(t *testing.T) {
856856
bucketName: "dummy",
857857
beforeFunc: func(obj *bucketv1.Bucket) {
858858
obj.Status.Artifact = &sourcev1.Artifact{
859-
Revision: "b4c2a60ce44b67f5b659a95ce4e4cc9e2a86baf13afb72bd397c5384cbc0e479",
859+
Revision: "sha256:b4c2a60ce44b67f5b659a95ce4e4cc9e2a86baf13afb72bd397c5384cbc0e479",
860860
}
861861
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
862862
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")

controllers/gitrepository_controller_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -732,27 +732,6 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
732732
wantRevision: "staging@sha1:<commit>",
733733
wantReconciling: false,
734734
},
735-
{
736-
name: "Optimized clone (legacy revision format)",
737-
reference: &sourcev1.GitRepositoryRef{
738-
Branch: "staging",
739-
},
740-
beforeFunc: func(obj *sourcev1.GitRepository, latestRev string) {
741-
// Add existing artifact on the object and storage.
742-
obj.Status = sourcev1.GitRepositoryStatus{
743-
Artifact: &sourcev1.Artifact{
744-
Revision: "staging/" + latestRev,
745-
Path: randStringRunes(10),
746-
},
747-
}
748-
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
749-
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "foo")
750-
},
751-
want: sreconcile.ResultEmpty,
752-
wantErr: true,
753-
wantRevision: "staging@sha1:<commit>",
754-
wantReconciling: false,
755-
},
756735
{
757736
name: "Optimized clone different ignore",
758737
reference: &sourcev1.GitRepositoryRef{
@@ -775,28 +754,6 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
775754
wantRevision: "staging@sha1:<commit>",
776755
wantReconciling: false,
777756
},
778-
{
779-
name: "Optimized clone different ignore (legacy revision format)",
780-
reference: &sourcev1.GitRepositoryRef{
781-
Branch: "staging",
782-
},
783-
beforeFunc: func(obj *sourcev1.GitRepository, latestRev string) {
784-
// Set new ignore value.
785-
obj.Spec.Ignore = pointer.StringPtr("foo")
786-
// Add existing artifact on the object and storage.
787-
obj.Status = sourcev1.GitRepositoryStatus{
788-
Artifact: &sourcev1.Artifact{
789-
Revision: "staging/" + latestRev,
790-
Path: randStringRunes(10),
791-
},
792-
}
793-
conditions.MarkTrue(obj, sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "foo")
794-
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "foo")
795-
},
796-
want: sreconcile.ResultSuccess,
797-
wantRevision: "staging@sha1:<commit>",
798-
wantReconciling: false,
799-
},
800757
}
801758

802759
server, err := gittestserver.NewTempGitServer()
@@ -956,28 +913,6 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
956913
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for revision 'main@sha1:b9b3feadba509cb9b22e968a5d27e96c2bc2ff91'"),
957914
},
958915
},
959-
{
960-
name: "Up-to-date artifact with legacy revision format should not update status",
961-
dir: "testdata/git/repository",
962-
includes: artifactSet{&sourcev1.Artifact{Revision: "main@sha1:b9b3feadba509cb9b22e968a5d27e96c2bc2ff91", Digest: "some-checksum"}},
963-
beforeFunc: func(obj *sourcev1.GitRepository) {
964-
obj.Spec.Interval = metav1.Duration{Duration: interval}
965-
obj.Spec.Include = []sourcev1.GitRepositoryInclude{
966-
{GitRepositoryRef: meta.LocalObjectReference{Name: "foo"}},
967-
}
968-
obj.Status.Artifact = &sourcev1.Artifact{Revision: "main/b9b3feadba509cb9b22e968a5d27e96c2bc2ff91"}
969-
obj.Status.IncludedArtifacts = []*sourcev1.Artifact{{Revision: "main/b9b3feadba509cb9b22e968a5d27e96c2bc2ff91", Digest: "some-checksum"}}
970-
obj.Status.ObservedInclude = obj.Spec.Include
971-
},
972-
afterFunc: func(t *WithT, obj *sourcev1.GitRepository) {
973-
t.Expect(obj.Status.URL).To(BeEmpty())
974-
t.Expect(obj.Status.Artifact.Revision).To(Equal("main/b9b3feadba509cb9b22e968a5d27e96c2bc2ff91"))
975-
},
976-
want: sreconcile.ResultSuccess,
977-
assertConditions: []metav1.Condition{
978-
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for revision 'main/b9b3feadba509cb9b22e968a5d27e96c2bc2ff91'"),
979-
},
980-
},
981916
{
982917
name: "Spec ignore overwrite is taken into account",
983918
dir: "testdata/git/repository",

controllers/helmchart_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj
794794
rev = git.ExtractHashFromRevision(rev).String()
795795
}
796796
if obj.Spec.SourceRef.Kind == helmv1.BucketKind {
797-
if dig := digest.Digest(sourcev1.TransformLegacyRevision(rev)); dig.Validate() == nil {
797+
if dig := digest.Digest(rev); dig.Validate() == nil {
798798
rev = dig.Encoded()
799799
}
800800
}

controllers/helmrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
489489
// Check if index has changed compared to current Artifact revision.
490490
var changed bool
491491
if artifact := obj.Status.Artifact; artifact != nil {
492-
curRev := digest.Digest(sourcev1.TransformLegacyRevision(artifact.Revision))
492+
curRev := digest.Digest(artifact.Revision)
493493
changed = curRev.Validate() != nil || curRev != chartRepo.Digest(curRev.Algorithm())
494494
}
495495

controllers/ocirepository_controller_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,17 +1317,6 @@ func TestOCIRepository_reconcileSource_noop(t *testing.T) {
13171317
g.Expect(artifact.Metadata).To(BeEmpty())
13181318
},
13191319
},
1320-
{
1321-
name: "noop - artifact revisions match (legacy)",
1322-
beforeFunc: func(obj *ociv1.OCIRepository) {
1323-
obj.Status.Artifact = &sourcev1.Artifact{
1324-
Revision: "6.1.5/8e4057c22d531d40e12b065443cb0d80394b7257c4dc557cb1fbd4dce892b86d",
1325-
}
1326-
},
1327-
afterFunc: func(g *WithT, artifact *sourcev1.Artifact) {
1328-
g.Expect(artifact.Metadata).To(BeEmpty())
1329-
},
1330-
},
13311320
{
13321321
name: "full reconcile - same rev, unobserved ignore",
13331322
beforeFunc: func(obj *ociv1.OCIRepository) {

0 commit comments

Comments
 (0)