@@ -45,6 +45,11 @@ import (
4545 "sigs.k8s.io/controller-runtime/pkg/client/interceptor"
4646)
4747
48+ const (
49+ machineIDFromStatusUpdate = "machine-id-from-status-update"
50+ cidrFromStatusUpdate = "cidr-from-status-update"
51+ )
52+
4853var _ = Describe ("Fake client" , func () {
4954 var dep * appsv1.Deployment
5055 var dep2 * appsv1.Deployment
@@ -1456,15 +1461,15 @@ var _ = Describe("Fake client", func() {
14561461 cl := NewClientBuilder ().WithStatusSubresource (obj ).WithObjects (obj ).Build ()
14571462 objOriginal := obj .DeepCopy ()
14581463
1459- obj .Spec .PodCIDR = "cidr-from-status-update"
1464+ obj .Spec .PodCIDR = cidrFromStatusUpdate
14601465 obj .Annotations = map [string ]string {
14611466 "some-annotation-key" : "some-annotation-value" ,
14621467 }
14631468 obj .Labels = map [string ]string {
14641469 "some-label-key" : "some-label-value" ,
14651470 }
14661471
1467- obj .Status .NodeInfo .MachineID = "machine-id-from-status-update"
1472+ obj .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
14681473 Expect (cl .Status ().Update (context .Background (), obj )).NotTo (HaveOccurred ())
14691474
14701475 actual := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : obj .Name }}
@@ -1473,9 +1478,87 @@ var _ = Describe("Fake client", func() {
14731478 objOriginal .APIVersion = actual .APIVersion
14741479 objOriginal .Kind = actual .Kind
14751480 objOriginal .ResourceVersion = actual .ResourceVersion
1476- objOriginal .Status .NodeInfo .MachineID = "machine-id-from-status-update"
1481+ objOriginal .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
14771482 Expect (cmp .Diff (objOriginal , actual )).To (BeEmpty ())
14781483 })
1484+
1485+ It ("should be able to update an object after updating an object's status" , func () {
1486+ obj := & corev1.Node {
1487+ ObjectMeta : metav1.ObjectMeta {
1488+ Name : "node" ,
1489+ },
1490+ Spec : corev1.NodeSpec {
1491+ PodCIDR : "old-cidr" ,
1492+ },
1493+ Status : corev1.NodeStatus {
1494+ NodeInfo : corev1.NodeSystemInfo {
1495+ MachineID : "machine-id" ,
1496+ },
1497+ },
1498+ }
1499+ cl := NewClientBuilder ().WithStatusSubresource (obj ).WithObjects (obj ).Build ()
1500+ expectedObj := obj .DeepCopy ()
1501+
1502+ obj .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
1503+ Expect (cl .Status ().Update (context .Background (), obj )).NotTo (HaveOccurred ())
1504+
1505+ obj .Annotations = map [string ]string {
1506+ "some-annotation-key" : "some" ,
1507+ }
1508+ expectedObj .Annotations = map [string ]string {
1509+ "some-annotation-key" : "some" ,
1510+ }
1511+ Expect (cl .Update (context .Background (), obj )).NotTo (HaveOccurred ())
1512+
1513+ actual := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : obj .Name }}
1514+ Expect (cl .Get (context .Background (), client .ObjectKeyFromObject (actual ), actual )).NotTo (HaveOccurred ())
1515+
1516+ expectedObj .APIVersion = actual .APIVersion
1517+ expectedObj .Kind = actual .Kind
1518+ expectedObj .ResourceVersion = actual .ResourceVersion
1519+ expectedObj .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
1520+ Expect (cmp .Diff (expectedObj , actual )).To (BeEmpty ())
1521+ })
1522+
1523+ It ("should be able to update an object's status after updating an object" , func () {
1524+ obj := & corev1.Node {
1525+ ObjectMeta : metav1.ObjectMeta {
1526+ Name : "node" ,
1527+ },
1528+ Spec : corev1.NodeSpec {
1529+ PodCIDR : "old-cidr" ,
1530+ },
1531+ Status : corev1.NodeStatus {
1532+ NodeInfo : corev1.NodeSystemInfo {
1533+ MachineID : "machine-id" ,
1534+ },
1535+ },
1536+ }
1537+ cl := NewClientBuilder ().WithStatusSubresource (obj ).WithObjects (obj ).Build ()
1538+ expectedObj := obj .DeepCopy ()
1539+
1540+ obj .Annotations = map [string ]string {
1541+ "some-annotation-key" : "some" ,
1542+ }
1543+ expectedObj .Annotations = map [string ]string {
1544+ "some-annotation-key" : "some" ,
1545+ }
1546+ Expect (cl .Update (context .Background (), obj )).NotTo (HaveOccurred ())
1547+
1548+ obj .Spec .PodCIDR = cidrFromStatusUpdate
1549+ obj .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
1550+ Expect (cl .Status ().Update (context .Background (), obj )).NotTo (HaveOccurred ())
1551+
1552+ actual := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : obj .Name }}
1553+ Expect (cl .Get (context .Background (), client .ObjectKeyFromObject (actual ), actual )).NotTo (HaveOccurred ())
1554+
1555+ expectedObj .APIVersion = actual .APIVersion
1556+ expectedObj .Kind = actual .Kind
1557+ expectedObj .ResourceVersion = actual .ResourceVersion
1558+ expectedObj .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
1559+ Expect (cmp .Diff (expectedObj , actual )).To (BeEmpty ())
1560+ })
1561+
14791562 It ("Should only override status fields of typed objects that have a status subresource on status update" , func () {
14801563 obj := & corev1.Node {
14811564 ObjectMeta : metav1.ObjectMeta {
@@ -1536,7 +1619,7 @@ var _ = Describe("Fake client", func() {
15361619 cl := NewClientBuilder ().WithStatusSubresource (obj ).WithObjects (obj ).Build ()
15371620 objOriginal := obj .DeepCopy ()
15381621
1539- obj .Spec .PodCIDR = "cidr-from-status-update"
1622+ obj .Spec .PodCIDR = cidrFromStatusUpdate
15401623 obj .Status .NodeInfo .MachineID = "machine-id"
15411624 Expect (cl .Status ().Patch (context .Background (), obj , client .MergeFrom (objOriginal ))).NotTo (HaveOccurred ())
15421625
0 commit comments