Skip to content

Commit

Permalink
e2e/framework: fix NewPrivilegedOrganizationFixture cross-shard
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Jan 27, 2023
1 parent b569732 commit e5b7fe8
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions test/e2e/framework/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func WithName(s string, formatArgs ...interface{}) UnprivilegedWorkspaceOption {
}
}

func newWorkspaceFixture[O WorkspaceOption](t *testing.T, clusterClient kcpclientset.ClusterInterface, parent logicalcluster.Path, options ...O) *tenancyv1alpha1.Workspace {
func newWorkspaceFixture[O WorkspaceOption](t *testing.T, createClusterClient, clusterClient kcpclientset.ClusterInterface, parent logicalcluster.Path, options ...O) *tenancyv1alpha1.Workspace {
t.Helper()

ctx, cancelFunc := context.WithCancel(context.Background())
Expand Down Expand Up @@ -138,7 +138,7 @@ func newWorkspaceFixture[O WorkspaceOption](t *testing.T, clusterClient kcpclien
var ws *tenancyv1alpha1.Workspace
Eventually(t, func() (bool, string) {
var err error
ws, err = clusterClient.Cluster(parent).TenancyV1alpha1().Workspaces().Create(ctx, tmpl, metav1.CreateOptions{})
ws, err = createClusterClient.Cluster(parent).TenancyV1alpha1().Workspaces().Create(ctx, tmpl, metav1.CreateOptions{})
return err == nil, fmt.Sprintf("error creating workspace under %s: %v", parent, err)
}, wait.ForeverTestTimeout, time.Millisecond*100, "failed to create %s workspace under %s", tmpl.Spec.Type.Name, parent)

Expand Down Expand Up @@ -170,12 +170,14 @@ func newWorkspaceFixture[O WorkspaceOption](t *testing.T, clusterClient kcpclien
}, wait.ForeverTestTimeout, time.Millisecond*100, "failed to wait for %s workspace %s to become ready", ws.Spec.Type, parent.Join(ws.Name))

Eventually(t, func() (bool, string) {
var err error
_, err = clusterClient.Cluster(parent.Join(ws.Name)).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{})
require.Falsef(t, apierrors.IsNotFound(err), "workspace %s was deleted", parent.Join(ws.Name))
require.NoError(t, err, "failed to get LogicalCluster %s", parent.Join(ws.Name).Join(corev1alpha1.LogicalClusterName))
if _, err := clusterClient.Cluster(logicalcluster.NewPath(ws.Spec.Cluster)).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}); err != nil {
return false, fmt.Sprintf("failed to get LogicalCluster %s by cluster name %s: %v", parent.Join(ws.Name), ws.Spec.Cluster, err)
}
if _, err := clusterClient.Cluster(parent.Join(ws.Name)).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}); err != nil {
return false, fmt.Sprintf("failed to get LogicalCluster %s via path: %v", parent.Join(ws.Name), err)
}
return true, ""
}, wait.ForeverTestTimeout, time.Millisecond*100, "failed to wait for %s workspace %s to become accessible, potentially through eventual consistent workspace index", ws.Spec.Type, parent.Join(ws.Name))
}, wait.ForeverTestTimeout, time.Millisecond*100, "failed to wait for %s workspace %s to become accessible", ws.Spec.Type, parent.Join(ws.Name))

// best effort to get a shard name from the hash in the annotation
hash := ws.Annotations[reconcilerworkspace.WorkspaceShardHashAnnotationKey]
Expand Down Expand Up @@ -205,7 +207,7 @@ func NewWorkspaceFixture(t *testing.T, server RunningServer, parent logicalclust
clusterClient, err := kcpclientset.NewForConfig(cfg)
require.NoError(t, err, "failed to construct client for server")

ws := newWorkspaceFixture(t, clusterClient, parent, options...)
ws := newWorkspaceFixture(t, clusterClient, clusterClient, parent, options...)
return parent.Join(ws.Name), ws
}

Expand All @@ -217,10 +219,14 @@ func NewOrganizationFixture(t *testing.T, server RunningServer, options ...Unpri
func NewPrivilegedOrganizationFixture[O WorkspaceOption](t *testing.T, server RunningServer, options ...O) (logicalcluster.Path, *tenancyv1alpha1.Workspace) {
t.Helper()

cfg := server.RootShardSystemMasterBaseConfig(t)
rootConfig := server.RootShardSystemMasterBaseConfig(t)
rootClusterClient, err := kcpclientset.NewForConfig(rootConfig)
require.NoError(t, err, "failed to construct client for server")

cfg := server.BaseConfig(t)
clusterClient, err := kcpclientset.NewForConfig(cfg)
require.NoError(t, err, "failed to construct client for server")

ws := newWorkspaceFixture(t, clusterClient, core.RootCluster.Path(), append(options, O(WithType(core.RootCluster.Path(), "organization")))...)
ws := newWorkspaceFixture(t, rootClusterClient, clusterClient, core.RootCluster.Path(), append(options, O(WithType(core.RootCluster.Path(), "organization")))...)
return core.RootCluster.Path().Join(ws.Name), ws
}

0 comments on commit e5b7fe8

Please sign in to comment.