@@ -17,14 +17,9 @@ limitations under the License.
17
17
package common
18
18
19
19
import (
20
- "context"
21
- "fmt"
22
- "time"
23
-
24
20
v1 "k8s.io/api/core/v1"
25
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
22
"k8s.io/apimachinery/pkg/util/uuid"
27
- "k8s.io/apimachinery/pkg/util/wait"
28
23
"k8s.io/kubernetes/test/e2e/framework"
29
24
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
30
25
imageutils "k8s.io/kubernetes/test/utils/image"
@@ -362,110 +357,6 @@ var _ = framework.KubeDescribe("Variable Expansion", func() {
362
357
err = e2epod .DeletePodWithWait (f .ClientSet , pod )
363
358
framework .ExpectNoError (err , "failed to delete pod" )
364
359
})
365
-
366
- /*
367
- Release : v1.19
368
- Testname: VolumeSubpathEnvExpansion, subpath lifecycle
369
- Description: Verify should not change the subpath mount on a container restart if the environment variable changes
370
- 1. valid subpathexpr starts a container running
371
- 2. test for valid subpath writes
372
- 3. container restarts
373
- 4. delete cleanly
374
- */
375
- framework .ConformanceIt ("should not change the subpath mount on a container restart if the environment variable changes [sig-storage][Slow]" , func () {
376
- envVars := []v1.EnvVar {
377
- {
378
- Name : "POD_NAME" ,
379
- ValueFrom : & v1.EnvVarSource {
380
- FieldRef : & v1.ObjectFieldSelector {
381
- APIVersion : "v1" ,
382
- FieldPath : "metadata.annotations['mysubpath']" ,
383
- },
384
- },
385
- },
386
- }
387
- mounts := []v1.VolumeMount {
388
- {
389
- Name : "workdir1" ,
390
- MountPath : "/subpath_mount" ,
391
- },
392
- {
393
- Name : "workdir1" ,
394
- MountPath : "/volume_mount" ,
395
- },
396
- }
397
- subpathMounts := []v1.VolumeMount {
398
- {
399
- Name : "workdir1" ,
400
- MountPath : "/subpath_mount" ,
401
- SubPathExpr : "$(POD_NAME)" ,
402
- },
403
- {
404
- Name : "workdir1" ,
405
- MountPath : "/volume_mount" ,
406
- },
407
- }
408
- volumes := []v1.Volume {
409
- {
410
- Name : "workdir1" ,
411
- VolumeSource : v1.VolumeSource {
412
- EmptyDir : & v1.EmptyDirVolumeSource {},
413
- },
414
- },
415
- }
416
- pod := newPod ([]string {"/bin/sh" , "-ec" , "sleep 100000" }, envVars , subpathMounts , volumes )
417
- pod .Spec .RestartPolicy = v1 .RestartPolicyOnFailure
418
- pod .ObjectMeta .Annotations = map [string ]string {"mysubpath" : "foo" }
419
- sideContainerName := "side-container"
420
- pod .Spec .Containers = append (pod .Spec .Containers , newContainer (sideContainerName , []string {"/bin/sh" , "-ec" , "sleep 100000" }, envVars , subpathMounts ))
421
- suffix := string (uuid .NewUUID ())
422
- pod .Spec .InitContainers = []v1.Container {newContainer (
423
- fmt .Sprintf ("init-volume-%s" , suffix ), []string {"sh" , "-c" , "mkdir -p /volume_mount/foo; touch /volume_mount/foo/test.log" }, nil , mounts )}
424
-
425
- // Add liveness probe to subpath container
426
- pod .Spec .Containers [0 ].LivenessProbe = & v1.Probe {
427
- Handler : v1.Handler {
428
- Exec : & v1.ExecAction {
429
-
430
- Command : []string {"cat" , "/subpath_mount/test.log" },
431
- },
432
- },
433
- InitialDelaySeconds : 1 ,
434
- FailureThreshold : 1 ,
435
- PeriodSeconds : 2 ,
436
- }
437
-
438
- // Start pod
439
- ginkgo .By (fmt .Sprintf ("Creating pod %s" , pod .Name ))
440
- var podClient * framework.PodClient = f .PodClient ()
441
- pod = podClient .Create (pod )
442
- defer func () {
443
- e2epod .DeletePodWithWait (f .ClientSet , pod )
444
- }()
445
- err := e2epod .WaitForPodRunningInNamespace (f .ClientSet , pod )
446
- framework .ExpectNoError (err , "while waiting for pod to be running" )
447
-
448
- ginkgo .By ("updating the pod" )
449
- podClient .Update (pod .ObjectMeta .Name , func (pod * v1.Pod ) {
450
- pod .ObjectMeta .Annotations = map [string ]string {"mysubpath" : "newsubpath" }
451
- })
452
-
453
- ginkgo .By ("waiting for pod and container restart" )
454
- waitForPodContainerRestart (f , pod , "/volume_mount/foo/test.log" )
455
-
456
- ginkgo .By ("test for subpath mounted with old value" )
457
- cmd := "test -f /volume_mount/foo/test.log"
458
- _ , _ , err = f .ExecShellInPodWithFullOutput (pod .Name , cmd )
459
- if err != nil {
460
- framework .Failf ("expected to be able to verify old file exists" )
461
- }
462
-
463
- cmd = "test ! -f /volume_mount/newsubpath/test.log"
464
- _ , _ , err = f .ExecShellInPodWithFullOutput (pod .Name , cmd )
465
- if err != nil {
466
- framework .Failf ("expected to be able to verify new file does not exist" )
467
- }
468
- })
469
360
})
470
361
471
362
func testPodFailSubpath (f * framework.Framework , pod * v1.Pod ) {
@@ -480,72 +371,6 @@ func testPodFailSubpath(f *framework.Framework, pod *v1.Pod) {
480
371
framework .ExpectError (err , "while waiting for pod to be running" )
481
372
}
482
373
483
- // Tests that the existing subpath mount is detected when a container restarts
484
- func waitForPodContainerRestart (f * framework.Framework , pod * v1.Pod , volumeMount string ) {
485
-
486
- ginkgo .By ("Failing liveness probe" )
487
- stdout , stderr , err := f .ExecShellInPodWithFullOutput (pod .Name , fmt .Sprintf ("rm %v" , volumeMount ))
488
-
489
- framework .Logf ("Pod exec output: %v / %v" , stdout , stderr )
490
- framework .ExpectNoError (err , "while failing liveness probe" )
491
-
492
- // Check that container has restarted
493
- ginkgo .By ("Waiting for container to restart" )
494
- restarts := int32 (0 )
495
- err = wait .PollImmediate (10 * time .Second , 2 * time .Minute , func () (bool , error ) {
496
- pod , err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Get (context .TODO (), pod .Name , metav1.GetOptions {})
497
- if err != nil {
498
- return false , err
499
- }
500
- for _ , status := range pod .Status .ContainerStatuses {
501
- if status .Name == pod .Spec .Containers [0 ].Name {
502
- framework .Logf ("Container %v, restarts: %v" , status .Name , status .RestartCount )
503
- restarts = status .RestartCount
504
- if restarts > 0 {
505
- framework .Logf ("Container has restart count: %v" , restarts )
506
- return true , nil
507
- }
508
- }
509
- }
510
- return false , nil
511
- })
512
- framework .ExpectNoError (err , "while waiting for container to restart" )
513
-
514
- // Fix liveness probe
515
- ginkgo .By ("Rewriting the file" )
516
- stdout = f .ExecShellInContainer (pod .Name , pod .Spec .Containers [1 ].Name , fmt .Sprintf ("echo test-after > %v" , volumeMount ))
517
- framework .Logf ("Pod exec output: %v" , stdout )
518
-
519
- // Wait for container restarts to stabilize
520
- ginkgo .By ("Waiting for container to stop restarting" )
521
- stableCount := int (0 )
522
- stableThreshold := int (time .Minute / framework .Poll )
523
- err = wait .PollImmediate (framework .Poll , 2 * time .Minute , func () (bool , error ) {
524
- pod , err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Get (context .TODO (), pod .Name , metav1.GetOptions {})
525
- if err != nil {
526
- return false , err
527
- }
528
- for _ , status := range pod .Status .ContainerStatuses {
529
- if status .Name == pod .Spec .Containers [0 ].Name {
530
- if status .RestartCount == restarts {
531
- stableCount ++
532
- if stableCount > stableThreshold {
533
- framework .Logf ("Container restart has stabilized" )
534
- return true , nil
535
- }
536
- } else {
537
- restarts = status .RestartCount
538
- stableCount = 0
539
- framework .Logf ("Container has restart count: %v" , restarts )
540
- }
541
- break
542
- }
543
- }
544
- return false , nil
545
- })
546
- framework .ExpectNoError (err , "while waiting for container to stabilize" )
547
- }
548
-
549
374
func newPod (command []string , envVars []v1.EnvVar , mounts []v1.VolumeMount , volumes []v1.Volume ) * v1.Pod {
550
375
podName := "var-expansion-" + string (uuid .NewUUID ())
551
376
return & v1.Pod {
0 commit comments