Skip to content

Commit

Permalink
Fix backend config error 0 17 (#771)
Browse files Browse the repository at this point in the history
* Fix the error that backendconfig doesn't work when no env specified

* fix ci

* fix ci
  • Loading branch information
jiangpengcheng authored Jul 12, 2024
1 parent 9b557b8 commit e348e97
Show file tree
Hide file tree
Showing 33 changed files with 757 additions and 137 deletions.
1 change: 1 addition & 0 deletions .ci/clusters/global_backend_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: BackendConfig
metadata:
name: global-backend-config
spec:
autoUpdate: true
env:
global1: globalvalue1
shared1: fromglobal
Expand Down
10 changes: 10 additions & 0 deletions .ci/clusters/global_backend_config_without_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: BackendConfig
metadata:
name: global-backend-config
spec:
autoUpdate: true
pod:
liveness:
initialDelaySeconds: 10
periodSeconds: 30
2 changes: 1 addition & 1 deletion .ci/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ function ci::verify_log_topic_with_auth() {
}

function ci::verify_env() {
pod="$1-function-0"
pod=$1
key=$2
expect=$3
result=$(kubectl exec -n ${NAMESPACE} ${pod} -- env | grep "${key}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: Source
metadata:
name: test-datagen-source
spec:
className: org.apache.pulsar.io.datagenerator.DataGeneratorSource
clusterName: test-pulsar
forwardSourceMessageProperty: true
image: docker.io/streamnative/pulsar-io-data-generator:3.2.2.1
java:
extraDependenciesDir: /pulsar/lib
jar: connectors/pulsar-io-data-generator-3.2.2.1.nar
minReplicas: 1
name: test-datagen-source
namespace: default
output:
producerConf: {}
topic: public/default/test-datagen-source
typeClassName: org.apache.pulsar.io.datagenerator.Person
processingGuarantee: atleast_once
pulsar:
authConfig:
oauth2Config:
audience: urn:sn:pulsar:sndev:test
issuerUrl: https://auth.sncloud-stg.dev/
keySecretName: sn-platform-oauth2-private-key
keySecretKey: auth.json
pulsarConfig: test-source
replicas: 1
resources:
limits:
cpu: "0.2"
memory: 1.1G
requests:
cpu: "0.1"
memory: 1G
sourceConfig:
sleepBetweenMessages: "5000"
tenant: public
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test-source
data:
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: BackendConfig
metadata:
name: backend-config
namespace: default
spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
podenv: backendconfigvalue
pod:
liveness:
initialDelaySeconds: 30
periodSeconds: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/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-oauth2/cases/global-and-namespaced-config-without-auto-update/manifests.yaml
mesh_config_file="${BASE_DIR}"/.ci/tests/integration-oauth2/cases/global-and-namespaced-config-without-auto-update/mesh-config.yaml
global_mesh_config_file="${BASE_DIR}"/.ci/clusters/global_backend_config.yaml

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

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

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" global1 global1=globalvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" namespaced1 namespaced1=namespacedvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# if global and namespaced config has same key, the value from namespace should be used
verify_env_result=$(ci::verify_env "test-datagen-source-source-0" shared1 shared1=fromnamespace 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# verify liveness config
verify_liveness_result=$(ci::verify_liveness_probe test-datagen-source-source-0 '{"failureThreshold":3,"httpGet":{"path":"/","port":9094,"scheme":"HTTP"},"initialDelaySeconds":30,"periodSeconds":10,"successThreshold":1,"timeoutSeconds":10}' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_liveness_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# update the namespaced config, it should not trigger the reconcile since the autoUpdate is false
kubectl patch BackendConfig backend-config --type='json' -p='[{"op": "replace", "path": "/spec/env/shared1", "value": "newvalue"}]' > /dev/null 2>&1
sleep 30

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" shared1 shared1=fromnamespace 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# delete the namespaced config, the source should not be reconciled since the autoUpdate is false
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
sleep 30

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" namespaced1 namespaced1=namespacedvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" shared1 shared1=fromnamespace 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_liveness_result=$(ci::verify_liveness_probe test-datagen-source-source-0 '{"failureThreshold":3,"httpGet":{"path":"/","port":9094,"scheme":"HTTP"},"initialDelaySeconds":30,"periodSeconds":10,"successThreshold":1,"timeoutSeconds":10}' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_liveness_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# delete the global config, the source should be reconciled since the autoUpdate is true in the global config
kubectl delete -f "${global_mesh_config_file}" -n $FUNCTION_MESH_NAMESPACE > /dev/null 2>&1 || true
sleep 30

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

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" global1 "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" namespaced1 "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "test-datagen-source-source-0" shared1 "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# it should use liveness config from namespaced config
verify_liveness_result=$(ci::verify_liveness_probe test-datagen-source-source-0 "" 2>&1)
if [ $? -eq 0 ]; then
echo "e2e-test: ok" | yq eval -
else
echo "$verify_liveness_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: Sink
metadata:
name: test-datagen-sink
spec:
autoAck: true
className: org.apache.pulsar.io.datagenerator.DataGeneratorPrintSink
clusterName: test-pulsar
image: docker.io/streamnative/pulsar-io-data-generator:3.2.2.1
input:
sourceSpecs:
public/default/datagen:
receiverQueueSize: 1000
topics:
- public/default/datagen
typeClassName: org.apache.pulsar.io.datagenerator.Person
java:
extraDependenciesDir: /pulsar/lib
jar: connectors/pulsar-io-data-generator-3.2.2.1.nar
minReplicas: 1
namespace: default
processingGuarantee: atleast_once
sinkConfig: {}
pulsar:
authConfig:
oauth2Config:
audience: urn:sn:pulsar:sndev:test
issuerUrl: https://auth.sncloud-stg.dev/
keySecretName: sn-platform-oauth2-private-key
keySecretKey: auth.json
pulsarConfig: test-sink
replicas: 1
resources:
limits:
cpu: "0.2"
memory: 1.1G
requests:
cpu: "0.1"
memory: 1G
subscriptionName: mysub
subscriptionPosition: latest
tenant: public
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test-sink
data:
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: BackendConfig
metadata:
name: backend-config
namespace: kube-system
spec:
autoUpdate: true
pod:
liveness:
initialDelaySeconds: 50
periodSeconds: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: BackendConfig
metadata:
name: backend-config
namespace: default
spec:
autoUpdate: true
pod:
liveness:
initialDelaySeconds: 30
periodSeconds: 10
Loading

0 comments on commit e348e97

Please sign in to comment.