@@ -157,7 +157,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
157
157
158
158
b .create (ctx , claim , pod )
159
159
160
- b .testPod (ctx , f . ClientSet , pod )
160
+ b .testPod (ctx , f , pod )
161
161
162
162
ginkgo .By (fmt .Sprintf ("force delete test pod %s" , pod .Name ))
163
163
err := b .f .ClientSet .CoreV1 ().Pods (b .f .Namespace .Name ).Delete (ctx , pod .Name , metav1.DeleteOptions {GracePeriodSeconds : & zero })
@@ -280,8 +280,8 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
280
280
err := e2epod .WaitForPodRunningInNamespace (ctx , f .ClientSet , pod )
281
281
framework .ExpectNoError (err , "start pod" )
282
282
283
- testContainerEnv (ctx , f . ClientSet , pod , pod .Spec .Containers [0 ].Name , true , container0Env ... )
284
- testContainerEnv (ctx , f . ClientSet , pod , pod .Spec .Containers [1 ].Name , true , container1Env ... )
283
+ testContainerEnv (ctx , f , pod , pod .Spec .Containers [0 ].Name , true , container0Env ... )
284
+ testContainerEnv (ctx , f , pod , pod .Spec .Containers [1 ].Name , true , container1Env ... )
285
285
})
286
286
})
287
287
@@ -291,20 +291,20 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
291
291
ginkgo .It ("supports simple pod referencing inline resource claim" , func (ctx context.Context ) {
292
292
pod , template := b .podInline ()
293
293
b .create (ctx , pod , template )
294
- b .testPod (ctx , f . ClientSet , pod )
294
+ b .testPod (ctx , f , pod )
295
295
})
296
296
297
297
ginkgo .It ("supports inline claim referenced by multiple containers" , func (ctx context.Context ) {
298
298
pod , template := b .podInlineMultiple ()
299
299
b .create (ctx , pod , template )
300
- b .testPod (ctx , f . ClientSet , pod )
300
+ b .testPod (ctx , f , pod )
301
301
})
302
302
303
303
ginkgo .It ("supports simple pod referencing external resource claim" , func (ctx context.Context ) {
304
304
pod := b .podExternal ()
305
305
claim := b .externalClaim ()
306
306
b .create (ctx , claim , pod )
307
- b .testPod (ctx , f . ClientSet , pod )
307
+ b .testPod (ctx , f , pod )
308
308
})
309
309
310
310
ginkgo .It ("supports external claim referenced by multiple pods" , func (ctx context.Context ) {
@@ -315,7 +315,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
315
315
b .create (ctx , claim , pod1 , pod2 , pod3 )
316
316
317
317
for _ , pod := range []* v1.Pod {pod1 , pod2 , pod3 } {
318
- b .testPod (ctx , f . ClientSet , pod )
318
+ b .testPod (ctx , f , pod )
319
319
}
320
320
})
321
321
@@ -327,7 +327,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
327
327
b .create (ctx , claim , pod1 , pod2 , pod3 )
328
328
329
329
for _ , pod := range []* v1.Pod {pod1 , pod2 , pod3 } {
330
- b .testPod (ctx , f . ClientSet , pod )
330
+ b .testPod (ctx , f , pod )
331
331
}
332
332
})
333
333
@@ -339,7 +339,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
339
339
pod .Spec .InitContainers [0 ].Command = []string {"sh" , "-c" , "env | grep user_a=b" }
340
340
b .create (ctx , pod , template )
341
341
342
- b .testPod (ctx , f . ClientSet , pod )
342
+ b .testPod (ctx , f , pod )
343
343
})
344
344
345
345
ginkgo .It ("removes reservation from claim when pod is done" , func (ctx context.Context ) {
@@ -394,7 +394,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
394
394
return b .f .ClientSet .ResourceV1beta1 ().ResourceClaims (b .f .Namespace .Name ).Get (ctx , claim .Name , metav1.GetOptions {})
395
395
}).WithTimeout (f .Timeouts .PodDelete ).ShouldNot (gomega .HaveField ("Status.Allocation" , (* resourceapi .AllocationResult )(nil )))
396
396
397
- b .testPod (ctx , f . ClientSet , pod )
397
+ b .testPod (ctx , f , pod )
398
398
399
399
ginkgo .By (fmt .Sprintf ("deleting pod %s" , klog .KObj (pod )))
400
400
framework .ExpectNoError (b .f .ClientSet .CoreV1 ().Pods (b .f .Namespace .Name ).Delete (ctx , pod .Name , metav1.DeleteOptions {}))
@@ -496,7 +496,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
496
496
ginkgo .It ("supports claim and class parameters" , func (ctx context.Context ) {
497
497
pod , template := b .podInline ()
498
498
b .create (ctx , pod , template )
499
- b .testPod (ctx , f . ClientSet , pod , expectedEnv ... )
499
+ b .testPod (ctx , f , pod , expectedEnv ... )
500
500
})
501
501
502
502
ginkgo .It ("supports reusing resources" , func (ctx context.Context ) {
@@ -518,7 +518,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
518
518
go func () {
519
519
defer ginkgo .GinkgoRecover ()
520
520
defer wg .Done ()
521
- b .testPod (ctx , f . ClientSet , pod , expectedEnv ... )
521
+ b .testPod (ctx , f , pod , expectedEnv ... )
522
522
err := f .ClientSet .CoreV1 ().Pods (pod .Namespace ).Delete (ctx , pod .Name , metav1.DeleteOptions {})
523
523
framework .ExpectNoError (err , "delete pod" )
524
524
framework .ExpectNoError (e2epod .WaitForPodNotFoundInNamespace (ctx , f .ClientSet , pod .Name , pod .Namespace , time .Duration (numPods )* f .Timeouts .PodStartSlow ))
@@ -548,7 +548,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
548
548
go func () {
549
549
defer ginkgo .GinkgoRecover ()
550
550
defer wg .Done ()
551
- b .testPod (ctx , f . ClientSet , pod , expectedEnv ... )
551
+ b .testPod (ctx , f , pod , expectedEnv ... )
552
552
}()
553
553
}
554
554
wg .Wait ()
@@ -572,7 +572,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
572
572
class .Name = deviceClassName
573
573
b .create (ctx , class )
574
574
575
- b .testPod (ctx , f . ClientSet , pod , expectedEnv ... )
575
+ b .testPod (ctx , f , pod , expectedEnv ... )
576
576
})
577
577
578
578
ginkgo .It ("retries pod scheduling after updating device class" , func (ctx context.Context ) {
@@ -603,7 +603,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
603
603
_ , err = f .ClientSet .ResourceV1beta1 ().DeviceClasses ().Update (ctx , class , metav1.UpdateOptions {})
604
604
framework .ExpectNoError (err )
605
605
606
- b .testPod (ctx , f . ClientSet , pod , expectedEnv ... )
606
+ b .testPod (ctx , f , pod , expectedEnv ... )
607
607
})
608
608
609
609
ginkgo .It ("runs a pod without a generated resource claim" , func (ctx context.Context ) {
@@ -1037,7 +1037,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
1037
1037
pod .Spec .Containers [0 ].Resources .Claims [0 ].Name = pod .Spec .ResourceClaims [0 ].Name
1038
1038
b .create (ctx , template , pod )
1039
1039
1040
- b .testPod (ctx , f . ClientSet , pod )
1040
+ b .testPod (ctx , f , pod )
1041
1041
})
1042
1042
1043
1043
ginkgo .It ("supports count/resourceclaims.resource.k8s.io ResourceQuota" , func (ctx context.Context ) {
@@ -1360,7 +1360,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
1360
1360
)
1361
1361
}
1362
1362
b1 .create (ctx , claim1 , claim1b , claim2 , claim2b , pod )
1363
- b1 .testPod (ctx , f . ClientSet , pod )
1363
+ b1 .testPod (ctx , f , pod )
1364
1364
})
1365
1365
}
1366
1366
multipleDriversContext := func (prefix string , nodeV1alpha4 , nodeV1beta1 bool ) {
@@ -1391,7 +1391,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
1391
1391
driver .Run (nodes , perNode (1 , nodes ))
1392
1392
1393
1393
// Now it should run.
1394
- b .testPod (ctx , f . ClientSet , pod )
1394
+ b .testPod (ctx , f , pod )
1395
1395
1396
1396
// We need to clean up explicitly because the normal
1397
1397
// cleanup doesn't work (driver shuts down first).
@@ -1494,7 +1494,7 @@ func (b *builder) parametersEnv() (string, []string) {
1494
1494
// makePod returns a simple pod with no resource claims.
1495
1495
// The pod prints its env and waits.
1496
1496
func (b * builder ) pod () * v1.Pod {
1497
- pod := e2epod .MakePod (b .f .Namespace .Name , nil , nil , b .f .NamespacePodSecurityLevel , "env && sleep 100000" )
1497
+ pod := e2epod .MakePod (b .f .Namespace .Name , nil , nil , b .f .NamespacePodSecurityLevel , "" /* no command = pause */ )
1498
1498
pod .Labels = make (map [string ]string )
1499
1499
pod .Spec .RestartPolicy = v1 .RestartPolicyNever
1500
1500
// Let kubelet kill the pods quickly. Setting
@@ -1621,30 +1621,39 @@ func (b *builder) create(ctx context.Context, objs ...klog.KMetadata) []klog.KMe
1621
1621
}
1622
1622
1623
1623
// testPod runs pod and checks if container logs contain expected environment variables
1624
- func (b * builder ) testPod (ctx context.Context , clientSet kubernetes. Interface , pod * v1.Pod , env ... string ) {
1624
+ func (b * builder ) testPod (ctx context.Context , f * framework. Framework , pod * v1.Pod , env ... string ) {
1625
1625
ginkgo .GinkgoHelper ()
1626
- err := e2epod .WaitForPodRunningInNamespace (ctx , clientSet , pod )
1626
+ err := e2epod .WaitForPodRunningInNamespace (ctx , f . ClientSet , pod )
1627
1627
framework .ExpectNoError (err , "start pod" )
1628
1628
1629
1629
if len (env ) == 0 {
1630
1630
_ , env = b .parametersEnv ()
1631
1631
}
1632
1632
for _ , container := range pod .Spec .Containers {
1633
- testContainerEnv (ctx , clientSet , pod , container .Name , false , env ... )
1633
+ testContainerEnv (ctx , f , pod , container .Name , false , env ... )
1634
1634
}
1635
1635
}
1636
1636
1637
1637
// envLineRE matches env output with variables set by test/e2e/dra/test-driver.
1638
1638
var envLineRE = regexp .MustCompile (`^(?:admin|user|claim)_[a-zA-Z0-9_]*=.*$` )
1639
1639
1640
- func testContainerEnv (ctx context.Context , clientSet kubernetes. Interface , pod * v1.Pod , containerName string , fullMatch bool , env ... string ) {
1640
+ func testContainerEnv (ctx context.Context , f * framework. Framework , pod * v1.Pod , containerName string , fullMatch bool , env ... string ) {
1641
1641
ginkgo .GinkgoHelper ()
1642
- log , err := e2epod .GetPodLogs (ctx , clientSet , pod .Namespace , pod .Name , containerName )
1643
- framework .ExpectNoError (err , fmt .Sprintf ("get logs for container %s" , containerName ))
1642
+ stdout , stderr , err := e2epod .ExecWithOptionsContext (ctx , f , e2epod.ExecOptions {
1643
+ Command : []string {"env" },
1644
+ Namespace : pod .Namespace ,
1645
+ PodName : pod .Name ,
1646
+ ContainerName : containerName ,
1647
+ CaptureStdout : true ,
1648
+ CaptureStderr : true ,
1649
+ Quiet : true ,
1650
+ })
1651
+ framework .ExpectNoError (err , fmt .Sprintf ("get env output for container %s" , containerName ))
1652
+ gomega .Expect (stderr ).To (gomega .BeEmpty (), fmt .Sprintf ("env stderr for container %s" , containerName ))
1644
1653
if fullMatch {
1645
1654
// Find all env variables set by the test driver.
1646
1655
var actualEnv , expectEnv []string
1647
- for _ , line := range strings .Split (log , "\n " ) {
1656
+ for _ , line := range strings .Split (stdout , "\n " ) {
1648
1657
if envLineRE .MatchString (line ) {
1649
1658
actualEnv = append (actualEnv , line )
1650
1659
}
@@ -1654,11 +1663,11 @@ func testContainerEnv(ctx context.Context, clientSet kubernetes.Interface, pod *
1654
1663
}
1655
1664
sort .Strings (actualEnv )
1656
1665
sort .Strings (expectEnv )
1657
- gomega .Expect (actualEnv ).To (gomega .Equal (expectEnv ), fmt .Sprintf ("container %s log output:\n %s" , containerName , log ))
1666
+ gomega .Expect (actualEnv ).To (gomega .Equal (expectEnv ), fmt .Sprintf ("container %s env output:\n %s" , containerName , stdout ))
1658
1667
} else {
1659
1668
for i := 0 ; i < len (env ); i += 2 {
1660
1669
envStr := fmt .Sprintf ("\n %s=%s\n " , env [i ], env [i + 1 ])
1661
- gomega .Expect (log ).To (gomega .ContainSubstring (envStr ), fmt .Sprintf ("container %s env variables" , containerName ))
1670
+ gomega .Expect (stdout ).To (gomega .ContainSubstring (envStr ), fmt .Sprintf ("container %s env variables" , containerName ))
1662
1671
}
1663
1672
}
1664
1673
}
0 commit comments