@@ -1687,11 +1687,13 @@ var _ = Describe("Node Health Check CR", func() {
1687
1687
})
1688
1688
1689
1689
When ("Nodes are candidates for remediation and cluster is upgrading" , func () {
1690
+ BeforeEach (func () {
1691
+ clusterUpgradeRequeueAfter = 5 * time .Second
1692
+ setupObjects (1 , 2 , true )
1693
+ })
1690
1694
When ("non HCP Upgrade" , func () {
1691
1695
BeforeEach (func () {
1692
- clusterUpgradeRequeueAfter = 5 * time .Second
1693
1696
upgradeChecker .Upgrading = true
1694
- setupObjects (1 , 2 , true )
1695
1697
})
1696
1698
1697
1699
AfterEach (func () {
@@ -1722,49 +1724,31 @@ var _ = Describe("Node Health Check CR", func() {
1722
1724
1723
1725
})
1724
1726
When ("HCP Upgrade" , func () {
1725
- var unhealthyCPNodeName string
1727
+ var currentMachineConfigAnnotationKey = "machineconfiguration.openshift.io/currentConfig"
1728
+ var desiredMachineConfigAnnotationKey = "machineconfiguration.openshift.io/desiredConfig"
1726
1729
BeforeEach (func () {
1727
- clusterUpgradeRequeueAfter = 5 * time .Second
1728
- objects = newNodes (1 , 0 , true , true )
1729
- cpNode := objects [0 ]
1730
- objects = append (objects , newNodes (0 , 2 , false , false )... )
1731
- objects = append (objects , underTest )
1732
- unhealthyCPNodeName = cpNode .GetName ()
1733
- cpNodeAnnotations := map [string ]string {}
1734
- if cpNode .GetAnnotations () != nil {
1735
- cpNodeAnnotations = cpNode .GetAnnotations ()
1736
- }
1737
- cpNodeAnnotations [currentMachineConfigAnnotationKey ] = "fakeVersion1"
1738
- cpNodeAnnotations [desiredMachineConfigAnnotationKey ] = "fakeVersion2"
1739
- cpNode .SetAnnotations (cpNodeAnnotations )
1740
-
1741
- //Mock PDB in order to allow creation of CP remediation
1742
- etcdNs := & v1.Namespace {
1743
- ObjectMeta : metav1.ObjectMeta {
1744
- Name : "openshift-etcd" ,
1745
- },
1746
- Spec : v1.NamespaceSpec {},
1747
- }
1748
- err := k8sClient .Create (context .Background (), etcdNs )
1749
- if err != nil {
1750
- Expect (errors .IsAlreadyExists (err )).To (BeTrue ())
1751
- }
1752
-
1753
- pdb := & policyv1.PodDisruptionBudget {}
1754
- pdb .Namespace = etcdNs .Name
1755
- pdb .Name = "mockPDB"
1756
- Expect (k8sClient .Create (context .TODO (), pdb )).To (Succeed ())
1757
- pdb .Status .DisruptionsAllowed = 1
1758
- Expect (k8sClient .Status ().Update (context .TODO (), pdb )).To (Succeed ())
1730
+ //Use a real upgrade checker instead of mock
1731
+ prevUpgradeChecker := nhcReconciler .ClusterUpgradeStatusChecker
1732
+ nhcReconciler .ClusterUpgradeStatusChecker = ocpUpgradeChecker
1759
1733
DeferCleanup (func () {
1760
- Expect ( k8sClient . Delete ( context . TODO (), pdb )). To ( Succeed ())
1734
+ nhcReconciler . ClusterUpgradeStatusChecker = prevUpgradeChecker
1761
1735
})
1762
1736
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
+
1763
1747
})
1764
1748
1765
1749
It ("doesn't not remediate but requeues reconciliation and updates status" , func () {
1766
1750
1767
- cr := findRemediationCRForNHC (unhealthyCPNodeName , underTest )
1751
+ cr := findRemediationCRForNHC (unhealthyNodeName , underTest )
1768
1752
Expect (cr ).To (BeNil ())
1769
1753
1770
1754
Expect (* underTest .Status .HealthyNodes ).To (Equal (0 ))
@@ -1774,20 +1758,16 @@ var _ = Describe("Node Health Check CR", func() {
1774
1758
Expect (underTest .Status .Reason ).ToNot (BeEmpty ())
1775
1759
1776
1760
By ("stopping upgrade and waiting for requeue" )
1777
- nodeList := v1.NodeList {}
1778
- Expect (k8sClient .List (context .TODO (), & nodeList )).To (Succeed ())
1779
- for _ , node := range nodeList .Items {
1780
- if len (node .GetAnnotations ()) == 0 {
1781
- continue
1782
- }
1783
- if node .GetAnnotations ()[currentMachineConfigAnnotationKey ] != node .GetAnnotations ()[desiredMachineConfigAnnotationKey ] {
1784
- node .Annotations [currentMachineConfigAnnotationKey ] = node .GetAnnotations ()[desiredMachineConfigAnnotationKey ]
1785
- Expect (k8sClient .Update (context .TODO (), & node )).To (Succeed ())
1786
- }
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 ())
1787
1767
}
1788
1768
1789
1769
time .Sleep (10 * time .Second )
1790
- cr = findRemediationCRForNHC (unhealthyCPNodeName , underTest )
1770
+ cr = findRemediationCRForNHC (unhealthyNodeName , underTest )
1791
1771
Expect (cr ).ToNot (BeNil ())
1792
1772
1793
1773
Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (underTest ), underTest )).To (Succeed ())
0 commit comments