@@ -10,7 +10,6 @@ import (
1010 "github.com/ghodss/yaml"
1111 managementv1 "github.com/loft-sh/api/v4/pkg/apis/management/v1"
1212 "github.com/loft-sh/log"
13- "github.com/loft-sh/vcluster/config"
1413 "github.com/loft-sh/vcluster/pkg/cli/find"
1514 "github.com/loft-sh/vcluster/pkg/cli/flags"
1615 "github.com/loft-sh/vcluster/pkg/cli/localkubernetes"
@@ -23,6 +22,7 @@ import (
2322 corev1 "k8s.io/api/core/v1"
2423 kerrors "k8s.io/apimachinery/pkg/api/errors"
2524 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2626 "k8s.io/client-go/kubernetes"
2727 "k8s.io/client-go/rest"
2828 "k8s.io/client-go/tools/clientcmd"
@@ -127,10 +127,17 @@ func DeleteHelm(ctx context.Context, platformClient platform.Client, options *De
127127 return err
128128 }
129129
130- vclusterConfig := & config.Config {}
131- err = yaml .Unmarshal (values , vclusterConfig )
132- if err != nil {
133- return err
130+ var configValues map [string ]any
131+ namespacesSyncEnabled := false
132+ if err := yaml .Unmarshal (values , & configValues ); err != nil {
133+ cmd .log .Debugf ("Error parsing vcluster config from Helm values: %v. Namespace sync will be disabled" , err )
134+ } else {
135+ enabled , isFound , err := unstructured .NestedBool (configValues , "sync" , "toHost" , "namespaces" , "enabled" )
136+ if err != nil {
137+ cmd .log .Debugf ("Error getting namespace sync enabled flag: %v. Namespace sync will be disabled" , err )
138+ } else if isFound {
139+ namespacesSyncEnabled = enabled
140+ }
134141 }
135142
136143 // we have to delete the chart
@@ -203,7 +210,7 @@ func DeleteHelm(ctx context.Context, platformClient platform.Client, options *De
203210 }
204211
205212 // if namespace sync is enabled, use cleanup handlers to handle namespace cleanup
206- if vclusterConfig . Sync . ToHost . Namespaces . Enabled {
213+ if namespacesSyncEnabled {
207214 if err := CleanupSyncedNamespaces (ctx , cmd .Namespace , vClusterName , cmd .restConfig , cmd .kubeClient , cmd .log ); err != nil {
208215 return fmt .Errorf ("run namespace cleanup: %w" , err )
209216 }
0 commit comments