Skip to content

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:

bash
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.

yaml
apiVersion: serverless.kyma-project.io/v1alpha2
kind: Function
metadata:
  name: my-test-function
  namespace: default
  labels:
    app: my-test-function
spec:
  runtime: nodejs20
  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;
          }
        }
  resourceConfiguration:
    function:
      resources:
        limits:
          cpu: 1
          memory: 1Gi
        requests:
          cpu: 500m
          memory: 500Mi
  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:

yaml
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: "nodejs20"

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.
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 nodejs20 and python312.
runtimeImageOverridestringSpecifies the runtime image used instead of the default one.
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.

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.
runtimeImageOverridestringSpecifies 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
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.
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
DeploymentServes the Function's image as a microservice.
ServiceExposes the Function's Deployment as a network service inside the Kubernetes cluster.

These components use this CR:

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