@@ -359,7 +359,7 @@ func TestAPIBinding(t *testing.T) {
359
359
360
360
var names []string
361
361
for _ , shard := range shards .Items {
362
- t .Logf ("Doing a wildcard identity list for %v against %s workspace shard" , gvrWithIdentity , consumerWorkspace )
362
+ t .Logf ("Doing a wildcard identity list for %v against %s workspace on shard %s " , gvrWithIdentity , consumerWorkspace , shard . Name )
363
363
shardDynamicClusterClients , err := kcpdynamic .NewForConfig (server .ShardSystemMasterBaseConfig (t , shard .Name ))
364
364
require .NoError (t , err )
365
365
list , err := shardDynamicClusterClients .Resource (gvrWithIdentity ).List (ctx , metav1.ListOptions {})
@@ -385,29 +385,43 @@ func TestAPIBinding(t *testing.T) {
385
385
t .Logf ("=== Verify that in %q (bound to %q) wildcard list works" , consumer3Path , provider2Path )
386
386
verifyWildcardList (consumer3Path , 1 )
387
387
388
+ t .Logf ("=== Verify that %s|%s export virtual workspace shows cowboys" , provider2Path , exportName )
388
389
rawConfig , err := server .RawConfig ()
389
390
require .NoError (t , err )
390
-
391
- t .Logf ("Smoke test %s|today-cowboys virtual workspace with explicit /cluster/%s" , provider2Path , consumer3Path )
392
- vw2ClusterClient , err := kcpdynamic .NewForConfig (apiexportVWConfig (t , rawConfig , provider2ClusterName , "today-cowboys" ))
391
+ export2 , err := kcpClusterClient .Cluster (provider2Path ).ApisV1alpha1 ().APIExports ().Get (ctx , exportName , metav1.GetOptions {})
393
392
require .NoError (t , err )
394
- gvr := wildwestv1alpha1 .SchemeGroupVersion .WithResource ("cowboys" )
395
- list , err := vw2ClusterClient .Cluster (consumer3ClusterName .Path ()).Resource (gvr ).Namespace ("" ).List (ctx , metav1.ListOptions {})
396
- require .NoError (t , err , "error listing through virtual workspace with explicit workspace" )
397
- require .Equal (t , 1 , len (list .Items ), "unexpected # of cowboys through virtual workspace with explicit workspace" )
398
-
399
- t .Logf ("Smoke test %s|today-cowboys virtual workspace with wildcard" , provider2Path )
400
- list , err = vw2ClusterClient .Resource (gvr ).List (ctx , metav1.ListOptions {})
401
- require .NoError (t , err , "error listing through virtual workspace wildcard" )
402
- require .Equal (t , 1 , len (list .Items ), "unexpected # of cowboys through virtual workspace with wildcard" )
393
+
394
+ foundOnShards := 0
395
+ //nolint:staticcheck // SA1019 VirtualWorkspaces is deprecated but not removed yet
396
+ for _ , vw := range export2 .Status .VirtualWorkspaces {
397
+ vw2ClusterClient , err := kcpdynamic .NewForConfig (apiexportVWConfig (t , rawConfig , vw .URL ))
398
+ require .NoError (t , err )
399
+
400
+ t .Logf ("Listing %s|%s cowboys via virtual workspace %s/clusters/%s" , provider2Path , exportName , vw .URL , consumer3ClusterName )
401
+ gvr := wildwestv1alpha1 .SchemeGroupVersion .WithResource ("cowboys" )
402
+ list , err := vw2ClusterClient .Cluster (consumer3ClusterName .Path ()).Resource (gvr ).Namespace ("" ).List (ctx , metav1.ListOptions {})
403
+ if err != nil {
404
+ t .Logf ("Error: %v" , err )
405
+ continue
406
+ }
407
+ require .Equal (t , 1 , len (list .Items ), "unexpected # of cowboys through virtual workspace with explicit workspace" )
408
+ foundOnShards ++
409
+
410
+ t .Logf ("Listing %s|%s cowboys via virtual workspace wildcard list" , provider2Path , exportName )
411
+ list , err = vw2ClusterClient .Resource (gvr ).List (ctx , metav1.ListOptions {})
412
+ require .NoError (t , err , "error listing through virtual workspace wildcard" )
413
+ require .Equal (t , 1 , len (list .Items ), "unexpected # of cowboys through virtual workspace with wildcard" )
414
+ }
415
+ //nolint:staticcheck // SA1019 VirtualWorkspaces is deprecated but not removed yet
416
+ require .Equal (t , 1 , foundOnShards , "cowboys not found exactly on one shard, but on %d/%d" , foundOnShards , len (export2 .Status .VirtualWorkspaces ))
403
417
}
404
418
405
- func apiexportVWConfig (t * testing.T , kubeconfig clientcmdapi.Config , clusterName logicalcluster. Name , apiexportName string ) * rest.Config {
419
+ func apiexportVWConfig (t * testing.T , kubeconfig clientcmdapi.Config , url string ) * rest.Config {
406
420
t .Helper ()
407
421
408
422
virtualWorkspaceRawConfig := kubeconfig .DeepCopy ()
409
423
virtualWorkspaceRawConfig .Clusters ["apiexport" ] = kubeconfig .Clusters ["base" ].DeepCopy ()
410
- virtualWorkspaceRawConfig .Clusters ["apiexport" ].Server = fmt . Sprintf ( "%s/services/apiexport/%s/%s/" , kubeconfig . Clusters [ "base" ]. Server , clusterName . String (), apiexportName )
424
+ virtualWorkspaceRawConfig .Clusters ["apiexport" ].Server = url
411
425
virtualWorkspaceRawConfig .Contexts ["apiexport" ] = kubeconfig .Contexts ["base" ].DeepCopy ()
412
426
virtualWorkspaceRawConfig .Contexts ["apiexport" ].Cluster = "apiexport"
413
427
0 commit comments