-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Currently, templateResourceRefs in both addon-controller and event-manager only support ObjectReference, as implemented in the following example:
Meanwhile, Crossplane's function-extra-resources supports two methods of resource referencing:
-
ObjectReference
Similar to the existing implementation, this method references resources by specifyingtype: Reference -
ResourceSourceSelector
This method enables selector-based resource selection that cannot be handled by ObjectReference
(For details, please refer to https://github.com/crossplane-contrib/function-extra-resources/blob/7a4ef280ea9aea3e37b3f0d324188537e4a6b4fe/input/v1beta1/resource_select.go#L69-L94)
Here's an example YAML using ResourceSourceSelector:
extraResources:
- kind: XCluster
into: XCluster
apiVersion: example.crossplane.io/v1
type: Selector
selector:
maxMatch: 2
minMatch: 1
matchLabels:
- key: type
type: Value
value: clusterAs a practical example, extraResources can be pulled within a Composition and used for template processing:
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-environment-configs
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1
kind: XR
mode: Pipeline
pipeline:
- step: pull-extra-resources
functionRef:
name: function-extra-resources
input:
apiVersion: extra-resources.fn.crossplane.io/v1beta1
kind: Input
spec:
extraResources:
- kind: XCluster
into: XCluster
apiVersion: example.crossplane.io/v1
type: Selector
selector:
minMatch: 0
matchLabels:
- key: type
type: Value
value: cluster
- step: go-templating
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
{{- $XClusters := index (index .context "apiextensions.crossplane.io/extra-resources") "XCluster" }}
{{- range $i, $A := $XClusters }}
---
apiVersion: vault.upbound.io/v1beta1
kind: VaultRole
metadata:
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: {{index (index $A "metadata") "name"}}
spec:
forProvider:
{{- end}}We believe implementing selector support (preferably with a mechanism similar to ResourceSourceSelector) in Sveltos would offer the following benefits:
-
Reference resources with dynamic names
While ObjectReference requires fixed names, using selectors enables flexible referencing of dynamically generated resources. -
Generate resources based on multiple resource contents
This enables flexible operations that consider the states and attributes of multiple resources when generating final resources. While aggregatedSelection is supported in EventSource, we would like to see similar functionality in EventTrigger and ClusterProfile as well. -
Enable recursive processing
This enables recursive processing, such as referencing resources generated within the same ClusterProfile or EventTrigger, which previously required combining multiple ClusterProfiles.
For these reasons, we would like to request your consideration for implementing selector support (functionality equivalent to ResourceSourceSelector) in Sveltos. We believe this would expand the range of use cases by allowing users to reference and utilize resources more flexibly.
Thank you for your consideration.