@@ -19,6 +19,7 @@ package framework
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "reflect"
22
23
23
24
"github.com/onsi/ginkgo/v2"
24
25
"github.com/onsi/gomega"
@@ -53,15 +54,23 @@ func UpdateDeploymentPaused(client kubernetes.Interface, deployment *appsv1.Depl
53
54
})
54
55
}
55
56
56
- // UpdateDeploymentWithSpec update deployment with the given spec .
57
- func UpdateDeploymentWithSpec (client kubernetes.Interface , namespace , name string , spec appsv1.DeploymentSpec ) {
57
+ // UpdateDeploymentWith update deployment with the given mutate function .
58
+ func UpdateDeploymentWith (client kubernetes.Interface , namespace , name string , mutateFunc func ( deploy * appsv1.Deployment ) ) {
58
59
ginkgo .By (fmt .Sprintf ("Update Deployment(%s/%s)" , namespace , name ), func () {
59
- newDeployment , err := client .AppsV1 ().Deployments (namespace ).Get (context .TODO (), name , metav1.GetOptions {})
60
- gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
60
+ gomega .Eventually (func () error {
61
+ deploy , err := client .AppsV1 ().Deployments (namespace ).Get (context .TODO (), name , metav1.GetOptions {})
62
+ if err != nil {
63
+ return err
64
+ }
61
65
62
- newDeployment .Spec = spec
63
- _ , err = client .AppsV1 ().Deployments (namespace ).Update (context .TODO (), newDeployment , metav1.UpdateOptions {})
64
- gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
66
+ deployCopy := deploy .DeepCopy ()
67
+ mutateFunc (deployCopy )
68
+ if reflect .DeepEqual (deploy , deployCopy ) {
69
+ return nil
70
+ }
71
+ _ , err = client .AppsV1 ().Deployments (namespace ).Update (context .TODO (), deployCopy , metav1.UpdateOptions {})
72
+ return err
73
+ }, PollTimeout , PollInterval ).ShouldNot (gomega .HaveOccurred ())
65
74
})
66
75
}
67
76
0 commit comments