@@ -1552,6 +1552,63 @@ func TestAtomicRelease_actionForState(t *testing.T) {
15521552 * conditions .FalseCondition (meta .ReadyCondition , v2 .UpgradeFailedReason , "upgrade failed" ),
15531553 },
15541554 },
1555+ {
1556+ name : "in-sync release with drift detection enabled sets Drifted condition to false" ,
1557+ spec : func (spec * v2.HelmReleaseSpec ) {
1558+ spec .DriftDetection = & v2.DriftDetection {
1559+ Mode : v2 .DriftDetectionEnabled ,
1560+ }
1561+ },
1562+ status : func (releases []* helmrelease.Release ) v2.HelmReleaseStatus {
1563+ return v2.HelmReleaseStatus {
1564+ History : v2.Snapshots {
1565+ {Version : 1 },
1566+ },
1567+ }
1568+ },
1569+ state : ReleaseState {Status : ReleaseStatusInSync },
1570+ want : nil ,
1571+ assertConditions : []metav1.Condition {
1572+ * conditions .FalseCondition (v2 .DriftedCondition , v2 .NoDriftDetectedReason , "No drift detected against the cluster state" ),
1573+ },
1574+ },
1575+ {
1576+ name : "in-sync release with drift detection warn sets Drifted condition to false" ,
1577+ spec : func (spec * v2.HelmReleaseSpec ) {
1578+ spec .DriftDetection = & v2.DriftDetection {
1579+ Mode : v2 .DriftDetectionWarn ,
1580+ }
1581+ },
1582+ status : func (releases []* helmrelease.Release ) v2.HelmReleaseStatus {
1583+ return v2.HelmReleaseStatus {
1584+ History : v2.Snapshots {
1585+ {Version : 1 },
1586+ },
1587+ }
1588+ },
1589+ state : ReleaseState {Status : ReleaseStatusInSync },
1590+ want : nil ,
1591+ assertConditions : []metav1.Condition {
1592+ * conditions .FalseCondition (v2 .DriftedCondition , v2 .NoDriftDetectedReason , "No drift detected against the cluster state" ),
1593+ },
1594+ },
1595+ {
1596+ name : "in-sync release with drift detection disabled does not set Drifted condition" ,
1597+ spec : func (spec * v2.HelmReleaseSpec ) {
1598+ spec .DriftDetection = & v2.DriftDetection {
1599+ Mode : v2 .DriftDetectionDisabled ,
1600+ }
1601+ },
1602+ status : func (releases []* helmrelease.Release ) v2.HelmReleaseStatus {
1603+ return v2.HelmReleaseStatus {
1604+ History : v2.Snapshots {
1605+ {Version : 1 },
1606+ },
1607+ }
1608+ },
1609+ state : ReleaseState {Status : ReleaseStatusInSync },
1610+ want : nil ,
1611+ },
15551612 {
15561613 name : "locked release triggers unlock action" ,
15571614 state : ReleaseState {Status : ReleaseStatusLocked },
@@ -1634,6 +1691,9 @@ func TestAtomicRelease_actionForState(t *testing.T) {
16341691 "Deployment/something/mock removed" ,
16351692 ),
16361693 },
1694+ assertConditions : []metav1.Condition {
1695+ * conditions .TrueCondition (v2 .DriftedCondition , v2 .DriftDetectedReason , "Cluster state of release mock-ns/mock-release.v1 has drifted from the desired state:\n Deployment/something/mock removed" ),
1696+ },
16371697 },
16381698 {
16391699 name : "drifted release only triggers event if mode is warn" ,
@@ -1703,6 +1763,81 @@ func TestAtomicRelease_actionForState(t *testing.T) {
17031763 "Deployment/something/mock changed (0 additions, 1 changes, 0 removals)" ,
17041764 ),
17051765 },
1766+ assertConditions : []metav1.Condition {
1767+ * conditions .TrueCondition (v2 .DriftedCondition , v2 .DriftDetectedReason , "Cluster state of release mock-ns/mock-release.v1 has drifted from the desired state:\n Deployment/something/mock changed (0 additions, 1 changes, 0 removals)" ),
1768+ },
1769+ },
1770+ {
1771+ name : "drifted release sets Drifted condition if mode is warn" ,
1772+ spec : func (spec * v2.HelmReleaseSpec ) {
1773+ spec .DriftDetection = & v2.DriftDetection {
1774+ Mode : v2 .DriftDetectionWarn ,
1775+ }
1776+ },
1777+ status : func (releases []* helmrelease.Release ) v2.HelmReleaseStatus {
1778+ return v2.HelmReleaseStatus {
1779+ History : v2.Snapshots {
1780+ {
1781+ Name : mockReleaseName ,
1782+ Namespace : mockReleaseNamespace ,
1783+ Version : 1 ,
1784+ },
1785+ },
1786+ }
1787+ },
1788+ state : ReleaseState {Status : ReleaseStatusDrifted , Diff : jsondiff.DiffSet {
1789+ {
1790+ Type : jsondiff .DiffTypeUpdate ,
1791+ DesiredObject : & unstructured.Unstructured {
1792+ Object : map [string ]interface {}{
1793+ "apiVersion" : "apps/v1" ,
1794+ "kind" : "Deployment" ,
1795+ "metadata" : map [string ]interface {}{
1796+ "name" : "mock" ,
1797+ "namespace" : "something" ,
1798+ },
1799+ "spec" : map [string ]interface {}{
1800+ "replicas" : 2 ,
1801+ },
1802+ },
1803+ },
1804+ ClusterObject : & unstructured.Unstructured {
1805+ Object : map [string ]interface {}{
1806+ "apiVersion" : "apps/v1" ,
1807+ "kind" : "Deployment" ,
1808+ "metadata" : map [string ]interface {}{
1809+ "name" : "mock" ,
1810+ "namespace" : "something" ,
1811+ },
1812+ "spec" : map [string ]interface {}{
1813+ "replicas" : 1 ,
1814+ },
1815+ },
1816+ },
1817+ Patch : extjsondiff.Patch {
1818+ {
1819+ Type : extjsondiff .OperationReplace ,
1820+ Path : "/spec/replicas" ,
1821+ OldValue : 1 ,
1822+ Value : 2 ,
1823+ },
1824+ },
1825+ },
1826+ }},
1827+ want : nil ,
1828+ wantErr : nil ,
1829+ wantEvent : & corev1.Event {
1830+ Reason : "DriftDetected" ,
1831+ Type : corev1 .EventTypeWarning ,
1832+ Message : fmt .Sprintf (
1833+ "Cluster state of release %s has drifted from the desired state:\n %s" ,
1834+ mockReleaseNamespace + "/" + mockReleaseName + ".v1" ,
1835+ "Deployment/something/mock changed (0 additions, 1 changes, 0 removals)" ,
1836+ ),
1837+ },
1838+ assertConditions : []metav1.Condition {
1839+ * conditions .TrueCondition (v2 .DriftedCondition , v2 .DriftDetectedReason , "Cluster state of release mock-ns/mock-release.v1 has drifted from the desired state:\n Deployment/something/mock changed (0 additions, 1 changes, 0 removals)" ),
1840+ },
17061841 },
17071842 {
17081843 name : "out-of-sync release triggers upgrade" ,
0 commit comments