4
4
"context"
5
5
"fmt"
6
6
"net/url"
7
- "path"
8
7
"slices"
9
8
"strings"
10
9
@@ -138,7 +137,23 @@ func ContentConfigurationLookup(client dynamic.ClusterInterface, cfg config.Serv
138
137
})
139
138
}
140
139
141
- func setupVirtualWorkspaceClient (kubeconfigPath , serverURL , virtualWorkspacePath string ) (* dynamic.ClusterClientset , error ) {
140
+ func setupVirtualWorkspaceClient (ctx context.Context , dynamicClient dynamic.ClusterInterface , kubeconfigPath , serverURL , endpointSliceWorkspace , endpointSliceName string ) (* dynamic.ClusterClientset , error ) {
141
+
142
+ res , err := dynamicClient .Cluster (logicalcluster .NewPath (endpointSliceWorkspace )).Resource (schema.GroupVersionResource {
143
+ Group : "apis.kcp.io" ,
144
+ Version : "v1alpha1" ,
145
+ Resource : "apiexportendpointslices" ,
146
+ }).Get (ctx , endpointSliceName , metav1.GetOptions {})
147
+ if err != nil {
148
+ return nil , err
149
+ }
150
+
151
+ var eps apisv1alpha1.APIExportEndpointSlice
152
+ err = runtime .DefaultUnstructuredConverter .FromUnstructured (res .Object , & eps )
153
+ if err != nil {
154
+ return nil , err
155
+ }
156
+
142
157
clientCfg , err := clientcmd .BuildConfigFromFlags ("" , kubeconfigPath )
143
158
if err != nil {
144
159
return nil , err
@@ -150,22 +165,20 @@ func setupVirtualWorkspaceClient(kubeconfigPath, serverURL, virtualWorkspacePath
150
165
clientCfg .Host = serverURL
151
166
}
152
167
168
+ epsURL , _ := url .Parse (eps .Status .APIExportEndpoints [0 ].URL )
169
+
153
170
parsed , _ := url .Parse (clientCfg .Host )
154
- pathSegments := strings .Split (virtualWorkspacePath , "/" )
155
- parsed .Path = path .Join (pathSegments ... )
171
+ parsed .Path = epsURL .Path
156
172
157
173
clientCfg .Host = parsed .String ()
158
174
175
+ fmt .Println ("Using APIExportEndpointSlice URL:" , clientCfg .Host )
176
+
159
177
return dynamic .NewForConfig (clientCfg )
160
178
}
161
179
162
- func Marketplace (cfg config.ServiceConfig ) (forwardingregistry.StorageWrapper , error ) {
163
- providerMetadataClient , err := setupVirtualWorkspaceClient (cfg .Kubeconfig , cfg .ServerURL , cfg .ProviderMetadataVirtualWorkspacePath )
164
- if err != nil {
165
- return nil , err
166
- }
167
-
168
- apiExportClient , err := setupVirtualWorkspaceClient (cfg .Kubeconfig , cfg .ServerURL , cfg .APIExportVirtualWorkspacePath )
180
+ func Marketplace (ctx context.Context , cfg config.ServiceConfig , dynamicClient dynamic.ClusterInterface ) (forwardingregistry.StorageWrapper , error ) {
181
+ resourceClient , err := setupVirtualWorkspaceClient (ctx , dynamicClient , cfg .Kubeconfig , cfg .ServerURL , cfg .ResourceSchemaWorkspace , cfg .ResourceAPIExportEndpointSliceName )
169
182
if err != nil {
170
183
return nil , err
171
184
}
@@ -176,7 +189,7 @@ func Marketplace(cfg config.ServiceConfig) (forwardingregistry.StorageWrapper, e
176
189
var installedAPIBindings apisv1alpha1.APIBindingList
177
190
cluster := genericapirequest .ClusterFrom (ctx )
178
191
179
- rawBindings , err := apiExportClient .Cluster (cluster .Name .Path ()).
192
+ rawBindings , err := resourceClient .Cluster (cluster .Name .Path ()).
180
193
Resource (apisv1alpha1 .SchemeGroupVersion .WithResource ("apibindings" )).
181
194
List (ctx , metav1.ListOptions {})
182
195
if err != nil {
@@ -197,7 +210,7 @@ func Marketplace(cfg config.ServiceConfig) (forwardingregistry.StorageWrapper, e
197
210
return nil , err
198
211
}
199
212
200
- providers , err := providerMetadataClient .Cluster (logicalcluster .Wildcard ).
213
+ providers , err := resourceClient .Cluster (logicalcluster .Wildcard ).
201
214
Resource (extensionapiv1alpha1 .GroupVersion .WithResource ("providermetadatas" )).
202
215
List (ctx , metav1.ListOptions {})
203
216
if err != nil {
@@ -215,7 +228,7 @@ func Marketplace(cfg config.ServiceConfig) (forwardingregistry.StorageWrapper, e
215
228
return err
216
229
}
217
230
218
- rawExports , err := apiExportClient .Cluster (logicalcluster .Wildcard ).Resource (
231
+ rawExports , err := resourceClient .Cluster (logicalcluster .Wildcard ).Resource (
219
232
schema.GroupVersionResource {
220
233
Group : apisv1alpha1 .SchemeGroupVersion .Group ,
221
234
Version : apisv1alpha1 .SchemeGroupVersion .Version ,
0 commit comments