@@ -40,6 +40,7 @@ import (
4040 "k8s.io/apimachinery/pkg/types"
4141 "k8s.io/apimachinery/pkg/watch"
4242 "k8s.io/client-go/kubernetes/fake"
43+ "k8s.io/utils/pointer"
4344
4445 "sigs.k8s.io/controller-runtime/pkg/client"
4546 "sigs.k8s.io/controller-runtime/pkg/client/interceptor"
@@ -1590,6 +1591,28 @@ var _ = Describe("Fake client", func() {
15901591 Expect (objOriginal .Status .Phase ).ToNot (Equal (actual .Status .Phase ))
15911592 })
15921593
1594+ It ("should be able to change typed objects that have a scale subresource on patch" , func () {
1595+ obj := & appsv1.Deployment {
1596+ ObjectMeta : metav1.ObjectMeta {
1597+ Name : "deploy" ,
1598+ },
1599+ }
1600+ cl := NewClientBuilder ().WithObjects (obj ).Build ()
1601+ objOriginal := obj .DeepCopy ()
1602+
1603+ patch := []byte (fmt .Sprintf (`{"spec":{"replicas":%d}}` , 2 ))
1604+ Expect (cl .SubResource ("scale" ).Patch (context .Background (), obj , client .RawPatch (types .MergePatchType , patch ))).NotTo (HaveOccurred ())
1605+
1606+ actual := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : obj .Name }}
1607+ Expect (cl .Get (context .Background (), client .ObjectKeyFromObject (actual ), actual )).To (Succeed ())
1608+
1609+ objOriginal .APIVersion = actual .APIVersion
1610+ objOriginal .Kind = actual .Kind
1611+ objOriginal .ResourceVersion = actual .ResourceVersion
1612+ objOriginal .Spec .Replicas = pointer .Int32 (2 )
1613+ Expect (cmp .Diff (objOriginal , actual )).To (BeEmpty ())
1614+ })
1615+
15931616 It ("should not change the status of typed objects that have a status subresource on patch" , func () {
15941617 obj := & corev1.Pod {
15951618 ObjectMeta : metav1.ObjectMeta {
0 commit comments