Skip to content

Commit 7e029ab

Browse files
committed
redefine the API again
On-behalf-of: @SAP [email protected]
1 parent 115e423 commit 7e029ab

File tree

2 files changed

+97
-105
lines changed

2 files changed

+97
-105
lines changed

sdk/apis/syncagent/v1alpha1/published_resource.go

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

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"`
174+
// Object describes how the related resource can be found on the origin side
175+
// and where it is to supposed to be created on the destination side.
176+
Object RelatedResourceObject `json:"object"`
179177

180178
// Mutation configures optional transformation rules for the related resource.
181179
// Status mutations are only performed when the related resource originates in kcp.
182180
Mutation *ResourceMutationSpec `json:"mutation,omitempty"`
183181
}
184182

185-
// RelatedResourceSource configures how a related object can be found on its origin side.
186-
type RelatedResourceSource struct {
187-
RelatedResourceSourceSpec `json:",inline"`
183+
// RelatedResourceSource configures how the related resource can be found on the origin side
184+
// and where it is to supposed to be created on the destination side.
185+
type RelatedResourceObject struct {
186+
RelatedResourceObjectSpec `json:",inline"`
188187

189188
// Namespace configures in what namespace the related object resides in. If
190189
// 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"`
190+
// main object is cluster-scoped, this field is required and an error will be
191+
// raised during syncing if the field is not specified.
192+
Namespace *RelatedResourceObjectSpec `json:"namespace,omitempty"`
193193
}
194194

195-
// RelatedResourceSourceSpec configures different ways an object can be located.
195+
// RelatedResourceObjectSpec configures different ways an object can be located.
196196
// All fields are mutually exclusive.
197-
type RelatedResourceSourceSpec struct {
197+
type RelatedResourceObjectSpec struct {
198198
// Selector is a label selector that is useful if no reference is in the
199199
// main resource (i.e. if the related object links back to its parent, instead
200200
// of the parent pointing to the related object).
201-
Selector *RelatedResourceSelector `json:"selector,omitempty"`
201+
Selector *RelatedResourceObjectSelector `json:"selector,omitempty"`
202202
// Reference points to a field inside the main object. This reference is
203203
// 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
204+
Reference *RelatedResourceObjectReference `json:"reference,omitempty"`
205+
// Template is a Go templated string that can make use of variables to
206206
// 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"`
207+
Template TemplateExpression `json:"template,omitempty"`
220208
}
221209

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"`
231-
}
232-
233-
// RelatedResourceReference describes a path expression that is evaluated inside
210+
// RelatedResourceObjectReference describes a path expression that is evaluated inside
234211
// a JSON-marshalled Kubernetes object, yielding a string when evaluated.
235-
type RelatedResourceReference struct {
212+
type RelatedResourceObjectReference struct {
236213
// Path is a simplified JSONPath expression like "metadata.name". A reference
237214
// must always select at least _something_ in the object, even if the value
238215
// is discarded by the regular expression.
@@ -242,6 +219,25 @@ type RelatedResourceReference struct {
242219
Regex *RegularExpression `json:"regex,omitempty"`
243220
}
244221

222+
// RelatedResourceSelector is a dedicated struct in case we need additional options
223+
// for evaluating the label selector.
224+
225+
// RelatedResourceObjectSelector describes how to locate a related object based on
226+
// labels. This is useful if the main resource has no and cannot construct a
227+
// reference to the related object because its name/namespace might be randomized.
228+
type RelatedResourceObjectSelector struct {
229+
metav1.LabelSelector `json:",inline"`
230+
231+
Rewrite RelatedResourceSelectorRewrite `json:"rewrite"`
232+
}
233+
234+
type RelatedResourceSelectorRewrite struct {
235+
// Regex is a Go regular expression that is optionally applied to the selected
236+
// value from the path.
237+
Regex *RegularExpression `json:"regex,omitempty"`
238+
Template *TemplateExpression `json:"template,omitempty"`
239+
}
240+
245241
// RegularExpression models a Go regular expression string replacement. See
246242
// https://pkg.go.dev/regexp/syntax for more information on the syntax.
247243
type RegularExpression struct {
@@ -253,14 +249,10 @@ type RegularExpression struct {
253249
Replacement string `json:"replacement,omitempty"`
254250
}
255251

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"`
252+
// TemplateExpression is a Go templated string that can make use of variables to
253+
// construct the resulting string.
254+
type TemplateExpression struct {
255+
Template string `json:"template,omitempty"`
264256
}
265257

266258
// SourceResourceDescriptor and ResourceProjection are very similar, but as we do not

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

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

0 commit comments

Comments
 (0)