@@ -591,6 +591,109 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
591591 }))
592592 })
593593
594+ t .Run ("Upgrades HelmRelease if chart name changed with default ChartNameChangeStrategy" , func (t * testing.T ) {
595+ g := NewWithT (t )
596+
597+ // Create HelmChart mock.
598+ chartMock := testutil .BuildChart ()
599+ chartArtifact , err := testutil .SaveChartAsArtifact (chartMock , digest .SHA256 , testServer .URL (), testServer .Root ())
600+ g .Expect (err ).ToNot (HaveOccurred ())
601+
602+ ns , err := testEnv .CreateNamespace (context .TODO (), "mock" )
603+ g .Expect (err ).ToNot (HaveOccurred ())
604+ t .Cleanup (func () {
605+ _ = testEnv .Delete (context .TODO (), ns )
606+ })
607+
608+ hc := & sourcev1.HelmChart {
609+ ObjectMeta : metav1.ObjectMeta {
610+ Name : chartMock .Name (),
611+ Namespace : ns .Name ,
612+ Generation : 1 ,
613+ },
614+ Spec : sourcev1.HelmChartSpec {
615+ Chart : chartMock .Name (),
616+ Version : chartMock .Metadata .Version ,
617+ },
618+ Status : sourcev1.HelmChartStatus {
619+ ObservedGeneration : 1 ,
620+ Artifact : chartArtifact ,
621+ Conditions : []metav1.Condition {
622+ {
623+ Type : meta .ReadyCondition ,
624+ Status : metav1 .ConditionTrue ,
625+ },
626+ },
627+ },
628+ }
629+
630+ // Create a test Helm release storage mock.
631+ rls := testutil .BuildRelease (& helmrelease.MockReleaseOptions {
632+ Name : "release" ,
633+ Namespace : ns .Name ,
634+ Version : 1 ,
635+ Chart : chartMock ,
636+ Status : helmreleasecommon .StatusDeployed ,
637+ })
638+
639+ snapshot := release .ObservedToSnapshot (release .ObserveRelease (rls ))
640+ snapshot .ChartName = "oldChartName"
641+ obj := & v2.HelmRelease {
642+ ObjectMeta : metav1.ObjectMeta {
643+ Name : "release" ,
644+ Namespace : ns .Name ,
645+ },
646+ Spec : v2.HelmReleaseSpec {
647+ ChartRef : & v2.CrossNamespaceSourceReference {
648+ Kind : sourcev1 .HelmChartKind ,
649+ Name : hc .Name ,
650+ },
651+ },
652+ Status : v2.HelmReleaseStatus {
653+ StorageNamespace : ns .Name ,
654+ History : v2.Snapshots {
655+ snapshot ,
656+ },
657+ HelmChart : hc .Namespace + "/" + hc .Name ,
658+ },
659+ }
660+
661+ c := fake .NewClientBuilder ().
662+ WithScheme (NewTestScheme ()).
663+ WithStatusSubresource (& v2.HelmRelease {}).
664+ WithObjects (hc , obj ).
665+ Build ()
666+
667+ r := & HelmReleaseReconciler {
668+ Client : c ,
669+ GetClusterConfig : GetTestClusterConfig ,
670+ EventRecorder : record .NewFakeRecorder (32 ),
671+ }
672+
673+ //Store the Helm release mock in the test namespace.
674+ getter , err := r .buildRESTClientGetter (context .TODO (), obj )
675+ g .Expect (err ).ToNot (HaveOccurred ())
676+
677+ cfg , err := action .NewConfigFactory (getter , action .WithStorage (helmdriver .SecretsDriverName , obj .Status .StorageNamespace ))
678+ g .Expect (err ).ToNot (HaveOccurred ())
679+
680+ store := helmstorage .Init (cfg .Driver )
681+ g .Expect (store .Create (rls )).To (Succeed ())
682+
683+ _ , err = r .reconcileRelease (context .TODO (), patch .NewSerialPatcher (obj , r .Client ), obj , nil )
684+ g .Expect (err ).ToNot (HaveOccurred ())
685+
686+ g .Expect (obj .Status .Conditions ).To (conditions .MatchConditions ([]metav1.Condition {
687+ * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "Fulfilling prerequisites" ),
688+ * conditions .FalseCondition (meta .ReadyCondition , v2 .UninstallSucceededReason , "Helm uninstall succeeded for release %s with chart %s" ,
689+ fmt .Sprintf ("%s/%s.v%d" , rls .Namespace , rls .Name , rls .Version ), fmt .Sprintf ("%s@%s" , chartMock .Name (),
690+ chartMock .Metadata .Version )),
691+ * conditions .FalseCondition (v2 .ReleasedCondition , v2 .UninstallSucceededReason , "Helm uninstall succeeded for release %s with chart %s" ,
692+ fmt .Sprintf ("%s/%s.v%d" , rls .Namespace , rls .Name , rls .Version ), fmt .Sprintf ("%s@%s" , chartMock .Name (),
693+ chartMock .Metadata .Version )),
694+ }))
695+ })
696+
594697 t .Run ("resets failure counts on configuration change" , func (t * testing.T ) {
595698 g := NewWithT (t )
596699
0 commit comments