@@ -1015,15 +1015,16 @@ func TestAtomicRelease_Reconcile_Scenarios(t *testing.T) {
1015
1015
1016
1016
func TestAtomicRelease_actionForState (t * testing.T ) {
1017
1017
tests := []struct {
1018
- name string
1019
- releases []* helmrelease.Release
1020
- annotations map [string ]string
1021
- spec func (spec * v2.HelmReleaseSpec )
1022
- status func (releases []* helmrelease.Release ) v2.HelmReleaseStatus
1023
- state ReleaseState
1024
- want ActionReconciler
1025
- wantEvent * corev1.Event
1026
- wantErr error
1018
+ name string
1019
+ releases []* helmrelease.Release
1020
+ annotations map [string ]string
1021
+ spec func (spec * v2.HelmReleaseSpec )
1022
+ status func (releases []* helmrelease.Release ) v2.HelmReleaseStatus
1023
+ state ReleaseState
1024
+ want ActionReconciler
1025
+ wantEvent * corev1.Event
1026
+ wantErr error
1027
+ assertConditions []metav1.Condition
1027
1028
}{
1028
1029
{
1029
1030
name : "in-sync release does not trigger any action" ,
@@ -1053,6 +1054,25 @@ func TestAtomicRelease_actionForState(t *testing.T) {
1053
1054
},
1054
1055
want : & Upgrade {},
1055
1056
},
1057
+ {
1058
+ name : "in-sync release with stale remediated condition" ,
1059
+ status : func (releases []* helmrelease.Release ) v2.HelmReleaseStatus {
1060
+ return v2.HelmReleaseStatus {
1061
+ History : v2.Snapshots {
1062
+ {Version : 1 },
1063
+ },
1064
+ Conditions : []metav1.Condition {
1065
+ * conditions .FalseCondition (v2 .ReleasedCondition , v2 .UpgradeFailedReason , "upgrade failed" ),
1066
+ * conditions .TrueCondition (v2 .RemediatedCondition , v2 .RollbackSucceededReason , "rolled back" ),
1067
+ },
1068
+ }
1069
+ },
1070
+ state : ReleaseState {Status : ReleaseStatusInSync },
1071
+ want : nil ,
1072
+ assertConditions : []metav1.Condition {
1073
+ * conditions .TrueCondition (v2 .ReleasedCondition , v2 .UpgradeSucceededReason , "upgrade succeeded" ),
1074
+ },
1075
+ },
1056
1076
{
1057
1077
name : "locked release triggers unlock action" ,
1058
1078
state : ReleaseState {Status : ReleaseStatusLocked },
@@ -1245,6 +1265,25 @@ func TestAtomicRelease_actionForState(t *testing.T) {
1245
1265
state : ReleaseState {Status : ReleaseStatusUntested },
1246
1266
want : & Test {},
1247
1267
},
1268
+ {
1269
+ name : "untested release with stale remediated condition" ,
1270
+ status : func (releases []* helmrelease.Release ) v2.HelmReleaseStatus {
1271
+ return v2.HelmReleaseStatus {
1272
+ History : v2.Snapshots {
1273
+ {Version : 1 },
1274
+ },
1275
+ Conditions : []metav1.Condition {
1276
+ * conditions .FalseCondition (v2 .ReleasedCondition , v2 .UpgradeFailedReason , "upgrade failed" ),
1277
+ * conditions .TrueCondition (v2 .RemediatedCondition , v2 .RollbackSucceededReason , "rolled back" ),
1278
+ },
1279
+ }
1280
+ },
1281
+ state : ReleaseState {Status : ReleaseStatusUntested },
1282
+ want : & Test {},
1283
+ assertConditions : []metav1.Condition {
1284
+ * conditions .TrueCondition (v2 .ReleasedCondition , v2 .UpgradeSucceededReason , "upgrade succeeded" ),
1285
+ },
1286
+ },
1248
1287
{
1249
1288
name : "failed release without active remediation triggers upgrade" ,
1250
1289
state : ReleaseState {Status : ReleaseStatusFailed },
@@ -1513,6 +1552,122 @@ func TestAtomicRelease_actionForState(t *testing.T) {
1513
1552
} else {
1514
1553
g .Expect (recorder .GetEvents ()).To (BeEmpty ())
1515
1554
}
1555
+
1556
+ g .Expect (obj .Status .Conditions ).To (conditions .MatchConditions (tt .assertConditions ))
1557
+ })
1558
+ }
1559
+ }
1560
+
1561
+ func Test_replaceCondition (t * testing.T ) {
1562
+ g := NewWithT (t )
1563
+ timestamp , err := time .Parse (time .UnixDate , "Wed Feb 25 11:06:39 GMT 2015" )
1564
+ g .Expect (err ).ToNot (HaveOccurred ())
1565
+
1566
+ tests := []struct {
1567
+ name string
1568
+ conditions []metav1.Condition
1569
+ target string
1570
+ replacement string
1571
+ wantConditions []metav1.Condition
1572
+ }{
1573
+ {
1574
+ name : "both conditions exist" ,
1575
+ conditions : []metav1.Condition {
1576
+ {
1577
+ Type : v2 .ReleasedCondition ,
1578
+ Status : metav1 .ConditionFalse ,
1579
+ Reason : v2 .UpgradeFailedReason ,
1580
+ Message : "upgrade failed" ,
1581
+ ObservedGeneration : 1 ,
1582
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1583
+ },
1584
+ {
1585
+ Type : v2 .RemediatedCondition ,
1586
+ Status : metav1 .ConditionTrue ,
1587
+ Reason : v2 .RollbackSucceededReason ,
1588
+ Message : "rollback" ,
1589
+ ObservedGeneration : 1 ,
1590
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1591
+ },
1592
+ },
1593
+ target : v2 .RemediatedCondition ,
1594
+ replacement : v2 .ReleasedCondition ,
1595
+ wantConditions : []metav1.Condition {
1596
+ {
1597
+ Type : v2 .ReleasedCondition ,
1598
+ Status : metav1 .ConditionTrue ,
1599
+ Reason : v2 .UpgradeSucceededReason ,
1600
+ Message : "foo" ,
1601
+ ObservedGeneration : 1 ,
1602
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1603
+ },
1604
+ },
1605
+ },
1606
+ {
1607
+ name : "no existing replacement condition" ,
1608
+ conditions : []metav1.Condition {
1609
+ {
1610
+ Type : v2 .RemediatedCondition ,
1611
+ Status : metav1 .ConditionTrue ,
1612
+ Reason : v2 .RollbackSucceededReason ,
1613
+ Message : "rollback" ,
1614
+ ObservedGeneration : 1 ,
1615
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1616
+ },
1617
+ },
1618
+ target : v2 .RemediatedCondition ,
1619
+ replacement : v2 .ReleasedCondition ,
1620
+ wantConditions : []metav1.Condition {
1621
+ {
1622
+ Type : v2 .ReleasedCondition ,
1623
+ Status : metav1 .ConditionTrue ,
1624
+ Reason : v2 .UpgradeSucceededReason ,
1625
+ Message : "foo" ,
1626
+ ObservedGeneration : 1 ,
1627
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1628
+ },
1629
+ },
1630
+ },
1631
+ {
1632
+ name : "no existing target condition" ,
1633
+ conditions : []metav1.Condition {
1634
+ {
1635
+ Type : v2 .ReleasedCondition ,
1636
+ Status : metav1 .ConditionFalse ,
1637
+ Reason : v2 .UpgradeFailedReason ,
1638
+ Message : "upgrade failed" ,
1639
+ ObservedGeneration : 1 ,
1640
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1641
+ },
1642
+ },
1643
+ target : v2 .RemediatedCondition ,
1644
+ replacement : v2 .ReleasedCondition ,
1645
+ wantConditions : []metav1.Condition {
1646
+ {
1647
+ Type : v2 .ReleasedCondition ,
1648
+ Status : metav1 .ConditionFalse ,
1649
+ Reason : v2 .UpgradeFailedReason ,
1650
+ Message : "upgrade failed" ,
1651
+ ObservedGeneration : 1 ,
1652
+ LastTransitionTime : metav1 .NewTime (timestamp ),
1653
+ },
1654
+ },
1655
+ },
1656
+ {
1657
+ name : "no existing target and replacement conditions" ,
1658
+ target : v2 .RemediatedCondition ,
1659
+ replacement : v2 .ReleasedCondition ,
1660
+ },
1661
+ }
1662
+ for _ , tt := range tests {
1663
+ t .Run (tt .name , func (t * testing.T ) {
1664
+ g := NewWithT (t )
1665
+
1666
+ obj := & v2.HelmRelease {}
1667
+ obj .Generation = 1
1668
+ obj .Status .Conditions = tt .conditions
1669
+ replaceCondition (obj , tt .target , tt .replacement , v2 .UpgradeSucceededReason , "foo" , metav1 .ConditionTrue )
1670
+ g .Expect (obj .Status .Conditions ).To (Equal (tt .wantConditions ))
1516
1671
})
1517
1672
}
1518
1673
}
0 commit comments