@@ -26,6 +26,7 @@ import (
26
26
"k8s.io/apimachinery/pkg/api/errors"
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
28
"k8s.io/apimachinery/pkg/runtime/schema"
29
+ "k8s.io/apimachinery/pkg/types"
29
30
"k8s.io/client-go/kubernetes"
30
31
"k8s.io/client-go/util/retry"
31
32
@@ -154,12 +155,10 @@ func (c *DeploymentController) ScaleToZero(cd *flaggerv1.Canary) error {
154
155
return fmt .Errorf ("deployment %s.%s get query error: %w" , targetName , cd .Namespace , err )
155
156
}
156
157
157
- depCopy := dep .DeepCopy ()
158
- depCopy .Spec .Replicas = int32p (0 )
159
-
160
- _ , err = c .kubeClient .AppsV1 ().Deployments (dep .Namespace ).Update (context .TODO (), depCopy , metav1.UpdateOptions {})
158
+ patch := []byte (fmt .Sprintf (`{"spec":{"replicas": %d}}` , 0 ))
159
+ _ , err = c .kubeClient .AppsV1 ().Deployments (dep .Namespace ).Patch (context .TODO (), dep .GetName (), types .MergePatchType , patch , metav1.PatchOptions {})
161
160
if err != nil {
162
- return fmt .Errorf ("deployment %s.%s update query error: %w" , targetName , cd .Namespace , err )
161
+ return fmt .Errorf ("deployment %s.%s patch query error: %w" , targetName , cd .Namespace , err )
163
162
}
164
163
return nil
165
164
}
@@ -210,12 +209,11 @@ func (c *DeploymentController) ScaleFromZero(cd *flaggerv1.Canary) error {
210
209
}
211
210
}
212
211
}
213
- depCopy := dep .DeepCopy ()
214
- depCopy .Spec .Replicas = replicas
215
212
216
- _ , err = c .kubeClient .AppsV1 ().Deployments (dep .Namespace ).Update (context .TODO (), depCopy , metav1.UpdateOptions {})
213
+ patch := []byte (fmt .Sprintf (`{"spec":{"replicas": %d}}` , * replicas ))
214
+ _ , err = c .kubeClient .AppsV1 ().Deployments (dep .Namespace ).Patch (context .TODO (), dep .GetName (), types .MergePatchType , patch , metav1.PatchOptions {})
217
215
if err != nil {
218
- return fmt .Errorf ("scaling up %s.%s to %v failed: %v" , depCopy .GetName (), depCopy .Namespace , replicas , err )
216
+ return fmt .Errorf ("scaling up %s.%s to %d failed: %v" , dep .GetName (), dep .Namespace , * replicas , err )
219
217
}
220
218
return nil
221
219
}
@@ -388,11 +386,10 @@ func (c *DeploymentController) scale(cd *flaggerv1.Canary, replicas int32) error
388
386
return fmt .Errorf ("deployment %s.%s query error: %w" , targetName , cd .Namespace , err )
389
387
}
390
388
391
- depCopy := dep .DeepCopy ()
392
- depCopy .Spec .Replicas = int32p (replicas )
393
- _ , err = c .kubeClient .AppsV1 ().Deployments (dep .Namespace ).Update (context .TODO (), depCopy , metav1.UpdateOptions {})
389
+ patch := []byte (fmt .Sprintf (`{"spec":{"replicas": %d}}` , replicas ))
390
+ _ , err = c .kubeClient .AppsV1 ().Deployments (dep .Namespace ).Patch (context .TODO (), dep .GetName (), types .MergePatchType , patch , metav1.PatchOptions {})
394
391
if err != nil {
395
- return fmt .Errorf ("scaling %s.%s to %v failed: %w" , depCopy .GetName (), depCopy .Namespace , replicas , err )
392
+ return fmt .Errorf ("scaling %s.%s to %d failed: %w" , dep .GetName (), dep .Namespace , replicas , err )
396
393
}
397
394
return nil
398
395
}
0 commit comments