Try out beta Composition Functions! #4639
Replies: 24 comments 28 replies
-
Also, please join #sig-composition-functions on Crossplane Slack to follow along with our progress! |
Beta Was this translation helpful? Give feedback.
-
Here's a proposed spec for how Functions should work: #4640 If this is accepted it will probably make sense to link from the template repo(s). |
Beta Was this translation helpful? Give feedback.
-
CIDR subnet calculation is used by many Terraform users. There is 'old style' Crossplane XFN code for a HashiCorp compatible implementation that could be converted to the current way of writing functions. |
Beta Was this translation helpful? Give feedback.
-
Here is a function to add k8s labels and annotations to resources: https://github.com/stevendborrelli/function-add-k8s-labels-annotations |
Beta Was this translation helpful? Give feedback.
-
One idea that comes up a lot is a Function that would allow you to express Composition logic using everyone's favorite hot new configuration language - CUE. 😉 No one is actively planning to work on this to my knowledge, but it would be a valuable contribution if someone wanted to try. |
Beta Was this translation helpful? Give feedback.
-
This week I put together https://github.com/negz/xrender.
We intend to make |
Beta Was this translation helpful? Give feedback.
-
I prototyped function-tee this morning :) It is similar to the tee command in Unix. It outputs the input request it receives into a ConfigMap, and then passes it through to the next Function in the pipeline. I am imagining such a function would only be helpful for debugging purposes where you want to see what is going in and out at different stages of the pipeline. It is also an interesting one, because it creates (actually desires) a ConfigMap wrapped as a provider-kubernetes Feedback on Development: I used A huge shout to @negz making this available so quick but still flawless 👏 I experienced the following relatively small issues but none of them was blocking:
|
Beta Was this translation helpful? Give feedback.
-
I'm currently trying to put https://github.com/crossplane-contrib/function-patch-and-transform through its paces. This Function implements contemporary P&T style Composition... but as a Function. I'd love it if it could handle say 90%1 of Compositions in time for v1.14. This way folks could port over if they found value in doing so (e.g. to use P&T together with other Functions).2 Something that would help a lot would be to test function-patch-and-transform with your hairier Compositions. You don't need Crossplane installed to to this, you can use https://github.com/crossplane-contrib/xrender to test them on your laptop. Start by creating a apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-patch-and-transform
spec:
# Unfortunately this image is only built for arm64 at the moment.
# I haven't setup CI/CD so if you're not running ARM you might need to check out
# the repo and `docker build` it locally. Sorry!
package: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform:v0.1.4 You'll then just need to "nest" the apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: example
spec:
resources:
# Your resource templates go here. To... apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: example
spec:
mode: Pipeline
pipeline:
- step: patch-and-transform
functionRef:
# This needs to match the name of the Function in functions.yaml
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:
# Your resource templates go here. You should then be able to run the following command, to have xrender some-xr.yaml composition.yaml functions.yaml Both the Function and Thank you! Footnotes
|
Beta Was this translation helpful? Give feedback.
-
Some things I've been thinking about:
|
Beta Was this translation helpful? Give feedback.
-
When trying to install a patch and transform function, I'm getting the following error on the function deployment:
Running Crossplane from master branch on a kind cluster. Here is some more environment info: ➜ ./__system_info.sh
-------------------
System Information:
-------------------
OS Details:
Linux pop-os 6.4.6-76060406-generic #202307241739~1694621917~22.04~ac5e1a8 SMP PREEMPT_DYNAMIC Wed S x86_64 x86_64 x86_64 GNU/Linux
----------------
Kind Version:
----------------
kind v0.20.0 go1.21.1 linux/amd64
-------------------
Kubectl Version:
-------------------
Client Version: v1.28.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.3
{
"major": "1",
"minor": "27",
"gitVersion": "v1.27.3",
"gitCommit": "25b4e43193bcda6c7328a6d147b1fb73a33f1598",
"gitTreeState": "clean",
"buildDate": "2023-06-15T00:36:28Z",
"goVersion": "go1.20.5",
"compiler": "gc",
"platform": "linux/amd64"
}
--------------------
Crossplane Version:
--------------------
crossplane/crossplane:v1.14.0-rc.0.387.g3dbe4b92
----------------------------------------
Kubernetes Node and Pod Information:
----------------------------------------
Node Information:
NAME STATUS ROLES AGE VERSION
control-plane-control-plane Ready control-plane 72m v1.27.3
control-plane-worker Ready <none> 72m v1.27.3
Pod Information:
NAMESPACE NAME READY STATUS RESTARTS AGE
crossplane-system crossplane-f9db6fc5d-pmhtx 1/1 Running 0 72m
crossplane-system crossplane-rbac-manager-5449787c66-k2nxg 1/1 Running 0 72m
crossplane-system function-patch-and-transform-5ee9b881186b-8657858768-mztxn 0/1 CrashLoopBackOff 7 (4m1s ago) 14m
crossplane-system provider-helm-59fc94cd939e-78f8f9c7d7-rtcl7 1/1 Running 0 71m
crossplane-system provider-kubernetes-a1a49ab74384-6776d5f6f8-76vw8 1/1 Running 0 71m
kube-system coredns-5d78c9869d-6sh7x 1/1 Running 0 72m
kube-system coredns-5d78c9869d-x5lxt 1/1 Running 0 72m
kube-system etcd-control-plane-control-plane 1/1 Running 0 72m
kube-system kindnet-26gwp 1/1 Running 0 72m
kube-system kindnet-gvzxv 1/1 Running 0 72m
kube-system kube-apiserver-control-plane-control-plane 1/1 Running 0 72m
kube-system kube-controller-manager-control-plane-control-plane 1/1 Running 0 72m
kube-system kube-proxy-8567c 1/1 Running 0 72m
kube-system kube-proxy-qjznr 1/1 Running 0 72m
kube-system kube-scheduler-control-plane-control-plane 1/1 Running 0 72m
kube-system metrics-server-7d75545b6c-29cs7 1/1 Running 0 71m
local-path-storage local-path-provisioner-6bc4bddd6b-fnx7b 1/1 Running 0 72m
Kubernetes Status:
[+]ping ok
[+]log ok
[+]etcd ok
[+]poststarthook/start-kube-apiserver-admission-initializer ok
[+]poststarthook/generic-apiserver-start-informers ok
[+]poststarthook/priority-and-fairness-config-consumer ok
[+]poststarthook/priority-and-fairness-filter ok
[+]poststarthook/storage-object-count-tracker-hook ok
[+]poststarthook/start-apiextensions-informers ok
[+]poststarthook/start-apiextensions-controllers ok
[+]poststarthook/crd-informer-synced ok
[+]poststarthook/start-system-namespaces-controller ok
[+]poststarthook/bootstrap-controller ok
[+]poststarthook/rbac/bootstrap-roles ok
[+]poststarthook/scheduling/bootstrap-system-priority-classes ok
[+]poststarthook/priority-and-fairness-config-producer ok
[+]poststarthook/start-cluster-authentication-info-controller ok
[+]poststarthook/start-kube-apiserver-identity-lease-controller ok
[+]poststarthook/start-deprecated-kube-apiserver-identity-lease-garbage-collector ok
[+]poststarthook/start-kube-apiserver-identity-lease-garbage-collector ok
[+]poststarthook/start-legacy-token-tracking-controller ok
[+]poststarthook/aggregator-reload-proxy-client-cert ok
[+]poststarthook/start-kube-aggregator-informers ok
[+]poststarthook/apiservice-registration-controller ok
[+]poststarthook/apiservice-status-available-controller ok
[+]poststarthook/kube-apiserver-autoregistration ok
[+]autoregister-completion ok
[+]poststarthook/apiservice-openapi-controller ok
[+]poststarthook/apiservice-openapiv3-controller ok
[+]poststarthook/apiservice-discovery-controller ok
healthz check passed
NAME STATUS ROLES AGE VERSION
control-plane-control-plane Ready control-plane 72m v1.27.3
control-plane-worker Ready <none> 72m v1.27.3
Kubernetes control plane is running at https://127.0.0.1:45475
CoreDNS is running at https://127.0.0.1:45475/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Client Version: v1.28.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.3 |
Beta Was this translation helpful? Give feedback.
-
#4706 Submit a pull request to address an issue related to the installation of functions with configurations. This problem currently results in an empty package and type in the lock lock
|
Beta Was this translation helpful? Give feedback.
-
During the hackathon today I created a simple This function is intentionally simple and not designed to compete with #4573 which will probably be the main function around to provide loops and conditionals.
Example of
Really nice, next-level DX, I was able to iterate quickly. https://github.com/crossplane/function-sdk-go was super helpful. More examples there will definitely enable faster Functions crafting in the long run. @negz thanks for the new beta functions and |
Beta Was this translation helpful? Give feedback.
-
During today's hackathon I built https://github.com/phisco/function-rego to allow specifying policies in rego, mostly to emit "results" based on some rule, e.g. fatal if some field is set, but I also managed to make it generate pretty complex responses directly. Overall, the experience was quite nice, thanks to the unit tests already properly scaffolded and the local development setup using It was not so straightforward to properly handle observed and desired state and build a full response from such a constrained language, but once found a few useful utilities it's doable even in rego, it's debatable whether one should actually do that, but that's another topic. The deeply nested structures were a bit painful to handle without a proper IDE knowing the schema of the input resources. If needed custom functions written in Go could be injected into the query context, so one could think of exposing the SDK utilities directly. Few times I was hit because I forgot the additional I had some issues with the reading back the json response due to how the In the template repository, I suggest making it easier to identify the items that need to be renamed by using more grep-friendly placeholders. Additionally, include an examples folder to facilitate the immediate usage of |
Beta Was this translation helpful? Give feedback.
-
Today on the hackathon I wrote a simple Here is the repo https://github.com/lsviben/function-external-namer. The biggest help to get me started was the video @negz created, recommend it to all who want to give a shot at writing functions. Also took some examples from existing functions like https://github.com/stevendborrelli/function-add-k8s-labels-annotations. Testing with Overall the experience was quite enjoyable. My other struggle was to think about which function could be really useful, and can be done during the hackathon. Most of my ideas ended up in: "Ah, probably you would be able to do that with @ezgidemirel's go-template function", so looking forward to seeing more of that in action. |
Beta Was this translation helpful? Give feedback.
-
Today during hackathon I spent some time extending @ytsarev's |
Beta Was this translation helpful? Give feedback.
-
I wrote a simple function that "swaps" the Composition that will actuate your XR based on the input to the function. It may not be very useful, but I can imagine using it for things like a bulk migration (without patching all of your composites) or a preprocessing step of some kind in conjunction with other functions being contributed. There are still some TODOs here, for example making sure the Composition exists and is compatible with the XR (i.e. matches https://github.com/jastang/function-composition-swap The SDK was fairly easy to acclimate to after a bit of use, and you can actually get reasonably far with unit testing - hence I will suggest some utilities in the SDK to help mock out test cases since the structures can get pretty complex when we inline them for test cases.
|
Beta Was this translation helpful? Give feedback.
-
I tested porting platform-ref-aws to using functions upbound/platform-ref-aws#115 and was successful in my initial efforts after @negz put in a few fixes to https://github.com/crossplane-contrib/function-patch-and-transform. Some findings:
Overall it was a positive experience. I'm convinced that functions are a big leap in functionality and experience. |
Beta Was this translation helpful? Give feedback.
-
I tried porting the configuration-caas and observed the same results as @stevendborrelli . In general, I had a great experience with it.
Should we consider creating Prometheus metrics based on this log line in the future? example:
changed to:
nested compositions not working - opened an issue: crossplane-contrib/function-patch-and-transform#13 |
Beta Was this translation helpful? Give feedback.
-
Another data point, I created crossplane-contrib/function-patch-and-transform#14 to add conditional rendering. With patch-and-transform as a function is is mind-blowing we quickly can make such changes. Adding something to the core patch-and-transform engine is something that would probably take months from design to implementation to release. Here I was able to implement it and do some tests in xrender while waiting at the airport. |
Beta Was this translation helpful? Give feedback.
-
Did we think about adding a conversion webhook to transition from embedded P&T to function P&T? I believe this could be the most effective way to make the switch to function P&T. What are your thoughts on this idea? We can activate this feature in version 1.15 and then eliminate the conversion webhook in version 1.17, along with the removal of embedded P&T. |
Beta Was this translation helpful? Give feedback.
-
This would imply that the P&T Function is installed by the core Crossplane installation, as mentioned here: #4583 (comment) |
Beta Was this translation helpful? Give feedback.
-
Adding breadcrumbs to #4728, which I think is a useful discussion around whether Functions should mostly be reading observed or desired state. |
Beta Was this translation helpful? Give feedback.
-
Hi, very interested in trying out beta functions, especially the gotemplating one from crossplane-contrib.
Thanks |
Beta Was this translation helpful? Give feedback.
-
I developed the Crossplane KCL function using the Crossplane Go function template and KCL Go SDK, which means we can use KCL (a DSL) to write logic without the need for repeated packaging of crossover functions, and we support KCL package management tools and the KRM KCL specification, which allows for OCI/git source and the reuse of KCL's module ecosystem. The entire development process is very smooth because KCL has already done a lot of work in the early stages. Reference
|
Beta Was this translation helpful? Give feedback.
-
In Crossplane v1.14 (coming late October) we've made big changes to the Composition Functions architecture, to make Functions more scalable. We're also investing in the developer experience to make them easier to build and use.
Leading up to the release, we'd love for you to try building a Function. This will help us identify and fix rough edges. The developer experience is still a rough MVP right now. In particular we've only built support for Go Functions right now - other languages such as Python will be supported after the v1.14 release.
The readme of https://github.com/crossplane/function-template-go is the best place to get started. If you'd like a more in-depth example you can watch me build a Function at https://youtu.be/otwg-bO757A?feature=shared&t=60. Here's the Functions we've built so far:
If you write a Function, please link it here! If you struggle, please use this thread for help and I'll try respond. Please feel free also to suggest ideas for Functions. I'm unlikely to build them myself, but they may help inspire someone else in the community.
Thanks!
P.S. If you don't feel up to building a Function, another thing that would help a lot is testing out https://github.com/crossplane-contrib/function-patch-and-transform. We want this Function to be able to do everything "native" patch-and-transform style Composition can do. It would be great if you could help validate it with some of your more complex Compositions. See #4639 (comment) for info on how to try it out.
Beta Was this translation helpful? Give feedback.
All reactions