@@ -59,8 +59,7 @@ const (
5959 // naming format <pod_name>_<namespace>_<container_name>-<containerdID(hash, with <docker/cri>:// prefix removed)>.log
6060 ContainerSymlinkSourceTemplate = "%s_%s_%s-%s.log"
6161
62- MultiNamespaceMode = "multi-namespace-mode"
63- SyncerContainer = "syncer"
62+ SyncerContainer = "syncer"
6463
6564 optionsKey key = iota
6665
@@ -84,6 +83,7 @@ type VirtualClusterOptions struct {
8483 VirtualPodLogsPath string
8584 VirtualContainerLogsPath string
8685 VirtualKubeletPodPath string
86+ ToHostNamespacesEnabled bool
8787}
8888
8989func NewHostpathMapperCommand () * cobra.Command {
@@ -228,29 +228,6 @@ func Start(ctx context.Context, options *VirtualClusterOptions, init bool) error
228228 return mapHostPaths (ctx , localManager , virtualClusterManager )
229229}
230230
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-
254231func getVclusterConfigFromSecret (ctx context.Context , kubeClient kubernetes.Interface , vclusterName , vclusterNamespace string ) (* config.Config , error ) {
255232 configSecret , err := kubeClient .CoreV1 ().Secrets (vclusterNamespace ).Get (ctx , fmt .Sprintf (configSecretNameTemplate , vclusterName ), metav1.GetOptions {})
256233 if err != nil {
@@ -273,11 +250,6 @@ func getVclusterConfigFromSecret(ctx context.Context, kubeClient kubernetes.Inte
273250 return rawConfig , nil
274251}
275252
276- func setMultiNamespaceMode (options * VirtualClusterOptions ) {
277- options .MultiNamespaceMode = true
278- translate .Default = translate .NewMultiNamespaceTranslator (options .TargetNamespace )
279- }
280-
281253func localManagerCtrlOptions (options * VirtualClusterOptions ) manager.Options {
282254 controllerOptions := ctrl.Options {
283255 Scheme : scheme ,
@@ -286,7 +258,7 @@ func localManagerCtrlOptions(options *VirtualClusterOptions) manager.Options {
286258 NewClient : pluginhookclient .NewPhysicalPluginClientFactory (blockingcacheclient .NewCacheClient ),
287259 }
288260
289- if ! options .MultiNamespaceMode {
261+ if ! options .ToHostNamespacesEnabled {
290262 controllerOptions .Cache .DefaultNamespaces = map [string ]cache.Config {options .TargetNamespace : {}}
291263 }
292264
@@ -297,26 +269,8 @@ func findVclusterModeAndSetDefaultTranslation(ctx context.Context, kubeClient ku
297269 vClusterConfig , err := getVclusterConfigFromSecret (ctx , kubeClient , options .Name , options .TargetNamespace )
298270 if err != nil && ! kerrors .IsNotFound (err ) {
299271 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- }
272+ } else if vClusterConfig != nil && vClusterConfig .Sync .ToHost .Namespaces .Enabled {
273+ options .ToHostNamespacesEnabled = true
320274 }
321275
322276 translate .Default = translate .NewSingleNamespaceTranslator (options .TargetNamespace )
@@ -477,7 +431,7 @@ func getPhysicalPodMap(ctx context.Context, options *VirtualClusterOptions, pMan
477431 }),
478432 }
479433
480- if ! options .MultiNamespaceMode {
434+ if ! options .ToHostNamespacesEnabled {
481435 podListOptions .Namespace = options .TargetNamespace
482436 }
483437
@@ -488,7 +442,7 @@ func getPhysicalPodMap(ctx context.Context, options *VirtualClusterOptions, pMan
488442 }
489443
490444 var pods []corev1.Pod
491- if options .MultiNamespaceMode {
445+ if options .ToHostNamespacesEnabled {
492446 // find namespaces managed by the current vcluster
493447 nsList := & corev1.NamespaceList {}
494448 err = pManager .GetClient ().List (ctx , nsList , & client.ListOptions {
0 commit comments