Skip to content

Commit f2f7708

Browse files
authored
Merge pull request kubernetes#126244 from googs1025/informer
chore(servicecidr): use WaitForCacheSync after sharedInformerFactory Start in integration test
2 parents 8f265b6 + bc514ff commit f2f7708

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

test/integration/servicecidr/migration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func TestMigrateServiceCIDR(t *testing.T) {
8282
client1,
8383
).Run(tCtx, 5)
8484
informers1.Start(tCtx.Done())
85+
informers1.WaitForCacheSync(tCtx.Done())
8586

8687
// the default serviceCIDR should have a finalizer and ready condition set to true
8788
if err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, time.Minute, false, func(ctx context.Context) (bool, error) {
@@ -220,6 +221,7 @@ func TestMigrateServiceCIDR(t *testing.T) {
220221
client2,
221222
).Run(tCtx2, 5)
222223
informers2.Start(tCtx2.Done())
224+
informers2.WaitForCacheSync(tCtx.Done())
223225

224226
// delete the kubernetes.default service so the old DefaultServiceCIDR can be deleted
225227
// and the new apiserver can take over

test/integration/servicecidr/servicecidr_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestServiceAllocNewServiceCIDR(t *testing.T) {
6868
client,
6969
).Run(ctx, 5)
7070
informerFactory.Start(ctx.Done())
71+
informerFactory.WaitForCacheSync(ctx.Done())
7172

7273
// /29 = 6 services, kubernetes.default takes the first address
7374
// make 5 more services to take up all IPs
@@ -169,6 +170,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
169170
client,
170171
).Run(ctx, 5)
171172
informerFactory.Start(ctx.Done())
173+
informerFactory.WaitForCacheSync(ctx.Done())
172174

173175
// /29 = 6 services, kubernetes.default takes the first address
174176
// make 5 more services to take up all IPs
@@ -180,7 +182,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
180182
// create a new ServiceCIDRs that overlaps the default one
181183
_, err = client.NetworkingV1beta1().ServiceCIDRs().Create(ctx, makeServiceCIDR("cidr1", cidr1, ""), metav1.CreateOptions{})
182184
if err != nil {
183-
t.Fatal((err))
185+
t.Fatal(err)
184186
}
185187
// Wait until is ready.
186188
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (bool, error) {
@@ -195,7 +197,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
195197
// we should be able to delete the ServiceCIDR despite it contains IP addresses as it overlaps with the default ServiceCIDR
196198
err = client.NetworkingV1beta1().ServiceCIDRs().Delete(ctx, "cidr1", metav1.DeleteOptions{})
197199
if err != nil {
198-
t.Fatal((err))
200+
t.Fatal(err)
199201
}
200202

201203
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (bool, error) {
@@ -211,7 +213,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
211213
// add a new ServiceCIDR with a new range
212214
_, err = client.NetworkingV1beta1().ServiceCIDRs().Create(ctx, makeServiceCIDR("cidr2", cidr2, ""), metav1.CreateOptions{})
213215
if err != nil {
214-
t.Fatal((err))
216+
t.Fatal(err)
215217
}
216218
// wait the allocator process the new ServiceCIDR
217219
// Wait until is ready.
@@ -237,7 +239,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
237239
// add a new ServiceCIDR that overlaps the existing one
238240
_, err = client.NetworkingV1beta1().ServiceCIDRs().Create(ctx, makeServiceCIDR("cidr3", cidr3, ""), metav1.CreateOptions{})
239241
if err != nil {
240-
t.Fatal((err))
242+
t.Fatal(err)
241243
}
242244
// Wait until is ready.
243245
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (bool, error) {
@@ -252,7 +254,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
252254
// we should be able to delete the ServiceCIDR2 despite it contains IP addresses as it is contained on ServiceCIDR3
253255
err = client.NetworkingV1beta1().ServiceCIDRs().Delete(ctx, "cidr2", metav1.DeleteOptions{})
254256
if err != nil {
255-
t.Fatal((err))
257+
t.Fatal(err)
256258
}
257259

258260
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (bool, error) {
@@ -268,7 +270,7 @@ func TestServiceCIDRDeletion(t *testing.T) {
268270
// serviceCIDR3 will not be able to be deleted until the IPAddress is removed
269271
err = client.NetworkingV1beta1().ServiceCIDRs().Delete(ctx, "cidr3", metav1.DeleteOptions{})
270272
if err != nil {
271-
t.Fatal((err))
273+
t.Fatal(err)
272274
}
273275
// Wait until is not ready.
274276
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (bool, error) {

0 commit comments

Comments
 (0)