@@ -22,6 +22,7 @@ import (
22
22
"github.com/onsi/ginkgo/v2"
23
23
"github.com/onsi/gomega"
24
24
appsv1 "k8s.io/api/apps/v1"
25
+ autoscalingv1 "k8s.io/api/autoscaling/v1"
25
26
v1 "k8s.io/api/autoscaling/v1"
26
27
corev1 "k8s.io/api/core/v1"
27
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -91,12 +92,10 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
91
92
updates : []* update {
92
93
{
93
94
lwsUpdateFn : func (lws * leaderworkerset.LeaderWorkerSet ) {
94
- var leaderworkerset leaderworkerset.LeaderWorkerSet
95
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderworkerset )).To (gomega .Succeed ())
96
- testing .UpdateReplicaCount (ctx , k8sClient , & leaderworkerset , int32 (3 ))
95
+ testing .UpdateReplicaCount (ctx , k8sClient , lws , int32 (3 ))
97
96
var leaderSts appsv1.StatefulSet
98
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : leaderworkerset .Name , Namespace : leaderworkerset .Namespace }, & leaderSts )).To (gomega .Succeed ())
99
- gomega .Expect (testing .CreateLeaderPods (ctx , leaderSts , k8sClient , & leaderworkerset , 2 , 3 )).To (gomega .Succeed ())
97
+ gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderSts )).To (gomega .Succeed ())
98
+ gomega .Expect (testing .CreateLeaderPods (ctx , leaderSts , k8sClient , lws , 2 , 3 )).To (gomega .Succeed ())
100
99
},
101
100
checkLWSState : func (deployment * leaderworkerset.LeaderWorkerSet ) {
102
101
testing .ExpectValidReplicasCount (ctx , deployment , 3 , k8sClient )
@@ -113,12 +112,10 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
113
112
updates : []* update {
114
113
{
115
114
lwsUpdateFn : func (lws * leaderworkerset.LeaderWorkerSet ) {
116
- var leaderworkerset leaderworkerset.LeaderWorkerSet
117
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderworkerset )).To (gomega .Succeed ())
118
- testing .UpdateReplicaCount (ctx , k8sClient , & leaderworkerset , int32 (3 ))
115
+ testing .UpdateReplicaCount (ctx , k8sClient , lws , int32 (3 ))
119
116
var leaderSts appsv1.StatefulSet
120
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : leaderworkerset .Name , Namespace : leaderworkerset .Namespace }, & leaderSts )).To (gomega .Succeed ())
121
- testing .DeleteLeaderPods (ctx , k8sClient , leaderworkerset )
117
+ gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderSts )).To (gomega .Succeed ())
118
+ testing .DeleteLeaderPods (ctx , k8sClient , lws )
122
119
},
123
120
checkLWSState : func (deployment * leaderworkerset.LeaderWorkerSet ) {
124
121
testing .ExpectValidReplicasCount (ctx , deployment , 3 , k8sClient )
@@ -135,12 +132,10 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
135
132
updates : []* update {
136
133
{
137
134
lwsUpdateFn : func (lws * leaderworkerset.LeaderWorkerSet ) {
138
- var leaderworkerset leaderworkerset.LeaderWorkerSet
139
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderworkerset )).To (gomega .Succeed ())
140
- testing .UpdateReplicaCount (ctx , k8sClient , & leaderworkerset , int32 (0 ))
135
+ testing .UpdateReplicaCount (ctx , k8sClient , lws , int32 (0 ))
141
136
var leaderSts appsv1.StatefulSet
142
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : leaderworkerset .Name , Namespace : leaderworkerset .Namespace }, & leaderSts )).To (gomega .Succeed ())
143
- testing .DeleteLeaderPods (ctx , k8sClient , leaderworkerset )
137
+ gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderSts )).To (gomega .Succeed ())
138
+ testing .DeleteLeaderPods (ctx , k8sClient , lws )
144
139
},
145
140
checkLWSState : func (deployment * leaderworkerset.LeaderWorkerSet ) {
146
141
testing .ExpectValidReplicasCount (ctx , deployment , 0 , k8sClient )
@@ -157,12 +152,10 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
157
152
updates : []* update {
158
153
{
159
154
lwsUpdateFn : func (lws * leaderworkerset.LeaderWorkerSet ) {
160
- var leaderworkerset leaderworkerset.LeaderWorkerSet
161
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderworkerset )).To (gomega .Succeed ())
162
- testing .UpdateReplicaCount (ctx , k8sClient , & leaderworkerset , int32 (3 ))
155
+ testing .UpdateReplicaCount (ctx , k8sClient , lws , int32 (3 ))
163
156
var leaderSts appsv1.StatefulSet
164
- gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : leaderworkerset .Name , Namespace : leaderworkerset .Namespace }, & leaderSts )).To (gomega .Succeed ())
165
- gomega .Expect (testing .CreateLeaderPods (ctx , leaderSts , k8sClient , & leaderworkerset , 0 , 3 )).To (gomega .Succeed ())
157
+ gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderSts )).To (gomega .Succeed ())
158
+ gomega .Expect (testing .CreateLeaderPods (ctx , leaderSts , k8sClient , lws , 0 , 3 )).To (gomega .Succeed ())
166
159
},
167
160
checkLWSState : func (deployment * leaderworkerset.LeaderWorkerSet ) {
168
161
testing .ExpectValidReplicasCount (ctx , deployment , 3 , k8sClient )
@@ -298,7 +291,7 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
298
291
updates : []* update {
299
292
{
300
293
checkLWSState : func (lws * leaderworkerset.LeaderWorkerSet ) {
301
- var scale v1 .Scale
294
+ var scale autoscalingv1 .Scale
302
295
gomega .Expect (k8sClient .SubResource ("scale" ).Get (ctx , lws , & scale )).To (gomega .Succeed ())
303
296
gomega .Expect (int32 (scale .Spec .Replicas )).To (gomega .Equal (* lws .Spec .Replicas ))
304
297
gomega .Expect (int32 (scale .Status .Replicas )).To (gomega .Equal (lws .Status .Replicas ))
@@ -307,24 +300,17 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
307
300
},
308
301
{
309
302
lwsUpdateFn : func (lws * leaderworkerset.LeaderWorkerSet ) {
310
- var scale v1.Scale
311
- gomega .Expect (k8sClient .SubResource ("scale" ).Get (ctx , lws , & scale )).To (gomega .Succeed ())
312
- scale .Spec .Replicas = 3
313
- lwsUnstructed , _ := ToUnstructured (lws )
314
- lwsUnstructed .SetAPIVersion ("leaderworkerset.x-k8s.io/v1" )
315
- lwsUnstructed .SetKind ("LeaderWorkerSet" )
316
- scaleUnstructed , _ := ToUnstructured (scale .DeepCopy ())
317
- scaleUnstructed .SetAPIVersion ("autoscaling/v1" )
318
- scaleUnstructed .SetKind ("Scale" )
319
- gomega .Expect (k8sClient .SubResource ("scale" ).Update (ctx , lwsUnstructed , client .WithSubResourceBody (scaleUnstructed ))).To (gomega .Succeed ())
303
+ dep := & leaderworkerset.LeaderWorkerSet {ObjectMeta : metav1.ObjectMeta {Namespace : lws .Namespace , Name : lws .Name }}
304
+ scale := & autoscalingv1.Scale {Spec : autoscalingv1.ScaleSpec {Replicas : 3 }}
305
+ gomega .Expect (k8sClient .SubResource ("scale" ).Update (ctx , dep , client .WithSubResourceBody (scale ))).To (gomega .Succeed ())
320
306
},
321
307
checkLWSState : func (lws * leaderworkerset.LeaderWorkerSet ) {
322
308
gomega .Eventually (func () (int32 , error ) {
323
309
var leaderWorkerSet leaderworkerset.LeaderWorkerSet
324
310
if err := k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderWorkerSet ); err != nil {
325
- return - 1 , err
311
+ return 0 , err
326
312
}
327
- return leaderWorkerSet .Status .Replicas , nil
313
+ return * leaderWorkerSet .Spec .Replicas , nil
328
314
}, testing .Timeout , testing .Interval ).Should (gomega .Equal (int32 (3 )))
329
315
},
330
316
},
@@ -451,13 +437,6 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
451
437
updates : []* update {
452
438
{
453
439
checkLWSState : func (lws * leaderworkerset.LeaderWorkerSet ) {
454
- gomega .Eventually (func () (int32 , error ) {
455
- var leaderWorkerSet leaderworkerset.LeaderWorkerSet
456
- if err := k8sClient .Get (ctx , types.NamespacedName {Name : lws .Name , Namespace : lws .Namespace }, & leaderWorkerSet ); err != nil {
457
- return - 1 , err
458
- }
459
- return leaderWorkerSet .Status .Replicas , nil
460
- }, testing .Timeout , testing .Interval ).Should (gomega .Equal (int32 (2 )))
461
440
testing .ExpectValidLeaderStatefulSet (ctx , lws , k8sClient )
462
441
testing .ExpectValidWorkerStatefulSets (ctx , lws , k8sClient , true )
463
442
testing .ExpectLeaderWorkerSetProgressing (ctx , k8sClient , lws , "Replicas are progressing" )
@@ -561,7 +540,8 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
561
540
testing .ExpectLeaderWorkerSetUnavailable (ctx , k8sClient , lws , "All replicas are ready" )
562
541
testing .ExpectStatefulsetPartitionEqualTo (ctx , k8sClient , lws , 2 )
563
542
testing .ExpectValidLeaderStatefulSet (ctx , lws , k8sClient )
564
- testing .ExpectLeaderWorkerSetStatusReplicas (ctx , k8sClient , lws , 3 , 1 )
543
+ // 3-index status is unready but template already updated.
544
+ testing .ExpectLeaderWorkerSetStatusReplicas (ctx , k8sClient , lws , 3 , 2 )
565
545
},
566
546
},
567
547
{
@@ -884,7 +864,7 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() {
884
864
return k8sClient .Update (ctx , & leaderworkerset )
885
865
}, testing .Timeout , testing .Interval ).Should (gomega .Succeed ())
886
866
// Manually delete leader pods here because we have no statefulset controller.
887
- testing .DeleteLeaderPods (ctx , k8sClient , leaderworkerset )
867
+ testing .DeleteLeaderPods (ctx , k8sClient , & leaderworkerset )
888
868
},
889
869
checkLWSState : func (lws * leaderworkerset.LeaderWorkerSet ) {
890
870
testing .ExpectValidLeaderStatefulSet (ctx , lws , k8sClient )
0 commit comments