Skip to content

Commit 4b4d9d7

Browse files
committed
s/clusterPath/workspacePath/g due to popular demand
On-behalf-of: @SAP [email protected]
1 parent 778b49e commit 4b4d9d7

File tree

12 files changed

+70
-70
lines changed

12 files changed

+70
-70
lines changed

deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ spec:
4747
PublishedResourceSpec describes the desired resource publication from a service
4848
cluster to kcp.
4949
properties:
50-
enableClusterPaths:
50+
enableWorkspacePaths:
5151
description: |-
52-
EnableClusterPaths toggles whether the Sync Agent will not just store the kcp
53-
cluster name as a label on each locally synced object, but also the full cluster
52+
EnableWorkspacePaths toggles whether the Sync Agent will not just store the kcp
53+
cluster name as a label on each locally synced object, but also the full workspace
5454
path. This is optional because it requires additional requests to kcp and
55-
should only be used if the cluster path is of interest on the
55+
should only be used if the workspace path is of interest on the
5656
service cluster side.
5757
type: boolean
5858
filter:

internal/controller/sync/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
162162

163163
// if desired, fetch the cluster path as well (some downstream service providers might make use of it,
164164
// but since it requires an additional permission claim, it's optional)
165-
if r.pubRes.Spec.EnableClusterPaths {
165+
if r.pubRes.Spec.EnableWorkspacePaths {
166166
lc := &kcpdevcorev1alpha1.LogicalCluster{}
167167
if err := r.vwClient.Get(wsCtx, types.NamespacedName{Name: kcpdevcorev1alpha1.LogicalClusterName}, lc); err != nil {
168168
return reconcile.Result{}, fmt.Errorf("failed to retrieve remote logicalcluster: %w", err)
169169
}
170170

171171
path := lc.Annotations[kcpcore.LogicalClusterPathAnnotationKey]
172-
syncContext = syncContext.WithClusterPath(logicalcluster.NewPath(path))
172+
syncContext = syncContext.WithWorkspacePath(logicalcluster.NewPath(path))
173173
}
174174

175175
// sync main object

internal/controller/syncmanager/lifecycle/cluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ func (c clusterRoundTripper) RoundTrip(req *http.Request) (*http.Response, error
103103
var apiRegex = regexp.MustCompile(`(/api/|/apis/)`)
104104

105105
// generatePath formats the request path to target the specified cluster.
106-
func generatePath(originalPath string, clusterPath logicalcluster.Path) string {
106+
func generatePath(originalPath string, workspacePath logicalcluster.Path) string {
107107
// If the originalPath already has cluster.Path() then the path was already modifed and no change needed
108-
if strings.Contains(originalPath, clusterPath.RequestPath()) {
108+
if strings.Contains(originalPath, workspacePath.RequestPath()) {
109109
return originalPath
110110
}
111111
// If the originalPath has /api/ or /apis/ in it, it might be anywhere in the path, so we use a regex to find and
112112
// replaces /api/ or /apis/ with $cluster/api/ or $cluster/apis/
113113
if apiRegex.MatchString(originalPath) {
114-
return apiRegex.ReplaceAllString(originalPath, fmt.Sprintf("%s$1", clusterPath.RequestPath()))
114+
return apiRegex.ReplaceAllString(originalPath, fmt.Sprintf("%s$1", workspacePath.RequestPath()))
115115
}
116116
// Otherwise, we're just prepending /clusters/$name
117-
path := clusterPath.RequestPath()
117+
path := workspacePath.RequestPath()
118118
// if the original path is relative, add a / separator
119119
if len(originalPath) > 0 && originalPath[0] != '/' {
120120
path += "/"

internal/sync/context.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
type Context struct {
28-
clusterName logicalcluster.Name
29-
clusterPath logicalcluster.Path
30-
local context.Context
31-
remote context.Context
28+
clusterName logicalcluster.Name
29+
workspacePath logicalcluster.Path
30+
local context.Context
31+
remote context.Context
3232
}
3333

3434
func NewContext(local, remote context.Context) Context {
@@ -44,11 +44,11 @@ func NewContext(local, remote context.Context) Context {
4444
}
4545
}
4646

47-
func (c *Context) WithClusterPath(path logicalcluster.Path) Context {
47+
func (c *Context) WithWorkspacePath(path logicalcluster.Path) Context {
4848
return Context{
49-
clusterName: c.clusterName,
50-
clusterPath: path,
51-
local: c.local,
52-
remote: c.remote,
49+
clusterName: c.clusterName,
50+
workspacePath: path,
51+
local: c.local,
52+
remote: c.remote,
5353
}
5454
}

internal/sync/meta.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ func removeFinalizer(ctx context.Context, log *zap.SugaredLogger, client ctrlrun
9494
}
9595

9696
type objectKey struct {
97-
ClusterName logicalcluster.Name
98-
ClusterPath logicalcluster.Path
99-
Namespace string
100-
Name string
97+
ClusterName logicalcluster.Name
98+
WorkspacePath logicalcluster.Path
99+
Namespace string
100+
Name string
101101
}
102102

103-
func newObjectKey(obj metav1.Object, clusterName logicalcluster.Name, clusterPath logicalcluster.Path) objectKey {
103+
func newObjectKey(obj metav1.Object, clusterName logicalcluster.Name, workspacePath logicalcluster.Path) objectKey {
104104
return objectKey{
105-
ClusterName: clusterName,
106-
ClusterPath: clusterPath,
107-
Namespace: obj.GetNamespace(),
108-
Name: obj.GetName(),
105+
ClusterName: clusterName,
106+
WorkspacePath: workspacePath,
107+
Namespace: obj.GetNamespace(),
108+
Name: obj.GetName(),
109109
}
110110
}
111111

@@ -144,8 +144,8 @@ func (k objectKey) Labels() labels.Set {
144144
func (k objectKey) Annotations() labels.Set {
145145
s := labels.Set{}
146146

147-
if !k.ClusterPath.Empty() {
148-
s[remoteObjectClusterPathAnnotation] = k.ClusterPath.String()
147+
if !k.WorkspacePath.Empty() {
148+
s[remoteObjectWorkspacePathAnnotation] = k.WorkspacePath.String()
149149
}
150150

151151
return s

internal/sync/meta_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func createNewObject(name, namespace string) metav1.Object {
3535

3636
func TestObjectKey(t *testing.T) {
3737
testcases := []struct {
38-
object metav1.Object
39-
clusterName logicalcluster.Name
40-
clusterPath logicalcluster.Path
41-
expected string
38+
object metav1.Object
39+
clusterName logicalcluster.Name
40+
workspacePath logicalcluster.Path
41+
expected string
4242
}{
4343
{
4444
object: createNewObject("test", ""),
@@ -61,16 +61,16 @@ func TestObjectKey(t *testing.T) {
6161
expected: "abc123|namespace/test",
6262
},
6363
{
64-
object: createNewObject("test", "namespace"),
65-
clusterName: "abc123",
66-
clusterPath: logicalcluster.NewPath("this:should:not:appear:in:the:key"),
67-
expected: "abc123|namespace/test",
64+
object: createNewObject("test", "namespace"),
65+
clusterName: "abc123",
66+
workspacePath: logicalcluster.NewPath("this:should:not:appear:in:the:key"),
67+
expected: "abc123|namespace/test",
6868
},
6969
}
7070

7171
for _, testcase := range testcases {
7272
t.Run("", func(t *testing.T) {
73-
key := newObjectKey(testcase.object, testcase.clusterName, testcase.clusterPath)
73+
key := newObjectKey(testcase.object, testcase.clusterName, testcase.workspacePath)
7474

7575
if stringified := key.String(); stringified != testcase.expected {
7676
t.Fatalf("Expected %q but got %q.", testcase.expected, stringified)

internal/sync/object_syncer.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ type objectSyncer struct {
5454
}
5555

5656
type syncSide struct {
57-
ctx context.Context
58-
clusterName logicalcluster.Name
59-
clusterPath logicalcluster.Path
60-
client ctrlruntimeclient.Client
61-
object *unstructured.Unstructured
57+
ctx context.Context
58+
clusterName logicalcluster.Name
59+
workspacePath logicalcluster.Path
60+
client ctrlruntimeclient.Client
61+
object *unstructured.Unstructured
6262
}
6363

6464
func (s *objectSyncer) Sync(log *zap.SugaredLogger, source, dest syncSide) (requeue bool, err error) {
@@ -183,9 +183,9 @@ func (s *objectSyncer) syncObjectSpec(log *zap.SugaredLogger, source, dest syncS
183183
lastKnownSourceState.SetAPIVersion(sourceObjCopy.GetAPIVersion())
184184
lastKnownSourceState.SetKind(sourceObjCopy.GetKind())
185185

186-
// update annotations (this is important if the admin later flipped the enableClusterPaths
186+
// update annotations (this is important if the admin later flipped the enableWorkspacePaths
187187
// option in the PublishedResource)
188-
sourceKey := newObjectKey(source.object, source.clusterName, source.clusterPath)
188+
sourceKey := newObjectKey(source.object, source.clusterName, source.workspacePath)
189189
ensureAnnotations(sourceObjCopy, sourceKey.Annotations())
190190

191191
// now we can diff the two versions and create a patch
@@ -278,7 +278,7 @@ func (s *objectSyncer) ensureDestinationObject(log *zap.SugaredLogger, source, d
278278
stripMetadata(destObj)
279279

280280
// remember the connection between the source and destination object
281-
sourceObjKey := newObjectKey(source.object, source.clusterName, source.clusterPath)
281+
sourceObjKey := newObjectKey(source.object, source.clusterName, source.workspacePath)
282282
ensureLabels(destObj, sourceObjKey.Labels())
283283

284284
// put optional additional annotations on the new object

internal/sync/state_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func hashObject(obj *unstructured.Unstructured) string {
133133
func newKubernetesBackend(namespace string, primaryObject, stateCluster syncSide) *kubernetesBackend {
134134
keyHash := hashObject(primaryObject.object)
135135

136-
secretLabels := newObjectKey(primaryObject.object, primaryObject.clusterName, primaryObject.clusterPath).Labels()
136+
secretLabels := newObjectKey(primaryObject.object, primaryObject.clusterName, primaryObject.workspacePath).Labels()
137137
secretLabels[objectStateLabelName] = objectStateLabelValue
138138

139139
return &kubernetesBackend{

internal/sync/syncer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func NewResourceSyncer(
112112
// case, the caller should re-fetch the remote object and call Process() again (most likely in the
113113
// next reconciliation). Only when (false, nil) is returned is the entire process finished.
114114
func (s *ResourceSyncer) Process(ctx Context, remoteObj *unstructured.Unstructured) (requeue bool, err error) {
115-
log := s.log.With("source-object", newObjectKey(remoteObj, ctx.clusterName, ctx.clusterPath))
115+
log := s.log.With("source-object", newObjectKey(remoteObj, ctx.clusterName, ctx.workspacePath))
116116

117117
// find the local equivalent object in the local service cluster
118118
localObj, err := s.findLocalObject(ctx, remoteObj)
@@ -126,11 +126,11 @@ func (s *ResourceSyncer) Process(ctx Context, remoteObj *unstructured.Unstructur
126126
// Prepare object sync sides.
127127

128128
sourceSide := syncSide{
129-
ctx: ctx.remote,
130-
clusterName: ctx.clusterName,
131-
clusterPath: ctx.clusterPath,
132-
client: s.remoteClient,
133-
object: remoteObj,
129+
ctx: ctx.remote,
130+
clusterName: ctx.clusterName,
131+
workspacePath: ctx.workspacePath,
132+
client: s.remoteClient,
133+
object: remoteObj,
134134
}
135135

136136
destSide := syncSide{
@@ -182,7 +182,7 @@ func (s *ResourceSyncer) Process(ctx Context, remoteObj *unstructured.Unstructur
182182
}
183183

184184
func (s *ResourceSyncer) findLocalObject(ctx Context, remoteObj *unstructured.Unstructured) (*unstructured.Unstructured, error) {
185-
localSelector := labels.SelectorFromSet(newObjectKey(remoteObj, ctx.clusterName, ctx.clusterPath).Labels())
185+
localSelector := labels.SelectorFromSet(newObjectKey(remoteObj, ctx.clusterName, ctx.workspacePath).Labels())
186186

187187
localObjects := &unstructured.UnstructuredList{}
188188
localObjects.SetAPIVersion(s.destDummy.GetAPIVersion())

internal/sync/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
remoteObjectNamespaceLabel = "syncagent.kcp.io/remote-object-namespace"
3030
remoteObjectNameLabel = "syncagent.kcp.io/remote-object-name"
3131

32-
remoteObjectClusterPathAnnotation = "syncagent.kcp.io/remote-object-cluster-path"
32+
remoteObjectWorkspacePathAnnotation = "syncagent.kcp.io/remote-object-workspace-path"
3333

3434
// objectStateLabelName is put on object state Secrets to allow for easier mass deletions
3535
// if ever necessary.

0 commit comments

Comments
 (0)