From 6b11c8a327b077b92a74f4695cf72dbdd5c406cb Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Tue, 24 Jun 2025 14:01:54 +0200 Subject: [PATCH 1/4] undeprecate references On-behalf-of: @SAP christoph.mewes@sap.com --- internal/sync/syncer_related.go | 1 - sdk/apis/syncagent/v1alpha1/published_resource.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/internal/sync/syncer_related.go b/internal/sync/syncer_related.go index 1567ccc..2f449ee 100644 --- a/internal/sync/syncer_related.go +++ b/internal/sync/syncer_related.go @@ -250,7 +250,6 @@ func resolveRelatedResourceObjects(relatedOrigin, relatedDest syncSide, relRes s func resolveRelatedResourceOriginNamespaces(relatedOrigin, relatedDest syncSide, origin syncagentv1alpha1.RelatedResourceOrigin, spec syncagentv1alpha1.RelatedResourceObjectSpec) (map[string]string, error) { switch { - //nolint:staticcheck // .Reference is deprecated, but we still support it for now. case spec.Reference != nil: originNamespace, err := resolveObjectReference(relatedOrigin.object, *spec.Reference) //nolint:staticcheck if err != nil { diff --git a/sdk/apis/syncagent/v1alpha1/published_resource.go b/sdk/apis/syncagent/v1alpha1/published_resource.go index 28e0fe2..12e86d0 100644 --- a/sdk/apis/syncagent/v1alpha1/published_resource.go +++ b/sdk/apis/syncagent/v1alpha1/published_resource.go @@ -217,8 +217,6 @@ type RelatedResourceObjectSpec struct { Selector *RelatedResourceObjectSelector `json:"selector,omitempty"` // Reference points to a field inside the main object. This reference is // evaluated on both source and destination sides to find the related object. - // - // Deprecated: Use Go templates instead. Reference *RelatedResourceObjectReference `json:"reference,omitempty"` // Template is a Go templated string that can make use of variables to // construct the resulting string. From fa373590475a15e387296e56642b326555e5a91c Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Tue, 24 Jun 2025 14:05:35 +0200 Subject: [PATCH 2/4] improve docs On-behalf-of: @SAP christoph.mewes@sap.com --- .../syncagent/v1alpha1/published_resource.go | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sdk/apis/syncagent/v1alpha1/published_resource.go b/sdk/apis/syncagent/v1alpha1/published_resource.go index 12e86d0..e35a977 100644 --- a/sdk/apis/syncagent/v1alpha1/published_resource.go +++ b/sdk/apis/syncagent/v1alpha1/published_resource.go @@ -102,10 +102,17 @@ type PublishedResourceSpec struct { // ResourceNaming describes how the names for local objects should be formed. type ResourceNaming struct { // The name field allows to control the name the local objects created by the Sync Agent. - // If left empty, "$remoteNamespaceHash-$remoteNameHash" is assumed. This guarantees unique - // names as long as the cluster name ($remoteClusterName) is used for the local namespace + // If left empty, the default value is: + // + // "{{ .Object.metadata.namespace | sha3short }}-{{ .Object.metadata.name | sha3short }}" + // + // This guarantees unique names as long as the cluster name is used for the local namespace // (the default unless configured otherwise). - // This is a string with placeholders. The following placeholders can be used: + // + // This value is a Go template, see the documentation for the available variables and functions. + // + // Alternatively (but deprecated), this value can be a simple string using one of the following + // placeholders: // // - $remoteClusterName -- the kcp workspace's cluster name (e.g. "1084s8ceexsehjm2") // - $remoteNamespace -- the original namespace used by the consumer inside the kcp @@ -116,11 +123,17 @@ type ResourceNaming struct { // (rarely used to construct local namespace names) // - $remoteNameHash -- first 20 hex characters of the SHA-1 hash of $remoteName // + // Authors are advised to use Go templates instead, as the custom variable syntax is deprecated + // and will be removed from a future release of the Sync Agent. Name string `json:"name,omitempty"` // For namespaced resources, the this field allows to control where the local objects will - // be created. If left empty, "$remoteClusterName" is assumed. - // This is a string with placeholders. The following placeholders can be used: + // be created. If left empty, "{{ .ClusterName }}" is assumed. + // + // This value is a Go template, see the documentation for the available variables and functions. + // + // Alternatively (but deprecated), this value can be a simple string using one of the following + // placeholders: // // - $remoteClusterName -- the kcp workspace's cluster name (e.g. "1084s8ceexsehjm2") // - $remoteNamespace -- the original namespace used by the consumer inside the kcp @@ -131,6 +144,8 @@ type ResourceNaming struct { // (rarely used to construct local namespace names) // - $remoteNameHash -- first 20 hex characters of the SHA-1 hash of $remoteName // + // Authors are advised to use Go templates instead, as the custom variable syntax is deprecated + // and will be removed from a future release of the Sync Agent. Namespace string `json:"namespace,omitempty"` } From f8dea03595e895581ef3bcf3d125febd376d49c0 Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Tue, 24 Jun 2025 14:07:34 +0200 Subject: [PATCH 3/4] codegen On-behalf-of: @SAP christoph.mewes@sap.com --- .../syncagent.kcp.io_publishedresources.yaml | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml b/deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml index ac878b8..88c01bf 100644 --- a/deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml +++ b/deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml @@ -239,10 +239,17 @@ spec: name: description: |- The name field allows to control the name the local objects created by the Sync Agent. - If left empty, "$remoteNamespaceHash-$remoteNameHash" is assumed. This guarantees unique - names as long as the cluster name ($remoteClusterName) is used for the local namespace + If left empty, the default value is: + + "{{ .Object.metadata.namespace | sha3short }}-{{ .Object.metadata.name | sha3short }}" + + This guarantees unique names as long as the cluster name is used for the local namespace (the default unless configured otherwise). - This is a string with placeholders. The following placeholders can be used: + + This value is a Go template, see the documentation for the available variables and functions. + + Alternatively (but deprecated), this value can be a simple string using one of the following + placeholders: - $remoteClusterName -- the kcp workspace's cluster name (e.g. "1084s8ceexsehjm2") - $remoteNamespace -- the original namespace used by the consumer inside the kcp @@ -252,12 +259,19 @@ spec: - $remoteName -- the original name of the object inside the kcp workspace (rarely used to construct local namespace names) - $remoteNameHash -- first 20 hex characters of the SHA-1 hash of $remoteName + + Authors are advised to use Go templates instead, as the custom variable syntax is deprecated + and will be removed from a future release of the Sync Agent. type: string namespace: description: |- For namespaced resources, the this field allows to control where the local objects will - be created. If left empty, "$remoteClusterName" is assumed. - This is a string with placeholders. The following placeholders can be used: + be created. If left empty, "{{ .ClusterName }}" is assumed. + + This value is a Go template, see the documentation for the available variables and functions. + + Alternatively (but deprecated), this value can be a simple string using one of the following + placeholders: - $remoteClusterName -- the kcp workspace's cluster name (e.g. "1084s8ceexsehjm2") - $remoteNamespace -- the original namespace used by the consumer inside the kcp @@ -267,6 +281,9 @@ spec: - $remoteName -- the original name of the object inside the kcp workspace (rarely used to construct local namespace names) - $remoteNameHash -- first 20 hex characters of the SHA-1 hash of $remoteName + + Authors are advised to use Go templates instead, as the custom variable syntax is deprecated + and will be removed from a future release of the Sync Agent. type: string type: object projection: @@ -438,8 +455,6 @@ spec: description: |- Reference points to a field inside the main object. This reference is evaluated on both source and destination sides to find the related object. - - Deprecated: Use Go templates instead. properties: path: description: |- @@ -555,8 +570,6 @@ spec: description: |- Reference points to a field inside the main object. This reference is evaluated on both source and destination sides to find the related object. - - Deprecated: Use Go templates instead. properties: path: description: |- From efc49d2672c922770291e543666ce03b270dbdba Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Tue, 24 Jun 2025 14:18:21 +0200 Subject: [PATCH 4/4] lint On-behalf-of: @SAP christoph.mewes@sap.com --- internal/sync/syncer_related.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/sync/syncer_related.go b/internal/sync/syncer_related.go index 2f449ee..29aa68f 100644 --- a/internal/sync/syncer_related.go +++ b/internal/sync/syncer_related.go @@ -251,7 +251,7 @@ func resolveRelatedResourceObjects(relatedOrigin, relatedDest syncSide, relRes s func resolveRelatedResourceOriginNamespaces(relatedOrigin, relatedDest syncSide, origin syncagentv1alpha1.RelatedResourceOrigin, spec syncagentv1alpha1.RelatedResourceObjectSpec) (map[string]string, error) { switch { case spec.Reference != nil: - originNamespace, err := resolveObjectReference(relatedOrigin.object, *spec.Reference) //nolint:staticcheck + originNamespace, err := resolveObjectReference(relatedOrigin.object, *spec.Reference) if err != nil { return nil, err } @@ -260,7 +260,7 @@ func resolveRelatedResourceOriginNamespaces(relatedOrigin, relatedDest syncSide, return nil, nil } - destNamespace, err := resolveObjectReference(relatedDest.object, *spec.Reference) //nolint:staticcheck + destNamespace, err := resolveObjectReference(relatedDest.object, *spec.Reference) if err != nil { return nil, err } @@ -367,9 +367,8 @@ func resolveRelatedResourceObjectsInNamespaces(relatedOrigin, relatedDest syncSi func resolveRelatedResourceObjectsInNamespace(relatedOrigin, relatedDest syncSide, relRes syncagentv1alpha1.RelatedResourceSpec, spec syncagentv1alpha1.RelatedResourceObjectSpec, namespace string) (map[string]string, error) { switch { - //nolint:staticcheck case spec.Reference != nil: - originName, err := resolveObjectReference(relatedOrigin.object, *spec.Reference) //nolint:staticcheck + originName, err := resolveObjectReference(relatedOrigin.object, *spec.Reference) if err != nil { return nil, err } @@ -378,7 +377,7 @@ func resolveRelatedResourceObjectsInNamespace(relatedOrigin, relatedDest syncSid return nil, nil } - destName, err := resolveObjectReference(relatedDest.object, *spec.Reference) //nolint:staticcheck + destName, err := resolveObjectReference(relatedDest.object, *spec.Reference) if err != nil { return nil, err }