-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathintegration_test.go
More file actions
720 lines (613 loc) · 20.3 KB
/
integration_test.go
File metadata and controls
720 lines (613 loc) · 20.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
//go:build integration
package main
import (
"context"
"fmt"
"net/url"
"os"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"cdr.dev/slog/v3"
"cdr.dev/slog/v3/sloggers/slogtest"
)
// getKubeClient creates a Kubernetes client from the default kubeconfig.
// It will use KUBECONFIG env var if set, otherwise ~/.kube/config.
// It also verifies the cluster is a KinD cluster to prevent accidentally
// running tests against production clusters.
func getKubeClient(t *testing.T) kubernetes.Interface {
t.Helper()
kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" {
home, err := os.UserHomeDir()
require.NoError(t, err, "failed to get user home dir")
kubeconfig = home + "/.kube/config"
}
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
require.NoError(t, err, "failed to build kubeconfig")
// Safety check: ensure we're connecting to a KinD cluster.
// KinD clusters run on localhost or have "kind" in the host.
// This prevents accidentally running destructive tests against production clusters.
if config.Host != "" && os.Getenv("INTEGRATION_TEST_UNSAFE") != "1" {
isKind := strings.Contains(config.Host, "127.0.0.1") ||
strings.Contains(config.Host, "localhost") ||
strings.Contains(strings.ToLower(config.Host), "kind")
if !isKind {
t.Fatalf("Safety check failed: integration tests must run against a KinD cluster. "+
"Current context points to %q. Set KUBECONFIG to a KinD cluster config or "+
"set INTEGRATION_TEST_UNSAFE=1 to bypass this check.", config.Host)
}
}
client, err := kubernetes.NewForConfig(config)
require.NoError(t, err, "failed to create kubernetes client")
return client
}
// createTestNamespace creates a unique namespace for test isolation.
// It registers cleanup to delete the namespace after the test.
func createTestNamespace(t *testing.T, ctx context.Context, client kubernetes.Interface) string {
t.Helper()
name := fmt.Sprintf("logstream-test-%d", time.Now().UnixNano())
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
_, err := client.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
require.NoError(t, err, "failed to create test namespace")
t.Cleanup(func() {
// Use a fresh context for cleanup in case the test context is cancelled
cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err := client.CoreV1().Namespaces().Delete(cleanupCtx, name, metav1.DeleteOptions{})
if err != nil {
t.Logf("warning: failed to delete test namespace %s: %v", name, err)
}
})
return name
}
// waitForLogContaining waits until a log containing the given substring is received.
// It collects all logs seen and returns them along with whether the target was found.
func waitForLogContaining(t *testing.T, ctx context.Context, api *fakeAgentAPI, timeout time.Duration, substring string) (allLogs []string, found bool) {
t.Helper()
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
for {
select {
case logs := <-api.logs:
for _, log := range logs {
allLogs = append(allLogs, log.Output)
if strings.Contains(log.Output, substring) {
return allLogs, true
}
}
case <-timeoutCtx.Done():
return allLogs, false
}
}
}
// waitForLogSource waits for log source registration with a timeout.
func waitForLogSource(t *testing.T, ctx context.Context, api *fakeAgentAPI, timeout time.Duration) {
t.Helper()
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
select {
case <-api.logSource:
return
case <-timeoutCtx.Done():
t.Fatal("timeout waiting for log source registration")
}
}
func TestIntegration_PodEvents(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
client := getKubeClient(t)
namespace := createTestNamespace(t, ctx, client)
// Start fake Coder API server
api := newFakeAgentAPI(t)
defer api.server.Close()
agentURL, err := url.Parse(api.server.URL)
require.NoError(t, err)
// Create the pod event logger
// Note: We don't set clock, so it uses a real clock for integration tests
reporter, err := newPodEventLogger(ctx, podEventLoggerOptions{
client: client,
coderURL: agentURL,
namespaces: []string{namespace},
logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
logDebounce: 5 * time.Second, // Use shorter debounce for faster tests
})
require.NoError(t, err)
defer reporter.Close()
// Wait a bit for informers to sync
time.Sleep(1 * time.Second)
// Create a pod with CODER_AGENT_TOKEN
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Namespace: namespace,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
Value: "test-token-integration",
},
},
},
},
// Use a non-existent node to keep the pod in Pending state
// This avoids needing to actually run the container
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
}
_, err = client.CoreV1().Pods(namespace).Create(ctx, pod, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source registration
waitForLogSource(t, ctx, api, 30*time.Second)
// Wait for the "Created pod" log (may receive other logs first like scheduling warnings)
logs, found := waitForLogContaining(t, ctx, api, 30*time.Second, "Created pod")
require.True(t, found, "expected 'Created pod' log, got: %v", logs)
// Delete the pod and verify deletion event
err = client.CoreV1().Pods(namespace).Delete(ctx, pod.Name, metav1.DeleteOptions{})
require.NoError(t, err)
// Wait for the "Deleted pod" log
logs, found = waitForLogContaining(t, ctx, api, 30*time.Second, "Deleted pod")
require.True(t, found, "expected 'Deleted pod' log, got: %v", logs)
}
func TestIntegration_ReplicaSetEvents(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
client := getKubeClient(t)
namespace := createTestNamespace(t, ctx, client)
// Start fake Coder API server
api := newFakeAgentAPI(t)
defer api.server.Close()
agentURL, err := url.Parse(api.server.URL)
require.NoError(t, err)
// Create the pod event logger
// Note: We don't set clock, so it uses a real clock for integration tests
reporter, err := newPodEventLogger(ctx, podEventLoggerOptions{
client: client,
coderURL: agentURL,
namespaces: []string{namespace},
logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
logDebounce: 5 * time.Second, // Use shorter debounce for faster tests
})
require.NoError(t, err)
defer reporter.Close()
// Wait a bit for informers to sync
time.Sleep(1 * time.Second)
// Create a ReplicaSet with CODER_AGENT_TOKEN
replicas := int32(1)
rs := &appsv1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-rs",
Namespace: namespace,
},
Spec: appsv1.ReplicaSetSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "test-rs",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "test-rs",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
Value: "test-token-rs-integration",
},
},
},
},
// Use a non-existent node to keep pods in Pending state
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
},
},
}
_, err = client.AppsV1().ReplicaSets(namespace).Create(ctx, rs, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source registration
waitForLogSource(t, ctx, api, 30*time.Second)
// Wait for the "Queued pod from ReplicaSet" log
logs, found := waitForLogContaining(t, ctx, api, 30*time.Second, "Queued pod from ReplicaSet")
require.True(t, found, "expected 'Queued pod from ReplicaSet' log, got: %v", logs)
// Delete the ReplicaSet
err = client.AppsV1().ReplicaSets(namespace).Delete(ctx, rs.Name, metav1.DeleteOptions{})
require.NoError(t, err)
// Wait for the "Deleted ReplicaSet" log
logs, found = waitForLogContaining(t, ctx, api, 30*time.Second, "Deleted ReplicaSet")
require.True(t, found, "expected 'Deleted ReplicaSet' log, got: %v", logs)
}
func TestIntegration_MultiNamespace(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
client := getKubeClient(t)
// Create two namespaces
namespace1 := createTestNamespace(t, ctx, client)
namespace2 := createTestNamespace(t, ctx, client)
// Start fake Coder API server
api := newFakeAgentAPI(t)
defer api.server.Close()
agentURL, err := url.Parse(api.server.URL)
require.NoError(t, err)
// Create the pod event logger watching both namespaces
// Note: We don't set clock, so it uses a real clock for integration tests
reporter, err := newPodEventLogger(ctx, podEventLoggerOptions{
client: client,
coderURL: agentURL,
namespaces: []string{namespace1, namespace2},
logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
logDebounce: 5 * time.Second, // Use shorter debounce for faster tests
})
require.NoError(t, err)
defer reporter.Close()
// Wait for informers to sync
time.Sleep(1 * time.Second)
// Create a pod in namespace1
pod1 := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-ns1",
Namespace: namespace1,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
Value: "test-token-ns1",
},
},
},
},
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
}
_, err = client.CoreV1().Pods(namespace1).Create(ctx, pod1, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source and logs from first pod
waitForLogSource(t, ctx, api, 30*time.Second)
logs, found := waitForLogContaining(t, ctx, api, 30*time.Second, "Created pod")
require.True(t, found, "expected 'Created pod' log for first pod, got: %v", logs)
// Create a pod in namespace2
pod2 := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-ns2",
Namespace: namespace2,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
Value: "test-token-ns2",
},
},
},
},
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
}
_, err = client.CoreV1().Pods(namespace2).Create(ctx, pod2, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source and logs from second pod
waitForLogSource(t, ctx, api, 30*time.Second)
logs, found = waitForLogContaining(t, ctx, api, 30*time.Second, "Created pod")
require.True(t, found, "expected 'Created pod' log for second pod, got: %v", logs)
// Both namespaces should have received events
t.Log("Successfully received events from both namespaces")
}
func TestIntegration_LabelSelector(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
client := getKubeClient(t)
namespace := createTestNamespace(t, ctx, client)
// Start fake Coder API server
api := newFakeAgentAPI(t)
defer api.server.Close()
agentURL, err := url.Parse(api.server.URL)
require.NoError(t, err)
// Create the pod event logger with a label selector
// Note: We don't set clock, so it uses a real clock for integration tests
reporter, err := newPodEventLogger(ctx, podEventLoggerOptions{
client: client,
coderURL: agentURL,
namespaces: []string{namespace},
labelSelector: "coder-workspace=true",
logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
logDebounce: 5 * time.Second, // Use shorter debounce for faster tests
})
require.NoError(t, err)
defer reporter.Close()
// Wait for informers to sync
time.Sleep(1 * time.Second)
// Create a pod WITHOUT the matching label - should be ignored
podNoLabel := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-no-label",
Namespace: namespace,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
Value: "test-token-no-label",
},
},
},
},
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
}
_, err = client.CoreV1().Pods(namespace).Create(ctx, podNoLabel, metav1.CreateOptions{})
require.NoError(t, err)
// Wait a bit to ensure the pod without label is not picked up
time.Sleep(2 * time.Second)
// Create a pod WITH the matching label - should be tracked
podWithLabel := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-with-label",
Namespace: namespace,
Labels: map[string]string{
"coder-workspace": "true",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
Value: "test-token-with-label",
},
},
},
},
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
}
_, err = client.CoreV1().Pods(namespace).Create(ctx, podWithLabel, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source registration - this should only happen for the labeled pod
waitForLogSource(t, ctx, api, 30*time.Second)
// Wait for logs - look specifically for "Created pod" with the labeled pod name
logs, found := waitForLogContaining(t, ctx, api, 30*time.Second, "Created pod")
require.True(t, found, "expected 'Created pod' log for labeled pod, got: %v", logs)
// Verify that none of the logs mention the unlabeled pod
for _, log := range logs {
require.NotContains(t, log, "test-pod-no-label", "should not receive logs for unlabeled pod")
}
}
func TestIntegration_PodWithSecretRef(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
client := getKubeClient(t)
namespace := createTestNamespace(t, ctx, client)
// Create a secret containing the agent token
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "agent-token-secret",
Namespace: namespace,
},
Data: map[string][]byte{
"token": []byte("secret-token-integration"),
},
}
_, err := client.CoreV1().Secrets(namespace).Create(ctx, secret, metav1.CreateOptions{})
require.NoError(t, err)
// Start fake Coder API server
api := newFakeAgentAPI(t)
defer api.server.Close()
agentURL, err := url.Parse(api.server.URL)
require.NoError(t, err)
// Create the pod event logger
reporter, err := newPodEventLogger(ctx, podEventLoggerOptions{
client: client,
coderURL: agentURL,
namespaces: []string{namespace},
logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
logDebounce: 5 * time.Second,
})
require.NoError(t, err)
defer reporter.Close()
// Wait for informers to sync
time.Sleep(1 * time.Second)
// Create a pod with CODER_AGENT_TOKEN from secretKeyRef
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-secret",
Namespace: namespace,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "agent-token-secret",
},
Key: "token",
},
},
},
},
},
},
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
}
_, err = client.CoreV1().Pods(namespace).Create(ctx, pod, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source registration
waitForLogSource(t, ctx, api, 30*time.Second)
// Wait for the "Created pod" log
logs, found := waitForLogContaining(t, ctx, api, 30*time.Second, "Created pod")
require.True(t, found, "expected 'Created pod' log, got: %v", logs)
// Delete the pod and verify deletion event
err = client.CoreV1().Pods(namespace).Delete(ctx, pod.Name, metav1.DeleteOptions{})
require.NoError(t, err)
// Wait for the "Deleted pod" log
logs, found = waitForLogContaining(t, ctx, api, 30*time.Second, "Deleted pod")
require.True(t, found, "expected 'Deleted pod' log, got: %v", logs)
}
func TestIntegration_ReplicaSetWithSecretRef(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
client := getKubeClient(t)
namespace := createTestNamespace(t, ctx, client)
// Create a secret containing the agent token
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "agent-token-secret",
Namespace: namespace,
},
Data: map[string][]byte{
"token": []byte("secret-token-rs-integration"),
},
}
_, err := client.CoreV1().Secrets(namespace).Create(ctx, secret, metav1.CreateOptions{})
require.NoError(t, err)
// Start fake Coder API server
api := newFakeAgentAPI(t)
defer api.server.Close()
agentURL, err := url.Parse(api.server.URL)
require.NoError(t, err)
// Create the pod event logger
reporter, err := newPodEventLogger(ctx, podEventLoggerOptions{
client: client,
coderURL: agentURL,
namespaces: []string{namespace},
logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
logDebounce: 5 * time.Second,
})
require.NoError(t, err)
defer reporter.Close()
// Wait for informers to sync
time.Sleep(1 * time.Second)
// Create a ReplicaSet with CODER_AGENT_TOKEN from secretKeyRef
replicas := int32(1)
rs := &appsv1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-rs-secret",
Namespace: namespace,
},
Spec: appsv1.ReplicaSetSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "test-rs-secret",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "test-rs-secret",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-container",
Image: "busybox:latest",
Command: []string{"sleep", "3600"},
Env: []corev1.EnvVar{
{
Name: "CODER_AGENT_TOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "agent-token-secret",
},
Key: "token",
},
},
},
},
},
},
NodeSelector: map[string]string{
"non-existent-label": "non-existent-value",
},
},
},
},
}
_, err = client.AppsV1().ReplicaSets(namespace).Create(ctx, rs, metav1.CreateOptions{})
require.NoError(t, err)
// Wait for log source registration
waitForLogSource(t, ctx, api, 30*time.Second)
// Wait for the "Queued pod from ReplicaSet" log
logs, found := waitForLogContaining(t, ctx, api, 30*time.Second, "Queued pod from ReplicaSet")
require.True(t, found, "expected 'Queued pod from ReplicaSet' log, got: %v", logs)
// Delete the ReplicaSet
err = client.AppsV1().ReplicaSets(namespace).Delete(ctx, rs.Name, metav1.DeleteOptions{})
require.NoError(t, err)
// Wait for the "Deleted ReplicaSet" log
logs, found = waitForLogContaining(t, ctx, api, 30*time.Second, "Deleted ReplicaSet")
require.True(t, found, "expected 'Deleted ReplicaSet' log, got: %v", logs)
}