@@ -70,6 +70,109 @@ var (
7070)
7171
7272var _ = Describe ("collaset controller" , func () {
73+ It ("inplaceUpdate with only metadata changed" , func () {
74+ testcase := "test-inplace-update-with-only-metadata-changed"
75+ Expect (createNamespace (c , testcase )).Should (BeNil ())
76+
77+ cs := & appsv1alpha1.CollaSet {
78+ ObjectMeta : metav1.ObjectMeta {
79+ Namespace : testcase ,
80+ Name : "foo" ,
81+ },
82+ Spec : appsv1alpha1.CollaSetSpec {
83+ Replicas : int32Pointer (2 ),
84+ Selector : & metav1.LabelSelector {
85+ MatchLabels : map [string ]string {
86+ "app" : "foo" ,
87+ },
88+ },
89+ Template : corev1.PodTemplateSpec {
90+ ObjectMeta : metav1.ObjectMeta {
91+ Labels : map [string ]string {
92+ "app" : "foo" ,
93+ },
94+ },
95+ Spec : corev1.PodSpec {
96+ Containers : []corev1.Container {
97+ {
98+ Name : "foo" ,
99+ Image : "nginx:v1" ,
100+ },
101+ },
102+ },
103+ },
104+ UpdateStrategy : appsv1alpha1.UpdateStrategy {
105+ OperationDelaySeconds : int32Pointer (1 ),
106+ PodUpdatePolicy : appsv1alpha1 .CollaSetInPlaceIfPossiblePodUpdateStrategyType ,
107+ },
108+ },
109+ }
110+ Expect (c .Create (context .TODO (), cs )).Should (BeNil ())
111+
112+ podList := & corev1.PodList {}
113+ Eventually (func () bool {
114+ Expect (c .List (context .TODO (), podList , client .InNamespace (cs .Namespace ))).Should (BeNil ())
115+ return len (podList .Items ) == 2
116+ }, 5 * time .Second , 1 * time .Second ).Should (BeTrue ())
117+ Expect (c .Get (context .TODO (), types.NamespacedName {Namespace : cs .Namespace , Name : cs .Name }, cs )).Should (BeNil ())
118+ Expect (expectedStatusReplicas (c , cs , 0 , 0 , 0 , 2 , 2 , 0 , 0 , 0 )).Should (BeNil ())
119+
120+ observedGeneration := cs .Status .ObservedGeneration
121+ // update CollaSet template metadata
122+ Expect (updateCollaSetWithRetry (c , cs .Namespace , cs .Name , func (cls * appsv1alpha1.CollaSet ) bool {
123+ cls .Spec .Template .Annotations = map [string ]string {
124+ "test" : "v1" ,
125+ }
126+ return true
127+ })).Should (BeNil ())
128+ Eventually (func () bool {
129+ Expect (c .Get (context .TODO (), types.NamespacedName {Namespace : cs .Namespace , Name : cs .Name }, cs )).Should (BeNil ())
130+ return cs .Status .ObservedGeneration != observedGeneration
131+ }, 5 * time .Second , 1 * time .Second ).Should (BeTrue ())
132+
133+ // allow origin pod to update
134+ Expect (c .List (context .TODO (), podList , client .InNamespace (cs .Namespace ))).Should (BeNil ())
135+ for i := range podList .Items {
136+ pod := & podList .Items [i ]
137+ Expect (updatePodWithRetry (c , pod .Namespace , pod .Name , func (pod * corev1.Pod ) bool {
138+ labelOperate := fmt .Sprintf ("%s/%s" , appsv1alpha1 .PodOperateLabelPrefix , collasetutils .UpdateOpsLifecycleAdapter .GetID ())
139+ pod .Labels [labelOperate ] = fmt .Sprintf ("%d" , time .Now ().UnixNano ())
140+ return true
141+ })).Should (BeNil ())
142+ }
143+
144+ // waiting for update finished
145+ Eventually (func () error {
146+ return expectedStatusReplicas (c , cs , 0 , 0 , 0 , 2 , 2 , 2 , 0 , 0 )
147+ }, 10 * time .Second , 1 * time .Second ).Should (BeNil ())
148+
149+ // mock container status
150+ Expect (c .List (context .TODO (), podList , client .InNamespace (cs .Namespace ))).Should (BeNil ())
151+ for i := range podList .Items {
152+ Expect (updatePodStatusWithRetry (c , podList .Items [i ].Namespace , podList .Items [i ].Name , func (pod * corev1.Pod ) bool {
153+ pod .Status .ContainerStatuses = []corev1.ContainerStatus {
154+ {
155+ Name : "foo" ,
156+ ImageID : "nginx:v1" ,
157+ },
158+ }
159+ return true
160+ })).Should (BeNil ())
161+ }
162+
163+ // check pods update are finished
164+ Eventually (func () bool {
165+ Expect (c .List (context .TODO (), podList , client .InNamespace (cs .Namespace ))).Should (BeNil ())
166+ for i := range podList .Items {
167+ pod := & podList .Items [i ]
168+ if podopslifecycle .IsDuringOps (collasetutils .UpdateOpsLifecycleAdapter , pod ) {
169+ return false
170+ }
171+ }
172+ return true
173+ }, 10 * time .Second , 1 * time .Second ).Should (BeTrue ())
174+ })
175+
73176 It ("replace pod with update" , func () {
74177 for _ , updateStrategy := range []appsv1alpha1.PodUpdateStrategyType {appsv1alpha1 .CollaSetRecreatePodUpdateStrategyType , appsv1alpha1 .CollaSetInPlaceIfPossiblePodUpdateStrategyType , appsv1alpha1 .CollaSetReplacePodUpdateStrategyType } {
75178 testcase := fmt .Sprintf ("test-replace-pod-with-%s-update" , strings .ToLower (string (updateStrategy )))
0 commit comments