Function

The functions.serverless.kyma-project.io CustomResourceDefinition (CRD) is a detailed description of the kind of data and the format used to manage Functions within Kyma. To get the up-to-date CRD and show the output in the YAML format, run this command:

Click to copy
kubectl get crd functions.serverless.kyma-project.io -o yaml

Sample custom resource

The following Function object creates a Function which responds to HTTP requests with the "Hello John" message. The Function's code (source) and dependencies (dependencies) are specified in the Function CR.

Click to copy
apiVersion: serverless.kyma-project.io/v1alpha2
kind: Function
metadata:
name: my-test-function
namespace: default
labels:
app: my-test-function
spec:
runtime: nodejs18
source:
inline:
dependencies: |
{
"name": "hellowithdeps",
"version": "0.0.1",
"dependencies": {
"end-of-stream": "^1.4.1",
"from2": "^2.3.0",
"lodash": "^4.17.5"
}
}
source: |
module.exports = {
main: function(event, context) {
const name = process.env.PERSON_NAME;
return 'Hello ' + name;
}
}
scaleConfig:
minReplicas: 3
maxReplicas: 3
resourceConfiguration:
function:
resources:
limits:
cpu: 1
memory: 1Gi
requests:
cpu: 500m
memory: 500Mi
build:
resources:
limits:
cpu: 2
memory: 2Gi
requests:
cpu: 1
memory: 1Gi
env:
- name: PERSON_NAME
value: "John"
secretMounts:
- secretName: SECRET_NAME
mountPath: /secret/mount/path
status:
conditions:
- lastTransitionTime: "2020-04-14T08:17:11Z"
message: "Deployment my-test-function-nxjdp is ready"
reason: DeploymentReady
status: "True"
type: Running
- lastTransitionTime: "2020-04-14T08:16:55Z"
message: "Job my-test-function-build-552ft finished"
reason: JobFinished
status: "True"
type: BuildReady
- lastTransitionTime: "2020-04-14T08:16:16Z"
message: "ConfigMap my-test-function-xv6pc created"
reason: ConfigMapCreated
status: "True"
type: ConfigurationReady

If you store the Function's source code and dependencies in a Git repository and want the Function Controller to fetch them from it, use these parameters in the Function CR:

Click to copy
apiVersion: serverless.kyma-project.io/v1alpha2
kind: Function
metadata:
name: my-test-function
spec:
source:
gitRepository:
url: github.com/username/repo
baseDir: "/"
reference: "branchA"
auth:
type: basic
secretName: secret-name
runtime: "nodejs18"

Custom resource parameters

Function.serverless.kyma-project.io/v1alpha2

Spec:

ParameterTypeDescription
annotationsmap[string]stringDefines annotations used in Deployment's PodTemplate and applied on the Function's runtime Pod.
env[]objectSpecifies an array of key-value pairs to be used as environment variables for the Function. You can define values as static strings or reference values from ConfigMaps or Secrets. For configuration details, see the official Kubernetes documentation.
labelsmap[string]stringDefines labels used in Deployment's PodTemplate and applied on the Function's runtime Pod.
replicasintegerDefines the exact number of Function's Pods to run at a time. If ScaleConfig is configured, or if the Function is targeted by an external scaler, then the Replicas field is used by the relevant HorizontalPodAutoscaler to control the number of active replicas.
resourceConfigurationobjectSpecifies resources requested by the Function and the build Job.
resourceConfiguration.buildobjectSpecifies resources requested by the build Job's Pod.
resourceConfiguration.build.profilestringDefines the name of the predefined set of values of the resource. Can't be used together with Resources.
resourceConfiguration.build.resourcesobjectDefines the amount of resources available for the Pod. Can't be used together with Profile. For configuration details, see the official Kubernetes documentation.
resourceConfiguration.functionobjectSpecifies resources requested by the Function's Pod.
resourceConfiguration.function.profilestringDefines the name of the predefined set of values of the resource. Can't be used together with Resources.
resourceConfiguration.function.resourcesobjectDefines the amount of resources available for the Pod. Can't be used together with Profile. For configuration details, see the official Kubernetes documentation.
runtime (required)stringSpecifies the runtime of the Function. The available values are nodejs16 - deprecated, nodejs18, and python39.
runtimeImageOverridestringSpecifies the runtime image used instead of the default one.
scaleConfigobjectDefines the minimum and maximum number of Function's Pods to run at a time. When it is configured, a HorizontalPodAutoscaler will be deployed and will control the Replicas field to scale the Function based on the CPU utilisation.
scaleConfig.maxReplicas (required)integerDefines the maximum number of Function's Pods to run at a time.
scaleConfig.minReplicas (required)integerDefines the minimum number of Function's Pods to run at a time.
secretMounts[]objectSpecifies Secrets to mount into the Function's container filesystem.
secretMounts.mountPath (required)stringSpecifies the path within the container where the Secret should be mounted.
secretMounts.secretName (required)stringSpecifies the name of the Secret in the Function's Namespace.
source (required)objectContains the Function's source code configuration.
source.gitRepositoryobjectDefines the Function as git-sourced. Can't be used together with Inline.
source.gitRepository.authobjectSpecifies the authentication method. Required for SSH.
source.gitRepository.auth.secretName (required)stringSpecifies the name of the Secret with credentials used by the Function Controller to authenticate to the Git repository in order to fetch the Function's source code and dependencies. This Secret must be stored in the same Namespace as the Function CR.
source.gitRepository.auth.type (required)stringDefines the repository authentication method. The value is either basic if you use a password or token, or key if you use an SSH key.
source.gitRepository.baseDirstringSpecifies the relative path to the Git directory that contains the source code from which the Function is built.
source.gitRepository.referencestringSpecifies either the branch name, tag or commit revision from which the Function Controller automatically fetches the changes in the Function's code and dependencies.
source.gitRepository.url (required)stringSpecifies the URL of the Git repository with the Function's code and dependencies. Depending on whether the repository is public or private and what authentication method is used to access it, the URL must start with the http(s), git, or ssh prefix.
source.inlineobjectDefines the Function as the inline Function. Can't be used together with GitRepository.
source.inline.dependenciesstringSpecifies the Function's dependencies.
source.inline.source (required)stringSpecifies the Function's full source code.
templateobjectDeprecated: Use Labels and Annotations to label and/or annotate Function's Pods.
template.annotationsmap[string]stringDeprecated: Use FunctionSpec.Annotations to annotate Function's Pods.
template.labelsmap[string]stringDeprecated: Use FunctionSpec.Labels to label Function's Pods.

