@@ -45,6 +45,11 @@ import (
45
45
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"
46
46
)
47
47
48
+ const (
49
+ machineIDFromStatusUpdate = "machine-id-from-status-update"
50
+ cidrFromStatusUpdate = "cidr-from-status-update"
51
+ )
52
+
48
53
var _ = Describe ("Fake client" , func () {
49
54
var dep * appsv1.Deployment
50
55
var dep2 * appsv1.Deployment
@@ -1456,15 +1461,15 @@ var _ = Describe("Fake client", func() {
1456
1461
cl := NewClientBuilder ().WithStatusSubresource (obj ).WithObjects (obj ).Build ()
1457
1462
objOriginal := obj .DeepCopy ()
1458
1463
1459
- obj .Spec .PodCIDR = "cidr-from-status-update"
1464
+ obj .Spec .PodCIDR = cidrFromStatusUpdate
1460
1465
obj .Annotations = map [string ]string {
1461
1466
"some-annotation-key" : "some-annotation-value" ,
1462
1467
}
1463
1468
obj .Labels = map [string ]string {
1464
1469
"some-label-key" : "some-label-value" ,
1465
1470
}
1466
1471
1467
- obj .Status .NodeInfo .MachineID = "machine-id-from-status-update"
1472
+ obj .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
1468
1473
Expect (cl .Status ().Update (context .Background (), obj )).NotTo (HaveOccurred ())
1469
1474
1470
1475
actual := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : obj .Name }}
@@ -1473,9 +1478,87 @@ var _ = Describe("Fake client", func() {
1473
1478
objOriginal .APIVersion = actual .APIVersion
1474
1479
objOriginal .Kind = actual .Kind
1475
1480
objOriginal .ResourceVersion = actual .ResourceVersion
1476
- objOriginal .Status .NodeInfo .MachineID = "machine-id-from-status-update"
1481
+ objOriginal .Status .NodeInfo .MachineID = machineIDFromStatusUpdate
1477
1482
Expect (cmp .Diff (objOriginal , actual )).To (BeEmpty ())
1478
1483
})
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
+
1479
1562
It ("Should only override status fields of typed objects that have a status subresource on status update" , func () {
1480
1563
obj := & corev1.Node {
1481
1564
ObjectMeta : metav1.ObjectMeta {
@@ -1536,7 +1619,7 @@ var _ = Describe("Fake client", func() {
1536
1619
cl := NewClientBuilder ().WithStatusSubresource (obj ).WithObjects (obj ).Build ()
1537
1620
objOriginal := obj .DeepCopy ()
1538
1621
1539
- obj .Spec .PodCIDR = "cidr-from-status-update"
1622
+ obj .Spec .PodCIDR = cidrFromStatusUpdate
1540
1623
obj .Status .NodeInfo .MachineID = "machine-id"
1541
1624
Expect (cl .Status ().Patch (context .Background (), obj , client .MergeFrom (objOriginal ))).NotTo (HaveOccurred ())
1542
1625
0 commit comments