Skip to content

Commit e27c70a

Browse files
committed
e2e/apibindings: in TestAPIBinding fix virtual workspace testing
1 parent 20fa070 commit e27c70a

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

test/e2e/apibinding/apibinding_test.go

+29-15
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestAPIBinding(t *testing.T) {
359359

360360
var names []string
361361
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)
363363
shardDynamicClusterClients, err := kcpdynamic.NewForConfig(server.ShardSystemMasterBaseConfig(t, shard.Name))
364364
require.NoError(t, err)
365365
list, err := shardDynamicClusterClients.Resource(gvrWithIdentity).List(ctx, metav1.ListOptions{})
@@ -385,29 +385,43 @@ func TestAPIBinding(t *testing.T) {
385385
t.Logf("=== Verify that in %q (bound to %q) wildcard list works", consumer3Path, provider2Path)
386386
verifyWildcardList(consumer3Path, 1)
387387

388+
t.Logf("=== Verify that %s|%s export virtual workspace shows cowboys", provider2Path, exportName)
388389
rawConfig, err := server.RawConfig()
389390
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{})
393392
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))
403417
}
404418

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 {
406420
t.Helper()
407421

408422
virtualWorkspaceRawConfig := kubeconfig.DeepCopy()
409423
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
411425
virtualWorkspaceRawConfig.Contexts["apiexport"] = kubeconfig.Contexts["base"].DeepCopy()
412426
virtualWorkspaceRawConfig.Contexts["apiexport"].Cluster = "apiexport"
413427

0 commit comments

Comments
 (0)