@@ -1689,38 +1689,95 @@ var _ = Describe("Node Health Check CR", func() {
1689
1689
When ("Nodes are candidates for remediation and cluster is upgrading" , func () {
1690
1690
BeforeEach (func () {
1691
1691
clusterUpgradeRequeueAfter = 5 * time .Second
1692
- upgradeChecker .Upgrading = true
1693
1692
setupObjects (1 , 2 , true )
1694
1693
})
1694
+ When ("non HCP Upgrade" , func () {
1695
+ BeforeEach (func () {
1696
+ upgradeChecker .Upgrading = true
1697
+ })
1695
1698
1696
- AfterEach (func () {
1697
- upgradeChecker .Upgrading = false
1698
- })
1699
+ AfterEach (func () {
1700
+ upgradeChecker .Upgrading = false
1701
+ })
1699
1702
1700
- It ("doesn't not remediate but requeues reconciliation and updates status" , func () {
1701
- cr := findRemediationCRForNHC (unhealthyNodeName , underTest )
1702
- Expect (cr ).To (BeNil ())
1703
+ It ("doesn't not remediate but requeues reconciliation and updates status" , func () {
1704
+ cr := findRemediationCRForNHC (unhealthyNodeName , underTest )
1705
+ Expect (cr ).To (BeNil ())
1703
1706
1704
- Expect (* underTest .Status .HealthyNodes ).To (Equal (0 ))
1705
- Expect (* underTest .Status .ObservedNodes ).To (Equal (0 ))
1706
- Expect (underTest .Status .UnhealthyNodes ).To (BeEmpty ())
1707
- Expect (underTest .Status .Phase ).To (Equal (v1alpha1 .PhaseEnabled ))
1708
- Expect (underTest .Status .Reason ).ToNot (BeEmpty ())
1707
+ Expect (* underTest .Status .HealthyNodes ).To (Equal (0 ))
1708
+ Expect (* underTest .Status .ObservedNodes ).To (Equal (0 ))
1709
+ Expect (underTest .Status .UnhealthyNodes ).To (BeEmpty ())
1710
+ Expect (underTest .Status .Phase ).To (Equal (v1alpha1 .PhaseEnabled ))
1711
+ Expect (underTest .Status .Reason ).ToNot (BeEmpty ())
1709
1712
1710
- By ("stopping upgrade and waiting for requeue" )
1711
- upgradeChecker .Upgrading = false
1712
- time .Sleep (10 * time .Second )
1713
- cr = findRemediationCRForNHC (unhealthyNodeName , underTest )
1714
- Expect (cr ).ToNot (BeNil ())
1713
+ By ("stopping upgrade and waiting for requeue" )
1714
+ upgradeChecker .Upgrading = false
1715
+ time .Sleep (10 * time .Second )
1716
+ cr = findRemediationCRForNHC (unhealthyNodeName , underTest )
1717
+ Expect (cr ).ToNot (BeNil ())
1718
+
1719
+ Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (underTest ), underTest )).To (Succeed ())
1720
+ Expect (* underTest .Status .HealthyNodes ).To (Equal (2 ))
1721
+ Expect (* underTest .Status .ObservedNodes ).To (Equal (3 ))
1722
+ Expect (underTest .Status .UnhealthyNodes ).To (HaveLen (1 ))
1723
+ })
1715
1724
1716
- Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (underTest ), underTest )).To (Succeed ())
1717
- Expect (* underTest .Status .HealthyNodes ).To (Equal (2 ))
1718
- Expect (* underTest .Status .ObservedNodes ).To (Equal (3 ))
1719
- Expect (underTest .Status .UnhealthyNodes ).To (HaveLen (1 ))
1720
1725
})
1726
+ When ("HCP Upgrade" , func () {
1727
+ var currentMachineConfigAnnotationKey = "machineconfiguration.openshift.io/currentConfig"
1728
+ var desiredMachineConfigAnnotationKey = "machineconfiguration.openshift.io/desiredConfig"
1729
+ BeforeEach (func () {
1730
+ //Use a real upgrade checker instead of mock
1731
+ prevUpgradeChecker := nhcReconciler .ClusterUpgradeStatusChecker
1732
+ nhcReconciler .ClusterUpgradeStatusChecker = ocpUpgradeChecker
1733
+ DeferCleanup (func () {
1734
+ nhcReconciler .ClusterUpgradeStatusChecker = prevUpgradeChecker
1735
+ })
1721
1736
1722
- })
1737
+ //Simulate HCP Upgrade on the unhealthy node
1738
+ upgradingNode := objects [0 ]
1739
+ upgradingNodeAnnotations := map [string ]string {}
1740
+ if upgradingNode .GetAnnotations () != nil {
1741
+ upgradingNodeAnnotations = upgradingNode .GetAnnotations ()
1742
+ }
1743
+ upgradingNodeAnnotations [currentMachineConfigAnnotationKey ] = "fakeVersion1"
1744
+ upgradingNodeAnnotations [desiredMachineConfigAnnotationKey ] = "fakeVersion2"
1745
+ upgradingNode .SetAnnotations (upgradingNodeAnnotations )
1746
+
1747
+ })
1748
+
1749
+ It ("doesn't not remediate but requeues reconciliation and updates status" , func () {
1750
+
1751
+ cr := findRemediationCRForNHC (unhealthyNodeName , underTest )
1752
+ Expect (cr ).To (BeNil ())
1753
+
1754
+ Expect (* underTest .Status .HealthyNodes ).To (Equal (0 ))
1755
+ Expect (* underTest .Status .ObservedNodes ).To (Equal (0 ))
1756
+ Expect (underTest .Status .UnhealthyNodes ).To (BeEmpty ())
1757
+ Expect (underTest .Status .Phase ).To (Equal (v1alpha1 .PhaseEnabled ))
1758
+ Expect (underTest .Status .Reason ).ToNot (BeEmpty ())
1723
1759
1760
+ By ("stopping upgrade and waiting for requeue" )
1761
+ unhealthyNode := & v1.Node {ObjectMeta : metav1.ObjectMeta {Name : unhealthyNodeName }}
1762
+ Expect (k8sClient .Get (context .TODO (), client .ObjectKeyFromObject (unhealthyNode ), unhealthyNode )).To (Succeed ())
1763
+ if unhealthyNode .GetAnnotations ()[currentMachineConfigAnnotationKey ] != unhealthyNode .GetAnnotations ()[desiredMachineConfigAnnotationKey ] {
1764
+ // Simulating upgrade complete.
1765
+ unhealthyNode .Annotations [currentMachineConfigAnnotationKey ] = unhealthyNode .GetAnnotations ()[desiredMachineConfigAnnotationKey ]
1766
+ Expect (k8sClient .Update (context .TODO (), unhealthyNode )).To (Succeed ())
1767
+ }
1768
+
1769
+ time .Sleep (10 * time .Second )
1770
+ cr = findRemediationCRForNHC (unhealthyNodeName , underTest )
1771
+ Expect (cr ).ToNot (BeNil ())
1772
+
1773
+ Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (underTest ), underTest )).To (Succeed ())
1774
+ Expect (* underTest .Status .HealthyNodes ).To (Equal (2 ))
1775
+ Expect (* underTest .Status .ObservedNodes ).To (Equal (3 ))
1776
+ Expect (underTest .Status .UnhealthyNodes ).To (HaveLen (1 ))
1777
+ })
1778
+
1779
+ })
1780
+ })
1724
1781
Context ("Machine owners" , func () {
1725
1782
When ("Metal3RemediationTemplate is in correct namespace" , func () {
1726
1783
0 commit comments