Skip to content

Commit

Permalink
Create one tunneler per shard in the Syncer
Browse files Browse the repository at this point in the history
Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal committed Apr 6, 2023
1 parent 290c102 commit 76e71dd
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 93 deletions.
14 changes: 14 additions & 0 deletions config/crds/workload.kcp.io_synctargets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ spec:
- versions
type: object
type: array
tunnelWorkspaces:
description: TunnelWorkspaces contains all URLs (one per shard) that
point to the SyncTarget workspace in order to setup the tunneler.
items:
properties:
url:
description: url is the URL the Syncer should use to connect
to the Syncer tunnel for a given shard.
minLength: 1
type: string
required:
- url
type: object
type: array
virtualWorkspaces:
description: VirtualWorkspaces contains all virtual workspace URLs.
items:
Expand Down
2 changes: 1 addition & 1 deletion config/root-phase0/apiexport-workload.kcp.io.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ metadata:
name: workload.kcp.io
spec:
latestResourceSchemas:
- v230329-c41ff68c.synctargets.workload.kcp.io
- v230405-65634c292.synctargets.workload.kcp.io
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apis.kcp.io/v1alpha1
kind: APIResourceSchema
metadata:
creationTimestamp: null
name: v230329-c41ff68c.synctargets.workload.kcp.io
name: v230405-65634c292.synctargets.workload.kcp.io
spec:
group: workload.kcp.io
names:
Expand Down Expand Up @@ -219,6 +219,20 @@ spec:
- versions
type: object
type: array
tunnelWorkspaces:
description: TunnelWorkspaces contains all URLs (one per shard) that
point to the SyncTarget workspace in order to setup the tunneler.
items:
properties:
url:
description: url is the URL the Syncer should use to connect to
the Syncer tunnel for a given shard.
minLength: 1
type: string
required:
- url
type: object
type: array
virtualWorkspaces:
description: VirtualWorkspaces contains all virtual workspace URLs.
items:
Expand Down
38 changes: 37 additions & 1 deletion pkg/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 25 additions & 13 deletions pkg/reconciler/workload/synctarget/synctarget_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"

Expand All @@ -44,7 +43,9 @@ func (c *Controller) reconcile(ctx context.Context, syncTarget *workloadv1alpha1
labels[workloadv1alpha1.InternalSyncTargetKeyLabel] = workloadv1alpha1.ToSyncTargetKey(logicalcluster.From(syncTargetCopy), syncTargetCopy.Name)
syncTargetCopy.SetLabels(labels)

desiredURLs := map[string]workloadv1alpha1.VirtualWorkspace{}
desiredVWURLs := map[string]workloadv1alpha1.VirtualWorkspace{}
desiredTunnelWorkspaceURLs := map[string]workloadv1alpha1.TunnelWorkspace{}
syncTargetClusterName := logicalcluster.From(syncTarget)

var rootShardKey string
for _, workspaceShard := range workspaceShards {
Expand Down Expand Up @@ -81,10 +82,18 @@ func (c *Controller) reconcile(ctx context.Context, syncTarget *workloadv1alpha1
if workspaceShard.Name == corev1alpha1.RootShard {
rootShardKey = shardVWURL.String()
}
desiredURLs[shardVWURL.String()] = workloadv1alpha1.VirtualWorkspace{
desiredVWURLs[shardVWURL.String()] = workloadv1alpha1.VirtualWorkspace{
SyncerURL: syncerURL,
UpsyncerURL: upsyncerURL,
}

tunnelWorkspaceURL, err := url.JoinPath(workspaceShard.Spec.BaseURL, syncTargetClusterName.Path().RequestPath())
if err != nil {
return nil, err
}
desiredTunnelWorkspaceURLs[shardVWURL.String()] = workloadv1alpha1.TunnelWorkspace{
URL: tunnelWorkspaceURL,
}
}
}

Expand All @@ -94,20 +103,23 @@ func (c *Controller) reconcile(ctx context.Context, syncTarget *workloadv1alpha1
// - urls for other shards which will be added in the lexical order of the
// corresponding shard URLs.
var desiredVirtualWorkspaces []workloadv1alpha1.VirtualWorkspace //nolint:prealloc
if rootShardVWURLs, ok := desiredURLs[rootShardKey]; ok {
desiredVirtualWorkspaces = append(desiredVirtualWorkspaces, rootShardVWURLs)
delete(desiredURLs, rootShardKey)
if rootShardVirtualWorkspace, ok := desiredVWURLs[rootShardKey]; ok {
desiredVirtualWorkspaces = append(desiredVirtualWorkspaces, rootShardVirtualWorkspace)
delete(desiredVWURLs, rootShardKey)
}
for _, shardURL := range sets.StringKeySet(desiredURLs).List() {
desiredVirtualWorkspaces = append(desiredVirtualWorkspaces, desiredURLs[shardURL])
for _, shardURL := range sets.StringKeySet(desiredVWURLs).List() {
desiredVirtualWorkspaces = append(desiredVirtualWorkspaces, desiredVWURLs[shardURL])
}

if syncTargetCopy.Status.VirtualWorkspaces != nil {
if equality.Semantic.DeepEqual(syncTargetCopy.Status.VirtualWorkspaces, desiredVirtualWorkspaces) {
return syncTargetCopy, nil
}
var desiredTunnelWorkspaces []workloadv1alpha1.TunnelWorkspace //nolint:prealloc
if rootShardTunnelWorkspace, ok := desiredTunnelWorkspaceURLs[rootShardKey]; ok {
desiredTunnelWorkspaces = append(desiredTunnelWorkspaces, rootShardTunnelWorkspace)
delete(desiredTunnelWorkspaceURLs, rootShardKey)
}
for _, shardURL := range sets.StringKeySet(desiredTunnelWorkspaceURLs).List() {
desiredTunnelWorkspaces = append(desiredTunnelWorkspaces, desiredTunnelWorkspaceURLs[shardURL])
}

syncTargetCopy.Status.VirtualWorkspaces = desiredVirtualWorkspaces
syncTargetCopy.Status.TunnelWorkspaces = desiredTunnelWorkspaces
return syncTargetCopy, nil
}
Loading

0 comments on commit 76e71dd

Please sign in to comment.