Skip to content

Commit

Permalink
Add testcases for nodejs function
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Mar 4, 2024
1 parent 5e4a2c4 commit 9ab2341
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .ci/examples/node-examples/exclamation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
async function process(message, context) {
return message.concat("!");
}
45 changes: 45 additions & 0 deletions .ci/tests/integration/cases/nodejs-function/manifests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: Function
metadata:
name: node-function-excla-generic-sample
namespace: default
spec:
className: exclamation
forwardSourceMessageProperty: true
maxPendingAsyncRequests: 1000
replicas: 1
input:
topics:
- persistent://public/default/node-generic-excla-input
typeClassName: string
output:
topic: persistent://public/default/node-generic-excla-output
typeClassName: string
resources:
requests:
cpu: 500m
memory: 0.5G
limits:
cpu: 500m
memory: 0.5G
pulsar:
pulsarConfig: "test-node-pulsar"
tlsConfig:
enabled: false
allowInsecure: true
hostnameVerification: true
genericRuntime:
functionFile: exclamation.js
functionFileLocation: function://public/default/test-node-function
language: nodejs
logLevel: warn
clusterName: test
autoAck: true
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test-node-pulsar
data:
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
54 changes: 54 additions & 0 deletions .ci/tests/integration/cases/nodejs-function/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

set -e

E2E_DIR=$(dirname "$0")
BASE_DIR=$(cd "${E2E_DIR}"/../../../../..;pwd)
PULSAR_NAMESPACE=${PULSAR_NAMESPACE:-"default"}
PULSAR_RELEASE_NAME=${PULSAR_RELEASE_NAME:-"sn-platform"}
E2E_KUBECONFIG=${E2E_KUBECONFIG:-"/tmp/e2e-k8s.config"}

source "${BASE_DIR}"/.ci/helm.sh

if [ ! "$KUBECONFIG" ]; then
export KUBECONFIG=${E2E_KUBECONFIG}
fi

manifests_file="${BASE_DIR}"/.ci/tests/integration/cases/nodejs-function/manifests.yaml

kubectl apply -f "${manifests_file}" > /dev/null 2>&1

verify_fm_result=$(ci::verify_function_mesh node-function-excla-generic-sample 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_fm_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_node_result=$(NAMESPACE=${PULSAR_NAMESPACE} CLUSTER=${PULSAR_RELEASE_NAME} ci::verify_exclamation_function "persistent://public/default/node-generic-excla-input" "persistent://public/default/node-generic-excla-output" "test-message" "test-message!" 10 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_node_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

echo "e2e-test: ok" | yq eval -
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
3 changes: 3 additions & 0 deletions .ci/tests/integration/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ setup:
bash .ci/upload_function.sh pyzip
bash .ci/upload_function.sh pypip
bash .ci/upload_function.sh go
bash .ci/upload_function.sh node
- name: install function-mesh operator
command: |
Expand Down Expand Up @@ -168,3 +169,5 @@ verify:
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/python-log-format-json/verify.sh
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/nodejs-function/verify.sh
expected: expected.data.yaml
3 changes: 3 additions & 0 deletions .ci/upload_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ case ${1} in
kubectl cp "${PULSAR_HOME}/.ci/examples/go-examples" "${NAMESPACE}/${CLUSTER}-pulsar-broker-0:/pulsar/"
kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-admin packages upload function://public/default/test-go-function --path /pulsar/go-examples/exclamationFunc --description "test golang function"
;;
node)
kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-admin packages upload function://public/default/test-node-function --path /pulsar/examples/node-examples/exclamation.js --description "test nodejs function"
;;
esac
1 change: 1 addition & 0 deletions api/compute/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ type GenericRuntime struct {
// +kubebuilder:validation:Required
Language string `json:"language"`
FunctionFileLocation string `json:"functionFileLocation,omitempty"`
LogLevel string `json:"logLevel,omitempty"`
}

type SecretRef struct {
Expand Down
15 changes: 10 additions & 5 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package spec
import (
"bytes"
"context"

Check failure on line 22 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

File is not `goimports`-ed (goimports)

Check failure on line 22 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

File is not `goimports`-ed (goimports)

// used for template
_ "embed"
"encoding/json"
Expand Down Expand Up @@ -56,7 +55,7 @@ const (
EnvShardID = "SHARD_ID"
FunctionsInstanceClasspath = "pulsar.functions.instance.classpath"
DefaultRunnerTag = "2.10.0.0-rc10"
DefaultGenericRunnerTag = "0.1.0"
DefaultGenericRunnerTag = "latest"
DefaultRunnerPrefix = "streamnative/"
DefaultRunnerImage = DefaultRunnerPrefix + "pulsar-all:" + DefaultRunnerTag
DefaultJavaRunnerImage = DefaultRunnerPrefix + "pulsar-functions-java-runner:" + DefaultRunnerTag
Expand Down Expand Up @@ -394,10 +393,10 @@ func MakeGoFunctionCommand(downloadPath, goExecFilePath string, function *v1alph

func MakeGenericFunctionCommand(downloadPath, functionFile, language, clusterName, details, uid string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
state *v1alpha1.Stateful,
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig) []string {
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig, logLevel string) []string {
processCommand := setShardIDEnvironmentVariableCommand() + " && " +
strings.Join(getProcessGenericRuntimeArgs(language, functionFile, clusterName,
details, uid, authProvided, tlsProvided, secretMaps, state, tlsConfig, authConfig), " ")
details, uid, authProvided, tlsProvided, secretMaps, state, tlsConfig, authConfig, logLevel), " ")
if downloadPath != "" && !utils.EnableInitContainers {
// prepend download command if the downPath is provided
downloadCommand := strings.Join(getDownloadCommand(downloadPath, functionFile, true, true,
Expand Down Expand Up @@ -1194,7 +1193,7 @@ func getProcessPythonRuntimeArgs(name, packageName, clusterName, details, uid st

func getProcessGenericRuntimeArgs(language, functionFile, clusterName, details, uid string, authProvided, tlsProvided bool,
secretMaps map[string]v1alpha1.SecretRef, state *v1alpha1.Stateful, tlsConfig TLSConfig,
authConfig *v1alpha1.AuthConfig) []string {
authConfig *v1alpha1.AuthConfig, logLevel string) []string {

args := []string{
"exec",
Expand All @@ -1210,6 +1209,12 @@ func getProcessGenericRuntimeArgs(language, functionFile, clusterName, details,
secretProviderArgs := getGenericSecretProviderArgs(secretMaps, language)
args = append(args, secretProviderArgs...)
}
if logLevel != "" {
args = append(args, []string{
"--log_level",
logLevel,
}...)
}
if state != nil && state.Pulsar != nil && state.Pulsar.ServiceURL != "" {
statefulArgs := []string{
"--state_storage_serviceurl",
Expand Down
3 changes: 2 additions & 1 deletion controllers/spec/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
spec.GenericRuntime.Language, spec.ClusterName,
generateFunctionDetailsInJSON(function), string(function.UID),
spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "", function.Spec.SecretsMap,
function.Spec.StateConfig, function.Spec.Pulsar.TLSConfig, function.Spec.Pulsar.AuthConfig)
function.Spec.StateConfig, function.Spec.Pulsar.TLSConfig, function.Spec.Pulsar.AuthConfig,
function.Spec.GenericRuntime.LogLevel)
}
}

Expand Down

0 comments on commit 9ab2341

Please sign in to comment.