@@ -22,6 +22,8 @@ import (
2222 "github.com/kcp-dev/logicalcluster/v3"
2323 "go.uber.org/zap"
2424
25+ "github.com/kcp-dev/api-syncagent/internal/crypto"
26+
2527 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2628 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2729 "k8s.io/apimachinery/pkg/labels"
@@ -56,7 +58,7 @@ func ensureAnnotations(obj metav1.Object, desiredAnnotations map[string]string)
5658}
5759
5860func ensureFinalizer (ctx context.Context , log * zap.SugaredLogger , client ctrlruntimeclient.Client , obj * unstructured.Unstructured , finalizer string ) (updated bool , err error ) {
59- finalizers := sets .New [ string ] (obj .GetFinalizers ()... )
61+ finalizers := sets .New (obj .GetFinalizers ()... )
6062 if finalizers .Has (deletionFinalizer ) {
6163 return false , nil
6264 }
@@ -75,7 +77,7 @@ func ensureFinalizer(ctx context.Context, log *zap.SugaredLogger, client ctrlrun
7577}
7678
7779func removeFinalizer (ctx context.Context , log * zap.SugaredLogger , client ctrlruntimeclient.Client , obj * unstructured.Unstructured , finalizer string ) (updated bool , err error ) {
78- finalizers := sets .New [ string ] (obj .GetFinalizers ()... )
80+ finalizers := sets .New (obj .GetFinalizers ()... )
7981 if ! finalizers .Has (deletionFinalizer ) {
8082 return false , nil
8183 }
@@ -122,27 +124,32 @@ func (k objectKey) String() string {
122124}
123125
124126func (k objectKey ) Key () string {
125- result := k .Name
126- if k .Namespace != "" {
127- result = k .Namespace + "_" + result
128- }
129- if k .ClusterName != "" {
130- result = string (k .ClusterName ) + "_" + result
131- }
132-
133- return result
127+ return crypto .Hash (k )
134128}
135129
136130func (k objectKey ) Labels () labels.Set {
137- return labels.Set {
138- remoteObjectClusterLabel : string (k .ClusterName ),
139- remoteObjectNamespaceLabel : k .Namespace ,
140- remoteObjectNameLabel : k .Name ,
131+ // Name and namespace can be more than 63 characters long, so we must hash them
132+ // to turn them into valid label values. The full, original value is kept as an annotation.
133+ s := labels.Set {
134+ remoteObjectClusterLabel : string (k .ClusterName ),
135+ remoteObjectNameHashLabel : crypto .Hash (k .Name ),
141136 }
137+
138+ if k .Namespace != "" {
139+ s [remoteObjectNamespaceHashLabel ] = crypto .Hash (k .Namespace )
140+ }
141+
142+ return s
142143}
143144
144145func (k objectKey ) Annotations () labels.Set {
145- s := labels.Set {}
146+ s := labels.Set {
147+ remoteObjectNameAnnotation : k .Name ,
148+ }
149+
150+ if k .Namespace != "" {
151+ s [remoteObjectNamespaceAnnotation ] = k .Namespace
152+ }
146153
147154 if ! k .WorkspacePath .Empty () {
148155 s [remoteObjectWorkspacePathAnnotation ] = k .WorkspacePath .String ()
0 commit comments