Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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: |-
Expand Down Expand Up @@ -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: |-
Expand Down
10 changes: 4 additions & 6 deletions internal/sync/syncer_related.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ 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
originNamespace, err := resolveObjectReference(relatedOrigin.object, *spec.Reference)
if err != nil {
return nil, err
}
Expand All @@ -261,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
}
Expand Down Expand Up @@ -368,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
}
Expand All @@ -379,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
}
Expand Down
27 changes: 20 additions & 7 deletions sdk/apis/syncagent/v1alpha1/published_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"`
}

Expand Down Expand Up @@ -217,8 +232,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.
Expand Down