https://github.com/web-seven/function-switcher
Crossplane Composition function to enable creation of resources by Composite annotations.
https://github.com/web-seven/function-switcher
composition crossplane function kndp kubernetes
Last synced: 3 months ago
JSON representation
Crossplane Composition function to enable creation of resources by Composite annotations.
- Host: GitHub
- URL: https://github.com/web-seven/function-switcher
- Owner: web-seven
- License: apache-2.0
- Created: 2024-03-02T10:54:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-15T07:32:13.000Z (12 months ago)
- Last Synced: 2025-06-22T01:38:08.784Z (4 months ago)
- Topics: composition, crossplane, function, kndp, kubernetes
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# function-switcher
[](https://github.com/kndpio/function-switcher/actions/workflows/ci.yml)Function Switcher is a Crossplane function that enables Composition users to enable or disable creation of resources, without update schema of XRD, just using annotations like in on this example:
```yaml
apiVersion: example.crossplane.io/v1
kind: XR
metadata:
name: example-xr
annotations:
## Annotations for enable/disable resources of Composition.
switcher.fn.kndp.io/disabled: "resourceTwo,resourceThree"
switcher.fn.kndp.io/enabled: "resourceOne"
spec:
resourceOne:
field1: "one"
field2: "two"
resourceTwo:
field1: "three"
field2: "four"
resourceThree:
field1: "five"
field2: "six"
```
## Installation:1. Create function using function package from registry:
```yaml
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-switcher
spec:
package: xpkg.upbound.io/kndp/function-switcher:v0.0.1
```2. Setup function required to add it after resources generation function like `function-patch-and-transform`:
```yaml
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-switcher
spec:
mode: Pipeline
pipeline:
- step: patch-and-transform
functionRef:
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:- name: resourceOne
base:
apiVersion: example.crossplane.io/v1
kind: Resource
spec:
field1: ""
field2: ""
patches:
- type: FromCompositeFieldPath
fromFieldPath: "spec.resourceOne.field1"
toFieldPath: "spec.field1"
- type: FromCompositeFieldPath
fromFieldPath: "spec.resourceOne.field2"
toFieldPath: "spec.field2"- name: resourceTwo
base:
apiVersion: example.crossplane.io/v1
kind: Resource
spec:
field1: ""
field2: ""
patches:
- type: FromCompositeFieldPath
fromFieldPath: "spec.resourceTwo.field1"
toFieldPath: "spec.field1"
- type: FromCompositeFieldPath
fromFieldPath: "spec.resourceTwo.field2"
toFieldPath: "spec.field2"- name: resourceThree
base:
apiVersion: example.crossplane.io/v1
kind: Resource
spec:
field1: ""
field2: ""
patches:
- type: FromCompositeFieldPath
fromFieldPath: "spec.resourceThree.field1"
toFieldPath: "spec.field1"
- type: FromCompositeFieldPath
fromFieldPath: "spec.resourceThree.field2"
toFieldPath: "spec.field2"
## Enable or disable resources from previous step
- step: enable-disable
functionRef:
name: function-switchercompositeTypeRef:
apiVersion: example.crossplane.io/v1
kind: XR
```
## Templates
You could use simple Go template in function annotation for enable or disable composition resources conditionally using `.observed` and `.desired`, or even print name of resource:
```yaml
apiVersion: example.crossplane.io/v1
kind: XR
metadata:
name: example-xr
annotations:
switcher.fn.kndp.io/enabled: 'resourceThree,resourceOne'
switcher.fn.kndp.io/disabled: '{{ if ne .observed.composite.resource.status.ready true }}resourceThree{{ end }}'
spec:
resourceOne:
field1: "one"
field2: "two"
resourceTwo:
field1: "three"
field2: "four"
resourceThree:
field1: "five"
field2: "six"
status:
ready: false
```