Skip to content

Commit

Permalink
Remove unnecessary private function
Browse files Browse the repository at this point in the history
Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal committed Feb 7, 2023
1 parent 8f125fe commit 0da8dad
Showing 1 changed file with 49 additions and 53 deletions.
102 changes: 49 additions & 53 deletions test/e2e/framework/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,55 @@ func (sf *syncerFixture) Create(t *testing.T) *appliedSyncerFixture {
ctx, cancelFunc := context.WithCancel(context.Background())
t.Cleanup(cancelFunc)

return sf.buildAppliedSyncerFixture(ctx, t, downstreamConfig, downstreamKubeClient, downstreamKubeconfigPath, syncerConfig, syncerID)
rawConfig, err := sf.upstreamServer.RawConfig()
require.NoError(t, err)

kcpClusterClient, err := kcpclientset.NewForConfig(syncerConfig.UpstreamConfig)
require.NoError(t, err)
var virtualWorkspaceURL string
var syncTargetClusterName logicalcluster.Name
Eventually(t, func() (success bool, reason string) {
syncTarget, err := kcpClusterClient.Cluster(syncerConfig.SyncTargetPath).WorkloadV1alpha1().SyncTargets().Get(ctx, syncerConfig.SyncTargetName, metav1.GetOptions{})
require.NoError(t, err)
if len(syncTarget.Status.VirtualWorkspaces) != 1 {
return false, ""
}
virtualWorkspaceURL = syncTarget.Status.VirtualWorkspaces[0].SyncerURL
syncTargetClusterName = logicalcluster.From(syncTarget)
return true, "Virtual workspace URL is available"
}, wait.ForeverTestTimeout, 100*time.Millisecond, "Syncer Virtual Workspace URL not available")

virtualWorkspaceRawConfig := rawConfig.DeepCopy()
virtualWorkspaceRawConfig.Clusters["syncer"] = rawConfig.Clusters["base"].DeepCopy()
virtualWorkspaceRawConfig.Clusters["syncer"].Server = virtualWorkspaceURL
virtualWorkspaceRawConfig.Contexts["syncer"] = rawConfig.Contexts["base"].DeepCopy()
virtualWorkspaceRawConfig.Contexts["syncer"].Cluster = "syncer"
virtualWorkspaceRawConfig.Clusters["upsyncer"] = rawConfig.Clusters["base"].DeepCopy()
virtualWorkspaceRawConfig.Clusters["upsyncer"].Server = strings.Replace(virtualWorkspaceURL, "/services/syncer/", "/services/upsyncer/", 1)
virtualWorkspaceRawConfig.Contexts["upsyncer"] = rawConfig.Contexts["base"].DeepCopy()
virtualWorkspaceRawConfig.Contexts["upsyncer"].Cluster = "upsyncer"
syncerVWConfig, err := clientcmd.NewNonInteractiveClientConfig(*virtualWorkspaceRawConfig, "syncer", nil, nil).ClientConfig()
require.NoError(t, err)
syncerVWConfig = rest.AddUserAgent(rest.CopyConfig(syncerVWConfig), t.Name())
require.NoError(t, err)
upsyncerVWConfig, err := clientcmd.NewNonInteractiveClientConfig(*virtualWorkspaceRawConfig, "upsyncer", nil, nil).ClientConfig()
require.NoError(t, err)
upsyncerVWConfig = rest.AddUserAgent(rest.CopyConfig(upsyncerVWConfig), t.Name())
require.NoError(t, err)

return &appliedSyncerFixture{
syncerFixture: *sf,

SyncerConfig: syncerConfig,
SyncerID: syncerID,
SyncTargetClusterName: syncTargetClusterName,
DownstreamConfig: downstreamConfig,
DownstreamKubeClient: downstreamKubeClient,
DownstreamKubeconfigPath: downstreamKubeconfigPath,

SyncerVirtualWorkspaceConfig: syncerVWConfig,
UpsyncerVirtualWorkspaceConfig: upsyncerVWConfig,
}
}

