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

Function.serverless.kyma-project.io/v1alpha2

Spec:

ParameterTypeDescription
annotationsmap[string]stringAnnotations will be used in Deployment's PodTemplate and will be applied on the function's runtime Pod.
env[]objectEnv specifies 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.
env.name (required)stringName of the environment variable. Must be a C_IDENTIFIER.
env.valuestringVariable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
env.valueFromobjectSource for the environment variable's value. Cannot be used if value is not empty.
env.valueFrom.configMapKeyRefobjectSelects a key of a ConfigMap.
env.valueFrom.configMapKeyRef.key (required)stringThe key to select.
env.valueFrom.configMapKeyRef.namestringName of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
env.valueFrom.configMapKeyRef.optionalbooleanSpecify whether the ConfigMap or its key must be defined
env.valueFrom.fieldRefobjectSelects a field of the pod: supports metadata.name, metadata.namespace, metadata.labels['<KEY>'], metadata.annotations['<KEY>'], spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
env.valueFrom.fieldRef.apiVersionstringVersion of the schema the FieldPath is written in terms of, defaults to "v1".
env.valueFrom.fieldRef.fieldPath (required)stringPath of the field to select in the specified API version.
env.valueFrom.resourceFieldRefobjectSelects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
env.valueFrom.resourceFieldRef.containerNamestringContainer name: required for volumes, optional for env vars
env.valueFrom.resourceFieldRef.divisor{integer or string}Specifies the output format of the exposed resources, defaults to "1"
env.valueFrom.resourceFieldRef.resource (required)stringRequired: resource to select
env.valueFrom.secretKeyRefobjectSelects a key of a secret in the pod's namespace
env.valueFrom.secretKeyRef.key (required)stringThe key of the secret to select from. Must be a valid secret key.
env.valueFrom.secretKeyRef.namestringName of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
env.valueFrom.secretKeyRef.optionalbooleanSpecify whether the Secret or its key must be defined
labelsmap[string]stringLabels will be used in Deployment's PodTemplate and will be applied on the function's runtime Pod.
replicasintegerReplicas defines the exact number of Function's Pods to run at a time. If ScaleConfig is configured, or if Function is targeted by an external scaler, then the Replicas field is used by the relevant HorizontalPodAutoscaler to control the number of active replicas.
resourceConfigurationobjectResourceConfiguration specifies resources requested by Function and build Job.
resourceConfiguration.buildobjectBuild specifies resources requested by the build Job's Pod.
resourceConfiguration.build.profilestringProfile defines name of predefined set of values of resource. Can't be used at the same time with Resources.
resourceConfiguration.build.resourcesobjectResources defines amount of resources available for the Pod to use. Can't be used at the same time with Profile.
resourceConfiguration.build.resources.limitsmap[string]{integer or string}Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
resourceConfiguration.build.resources.requestsmap[string]{integer or string}Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
resourceConfiguration.functionobjectFunction specifies resources requested by the Function's Pod.
resourceConfiguration.function.profilestringProfile defines name of predefined set of values of resource. Can't be used at the same time with Resources.
resourceConfiguration.function.resourcesobjectResources defines amount of resources available for the Pod to use. Can't be used at the same time with Profile.
resourceConfiguration.function.resources.limitsmap[string]{integer or string}Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
resourceConfiguration.function.resources.requestsmap[string]{integer or string}Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
runtime (required)stringRuntime specifies the runtime of the Function. The available values are nodejs16, nodejs18, and python39.
runtimeImageOverridestringRuntimeImageOverride specifies the runtimes image which must be used instead of the default one.
scaleConfigobjectScaleConfig defines 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 Function based on the CPU utilisation.
scaleConfig.maxReplicas (required)integerMaxReplicas defines the maximum number of Function's Pods to run at a time.
scaleConfig.minReplicas (required)integerMinReplicas defines the minimum number of Function's Pods to run at a time.
secretMounts[]objectSecretMounts specifies Secrets to mount into the Function's container filesystem.
secretMounts.mountPath (required)stringMountPath specifies path within the container at which the Secret should be mounted.
secretMounts.secretName (required)stringSecretName specifies name of the Secret in the Function's Namespace to use.
source (required)objectSource contains the Function's specification.
source.gitRepositoryobjectGitRepository defines Function as git-sourced. Can't be used at the same time with Inline.
source.gitRepository.authobjectAuth specifies that you must authenticate to the Git repository. Required for SSH.
source.gitRepository.auth.secretName (required)stringSecretName specifies 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)stringType defines 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.
source.gitRepository.baseDirstringBaseDir specifies the relative path to the Git directory that contains the source code from which the Function is built.
source.gitRepository.referencestringReference specifies 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.
source.gitRepository.url (required)stringURL provides 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.
source.inlineobjectInline defines Function as the inline Function. Can't be used at the same time with GitRepository.
source.inline.dependenciesstringDependencies specifies the Function's dependencies.
source.inline.source (required)stringSource provides the Function's full source code.
templateobjectDeprecated: .spec.Labels and .spec.Annotations should be used to annotate/label function's pods.
template.annotationsmap[string]stringDeprecated: .spec.Annotations should be used to annotate function's pods.
template.labelsmap[string]stringDeprecated: .spec.Labels should be used to label function's pods.

Status:

ParameterTypeDescription
baseDirstringBaseDir specifies the relative path to the Git directory that contains the source code from which the Function is built.
commitstringCommit hash used to build function
conditions[]objectAn array of conditions describing the status of the parser
conditions.lastTransitionTimestringLast time the condition transitioned from one status to another.
conditions.messagestringA human-readable message indicating details about the transition.
conditions.reasonstringThe reason for the condition's last transition.
conditions.status (required)stringStatus of the condition, one of True, False, Unknown.
conditions.typestringType of function condition.
podSelectorstringPod selector used to match pods in function deployment
referencestringReference specifies 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.
replicasintegerTotal number of non-terminated pods targeted by this function
runtimestringRuntime type of function
runtimeImagestringRuntime image version used to build and run function pods
runtimeImageOverridestringDeprecated: RuntimeImageOverride exists for historical compatibility and should be removed with v1alpha3 version. RuntimeImage has the override image if it isn't empty.

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.