Status:

ParameterTypeDescription
baseDirstringSpecifies the relative path to the Git directory that contains the source code from which the Function is built.
commitstringSpecifies the commit hash used to build the Function.
conditions[]objectSpecifies an array of conditions describing the status of the parser.
conditions.lastTransitionTimestringSpecifies the last time the condition transitioned from one status to another.
conditions.messagestringProvides a human-readable message indicating details about the transition.
conditions.reasonstringSpecifies the reason for the condition's last transition.
conditions.status (required)stringSpecifies the status of the condition. The value is either True, False, or Unknown.
conditions.typestringSpecifies the type of the Function's condition.
podSelectorstringSpecifies the Pod selector used to match Pods in the Function's Deployment.
referencestringSpecifies either the branch name, tag or commit revision from which the Function Controller automatically fetches the changes in the Function's code and dependencies.
replicasintegerSpecifies the total number of non-terminated Pods targeted by this Function.
runtimestringSpecifies the Runtime type of the Function.
runtimeImagestringSpecifies the image version used to build and run the Function's Pods.
runtimeImageOverridestringDeprecated: Specifies the runtime image version which overrides the RuntimeImage status parameter. RuntimeImageOverride exists for historical compatibility and should be removed with v1alpha3 version.

Status reasons

Processing of a Function CR can succeed, continue, or fail for one of these reasons:

ReasonTypeDescription
ConfigMapCreatedConfigurationReadyA new ConfigMap was created based on the Function CR definition.
ConfigMapUpdatedConfigurationReadyThe existing ConfigMap was updated after changes in the Function CR name, its source code or dependencies.
SourceUpdatedConfigurationReadyThe Function Controller managed to fetch changes in the Functions's source code and configuration from the Git repository.
SourceUpdateFailedConfigurationReadyThe Function Controller failed to fetch changes in the Functions's source code and configuration from the Git repository.
JobFailedBuildReadyThe image with the Function's configuration could not be created due to an error.
JobCreatedBuildReadyThe Kubernetes Job resource that builds the Function image was created.
JobUpdatedBuildReadyThe existing Job was updated after changing the Function's metadata or spec fields that do not affect the way of building the Function image, such as labels.
JobRunningBuildReadyThe Job is in progress.
JobsDeletedBuildReadyPrevious Jobs responsible for building Function images were deleted.
JobFinishedBuildReadyThe Job was finished and the Function's image was uploaded to the Docker Registry.
DeploymentCreatedRunningA new Deployment referencing the Function's image was created.
DeploymentUpdatedRunningThe existing Deployment was updated after changing the Function's image, scaling parameters, variables, or labels.
DeploymentFailedRunningThe Function's Pod crashed or could not start due to an error.
DeploymentWaitingRunningThe Function was deployed and is waiting for the Deployment to be ready.
DeploymentReadyRunningThe Function was deployed and is ready.
ServiceCreatedRunningA new Service referencing the Function's Deployment was created.
ServiceUpdatedRunningThe existing Service was updated after applying required changes.
ServiceFailedRunningThe Function's service could not be created or updated.
HorizontalPodAutoscalerCreatedRunningA new Horizontal Pod Scaler referencing the Function's Deployment was created.
HorizontalPodAutoscalerUpdatedRunningThe existing Horizontal Pod Scaler was updated after applying required changes.
MinimumReplicasUnavailableRunningInsufficient number of available Replicas. The Function is unhealthy.

These are the resources related to this CR:

Custom resourceDescription
ConfigMapStores the Function's source code and dependencies.
JobBuilds an image with the Function's code in a runtime.
DeploymentServes the Function's image as a microservice.
ServiceExposes the Function's Deployment as a network service inside the Kubernetes cluster.
HorizontalPodAutoscalerAutomatically scales the number of Function's Pods.

These components use this CR:

ComponentDescription
Function ControllerUses the Function CR for the detailed Function definition, including the environment on which it should run.