Skip to content

Commit ea71042

Browse files
committed
use annotation because labels do not allow colons
On-behalf-of: @SAP [email protected]
1 parent 9736d94 commit ea71042

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

internal/sync/meta.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,18 @@ func (k objectKey) Key() string {
134134
}
135135

136136
func (k objectKey) Labels() labels.Set {
137-
s := labels.Set{
137+
return labels.Set{
138138
remoteObjectClusterLabel: string(k.ClusterName),
139139
remoteObjectNamespaceLabel: k.Namespace,
140140
remoteObjectNameLabel: k.Name,
141141
}
142+
}
143+
144+
func (k objectKey) Annotations() labels.Set {
145+
s := labels.Set{}
142146

143147
if !k.ClusterPath.Empty() {
144-
s[remoteObjectClusterPathLabel] = k.ClusterPath.String()
148+
s[remoteObjectClusterPathAnnotation] = k.ClusterPath.String()
145149
}
146150

147151
return s

internal/sync/object_syncer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ 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
187+
// option in the PublishedResource)
188+
sourceKey := newObjectKey(source.object, source.clusterName, source.clusterPath)
189+
ensureAnnotations(sourceObjCopy, sourceKey.Annotations())
190+
186191
// now we can diff the two versions and create a patch
187192
rawPatch, err := s.createMergePatch(lastKnownSourceState, sourceObjCopy)
188193
if err != nil {
@@ -276,6 +281,9 @@ func (s *objectSyncer) ensureDestinationObject(log *zap.SugaredLogger, source, d
276281
sourceObjKey := newObjectKey(source.object, source.clusterName, source.clusterPath)
277282
ensureLabels(destObj, sourceObjKey.Labels())
278283

284+
// put optional additional annotations on the new object
285+
ensureAnnotations(destObj, sourceObjKey.Annotations())
286+
279287
// finally, we can create the destination object
280288
objectLog := log.With("dest-object", newObjectKey(destObj, dest.clusterName, logicalcluster.None))
281289
objectLog.Debugw("Creating destination object…")
@@ -318,6 +326,7 @@ func (s *objectSyncer) adoptExistingDestinationObject(log *zap.SugaredLogger, de
318326
// the destination object from another source object, which would then lead to the two source objects
319327
// "fighting" about the one destination object.
320328
ensureLabels(existingDestObj, sourceKey.Labels())
329+
ensureAnnotations(existingDestObj, sourceKey.Annotations())
321330

322331
if err := dest.client.Update(dest.ctx, existingDestObj); err != nil {
323332
return fmt.Errorf("failed to upsert current destination object labels: %w", err)

internal/sync/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ const (
2121
// them from being deleted before the local objects can be cleaned up.
2222
deletionFinalizer = "syncagent.kcp.io/cleanup"
2323

24-
// The following 4 labels are put on local objects to link them to their
24+
// The following 4 labels/annotations are put on local objects to link them to their
2525
// origin remote objects. Note that the cluster *path* label is optional and
2626
// has to be enabled per PublishedResource.
2727

28-
remoteObjectClusterLabel = "syncagent.kcp.io/remote-object-cluster"
29-
remoteObjectClusterPathLabel = "syncagent.kcp.io/remote-object-cluster-path"
30-
remoteObjectNamespaceLabel = "syncagent.kcp.io/remote-object-namespace"
31-
remoteObjectNameLabel = "syncagent.kcp.io/remote-object-name"
28+
remoteObjectClusterLabel = "syncagent.kcp.io/remote-object-cluster"
29+
remoteObjectNamespaceLabel = "syncagent.kcp.io/remote-object-namespace"
30+
remoteObjectNameLabel = "syncagent.kcp.io/remote-object-name"
31+
32+
remoteObjectClusterPathAnnotation = "syncagent.kcp.io/remote-object-cluster-path"
3233

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

0 commit comments

Comments
 (0)