Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the error that backendconfig doesn't work when no env specified
Browse files Browse the repository at this point in the history
jiangpengcheng committed Jul 11, 2024
1 parent 56e5bad commit 42766a5
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ spec:
topics:
- persistent://public/default/input-java-topic
typeClassName: java.lang.String
pod:
env:
- name: "podenv"
value: "podvalue"
output:
topic: persistent://public/default/output-java-topic
typeClassName: java.lang.String
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
podenv: backendconfigvalue
pod:
liveness:
initialDelaySeconds: 30
Original file line number Diff line number Diff line change
@@ -48,6 +48,15 @@ if [ $? -ne 0 ]; then
exit 1
fi

# if the function defines the same env, it will use the value from the function instead of the backend config
verify_env_result=$(ci::verify_env "function-sample-env" podenv podenv=podvalue 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 "function-sample-env" global1 global1=globalvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
9 changes: 4 additions & 5 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
@@ -341,10 +341,7 @@ func PatchStatefulSet(ctx context.Context, cli client.Client, namespace string,
}

// merge env
if len(envData) == 0 {
return globalBackendConfigVersion, namespacedBackendConfigVersion, nil
}
globalEnvs := make([]corev1.EnvVar, 0, len(envData))
var globalEnvs []corev1.EnvVar

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

GitHub Actions / unit-tests (1.21.9)

Consider pre-allocating `globalEnvs` (prealloc)

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

GitHub Actions / unit-tests (1.22.4)

Consider pre-allocating `globalEnvs` (prealloc)
for key, val := range envData {
globalEnvs = append(globalEnvs, corev1.EnvVar{
Name: key,
@@ -353,7 +350,9 @@ func PatchStatefulSet(ctx context.Context, cli client.Client, namespace string,
}
for i := range statefulSet.Spec.Template.Spec.Containers {
container := &statefulSet.Spec.Template.Spec.Containers[i]
container.Env = append(container.Env, globalEnvs...)
if globalEnvs != nil {
container.Env = append(globalEnvs, container.Env...)
}

// configs which only work for the workload container
switch container.Name {

0 comments on commit 42766a5

Please sign in to comment.