@@ -1834,6 +1834,41 @@ var _ = Describe("Fake client", func() {
18341834 Expect (initial ).To (BeComparableTo (actual ))
18351835 })
18361836
1837+ // https://github.com/kubernetes-sigs/controller-runtime/issues/3423
1838+ It ("should be able to status apply existing objects that have managedFields set" , func (ctx SpecContext ) {
1839+ cl := NewClientBuilder ().WithStatusSubresource (& corev1.Node {}).Build ()
1840+ node := corev1applyconfigurations .Node ("a-node" ).
1841+ WithSpec (corev1applyconfigurations .NodeSpec ().WithPodCIDR ("some-value" ))
1842+ Expect (cl .Apply (ctx , node , client .FieldOwner ("test-owner" ))).To (Succeed ())
1843+
1844+ node = node .
1845+ WithStatus (corev1applyconfigurations .NodeStatus ().WithPhase (corev1 .NodeRunning ))
1846+
1847+ Expect (cl .Status ().Apply (ctx , node , client .FieldOwner ("test-owner" ))).To (Succeed ())
1848+ })
1849+
1850+ It ("should not be able to manually update the fieldManager through a status update" , func (ctx SpecContext ) {
1851+ node := & corev1.Node {
1852+ ObjectMeta : metav1.ObjectMeta {
1853+ Name : "node" ,
1854+ },
1855+ Spec : corev1.NodeSpec {
1856+ PodCIDR : "old-cidr" ,
1857+ },
1858+ }
1859+ cl := NewClientBuilder ().WithStatusSubresource (& corev1.Node {}).WithObjects (node ).WithReturnManagedFields ().Build ()
1860+ node .Spec .PodCIDR = "new-cidr"
1861+ Expect (cl .Update (ctx , node , client .FieldOwner ("spec-owner" ))).To (Succeed ())
1862+
1863+ node .ManagedFields = []metav1.ManagedFieldsEntry {{}}
1864+ node .Status .Phase = corev1 .NodeRunning
1865+
1866+ Expect (cl .Status ().Update (ctx , node , client .FieldOwner ("status-owner" ))).To (Succeed ())
1867+ Expect (node .ManagedFields ).To (HaveLen (2 ))
1868+ Expect (node .ManagedFields [0 ].Manager ).To (Equal ("spec-owner" ))
1869+ Expect (node .ManagedFields [1 ].Manager ).To (Equal ("status-owner" ))
1870+ })
1871+
18371872 It ("should Unmarshal the schemaless object with int64 to preserve ints" , func (ctx SpecContext ) {
18381873 schemeBuilder := & scheme.Builder {GroupVersion : schema.GroupVersion {Group : "test" , Version : "v1" }}
18391874 schemeBuilder .Register (& WithSchemalessSpec {})
0 commit comments