@@ -72,13 +72,26 @@ func NewKCPManager(
7272 // to discover workspaces, not the base KCP host
7373 apiexportConfig := rest .CopyConfig (opts .Config )
7474
75- // Construct the APIExport URL from the base host
76- // We know the APIExport name is "core.platform-mesh.io" and we need to find the cluster hash
77- baseHost := opts .Config .Host
75+ // Extract base KCP host from kubeconfig, stripping any APIExport paths
76+ // This ensures we work with both base KCP hosts and APIExport URLs in kubeconfig
77+ originalHost := opts .Config .Host
78+ baseHost := stripAPIExportPath (originalHost )
7879
79- // For now, we'll construct a known APIExport URL
80- // TODO: This should be made configurable or discovered dynamically
81- apiexportURL := baseHost + "/services/apiexport/1mx3340lwq4c8kkw/core.platform-mesh.io/"
80+ log .Info ().
81+ Str ("originalHost" , originalHost ).
82+ Str ("baseHost" , baseHost ).
83+ Msg ("Extracted base KCP host from kubeconfig" )
84+
85+ // Construct the APIExport URL for multicluster-provider discovery
86+ // We need to extract the cluster hash from the original APIExport URL if present
87+ clusterHash := extractClusterHashFromAPIExportURL (originalHost )
88+ if clusterHash == "" {
89+ // Fallback to a known cluster hash - this should be made configurable
90+ clusterHash = "1mx3340lwq4c8kkw"
91+ log .Warn ().Str ("fallbackHash" , clusterHash ).Msg ("Could not extract cluster hash from kubeconfig, using fallback" )
92+ }
93+
94+ apiexportURL := fmt .Sprintf ("%s/services/apiexport/%s/core.platform-mesh.io/" , baseHost , clusterHash )
8295
8396 log .Info ().Str ("baseHost" , baseHost ).Str ("apiexportURL" , apiexportURL ).Msg ("Using APIExport URL for multicluster provider" )
8497 apiexportConfig .Host = apiexportURL
@@ -253,7 +266,9 @@ func (m *KCPManager) generateAndWriteSchemaForWorkspace(ctx context.Context, wor
253266 // The multicluster-provider is only used for workspace discovery in the listener
254267 // The gateway will use standard Kubernetes clients with direct workspace URLs
255268 baseConfig := m .mcMgr .GetLocalManager ().GetConfig ()
256- baseHost := baseConfig .Host
269+
270+ // Strip APIExport path from the base config host to get the clean KCP host
271+ baseHost := stripAPIExportPath (baseConfig .Host )
257272
258273 // Construct direct workspace URL like main branch: /clusters/{workspace}
259274 directWorkspaceHost := fmt .Sprintf ("%s/clusters/%s" , baseHost , workspacePath )
0 commit comments