// StartSyncer starts a new Syncer against the upstream kcp workspaces
Expand Down Expand Up @@ -492,58 +540,6 @@ func (sf *appliedSyncerFixture) StartSyncer(t *testing.T) *StartedSyncerFixture
return startedSyncer
}

func (sf *syncerFixture) buildAppliedSyncerFixture(ctx context.Context, t *testing.T, downstreamConfig *rest.Config, downstreamKubeClient kubernetesclient.Interface, DownstreamKubeconfigPath string, syncerConfig *syncer.SyncerConfig, syncerID string) *appliedSyncerFixture {
rawConfig, err := sf.upstreamServer.RawConfig()
require.NoError(t, err)

kcpClusterClient, err := kcpclientset.NewForConfig(syncerConfig.UpstreamConfig)
require.NoError(t, err)
var virtualWorkspaceURL string
var syncTargetClusterName logicalcluster.Name
Eventually(t, func() (success bool, reason string) {
syncTarget, err := kcpClusterClient.Cluster(syncerConfig.SyncTargetPath).WorkloadV1alpha1().SyncTargets().Get(ctx, syncerConfig.SyncTargetName, metav1.GetOptions{})
require.NoError(t, err)
if len(syncTarget.Status.VirtualWorkspaces) != 1 {
return false, ""
}
virtualWorkspaceURL = syncTarget.Status.VirtualWorkspaces[0].SyncerURL
syncTargetClusterName = logicalcluster.From(syncTarget)
return true, "Virtual workspace URL is available"
}, wait.ForeverTestTimeout, 100*time.Millisecond, "Syncer Virtual Workspace URL not available")

virtualWorkspaceRawConfig := rawConfig.DeepCopy()
virtualWorkspaceRawConfig.Clusters["syncer"] = rawConfig.Clusters["base"].DeepCopy()
virtualWorkspaceRawConfig.Clusters["syncer"].Server = virtualWorkspaceURL
virtualWorkspaceRawConfig.Contexts["syncer"] = rawConfig.Contexts["base"].DeepCopy()
virtualWorkspaceRawConfig.Contexts["syncer"].Cluster = "syncer"
virtualWorkspaceRawConfig.Clusters["upsyncer"] = rawConfig.Clusters["base"].DeepCopy()
virtualWorkspaceRawConfig.Clusters["upsyncer"].Server = strings.Replace(virtualWorkspaceURL, "/services/syncer/", "/services/upsyncer/", 1)
virtualWorkspaceRawConfig.Contexts["upsyncer"] = rawConfig.Contexts["base"].DeepCopy()
virtualWorkspaceRawConfig.Contexts["upsyncer"].Cluster = "upsyncer"
syncerVWConfig, err := clientcmd.NewNonInteractiveClientConfig(*virtualWorkspaceRawConfig, "syncer", nil, nil).ClientConfig()
require.NoError(t, err)
syncerVWConfig = rest.AddUserAgent(rest.CopyConfig(syncerVWConfig), t.Name())
require.NoError(t, err)
upsyncerVWConfig, err := clientcmd.NewNonInteractiveClientConfig(*virtualWorkspaceRawConfig, "upsyncer", nil, nil).ClientConfig()
require.NoError(t, err)
upsyncerVWConfig = rest.AddUserAgent(rest.CopyConfig(upsyncerVWConfig), t.Name())
require.NoError(t, err)

return &appliedSyncerFixture{
syncerFixture: *sf,

SyncerConfig: syncerConfig,
SyncerID: syncerID,
SyncTargetClusterName: syncTargetClusterName,
DownstreamConfig: downstreamConfig,
DownstreamKubeClient: downstreamKubeClient,
DownstreamKubeconfigPath: DownstreamKubeconfigPath,

SyncerVirtualWorkspaceConfig: syncerVWConfig,
UpsyncerVirtualWorkspaceConfig: upsyncerVWConfig,
}
}

// appliedSyncerFixture contains the configuration required to start a syncer and interact with its
// downstream cluster.
type appliedSyncerFixture struct {
Expand Down

0 comments on commit 0da8dad

Please sign in to comment.