Function

WARNING: The current API version is serverless.kyma-project.io/v1alpha2. The serverless.kyma-project.io/v1alpha1 version is still supported but deprecated. For the v1alpha1 version, see the previous Function documentation.

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: nodejs16
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: "nodejs16"

Custom resource parameters

This table lists all the possible parameters of a given resource together with their descriptions:

ParameterRequiredDescription
metadata.nameYesSpecifies the name of the CR.
metadata.namespaceNoDefines the Namespace in which the CR is available. It is set to default unless you specify otherwise.
metadata.labelsNoSpecifies the Function's Pod labels.
spec.runtimeYesSpecifies the runtime of the Function. The available values are nodejs16, nodejs16, and python39.
spec.runtimeImageOverrideNoSpecifies the runtimes image which must be used instead of the default one.
spec.sourceYesContains the Function's specification. Only one specification is allowed.
spec.source.inlineNoDefines Function as the inline Function.
spec.source.inline.dependenciesNoSpecifies the Function's dependencies.
spec.source.inline.sourceYesProvides the Function's full source code.
spec.source.gitRepositoryNoDefines Function as git-sourced.
spec.source.gitRepository.urlYesProvides the address to 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.
spec.source.gitRepository.baseDirNoSpecifies the relative path to the Git directory that contains the source code from which the Function is built.
spec.source.gitRepository.referenceNoSpecifies either the branch name, tag or the commit revision from which the Function Controller automatically fetches the changes in the Function's code and dependencies.
spec.source.gitRepository.authNoSpecifies that you must authenticate to the Git repository. Required for SSH.
spec.source.gitRepository.auth.typeYesDefines if you must authenticate to the repository with a password or token (basic), or an SSH key (key). For SSH, this parameter must be set to key.
spec.source.gitRepository.auth.secretNameYesSpecifies 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.
spec.envNoSpecifies 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.
spec.resourceConfigurationNoSpecifies resources requested by Function and build Job.
spec.resourceConfiguration.functionNoSpecifies resources requested by the Function's Pod.
spec.resourceConfiguration.function.profileNoDefines name of predefined set of values of resource. Can't be used at the same time with spec.resourceConfiguration.function.resources.
spec.resourceConfiguration.function.resourcesNoDefines amount of resources available for the Function's Pod to use. Can't be used at the same time with spec.resourceConfiguration.function.profile.
spec.resourceConfiguration.function.resources.limits.cpuNoDefines the maximum number of CPUs available for the Function's Pod to use.
spec.resourceConfiguration.function.resources.limits.memoryNoDefines the maximum amount of memory available for the Function's Pod to use.
spec.resourceConfiguration.function.resources.requests.cpuNoSpecifies the number of CPUs requested by the Function's Pod to operate.
spec.resourceConfiguration.function.resources.requests.memoryNoSpecifies the amount of memory requested by the Function's Pod to operate.
spec.resourceConfiguration.buildNoSpecifies resources requested by the build Job's Pod.
spec.resourceConfiguration.build.profileNoDefines name of predefined set of values of resource. Can't be used at the same time with spec.resourceConfiguration.build.resources.
spec.resourceConfiguration.build.resourcesNoDefines amount of resources available for the build Job's Pod to use. Can't be used at the same time with spec.resourceConfiguration.build.profile.
spec.resourceConfiguration.build.resources.limits.cpuNoDefines the maximum number of CPUs available to use for the Kubernetes Job's Pod responsible for building the Function's image.
spec.resourceConfiguration.build.resources.limits.memoryNoDefines the maximum amount of memory available for the Job's Pod to use.
spec.resourceConfiguration.build.resources.requests.cpuNoSpecifies the number of CPUs requested by the build Job's Pod to operate.
spec.resourceConfiguration.build.resources.requests.memoryNoSpecifies the amount of memory requested by the build Job's Pod to operate.
spec.replicasNoDefines the exact number of Function's Pods to run at a time. If spec.scaleConfig is configured, or if Function is targeted by an external scaler, then the spec.replicas field is used by the relevant HorizontalPodAutoscaler to control the number of active replicas.
spec.scaleConfigNoDefines 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 spec.replicas field to scale Function based on the CPU utilisation.
spec.scaleConfig.minReplicasYesDefines the minimum number of Function's Pods to run at a time.
spec.scaleConfig.maxReplicasYesDefines the maximum number of Function's Pods to run at a time.
spec.secretMountsNoSpecifies Secrets to mount into the Function's container filesystem.
spec.secretMounts.secretNameYesSpecifies name of the Secret in the Function's Namespace to use.
spec.secretMounts.mountPathYesSpecifies path within the container at which the Secret should be mounted.
status.conditions.lastTransitionTimeNot applicableProvides a timestamp for the last time the Function's condition status changed from one to another.
status.conditions.messageNot applicableDescribes a human-readable message on the CR processing progress, success, or failure.
status.conditions.reasonNot applicableProvides information on the Function CR processing success or failure. See the Reasons section for the full list of possible status reasons and their descriptions. All status reasons are in camelCase.
status.conditions.statusNot applicableDescribes the status of processing the Function CR by the Function Controller. It can be True for success, False for failure, or Unknown if the CR processing is still in progress. If the status of all conditions is True, the overall status of the Function CR is ready.
status.conditions.typeNot applicableDescribes a substage of the Function CR processing. There are three condition types that a Function has to meet to be ready: ConfigurationReady, BuildReady, and Running. When displaying the Function status in the terminal, these types are shown under CONFIGURED, BUILT, and RUNNING columns respectively. All condition types can change asynchronously depending on the type of Function modification, but all three need to be in the True status for the Function to be considered successfully processed.

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 (type: git).
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.
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.