Skip to content

Commit

Permalink
Merge pull request #594 from negz/functional-backup
Browse files Browse the repository at this point in the history
Update Composition Functions content to v1beta1
  • Loading branch information
negz authored Oct 30, 2023
2 parents 2370e5b + 6524c67 commit cc67ebd
Show file tree
Hide file tree
Showing 8 changed files with 701 additions and 958 deletions.
1,474 changes: 574 additions & 900 deletions content/master/concepts/composition-functions.md

Large diffs are not rendered by default.

90 changes: 63 additions & 27 deletions content/master/concepts/compositions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Optionally, Compositions also support:
* [Modifying and patching](#changing-resource-fields) resource settings.
* [Storing connection details](#storing-connection-details) and secrets
generated by the managed resources.
* Using [Composition functions](#composition-functions) to allow custom
programs to run alongside the Composition.
* Using [Composition Functions](#use-composition-functions) to template
resources using custom programs.
* Creating a
[custom check of when a resource is ready](#resource-readiness-checks)
to use.
Expand Down Expand Up @@ -664,40 +664,72 @@ spec:
The [EnvironmentConfigs]({{<ref "./environment-configs" >}}) page has
more information on EnvironmentConfigs options and usage.

### Composition functions
### Use composition functions

Composition functions (`XFNs`) are containers executing any code you define.
Composition functions can read and write to any resource in the Composition
they're attached to. This allows composition functions to perform complex
operations to patch fields, determine if a resource is ready for use or notify
an external system about the details of resource.
Composition functions (or just functions, for short) are custom programs that
template Crossplane resources. You can write a function to template resources
using a general purpose programming language like Go or Python. Using a general
purpose programming language allows a function to use more advanced logic to
template resources, like loops and conditionals.

{{<hint "important" >}}
Composition functions are an alpha feature. Alpha features aren't enabled by
default.
Composition functions is a beta feature. Crossplane enables beta functions by
default. The
[Composition Functions]({{<ref "./composition-functions#disable-composition-functions">}})
page explains how to disable composition functions.
{{< /hint >}}

To attach a composition function to a Composition define a
{{<hover label="xfn" line="7">}}function{{</hover>}} inside the Composition
{{<hover label="xfn" line="4">}}spec{{</hover>}}.
To use composition functions set the Composition
{{<hover label="xfn" line="6">}}mode{{</hover>}} to
{{<hover label="xfn" line="6">}}Pipeline{{</hover>}}.

Define a {{<hover label="xfn" line="7">}}pipeline{{</hover>}} of
{{<hover label="xfn" line="8">}}steps{{</hover>}}. Each
{{<hover label="xfn" line="8">}}step{{</hover>}} calls a Function.

Each {{<hover label="xfn" line="8">}}step{{</hover>}} uses a
{{<hover label="xfn" line="9">}}functionRef{{</hover>}} to reference the
{{<hover label="xfn" line="10">}}name{{</hover>}} of the Function to call.

Some Functions also allow you to specify an
{{<hover label="xfn" line="11">}}input{{</hover>}}.
The function defines the
{{<hover label="xfn" line="13">}}kind{{</hover>}} of input.

{{<hint "important" >}}
Compositions using {{<hover label="xfn" line="6">}}mode: Pipeline{{</hover>}}
can't specify resource templates with a `resources` field.

Use function "Patch and Transform" to create resource templates.
{{< /hint >}}

Provide a {{<hover label="xfn" line="8">}}name{{</hover>}} for the function.
The {{<hover label="xfn" line="9">}}type{{</hover>}} is always `Container`.
The {{<hover label="xfn" line="11">}}container.image{{</hover>}} is the
location of the composition function container image.
This example uses Function Patch and Transform. Function Patch and Transform is
a function that implements Crossplane resource templates. You can use Function
Patch and Transform to specify resource templates in a pipeline with other
Functions.

```yaml {label="xfn",copy-lines="none"}
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
# Removed for Brevity
spec:
resources:
# Removed for Brevity
functions:
- name: rds-instance-password
type: Container
container:
image: xpkg.upbound.io/provider-aws-xfns/random-rds-password:v0.1.0
mode: Pipeline
pipeline:
- step: patch-and-transform
functionRef:
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:
- name: storage-bucket
base:
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
spec:
forProvider:
region: "us-east-2"
```

Read the [composition functions]({{<ref "./composition-functions">}}) page for
Expand Down Expand Up @@ -1293,6 +1325,9 @@ Composition.
When creating a Composition Crossplane automatically validates specific
parameters in the Composition.

If using `mode: Resources`:

* The `resources` field isn't empty.
* All resources either use a `name` or don't. Compositions can't use both named
and unnamed resources.
* No duplicate resource names.
Expand All @@ -1303,10 +1338,11 @@ parameters in the Composition.
* Readiness checks using `matchString` aren't empty.
* Readiness checks using `matchInteger` isn't `0`.
* Readiness checks requiring a `fieldPath` value provide it.
* If using composition functions, all resources must have names.
* Composition function container field isn't empty.
* Composition function `type` is `container`.
* Composition function names are unique.

If using `mode: Pipeline` (Composition Functions):

* The `pipeline` field isn't empty.
* No duplicate step names.

### Resource schema validation
<!-- vale write-good.TooWordy = NO -->
Expand Down
31 changes: 0 additions & 31 deletions content/master/getting-started/install-crossplane-include.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,6 @@ serviceAccount:
tolerations: []
webhooks:
enabled: true
xfn:
args: []
cache:
configMap: ""
medium: ""
pvc: ""
sizeLimit: 1Gi
enabled: false
extraEnvVars: {}
image:
pullPolicy: IfNotPresent
repository: crossplane/xfn
tag: ""
resources:
limits:
cpu: 2000m
memory: 2Gi
requests:
cpu: 1000m
memory: 1Gi
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- SETUID
- SETGID
readOnlyRootFilesystem: true
runAsGroup: 65532
runAsUser: 65532
seccompProfile:
type: Unconfined

HOOKS:
MANIFEST:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{ .Page.Store.Set "hasMermaid" true }}
48 changes: 48 additions & 0 deletions themes/geekboot/layouts/partials/single-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,51 @@ <h1 class="bd-title mb-0" id="content">{{ .Title | markdownify }}</h1>
</div>
</main>
</div>

{{ if .Page.Store.Get "hasMermaid" }}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="module">

import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
document.addEventListener("DOMContentLoaded", setMermaidStyle());
document.addEventListener("DOMContentLoaded", colorModeListener());

function getMermaidConfig(){
var style = getComputedStyle(document.body)
var font = style.getPropertyValue("font-family")
var fontColor = style.getPropertyValue('--body-font-color')
var backgroundColor = style.getPropertyValue('--body-background')

var config = {
"theme": "base",
"fontFamily": font,
"themeVariables": {
"background": backgroundColor,
"textColor": fontColor,
}
}

return config
}

function setMermaidStyle(){
var config = getMermaidConfig()
mermaid.initialize( config )
}

function colorModeListener(){
darkSwitch.addEventListener("click", resetMermaidStyle())
}

function resetMermaidStyle(){
console.log("resetting")

var config = getMermaidConfig()
console.log(config)
mermaid.mermaidAPI.setConfig( config )
mermaid.mermaidAPI.reset()

}

</script>
{{ end }}
7 changes: 7 additions & 0 deletions utils/vale/styles/Crossplane/allowed-jargon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ base64
bool
boolean
booleans
Buf
CI
CLI
cluster-wide
Expand All @@ -20,6 +21,8 @@ Enum
Env
ESS
float64
Go
gRPC
JSONPath
key-pair
kube-apiserver
Expand All @@ -34,6 +37,8 @@ OCI
proselint
RBAC
SCSS
SDK
SDKs
semver
ServiceAccount
ServiceAccounts
Expand Down Expand Up @@ -61,6 +66,8 @@ SHA-256
SHA-512
base64
RBAC
RPC
RPCs
ServiceAccounts
ServiceAccount
ClusterRole
Expand Down
4 changes: 4 additions & 0 deletions utils/vale/styles/Crossplane/crossplane-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ InactivePackageRevision
initProvider
LateInitialize
managementPolicies
MR
MRs
PatchSet
PatchSets
ProviderConfig
ProviderConfigs
RunFunctionRequest
RunFunctionResponse
StoreConfig
StoreConfigs
ToCompositeFieldPath
Expand Down
1 change: 1 addition & 0 deletions utils/vale/styles/Crossplane/spelling-exceptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ double-check
double-checks
dry-run
end-points
end-to-end
free-form
hands-on
how-to
Expand Down

0 comments on commit cc67ebd

Please sign in to comment.