Skip to content

Commit 3ce44c1

Browse files
authored
update vcluster dependency to version 0.26.1 (#30)
* drop support for sync.toHost.namespaces * update vcluster dependency to version 0.26.1
1 parent 17d0d67 commit 3ce44c1

File tree

116 files changed

+11890
-4590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+11890
-4590
lines changed

cmd/hostpaths/hostpaths.go

Lines changed: 15 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
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-
254236
func 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-
296258
func 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)

go.mod

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ toolchain go1.24.2
66

77
require (
88
github.com/go-openapi/loads v0.21.2
9-
github.com/loft-sh/vcluster v0.25.0
9+
github.com/loft-sh/vcluster v0.26.1
1010
github.com/pkg/errors v0.9.1
1111
github.com/spf13/cobra v1.8.1
1212
gotest.tools v2.2.0+incompatible
13-
k8s.io/api v0.32.1
14-
k8s.io/apimachinery v0.32.1
15-
k8s.io/client-go v0.32.1
13+
k8s.io/api v0.32.8
14+
k8s.io/apimachinery v0.32.8
15+
k8s.io/client-go v0.32.8
1616
k8s.io/klog/v2 v2.130.1
1717
sigs.k8s.io/controller-runtime v0.20.1
1818
sigs.k8s.io/yaml v1.4.0
@@ -87,10 +87,10 @@ require (
8787
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
8888
github.com/kylelemons/godebug v1.1.0 // indirect
8989
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
90-
github.com/loft-sh/admin-apis v0.0.0-20240203010124-3600c1c582a8 // indirect
91-
github.com/loft-sh/agentapi/v4 v4.0.0-alpha.6.0.20240614131646-3359da6a4818 // indirect
92-
github.com/loft-sh/api/v4 v4.0.0-alpha.6.0.20240614134907-f9ecc1668e9e // indirect
93-
github.com/loft-sh/apiserver v0.0.0-20240607231110-634aeeab2b36 // indirect
90+
github.com/loft-sh/admin-apis v0.0.0-20250429193833-4e0a455c33dd // indirect
91+
github.com/loft-sh/agentapi/v4 v4.3.0-alpha.39 // indirect
92+
github.com/loft-sh/api/v4 v4.3.0-alpha.32 // indirect
93+
github.com/loft-sh/apiserver v0.0.0-20250206205835-422f1d472459 // indirect
9494
github.com/loft-sh/log v0.0.0-20240219160058-26d83ffb46ac // indirect
9595
github.com/mailru/easyjson v0.7.7 // indirect
9696
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -109,7 +109,7 @@ require (
109109
github.com/oklog/run v1.0.0 // indirect
110110
github.com/oklog/ulid v1.3.1 // indirect
111111
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
112-
github.com/prometheus/client_golang v1.20.4 // indirect
112+
github.com/prometheus/client_golang v1.20.5 // indirect
113113
github.com/prometheus/client_model v0.6.1 // indirect
114114
github.com/prometheus/common v0.60.0 // indirect
115115
github.com/prometheus/procfs v0.15.1 // indirect
@@ -142,15 +142,15 @@ require (
142142
go.uber.org/multierr v1.11.0 // indirect
143143
go.uber.org/zap v1.27.0 // indirect
144144
golang.org/x/crypto v0.36.0 // indirect
145-
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect
145+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
146146
golang.org/x/mod v0.22.0 // indirect
147147
golang.org/x/net v0.38.0 // indirect
148148
golang.org/x/oauth2 v0.28.0 // indirect
149149
golang.org/x/sync v0.12.0 // indirect
150150
golang.org/x/sys v0.31.0 // indirect
151151
golang.org/x/term v0.30.0 // indirect
152152
golang.org/x/text v0.23.0 // indirect
153-
golang.org/x/time v0.7.0 // indirect
153+
golang.org/x/time v0.9.0 // indirect
154154
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
155155
google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect
156156
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
@@ -161,15 +161,15 @@ require (
161161
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
162162
gopkg.in/yaml.v2 v2.4.0 // indirect
163163
gopkg.in/yaml.v3 v3.0.1 // indirect
164-
k8s.io/apiextensions-apiserver v0.32.1 // indirect
165-
k8s.io/apiserver v0.32.1 // indirect
166-
k8s.io/cli-runtime v0.32.1 // indirect
167-
k8s.io/component-base v0.32.1 // indirect
168-
k8s.io/component-helpers v0.32.1 // indirect
169-
k8s.io/kube-aggregator v0.32.1 // indirect
164+
k8s.io/apiextensions-apiserver v0.32.8 // indirect
165+
k8s.io/apiserver v0.32.8 // indirect
166+
k8s.io/cli-runtime v0.32.8 // indirect
167+
k8s.io/component-base v0.32.8 // indirect
168+
k8s.io/component-helpers v0.32.8 // indirect
169+
k8s.io/kube-aggregator v0.32.8 // indirect
170170
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
171-
k8s.io/kubectl v0.32.1 // indirect
172-
k8s.io/metrics v0.32.1 // indirect
171+
k8s.io/kubectl v0.32.8 // indirect
172+
k8s.io/metrics v0.32.8 // indirect
173173
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
174174
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
175175
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

0 commit comments

Comments
 (0)