Function Entrypoints

There are several methods to access a sync function. Let’s elaborate on this in the following section.

This documentation will assume you are using default OpenFunction Gateway and you have a sync function named function-sample.

Access functions from within the cluster

Access functions by the internal address

OpenFunction will create this service for every sync Function: {{.Name}}.{{.Namespace}}.svc.cluster.local. This service will be used to provide the Function internal address.

Get Function internal address by running following command:

  1. export FUNC_INTERNAL_ADDRESS=$(kubectl get function function-sample -o=jsonpath='{.status.addresses[?(@.type=="Internal")].value}')

This address provides the default method for accessing functions within the cluster, it’s suitable for use as sink.url of EventSource.

Access Function using curl in pod:

  1. kubectl run --rm ofn-test -i --tty --image=radial/busyboxplus:curl -- curl -sv $FUNC_INTERNAL_ADDRESS

Access functions from outside the cluster

Access functions by the Kubernetes Gateway’s IP address

Get Kubernetes Gateway’s ip address:

  1. export IP=$(kubectl get node -l "! node.kubernetes.io/exclude-from-external-load-balancers" -o=jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')

Get Function’s HOST and PATH:

  1. export FUNC_HOST=$(kubectl get function function-sample -o=jsonpath='{.status.route.hosts[0]}')
  2. export FUNC_PATH=$(kubectl get function function-sample -o=jsonpath='{.status.route.paths[0].value}')

Access Function using curl directly:

  1. curl -sv -HHOST:$FUNC_HOST http://$IP$FUNC_PATH

Access functions by the external address

To access a sync function by the external address, you’ll need to configure DNS first. Either Magic DNS or real DNS works:

  • Magic DNS

    Get Kubernetes Gateway’s ip address:

    1. export IP=$(kubectl get node -l "! node.kubernetes.io/exclude-from-external-load-balancers" -o=jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')

    Replace domain defined in OpenFunction Gateway with Magic DNS:

    1. export DOMAIN="$IP.sslip.io"
    2. kubectl patch gateway.networking.openfunction.io/openfunction -n openfunction --type merge --patch '{"spec": {"domain": "'$DOMAIN'"}}'

    Then, you can see Function external address in Function’s status field:

    1. kubectl get function function-sample -oyaml
    1. status:
    2. addresses:
    3. - type: External
    4. value: http://function-sample.default.172.31.73.53.sslip.io/
    5. - type: Internal
    6. value: http://function-sample.default.svc.cluster.local/
    7. build:
    8. resourceHash: "14903236521345556383"
    9. state: Skipped
    10. route:
    11. conditions:
    12. - lastTransitionTime: "2022-08-20T11:03:14Z"
    13. message: Valid HTTPRoute
    14. observedGeneration: 13
    15. reason: Valid
    16. status: "True"
    17. type: Accepted
    18. hosts:
    19. - function-sample.default.172.31.73.53.sslip.io
    20. - function-sample.default.svc.cluster.local
    21. paths:
    22. - type: PathPrefix
    23. value: /
    24. serving:
    25. lastSuccessfulResourceRef: serving-t56fq
    26. resourceHash: "2638289828407595605"
    27. resourceRef: serving-t56fq
    28. service: serving-t56fq-ksvc-bv8ng
    29. state: Running
  • Real DNS

    If you have an external IP address, you can configure a wildcard A record as your domain:

    1. # Here example.com is the domain defined in OpenFunction Gateway
    2. *.example.com == A <external-ip>

    If you have a CNAME, you can configure a CNAME record as your domain:

    1. # Here example.com is the domain defined in OpenFunction Gateway
    2. *.example.com == CNAME <external-name>

    Replace domain defined in OpenFunction Gateway with the domain you configured above:

    1. export DOMAIN="example.com"
    2. kubectl patch gateway.networking.openfunction.io/openfunction -n openfunction --type merge --patch '{"spec": {"domain": "'$DOMAIN'"}}'

    Then, you can see Function external address in Function’s status field:

    1. kubectl get function function-sample -oyaml
    1. status:
    2. addresses:
    3. - type: External
    4. value: http://function-sample.default.example.com/
    5. - type: Internal
    6. value: http://function-sample.default.svc.cluster.local/
    7. build:
    8. resourceHash: "14903236521345556383"
    9. state: Skipped
    10. route:
    11. conditions:
    12. - lastTransitionTime: "2022-08-20T13:07:17Z"
    13. message: Valid HTTPRoute
    14. observedGeneration: 14
    15. reason: Valid
    16. status: "True"
    17. type: Accepted
    18. hosts:
    19. - function-sample.default.example.com
    20. - function-sample.default.svc.cluster.local
    21. paths:
    22. - type: PathPrefix
    23. value: /
    24. serving:
    25. lastSuccessfulResourceRef: serving-t56fq
    26. resourceHash: "2638289828407595605"
    27. resourceRef: serving-t56fq
    28. service: serving-t56fq-ksvc-bv8ng
    29. state: Running

Then, you can get Function external address by running following command:

  1. export FUNC_EXTERNAL_ADDRESS=$(kubectl get function function-sample -o=jsonpath='{.status.addresses[?(@.type=="External")].value}')

Now, you can access Function using curl directly:

  1. curl -sv $FUNC_EXTERNAL_ADDRESS