Skip to content

Commit

Permalink
Fix the error that backendconfig doesn't work when no env specified
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Jul 11, 2024
1 parent 56e5bad commit 42766a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
podenv: backendconfigvalue
pod:
liveness:
initialDelaySeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / unit-tests (1.21.9)

Consider pre-allocating `globalEnvs` (prealloc)

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

View workflow job for this annotation

GitHub Actions / unit-tests (1.22.4)

Consider pre-allocating `globalEnvs` (prealloc)
for key, val := range envData {
globalEnvs = append(globalEnvs, corev1.EnvVar{
Name: key,
Expand All @@ -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 {
Expand Down

0 comments on commit 42766a5

Please sign in to comment.