@@ -224,8 +224,8 @@ func Start(ctx context.Context, options *VirtualClusterOptions, init bool) error
224
224
return err
225
225
}
226
226
}
227
- mapHostPaths ( ctx , localManager , virtualClusterManager )
228
- return nil
227
+
228
+ return mapHostPaths ( ctx , localManager , virtualClusterManager )
229
229
}
230
230
231
231
func getSyncerPodSpec (ctx context.Context , kubeClient kubernetes.Interface , vclusterName , vclusterNamespace string ) (* corev1.PodSpec , error ) {
@@ -378,14 +378,14 @@ podLoop:
378
378
return nil
379
379
}
380
380
381
- func mapHostPaths (ctx context.Context , pManager , vManager manager.Manager ) {
381
+ func mapHostPaths (ctx context.Context , pManager , vManager manager.Manager ) error {
382
382
options := ctx .Value (optionsKey ).(* VirtualClusterOptions )
383
383
384
- wait . Forever ( func () {
384
+ mapFunc := func () error {
385
385
podMappings , err := getPhysicalPodMap (ctx , options , pManager )
386
386
if err != nil {
387
387
klog .Errorf ("unable to get physical pod mapping: %v" , err )
388
- return
388
+ return nil
389
389
}
390
390
391
391
vPodList := & corev1.PodList {}
@@ -396,7 +396,7 @@ func mapHostPaths(ctx context.Context, pManager, vManager manager.Manager) {
396
396
})
397
397
if err != nil {
398
398
klog .Errorf ("unable to list pods: %v" , err )
399
- return
399
+ return nil
400
400
}
401
401
402
402
existingVPodsWithNamespace := make (map [string ]bool )
@@ -416,21 +416,27 @@ func mapHostPaths(ctx context.Context, pManager, vManager manager.Manager) {
416
416
417
417
_ , err := createPodLogSymlinkToPhysical (source , target )
418
418
if err != nil {
419
- klog .Errorf ("unable to create symlink for %s: %v " , podDetail .Target , err )
419
+ return fmt .Errorf ("unable to create symlink for %s: %w " , podDetail .Target , err )
420
420
}
421
421
422
422
// create kubelet pod symlink
423
423
kubeletPodSymlinkSource := filepath .Join (options .VirtualKubeletPodPath , string (vPod .GetUID ()))
424
424
kubeletPodSymlinkTarget := filepath .Join (podtranslate .PhysicalKubeletVolumeMountPath , string (podDetail .PhysicalPod .GetUID ()))
425
425
existingKubeletPodsPath [kubeletPodSymlinkSource ] = true
426
- createKubeletVirtualToPhysicalPodLinks (kubeletPodSymlinkSource , kubeletPodSymlinkTarget )
426
+ err = createKubeletVirtualToPhysicalPodLinks (kubeletPodSymlinkSource , kubeletPodSymlinkTarget )
427
+ if err != nil {
428
+ return err
429
+ }
427
430
428
431
// podDetail.SymLinkName = symlinkName
429
432
430
433
// create container to vPod symlinks
431
434
containerSymlinkTargetDir := filepath .Join (PodLogsMountPath ,
432
435
fmt .Sprintf ("%s_%s_%s" , vPod .Namespace , vPod .Name , string (vPod .UID )))
433
- createContainerToPodSymlink (ctx , vPod , podDetail , containerSymlinkTargetDir )
436
+ err = createContainerToPodSymlink (ctx , vPod , podDetail , containerSymlinkTargetDir )
437
+ if err != nil {
438
+ return err
439
+ }
434
440
}
435
441
}
436
442
@@ -451,7 +457,17 @@ func mapHostPaths(ctx context.Context, pManager, vManager manager.Manager) {
451
457
}
452
458
453
459
klog .Infof ("successfully reconciled mapper" )
454
- }, time .Second * 5 )
460
+ return nil
461
+ }
462
+
463
+ for {
464
+ err := mapFunc ()
465
+ if err != nil {
466
+ return err
467
+ }
468
+
469
+ time .Sleep (5 * time .Second )
470
+ }
455
471
}
456
472
457
473
func getPhysicalPodMap (ctx context.Context , options * VirtualClusterOptions , pManager manager.Manager ) (PhysicalPodMap , error ) {
@@ -557,20 +573,18 @@ func cleanupOldContainerPaths(ctx context.Context, existingVPodsWithNS map[strin
557
573
return nil
558
574
}
559
575
560
- func createKubeletVirtualToPhysicalPodLinks (vPodDirName , pPodDirName string ) {
576
+ func createKubeletVirtualToPhysicalPodLinks (vPodDirName , pPodDirName string ) error {
561
577
err := os .MkdirAll (vPodDirName , os .ModeDir )
562
578
if err != nil {
563
- klog .Errorf ("error creating vPod kubelet directory for %s: %v" , vPodDirName , err )
564
- return
579
+ return fmt .Errorf ("error creating vPod kubelet directory for %s: %w" , vPodDirName , err )
565
580
}
566
581
567
582
// scan all contents in the physical pod dir
568
583
// and create equivalent symlinks from virtual
569
584
// path to physical
570
585
contents , err := os .ReadDir (pPodDirName )
571
586
if err != nil {
572
- klog .Errorf ("error reading physical kubelet pod dir %s: %v" , pPodDirName , err )
573
- return
587
+ return fmt .Errorf ("error reading physical kubelet pod dir %s: %w" , pPodDirName , err )
574
588
}
575
589
576
590
for _ , content := range contents {
@@ -582,12 +596,14 @@ func createKubeletVirtualToPhysicalPodLinks(vPodDirName, pPodDirName string) {
582
596
fullKubeletVirtualPodPath )
583
597
if err != nil {
584
598
if ! os .IsExist (err ) {
585
- klog .Errorf ("error creating symlink for %s -> %s: %v " , fullKubeletVirtualPodPath , fullKubeletPhysicalPodPath , err )
599
+ return fmt .Errorf ("error creating symlink for %s -> %s: %w " , fullKubeletVirtualPodPath , fullKubeletPhysicalPodPath , err )
586
600
}
587
601
} else {
588
602
klog .Infof ("created kubelet pod symlink %s -> %s" , fullKubeletVirtualPodPath , fullKubeletPhysicalPodPath )
589
603
}
590
604
}
605
+
606
+ return nil
591
607
}
592
608
593
609
func cleanupOldPodPath (ctx context.Context , cleanupDirPath string , existingPodPathsFromAPIServer map [string ]bool ) error {
@@ -641,7 +657,7 @@ func cleanupOldPodPath(ctx context.Context, cleanupDirPath string, existingPodPa
641
657
return nil
642
658
}
643
659
644
- func createContainerToPodSymlink (ctx context.Context , vPod corev1.Pod , pPodDetail * PodDetail , targetDir string ) {
660
+ func createContainerToPodSymlink (ctx context.Context , vPod corev1.Pod , pPodDetail * PodDetail , targetDir string ) error {
645
661
options := ctx .Value (optionsKey ).(* VirtualClusterOptions )
646
662
647
663
for _ , containerStatus := range vPod .Status .ContainerStatuses {
@@ -673,14 +689,16 @@ func createContainerToPodSymlink(ctx context.Context, vPod corev1.Pod, pPodDetai
673
689
err = os .Symlink (target , source )
674
690
if err != nil {
675
691
if ! os .IsExist (err ) {
676
- klog .Errorf ("error creating container:%s to pod:%s symlink: %v " , source , target , err )
692
+ return fmt .Errorf ("error creating container:%s to pod:%s symlink: %w " , source , target , err )
677
693
}
678
694
679
695
continue
680
696
}
681
697
682
698
klog .Infof ("created container:%s -> pod:%s symlink" , source , target )
683
699
}
700
+
701
+ return nil
684
702
}
685
703
686
704
// we need to get the info that which log file in the physical pod dir
0 commit comments