Skip to content

Feature Request: Selector Support (equivalent to ResourceSourceSelector functionality) in Sveltos #473

@kahirokunn

Description

@kahirokunn

Currently, templateResourceRefs in both addon-controller and event-manager only support ObjectReference, as implemented in the following example:

https://github.com/projectsveltos/addon-controller/blob/d6fbb74b53d512cd2ebeeb1dbc914f379b689ebe/api/v1beta1/spec.go#L518-L532

Meanwhile, Crossplane's function-extra-resources supports two methods of resource referencing:

  1. ObjectReference
    Similar to the existing implementation, this method references resources by specifying type: Reference

  2. 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: cluster

As 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:

  1. Reference resources with dynamic names
    While ObjectReference requires fixed names, using selectors enables flexible referencing of dynamically generated resources.

  2. 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.

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions