@@ -2939,6 +2939,40 @@ var _ = Describe("Fake client", func() {
29392939 Expect (result .Object ["spec" ]).To (Equal (map [string ]any {"other" : "data" }))
29402940 })
29412941
2942+ It ("supports server-side apply of a custom resource via Apply method after List with a non-list kind" , func (ctx SpecContext ) {
2943+ cl := NewClientBuilder ().Build ()
2944+
2945+ // Previously this List call lead to addToSchemeIfUnknownAndUnstructuredOrPartial adding FakeResource as UnstructuredList to the scheme.
2946+ // This broke the subsequent SSA call as it was trying to create a new FakeResource object as an UnstructuredList.
2947+ // After a fix this List call leads to addToSchemeIfUnknownAndUnstructuredOrPartial adding FakeResourceList as UnstructuredList to the
2948+ // scheme even if the UnstructuredList here is missing the List suffix.
2949+ objList := & unstructured.UnstructuredList {}
2950+ objList .SetAPIVersion ("custom/v1" )
2951+ objList .SetKind ("FakeResource" )
2952+ Expect (cl .List (ctx , objList )).To (Succeed ())
2953+
2954+ obj := & unstructured.Unstructured {}
2955+ obj .SetAPIVersion ("custom/v1" )
2956+ obj .SetKind ("FakeResource" )
2957+ obj .SetName ("foo" )
2958+ result := obj .DeepCopy ()
2959+
2960+ Expect (unstructured .SetNestedField (obj .Object , map [string ]any {"some" : "data" }, "spec" )).To (Succeed ())
2961+
2962+ applyConfig := client .ApplyConfigurationFromUnstructured (obj )
2963+ Expect (cl .Apply (ctx , applyConfig , & client.ApplyOptions {FieldManager : "test-manager" })).To (Succeed ())
2964+
2965+ Expect (cl .Get (ctx , client .ObjectKeyFromObject (result ), result )).To (Succeed ())
2966+ Expect (result .Object ["spec" ]).To (Equal (map [string ]any {"some" : "data" }))
2967+
2968+ Expect (unstructured .SetNestedField (obj .Object , map [string ]any {"other" : "data" }, "spec" )).To (Succeed ())
2969+ applyConfig2 := client .ApplyConfigurationFromUnstructured (obj )
2970+ Expect (cl .Apply (ctx , applyConfig2 , & client.ApplyOptions {FieldManager : "test-manager" })).To (Succeed ())
2971+
2972+ Expect (cl .Get (ctx , client .ObjectKeyFromObject (result ), result )).To (Succeed ())
2973+ Expect (result .Object ["spec" ]).To (Equal (map [string ]any {"other" : "data" }))
2974+ })
2975+
29422976 It ("sets the fieldManager in create, patch and update" , func (ctx SpecContext ) {
29432977 owner := "test-owner"
29442978 cl := client .WithFieldOwner (
0 commit comments