crossplane-contrib / crossplane-contrib/function-sequencer

Specify sequence using context from the previous function (e.g Annotations)

Open
#39 2 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
37
Forks
19
Avg merge
1d 14h
Merged PRs (30d)
4

Description

Related issue: https://github.com/crossplane-contrib/function-go-templating/issues/154
### What problem are you facing?
We currently maintain a couple of medium-sized compositions using function-go-templating. We observe, that dependencies between the composite resources are unavoidable and therefore we are seeing ourselves a lot inside conditional blocks, which get fairly complex to oversee on a larger scale.
While this function addresses the problem, we lack a proper way of defining the sequences in a declarative way. Since we use the go-templating, resources names can be templated using user input and we cannot determine it well enough using regular expression matching.

### How could this Function help solve your problem?
We would somehow need a way of passing context from the previous function down to `function-sequencer` which bridges the gap between free templating and configuration.

One possible solution would be to extend this function to determine the sequence based on a special annotation similar to Argos [Sync waves](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/). The function will read the corresponding sequencing from the annotation.

It could look somehow like this:
```yaml
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: example-function-get-composed-resource
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1beta1
kind: XR
mode: Pipeline
pipeline:
- step: render-templates
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
---
{{ $flexServerResourceName := "flexServer" }}
apiVersion: dbforpostgresql.azure.upbound.io/v1beta1
kind: FlexibleServer
metadata:
annotations:
{{ setResourceNameAnnotation $flexServerResourceName }}
gotemplating.fn.crossplane.io/sync-wave: "1" # Server is in sync wave 1
spec:
forProvider:
storageMb: 32768
providerConfigRef:
name: my-provider-cfg
---
{{ $flexServer := getComposedResource . $flexServerResourceName }}

apiVersion: dbforpostgresql.azure.upbound.io/v1beta1
kind: FlexibleServerConfiguration
metadata:
annotations:
{{ setResourceNameAnnotation "flexServerConfig" }}
gotemplating.fn.crossplane.io/sync-wave: "2" # Config is in sync wave 2
spec:
forProvider:
# Populate the field using the observed status of the retrieved resource
serverId: {{ get $flexServer.status "id" }}

providerConfigRef:
name: my-provider-cfg

- step: sequence-creation
functionRef:
name: function-sequencer
input:
apiVersion: sequencer.fn.crossplane.io/v1beta1
kind: Input
sequenceAnnotation: "gotemplating.fn.crossplane.io/sync-wave"
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.