Skip to content

Commit 16dbf88

Browse files
committed
split source and destination config for RR's, everything else is just confusing
This is because now, with support for label selectors, we need explicit naming on the destination side, which means the old idea of "the same thing is done on both sides to figure out the names on origin and destination" doesn't apply anymore, because the logic is now slightly different between both sides. To not ack this in the CRD will just create endless confusion. On-behalf-of: @SAP [email protected]
1 parent c53499a commit 16dbf88

12 files changed

+797
-75
lines changed

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

Lines changed: 234 additions & 15 deletions
Large diffs are not rendered by default.

sdk/apis/syncagent/v1alpha1/published_resource.go

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,98 @@ type RelatedResourceSpec struct {
171171
// ConfigMap or Secret
172172
Kind string `json:"kind"`
173173

174-
Reference RelatedResourceReference `json:"reference"`
174+
// Source describes how the related resource can be found on the side where it originates.
175+
Source RelatedResourceSource `json:"source"`
176+
177+
// Destination describes where to place the copy of the object on the destination side.
178+
Destination RelatedResourceDestination `json:"destination"`
175179

176180
// Mutation configures optional transformation rules for the related resource.
177181
// Status mutations are only performed when the related resource originates in kcp.
178182
Mutation *ResourceMutationSpec `json:"mutation,omitempty"`
179183
}
180184

181-
type RelatedResourceReference struct {
182-
Name ResourceLocator `json:"name"`
183-
Namespace *ResourceLocator `json:"namespace,omitempty"`
185+
// RelatedResourceSource configures how a related object can be found on its origin side.
186+
type RelatedResourceSource struct {
187+
RelatedResourceSourceSpec `json:",inline"`
188+
189+
// Namespace configures in what namespace the related object resides in. If
190+
// not specified, the same namespace as the main object is assumed. If the
191+
// main object is cluster-scoped, an error will be raised during syncing.
192+
Namespace *RelatedResourceSourceSpec `json:"namespace,omitempty"`
193+
}
194+
195+
// RelatedResourceSourceSpec configures different ways an object can be located.
196+
// All fields are mutually exclusive.
197+
type RelatedResourceSourceSpec struct {
198+
// Selector is a label selector that is useful if no reference is in the
199+
// main resource (i.e. if the related object links back to its parent, instead
200+
// of the parent pointing to the related object).
201+
Selector *RelatedResourceSelector `json:"selector,omitempty"`
202+
// Reference points to a field inside the main object. This reference is
203+
// evaluated on both source and destination sides to find the related object.
204+
Reference *RelatedResourceReference `json:"reference,omitempty"`
205+
// Expression is a Go templated string that can make use of variables to
206+
// construct the resulting string.
207+
Expression string `json:"expression,omitempty"`
208+
}
209+
210+
// RelatedResourceDestination configures where the copy of the related object on the
211+
// destination side should be created.
212+
type RelatedResourceDestination struct {
213+
RelatedResourceDestinationSpec `json:",inline"`
214+
215+
// Namespace configures in what namespace the related object should be created
216+
// in. If not specified, the same namespace as the main object is assumed.
217+
// If the main object is cluster-scoped, an error will be raised during
218+
// syncing.
219+
Namespace *RelatedResourceDestinationSpec `json:"namespace,omitempty"`
184220
}
185221

186-
type ResourceLocator struct {
187-
Path string `json:"path"`
188-
Regex *RegexResourceLocator `json:"regex,omitempty"`
222+
// RelatedResourceDestinationSpec configures different ways an object can be located.
223+
// All fields are mutually exclusive.
224+
type RelatedResourceDestinationSpec struct {
225+
// Reference points to a field inside the main object. This reference is
226+
// evaluated on both source and destination sides to find the related object.
227+
Reference *RelatedResourceReference `json:"reference,omitempty"`
228+
// Expression is a Go templated string that can make use of variables to
229+
// construct the resulting string.
230+
Expression string `json:"expression,omitempty"`
189231
}
190232

191-
type RegexResourceLocator struct {
233+
// RelatedResourceReference describes a path expression that is evaluated inside
234+
// a JSON-marshalled Kubernetes object, yielding a string when evaluated.
235+
type RelatedResourceReference struct {
236+
// Path is a simplified JSONPath expression like "metadata.name". A reference
237+
// must always select at least _something_ in the object, even if the value
238+
// is discarded by the regular expression.
239+
Path string `json:"path"`
240+
// Regex is a Go regular expression that is optionally applied to the selected
241+
// value from the path.
242+
Regex *RegularExpression `json:"regex,omitempty"`
243+
}
244+
245+
// RegularExpression models a Go regular expression string replacement. See
246+
// https://pkg.go.dev/regexp/syntax for more information on the syntax.
247+
type RegularExpression struct {
192248
// Pattern can be left empty to simply replace the entire value with the
193249
// replacement.
194-
Pattern string `json:"pattern,omitempty"`
250+
Pattern string `json:"pattern,omitempty"`
251+
// Replacement is the string that the matched pattern is replaced with. It
252+
// can contain references to groups in the pattern by using \N.
195253
Replacement string `json:"replacement,omitempty"`
196254
}
197255

256+
// RelatedResourceSelector is a dedicated struct in case we need additional options
257+
// for evaluating the label selector.
258+
259+
// RelatedResourceSelector describes how to locate a related object based on
260+
// labels. This is useful if the main resource has no and cannot construct a
261+
// reference to the related object because its name/namespace might be randomized.
262+
type RelatedResourceSelector struct {
263+
metav1.LabelSelector `json:",inline"`
264+
}
265+
198266
// SourceResourceDescriptor and ResourceProjection are very similar, but as we do not
199267
// want to burden service clusters with validation webhooks, it's easier to split them
200268
// into 2 structs here and rely on the schema for validation.

sdk/apis/syncagent/v1alpha1/zz_generated.deepcopy.go

Lines changed: 111 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/applyconfiguration/syncagent/v1alpha1/regularexpression.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/applyconfiguration/syncagent/v1alpha1/relatedresourcedestination.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)