@@ -40,6 +40,7 @@ import (
40
40
"k8s.io/apimachinery/pkg/types"
41
41
"k8s.io/apimachinery/pkg/watch"
42
42
"k8s.io/client-go/kubernetes/fake"
43
+ "k8s.io/utils/pointer"
43
44
44
45
"sigs.k8s.io/controller-runtime/pkg/client"
45
46
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"
@@ -1590,6 +1591,28 @@ var _ = Describe("Fake client", func() {
1590
1591
Expect (objOriginal .Status .Phase ).ToNot (Equal (actual .Status .Phase ))
1591
1592
})
1592
1593
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
+
1593
1616
It ("should not change the status of typed objects that have a status subresource on patch" , func () {
1594
1617
obj := & corev1.Pod {
1595
1618
ObjectMeta : metav1.ObjectMeta {
0 commit comments