diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 4a49fef6..ecf47500 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -21,6 +21,7 @@ import ( "crypto/tls" "errors" "fmt" + "github.com/fluxcd/pkg/git" "net/url" "os" "path/filepath" @@ -789,10 +790,10 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj if obj.Spec.ReconcileStrategy == sourcev1.ReconcileStrategyRevision { rev := source.Revision if obj.Spec.SourceRef.Kind == sourcev1.GitRepositoryKind { - // Split the reference by the `/` delimiter which may be present, - // and take the last entry which contains the SHA. - split := strings.Split(source.Revision, "/") - rev = split[len(split)-1] + rev = git.ExtractHashFromRevision(rev).String() + } + if obj.Spec.SourceRef.Kind == sourcev1.BucketKind { + rev = backwardsCompatibleDigest(rev).Hex() } if kind := obj.Spec.SourceRef.Kind; kind == sourcev1.GitRepositoryKind || kind == sourcev1.BucketKind { // The SemVer from the metadata is at times used in e.g. the label metadata for a resource @@ -1243,9 +1244,10 @@ func (r *HelmChartReconciler) requestsForGitRepositoryChange(o client.Object) [] return nil } + revision := git.TransformRevision(repo.GetArtifact().Revision) var reqs []reconcile.Request for _, i := range list.Items { - if i.Status.ObservedSourceArtifactRevision != repo.GetArtifact().Revision { + if git.TransformRevision(i.Status.ObservedSourceArtifactRevision) != revision { reqs = append(reqs, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(&i)}) } } @@ -1270,9 +1272,10 @@ func (r *HelmChartReconciler) requestsForBucketChange(o client.Object) []reconci return nil } + revision := backwardsCompatibleDigest(bucket.GetArtifact().Revision) var reqs []reconcile.Request for _, i := range list.Items { - if i.Status.ObservedSourceArtifactRevision != bucket.GetArtifact().Revision { + if backwardsCompatibleDigest(i.Status.ObservedSourceArtifactRevision) != revision { reqs = append(reqs, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(&i)}) } } diff --git a/controllers/helmchart_controller_test.go b/controllers/helmchart_controller_test.go index 98e2b82a..a7460e8c 100644 --- a/controllers/helmchart_controller_test.go +++ b/controllers/helmchart_controller_test.go @@ -1394,6 +1394,9 @@ func TestHelmChartReconciler_buildFromTarballArtifact(t *testing.T) { } got, err := r.buildFromTarballArtifact(context.TODO(), obj, tt.source, &b) + if err != nil { + t.Log(err) + } g.Expect(err != nil).To(Equal(tt.wantErr != nil)) if tt.wantErr != nil { g.Expect(reflect.TypeOf(err).String()).To(Equal(reflect.TypeOf(tt.wantErr).String()))