From 203cf20dea059ec09511c56ceba9c7a3087532ab Mon Sep 17 00:00:00 2001
From: Philippe Scorsolini
Date: Tue, 19 Mar 2024 16:24:30 +0100
Subject: [PATCH] docs: add examples for kubecon 2024 demo
Signed-off-by: Philippe Scorsolini
---
example/kubecon-2024/README.md | 41 +++++++++++++++++++
example/kubecon-2024/composition.yaml | 42 ++++++++++++++++++++
example/kubecon-2024/environmentConfigs.yaml | 23 +++++++++++
example/kubecon-2024/functions.yaml | 18 +++++++++
example/kubecon-2024/old/composition.yaml | 38 ++++++++++++++++++
example/kubecon-2024/provider.yaml | 8 ++++
example/kubecon-2024/xr.yaml | 6 +++
example/kubecon-2024/xrd.yaml | 25 ++++++++++++
8 files changed, 201 insertions(+)
create mode 100644 example/kubecon-2024/README.md
create mode 100644 example/kubecon-2024/composition.yaml
create mode 100644 example/kubecon-2024/environmentConfigs.yaml
create mode 100644 example/kubecon-2024/functions.yaml
create mode 100644 example/kubecon-2024/old/composition.yaml
create mode 100644 example/kubecon-2024/provider.yaml
create mode 100644 example/kubecon-2024/xr.yaml
create mode 100644 example/kubecon-2024/xrd.yaml
diff --git a/example/kubecon-2024/README.md b/example/kubecon-2024/README.md
new file mode 100644
index 0000000..452f054
--- /dev/null
+++ b/example/kubecon-2024/README.md
@@ -0,0 +1,41 @@
+# Example manifests
+
+Before, one had to define references to `spec.environment.environmentConfigs`,
+see [./old/composition.yaml][].
+
+The same can now be achieved using `function-environment-config`, which allows
+to leverage the power of `crossplane beta render` to see both the `Context`
+containing the `environment` and the XR:
+```shell
+$ crossplane beta render \
+ --extra-resources example/environmentConfigs.yaml \
+ --include-full-xr \
+ --include-context \
+ example/xr.yaml example/composition.yaml example/functions.yaml
+---
+apiVersion: example.crossplane.io/v1
+kind: XR
+metadata:
+ name: example-xr
+spec: {}
+status:
+ conditions:
+ - lastTransitionTime: "2024-01-01T00:00:00Z"
+ reason: Available
+ status: "True"
+ type: Ready
+ fromEnv: by-label
+---
+apiVersion: render.crossplane.io/v1beta1
+kind: Context
+fields:
+ apiextensions.crossplane.io/environment:
+ apiVersion: internal.crossplane.io/v1alpha1
+ kind: Environment
+ complex:
+ a: b
+ c:
+ d: by-label
+ f: "1"
+ g: by-label
+```
diff --git a/example/kubecon-2024/composition.yaml b/example/kubecon-2024/composition.yaml
new file mode 100644
index 0000000..682de69
--- /dev/null
+++ b/example/kubecon-2024/composition.yaml
@@ -0,0 +1,42 @@
+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: environmentConfigs
+ functionRef:
+ name: function-environment-configs
+ input:
+ apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
+ kind: Input
+ spec:
+ environmentConfigs:
+ - type: Reference
+ ref:
+ name: example-config
+ - type: Selector
+ selector:
+ mode: Single
+ matchLabels:
+ - type: Value
+ key: org
+ value: foo
+ - step: go-templating
+ functionRef:
+ name: function-go-templating
+ input:
+ apiVersion: gotemplating.fn.crossplane.io/v1beta1
+ kind: GoTemplate
+ source: Inline
+ inline:
+ template: |
+ ---
+ apiVersion: example.crossplane.io/v1
+ kind: XR
+ status:
+ fromEnv: {{ index .context "apiextensions.crossplane.io/environment" "complex" "c" "d" }}
diff --git a/example/kubecon-2024/environmentConfigs.yaml b/example/kubecon-2024/environmentConfigs.yaml
new file mode 100644
index 0000000..340bdad
--- /dev/null
+++ b/example/kubecon-2024/environmentConfigs.yaml
@@ -0,0 +1,23 @@
+---
+apiVersion: apiextensions.crossplane.io/v1alpha1
+kind: EnvironmentConfig
+metadata:
+ name: example-config
+data:
+ complex:
+ a: b
+ c:
+ d: e
+ f: "1"
+---
+apiVersion: apiextensions.crossplane.io/v1alpha1
+kind: EnvironmentConfig
+metadata:
+ name: example-config-by-label
+ labels:
+ org: foo
+data:
+ complex:
+ c:
+ d: by-label
+ g: by-label
diff --git a/example/kubecon-2024/functions.yaml b/example/kubecon-2024/functions.yaml
new file mode 100644
index 0000000..dd61f09
--- /dev/null
+++ b/example/kubecon-2024/functions.yaml
@@ -0,0 +1,18 @@
+---
+apiVersion: pkg.crossplane.io/v1beta1
+kind: Function
+metadata:
+ name: function-environment-configs
+ annotations:
+ # This tells crossplane beta render to connect to the function locally.
+ #render.crossplane.io/runtime: Development
+spec:
+ # This is ignored when using the Development runtime.
+ package: xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.0.4
+---
+apiVersion: pkg.crossplane.io/v1beta1
+kind: Function
+metadata:
+ name: function-go-templating
+spec:
+ package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.1
diff --git a/example/kubecon-2024/old/composition.yaml b/example/kubecon-2024/old/composition.yaml
new file mode 100644
index 0000000..470912e
--- /dev/null
+++ b/example/kubecon-2024/old/composition.yaml
@@ -0,0 +1,38 @@
+apiVersion: apiextensions.crossplane.io/v1
+kind: Composition
+metadata:
+ name: function-environment-configs
+spec:
+ environment:
+ environmentConfigs:
+ - type: Reference
+ ref:
+ name: example-config
+ - type: Selector
+ selector:
+ mode: Single
+ matchLabels:
+ - type: Value
+ key: org
+ value: foo
+ policy:
+ resolve: Always
+ compositeTypeRef:
+ apiVersion: example.crossplane.io/v1
+ kind: XR
+ mode: Pipeline
+ pipeline:
+ - step: go-templating
+ functionRef:
+ name: function-go-templating
+ input:
+ apiVersion: gotemplating.fn.crossplane.io/v1beta1
+ kind: GoTemplate
+ source: Inline
+ inline:
+ template: |
+ ---
+ apiVersion: example.crossplane.io/v1
+ kind: XR
+ status:
+ fromEnv: {{ index .context "apiextensions.crossplane.io/environment" "complex" "c" "d" }}
diff --git a/example/kubecon-2024/provider.yaml b/example/kubecon-2024/provider.yaml
new file mode 100644
index 0000000..312de8b
--- /dev/null
+++ b/example/kubecon-2024/provider.yaml
@@ -0,0 +1,8 @@
+---
+apiVersion: pkg.crossplane.io/v1
+kind: Provider
+metadata:
+ name: provider-nop
+spec:
+ package: xpkg.upbound.io/crossplane-contrib/provider-nop:v0.2.1
+ ignoreCrossplaneConstraints: true
diff --git a/example/kubecon-2024/xr.yaml b/example/kubecon-2024/xr.yaml
new file mode 100644
index 0000000..25472b9
--- /dev/null
+++ b/example/kubecon-2024/xr.yaml
@@ -0,0 +1,6 @@
+# Replace this with your XR!
+apiVersion: example.crossplane.io/v1
+kind: XR
+metadata:
+ name: example-xr
+spec: {}
diff --git a/example/kubecon-2024/xrd.yaml b/example/kubecon-2024/xrd.yaml
new file mode 100644
index 0000000..8955af2
--- /dev/null
+++ b/example/kubecon-2024/xrd.yaml
@@ -0,0 +1,25 @@
+---
+apiVersion: apiextensions.crossplane.io/v1
+kind: CompositeResourceDefinition
+metadata:
+ name: xrs.example.crossplane.io
+spec:
+ group: example.crossplane.io
+ names:
+ kind: XR
+ plural: xrs
+ connectionSecretKeys:
+ - test
+ versions:
+ - name: v1
+ served: true
+ referenceable: true
+ schema:
+ openAPIV3Schema:
+ type: object
+ properties:
+ status:
+ type: object
+ properties:
+ fromEnv:
+ type: string
\ No newline at end of file