99 "strings"
1010 "time"
1111
12- "github.com/loft-sh/vcluster/pkg/controllers/resources/namespaces"
1312 podtranslate "github.com/loft-sh/vcluster/pkg/controllers/resources/pods/translate"
1413 "github.com/loft-sh/vcluster/pkg/util/clienthelper"
1514
@@ -24,7 +23,6 @@ import (
2423 kerrors "k8s.io/apimachinery/pkg/api/errors"
2524 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625 "k8s.io/apimachinery/pkg/fields"
27- "k8s.io/apimachinery/pkg/labels"
2826 "k8s.io/apimachinery/pkg/runtime"
2927 "k8s.io/apimachinery/pkg/util/wait"
3028 "k8s.io/client-go/kubernetes"
@@ -59,8 +57,7 @@ const (
5957 // naming format <pod_name>_<namespace>_<container_name>-<containerdID(hash, with <docker/cri>:// prefix removed)>.log
6058 ContainerSymlinkSourceTemplate = "%s_%s_%s-%s.log"
6159
62- MultiNamespaceMode = "multi-namespace-mode"
63- SyncerContainer = "syncer"
60+ SyncerContainer = "syncer"
6461
6562 optionsKey key = iota
6663
@@ -191,7 +188,15 @@ func Start(ctx context.Context, options *VirtualClusterOptions, init bool) error
191188 return fmt .Errorf ("find vcluster mode: %w" , err )
192189 }
193190
194- localManager , err := ctrl .NewManager (inClusterConfig , localManagerCtrlOptions (options ))
191+ localManager , err := ctrl .NewManager (inClusterConfig , ctrl.Options {
192+ Scheme : scheme ,
193+ Metrics : metricsserver.Options {BindAddress : "0" },
194+ LeaderElection : false ,
195+ NewClient : pluginhookclient .NewPhysicalPluginClientFactory (blockingcacheclient .NewCacheClient ),
196+ Cache : cache.Options {
197+ DefaultNamespaces : map [string ]cache.Config {options .TargetNamespace : {}},
198+ },
199+ })
195200 if err != nil {
196201 return err
197202 }
@@ -228,29 +233,6 @@ func Start(ctx context.Context, options *VirtualClusterOptions, init bool) error
228233 return mapHostPaths (ctx , localManager , virtualClusterManager )
229234}
230235
231- func getSyncerPodSpec (ctx context.Context , kubeClient kubernetes.Interface , vclusterName , vclusterNamespace string ) (* corev1.PodSpec , error ) {
232- // try looking for the stateful set first
233-
234- vclusterSts , err := kubeClient .AppsV1 ().StatefulSets (vclusterNamespace ).Get (ctx , vclusterName , metav1.GetOptions {})
235- if kerrors .IsNotFound (err ) {
236- // try looking for deployment - in case of eks/k8s
237- vclusterDeploy , err := kubeClient .AppsV1 ().Deployments (vclusterNamespace ).Get (ctx , vclusterName , metav1.GetOptions {})
238- if kerrors .IsNotFound (err ) {
239- klog .Errorf ("could not find vcluster either in statefulset or deployment: %v" , err )
240- return nil , err
241- } else if err != nil {
242- klog .Errorf ("error looking for vcluster deployment: %v" , err )
243- return nil , err
244- }
245-
246- return & vclusterDeploy .Spec .Template .Spec , nil
247- } else if err != nil {
248- return nil , err
249- }
250-
251- return & vclusterSts .Spec .Template .Spec , nil
252- }
253-
254236func getVclusterConfigFromSecret (ctx context.Context , kubeClient kubernetes.Interface , vclusterName , vclusterNamespace string ) (* config.Config , error ) {
255237 configSecret , err := kubeClient .CoreV1 ().Secrets (vclusterNamespace ).Get (ctx , fmt .Sprintf (configSecretNameTemplate , vclusterName ), metav1.GetOptions {})
256238 if err != nil {
@@ -273,50 +255,12 @@ func getVclusterConfigFromSecret(ctx context.Context, kubeClient kubernetes.Inte
273255 return rawConfig , nil
274256}
275257
276- func setMultiNamespaceMode (options * VirtualClusterOptions ) {
277- options .MultiNamespaceMode = true
278- translate .Default = translate .NewMultiNamespaceTranslator (options .TargetNamespace )
279- }
280-
281- func localManagerCtrlOptions (options * VirtualClusterOptions ) manager.Options {
282- controllerOptions := ctrl.Options {
283- Scheme : scheme ,
284- Metrics : metricsserver.Options {BindAddress : "0" },
285- LeaderElection : false ,
286- NewClient : pluginhookclient .NewPhysicalPluginClientFactory (blockingcacheclient .NewCacheClient ),
287- }
288-
289- if ! options .MultiNamespaceMode {
290- controllerOptions .Cache .DefaultNamespaces = map [string ]cache.Config {options .TargetNamespace : {}}
291- }
292-
293- return controllerOptions
294- }
295-
296258func findVclusterModeAndSetDefaultTranslation (ctx context.Context , kubeClient kubernetes.Interface , options * VirtualClusterOptions ) error {
297259 vClusterConfig , err := getVclusterConfigFromSecret (ctx , kubeClient , options .Name , options .TargetNamespace )
298260 if err != nil && ! kerrors .IsNotFound (err ) {
299261 return err
300- } else if vClusterConfig != nil && vClusterConfig .Experimental .MultiNamespaceMode .Enabled {
301- setMultiNamespaceMode (options )
302- return nil
303- }
304-
305- vclusterPodSpec , err := getSyncerPodSpec (ctx , kubeClient , options .Name , options .TargetNamespace )
306- if err != nil {
307- return err
308- }
309-
310- for _ , container := range vclusterPodSpec .Containers {
311- if container .Name == SyncerContainer {
312- // iterate over command args
313- for _ , arg := range container .Args {
314- if strings .Contains (arg , MultiNamespaceMode ) {
315- setMultiNamespaceMode (options )
316- return nil
317- }
318- }
319- }
262+ } else if vClusterConfig != nil && vClusterConfig .Sync .ToHost .Namespaces .Enabled {
263+ return fmt .Errorf ("unsupported vCluster config. Hostpathmapper is not compatible with toHost namespace syncing (sync.toHost.namespaces)" )
320264 }
321265
322266 translate .Default = translate .NewSingleNamespaceTranslator (options .TargetNamespace )
@@ -475,10 +419,7 @@ func getPhysicalPodMap(ctx context.Context, options *VirtualClusterOptions, pMan
475419 FieldSelector : fields .SelectorFromSet (fields.Set {
476420 NodeIndexName : os .Getenv (HostpathMapperSelfNodeNameEnvVar ),
477421 }),
478- }
479-
480- if ! options .MultiNamespaceMode {
481- podListOptions .Namespace = options .TargetNamespace
422+ Namespace : options .TargetNamespace ,
482423 }
483424
484425 podList := & corev1.PodList {}
@@ -487,32 +428,8 @@ func getPhysicalPodMap(ctx context.Context, options *VirtualClusterOptions, pMan
487428 return nil , fmt .Errorf ("unable to list pods: %w" , err )
488429 }
489430
490- var pods []corev1.Pod
491- if options .MultiNamespaceMode {
492- // find namespaces managed by the current vcluster
493- nsList := & corev1.NamespaceList {}
494- err = pManager .GetClient ().List (ctx , nsList , & client.ListOptions {
495- LabelSelector : labels .SelectorFromSet (labels.Set {
496- namespaces .VClusterNamespaceAnnotation : options .TargetNamespace ,
497- }),
498- })
499- if err != nil {
500- return nil , fmt .Errorf ("unable to list namespaces: %w" , err )
501- }
502-
503- vclusterNamespaces := make (map [string ]struct {}, len (nsList .Items ))
504- for _ , ns := range nsList .Items {
505- vclusterNamespaces [ns .Name ] = struct {}{}
506- }
507-
508- // Limit Pods
509- pods = filter (ctx , podList .Items , vclusterNamespaces )
510- } else {
511- pods = podList .Items
512- }
513-
514- podMappings := make (PhysicalPodMap , len (pods ))
515- for _ , pPod := range pods {
431+ podMappings := make (PhysicalPodMap , len (podList .Items ))
432+ for _ , pPod := range podList .Items {
516433 lookupName := fmt .Sprintf ("%s_%s_%s" , pPod .Namespace , pPod .Name , pPod .UID )
517434
518435 ok , err := checkIfPathExists (lookupName )
0 commit comments