The C# SDK for writing composition functions.
Working example, https://github.com/IvanJosipovic/function-kubemodelrepo
dotnet new install function-template-csharp
dotnet new function-csharp -n TheFunction -o c:\repos\func- XRD to model generation
- Modify
xrd.yamland models are generated automatically.
- Modify
- CRD to model generation
Add one or more
crd.yamlfiles to the project and models are generated automatically.Most Crossplane providers already publish KubernetesCRDModelGen.Models.
Group NuGet aws.upbound.io Link azapi.upbound.io Link azure.upbound.io Link azuread.upbound.io Link crossplane.io Link databricks.crossplane.io Link gcp.upbound.io Link helm.crossplane.io Link kubernetes.crossplane.io Link opentofu.upbound.io Link tf.upbound.io Link upbound.io Link vault.upbound.io Link
- Supports Crossplane v2 or greater.
All extensions are available from the Function.SDK.CSharp namespace.
| Extension | Description |
|---|---|
ConfigureFunction(WebApplicationBuilder, string[]) | Configures the gRPC function host, HTTP/2, TLS, logging, and reflection endpoints. |
MapFunctionService<TService>(WebApplication) | Maps a FunctionRunnerServiceBase implementation and gRPC reflection service. |
varbuilder=WebApplication.CreateSlimBuilder(args);builder.ConfigureFunction(args);varapp=builder.Build();app.MapFunctionService<RunFunctionService>();awaitapp.RunAsync();| Extension | Description |
|---|---|
To() | Creates a response from a request using the default one-minute TTL and copies desired state and context. |
To(Duration) | Creates a response using a custom TTL. |
GetObservedCompositeResource<T>() | Deserializes the observed composite resource as T. |
GetObservedResources() | Returns the raw observed resource dictionary. |
GetObservedResource<T>(key) | Gets an observed Kubernetes resource using its canonical API version, kind, and key. |
GetObservedResources<T>() | Enumerates observed resources matching the API version and kind of T. |
GetDesiredResources() | Returns the raw desired resource dictionary from the request. |
GetDesiredResource<T>(key) | Deserializes a desired request resource using its existing dictionary key. |
GetRequiredResource<T>(key) | Deserializes all required resources registered under a key. |
varresponse=request.To();varcomposite=request.GetObservedCompositeResource<V1alpha1Example>();varobserved=request.GetObservedResource<V1ConfigMap>("settings");varconfigMaps=request.GetObservedResources<V1ConfigMap>();| Extension | Description |
|---|---|
Fatal(message) | Adds a fatal result to the response. |
Warning(message) | Adds a warning result to the response. |
Normal(message) | Adds a normal result to the response. |
NormalF(message, args) | Adds a formatted normal result to the response. |
SetOutput(output) | Sets operation output from a Dictionary<string, object> or protobuf Struct. |
| Extension | Description |
|---|---|
RequireResources(...) | Requests resources by name or labels for the next function invocation. |
| Extension | Description |
|---|---|
AddDesiredResource(resource, key) | Adds or merges a desired Kubernetes resource using a canonical key. The optional key is used when metadata.name is absent. |
AddDesiredUsage(by, of, replayDeletion) | Adds a Crossplane Usage that protects one desired resource while another uses it. |
GetDesiredResource<T>(key) | Gets a desired Kubernetes resource using its canonical API version, kind, and key. |
GetDesiredResources<T>() | Enumerates desired resources matching the API version and kind of T. |
Canonical resource keys use the following format:
{apiVersion}/{kind}/{key}
Namespaced resources include their namespace:
{apiVersion}/{kind}/{namespace}/{key}
For grouped resources, apiVersion includes the group, for example apps/v1/Deployment/default/example. Core resources use keys such as v1/ConfigMap/default/settings. Cluster-scoped resources continue to use {apiVersion}/{kind}/{key}.
| Extension | Description |
|---|---|
UpdateDesiredReadyStatus(...) | Updates desired readiness from custom typed predicates, standard Kubernetes health, or observed Ready and Synced conditions. Unhealthy resources are explicitly marked not ready on every invocation. |
ValidateKubeResourceNames() | Validates desired metadata.name values as RFC 1123 DNS labels. |
UpdateDesiredReadyStatus provides the readiness behavior of Crossplane's
function-auto-ready function directly in the SDK. It evaluates observed
composed resources and updates their desired Ready fields, so a separate
function-auto-ready pipeline step is not required when this method is used.
response.AddDesiredResource(newV1ConfigMap{Metadata=newV1ObjectMeta{Name="settings"},Data=newDictionary<string,string>{["environment"]="production"}});varconfigMap=response.GetDesiredResource<V1ConfigMap>("settings");response.UpdateDesiredReadyStatus(request,logger,[ResourceReadinessCheck.For<MyCustomResource>(
resource =>resource.Status?.Phase=="Available",
resource =>resource.Status?.Healthy==true)]);response.ValidateKubeResourceNames();UpdateDesiredReadyStatus automatically evaluates these standard Kubernetes
resources using their native status fields:
ConfigMap,Namespace,Secret,ServiceAccount- Always ready.
PersistentVolumeClaim- Ready when
status.phaseisBound.
- Ready when
Pod- Ready when
status.phaseisSucceeded, or when it isRunningwithspec.restartPolicy: AlwaysandReady=True.
- Ready when
Service- Ready unless it is a
LoadBalancerwithout a load balancer ingress.
- Ready unless it is a
Deployment- Ready when updated and available replicas match the desired replica count
and
Available=True.
- Ready when updated and available replicas match the desired replica count
and
StatefulSet- Ready when ready and current replicas match the desired count and the current and update revisions match.
DaemonSet- Ready when desired replicas match ready, updated, and available replicas.
ReplicaSet- Ready when the observed generation is current, there is no
ReplicaFailure=True, and available replicas meet the desired count.
- Ready when the observed generation is current, there is no
CronJob- Ready when suspended, has an active Job, or has completed a schedule successfully.
Job- Ready when
Complete=Trueand it is not suspended or failed. - A
Failed=Truecondition marks the Job not ready and reports a fatal result, so the composite does not remain in a processing state after a terminal Job failure.
- Ready when
HorizontalPodAutoscaler- Ready when scaling is active or limited, unless one of its scale or metric retrieval conditions reports failure.
Ingress- Ready when at least one load balancer ingress is present.
For a custom resource type, pass an array of ResourceReadinessCheck instances
created with ResourceReadinessCheck.For<T>(...). Checks apply only to observed
resources with the exact API version and kind of T, and all matching checks
and predicates must return true for the resource to be ready.
Synced=False always takes precedence. Other resource types continue to use the
Crossplane-style Ready condition.
| Extension | Description |
|---|---|
AddOrUpdate(key, resource) | Adds a Kubernetes object to a State, initializes missing API identity, and merges an existing entry using protobuf merge semantics. |
GetKubeResource<T>() | Deserializes a protobuf function Resource as a Kubernetes object. |
GetCondition(conditionType) | Gets a condition from a resource status by condition type. |
response.Desired.AddOrUpdate("settings",configMap);varresource=response.Desired.Resources["settings"];vartypedResource=resource.GetKubeResource<V1ConfigMap>();varreadyCondition=resource.GetCondition("Ready");