function-extra-resources

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

function-extra-resources

CI

A function for selecting extra resources via composition functions in Go.

Using function-extra-resources

Please see the example in ./example

function-extra-resources is generally most useful in tandem with a function that can reference the many resources like function-go-templating.

Creating objects from other's found in the local cluster.
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:
              maxMatch: 2
              minMatch: 1
              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}}

Crossplane compatibility

A single build works on Crossplane v1.20+ and v2.x. It requests extra resources over the deprecated extra_resources protocol fields, which Crossplane v2 still resolves, rather than the required_resources fields that only exist on v2.

namespace behaves differently across the two majors, because Crossplane v1 has no notion of a namespace on an extra resource selector:

  • On v2, matches are filtered server-side and only the namespace's resources are sent to the function.
  • On v1, the namespace is dropped from the request. Selector matches are resolved across every namespace and filtered down by the function, so the result is the same but the full cluster-wide match still crosses the wire — which can exceed the 4MB default gRPC receive limit. Raise it with --max-recv-message-size if you hit it.
  • On v1, a Reference to a namespaced resource cannot be resolved at all, since the lookup is by name only. Such a reference fails rather than resolving to the wrong object.

In both cases namespace only applies to namespaced kinds. Cluster-scoped objects — EnvironmentConfig among them — have an empty namespace, so setting one selects nothing.

Local dev.

Air

air is not strictly necessary, but helpful.

Installing air allows quick iterative local development.

air is a live reloader that watches for local file changes.

Once installed, running

air -- --insecure --debug --address localhost:9443.

Shoud get the function process/server build and running to serve CLI function requests.

After locally serving function-extra-resources

./run.sh will use the crossplane CLI to run our basic example in ./example

Crossplane Function Basics

This function uses Go, Docker, and the Crossplane CLI.

# Run code generation - see input/generate.go
$ go generate ./...

# Run tests - see fn_test.go
$ go test ./...

# Build the function's runtime image - see Dockerfile
$ docker build . --tag=runtime

# Build a function package - see package/crossplane.yaml
$ crossplane xpkg build -f package --embed-runtime-image=runtime

Documentation

Overview

Package main implements a Composition Function.

Directories

Path Synopsis
input
v1beta1
Package v1beta1 contains the input type for this Function +kubebuilder:object:generate=true +groupName=extra-resources.fn.crossplane.io +versionName=v1beta1
Package v1beta1 contains the input type for this Function +kubebuilder:object:generate=true +groupName=extra-resources.fn.crossplane.io +versionName=v1beta1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL