codeant-ai-for-open-source[bot] commented on code in PR #41396: URL: https://github.com/apache/superset/pull/41396#discussion_r3616799842
########## helm/superset/tests/test-istio.sh: ########## @@ -0,0 +1,177 @@ +#!/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. +# +# Renders the chart with `helm template` for several `init.istio.*` value +# combinations and asserts that the relevant manifests contain (or omit) +# the expected fields. Intended to be run from the chart directory or via +# `bash helm/superset/tests/test-istio.sh` from the repo root. +# +# Covers the fix for: +# https://github.com/apache/superset/issues/25798 +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CHART_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" + +pass=0 +fail=0 + +assert_contains() { + local label="$1" + local needle="$2" + local haystack="$3" + if grep -qF -- "${needle}" <<<"${haystack}"; then + echo " PASS: ${label}" + pass=$((pass + 1)) + else + echo " FAIL: ${label}" + echo " expected to contain: ${needle}" + fail=$((fail + 1)) + fi +} + +assert_not_contains() { + local label="$1" + local needle="$2" + local haystack="$3" + if ! grep -qF -- "${needle}" <<<"${haystack}"; then + echo " PASS: ${label}" + pass=$((pass + 1)) + else + echo " FAIL: ${label}" + echo " expected NOT to contain: ${needle}" + fail=$((fail + 1)) + fi +} + +render() { + helm template release "${CHART_DIR}" "$@" +} + +extract_init_job() { + awk ' + /^# Source: superset\/templates\/init-job\.yaml/ { capture = 1 } + capture && /^---$/ { capture = 0 } + capture { print } + ' <<<"$1" +} + +extract_config_secret() { + awk ' + /^# Source: superset\/templates\/secret-superset-config\.yaml/ { capture = 1 } + capture && /^---$/ { capture = 0 } + capture { print } + ' <<<"$1" +} + +echo "==> defaults: no istio mitigations applied" +out_default="$(render)" +init_job_default="$(extract_init_job "${out_default}")" +config_default="$(extract_config_secret "${out_default}")" +assert_not_contains "default does not set sidecar.istio.io/inject label" \ + 'sidecar.istio.io/inject' "${init_job_default}" +assert_not_contains "default initscript does not register quitquitquit trap" \ + 'quitquitquit' "${config_default}" + +echo "==> init.istio.disableSidecarInjection=true" +out_disable="$(render --set init.istio.disableSidecarInjection=true)" +init_job_disable="$(extract_init_job "${out_disable}")" +config_disable="$(extract_config_secret "${out_disable}")" +assert_contains "init job sets sidecar.istio.io/inject: \"false\"" \ + 'sidecar.istio.io/inject: "false"' "${init_job_disable}" +assert_not_contains "disableSidecarInjection alone does not add quitquitquit trap" \ + 'quitquitquit' "${config_disable}" + +echo "==> init.istio.terminateSidecarOnExit=true" +out_terminate="$(render --set init.istio.terminateSidecarOnExit=true)" +init_job_terminate="$(extract_init_job "${out_terminate}")" +config_terminate="$(extract_config_secret "${out_terminate}")" +assert_not_contains "terminateSidecarOnExit alone does not add inject label" \ + 'sidecar.istio.io/inject' "${init_job_terminate}" +assert_contains "initscript registers EXIT trap that calls quitquitquit" \ + "trap 'rc=\$?; curl -fsS -m 5 -X POST" "${config_terminate}" +assert_contains "initscript trap targets the configured quit endpoint" \ + 'http://localhost:15020/quitquitquit' "${config_terminate}" +assert_contains "initscript trap binds to the EXIT signal" \ + "' EXIT" "${config_terminate}" + +echo "==> init.istio.quitEndpoint override" +out_endpoint="$(render --set init.istio.terminateSidecarOnExit=true \ + --set init.istio.quitEndpoint=http://127.0.0.1:15020/quitquitquit)" +config_endpoint="$(extract_config_secret "${out_endpoint}")" +assert_contains "trap honours custom quitEndpoint" \ + 'http://127.0.0.1:15020/quitquitquit' "${config_endpoint}" + +echo "==> both options combined" +out_both="$(render --set init.istio.disableSidecarInjection=true \ + --set init.istio.terminateSidecarOnExit=true)" +init_job_both="$(extract_init_job "${out_both}")" +config_both="$(extract_config_secret "${out_both}")" +assert_contains "combined: inject label present" \ + 'sidecar.istio.io/inject: "false"' "${init_job_both}" +assert_contains "combined: trap present" \ + 'quitquitquit' "${config_both}" + +echo "==> existing init.podLabels are preserved alongside istio label" +out_labels="$(render --set init.istio.disableSidecarInjection=true \ + --set init.podLabels.team=data-platform)" +init_job_labels="$(extract_init_job "${out_labels}")" +assert_contains "user-supplied podLabel still rendered" \ + 'team: data-platform' "${init_job_labels}" +assert_contains "istio inject label rendered alongside" \ + 'sidecar.istio.io/inject: "false"' "${init_job_labels}" + +echo "==> init.istio explicitly overridden to null" +out_null_istio="$(render --set init.istio=null)" +init_job_null_istio="$(extract_init_job "${out_null_istio}")" +config_null_istio="$(extract_config_secret "${out_null_istio}")" +assert_not_contains "null init.istio does not set inject label" \ + 'sidecar.istio.io/inject' "${init_job_null_istio}" +assert_not_contains "null init.istio does not register quitquitquit trap" \ + 'quitquitquit' "${config_null_istio}" + +echo "==> EXIT trap propagates the script's exit code, not the notification's" +# The trap's own curl call is best-effort (failures are logged with +# `|| echo ... >&2`, not swallowed with `|| true`) and must not mask a +# failed migration. Extract the two rendered lines and actually run them, +# with curl pointed at a closed local port so the notification itself fails, +# to make sure the wrapped script's real exit code still comes through. +quit_endpoint_line="$(grep -F 'ISTIO_QUIT_ENDPOINT=' <<<"${config_terminate}")" +trap_line="$(grep -F "trap 'rc=\$?; curl" <<<"${config_terminate}")" Review Comment: **Suggestion:** This `grep` is also fatal under `set -e`, so if the trap line format changes or is absent the script exits immediately rather than incrementing `fail` and continuing. Handle missing matches explicitly instead of relying on a command substitution that can hard-stop the run. [logic error] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ⚠️ Istio Helm test script can abort mid-run on grep. - ⚠️ EXIT-trap behavior test is skipped on missing line. - ⚠️ CI output loses final test summary diagnostics. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. In helm/superset/tests/test-istio.sh, `set -euo pipefail` at line 25 configures the shell to exit when a simple command fails outside conditional contexts. 2. `config_terminate` is built at lines 100-102 from `render --set init.istio.terminateSidecarOnExit=true` and is expected to contain the EXIT trap line that calls curl, as asserted earlier at lines 103-110. 3. At line 154, the script assigns `trap_line="$(grep -F "trap 'rc=\$?; curl" ...)"`; if the Helm template in superset/templates/secret-superset-config.yaml is refactored so the trap format changes or the line is missing from `config_terminate`, this grep exits with status 1. 4. Because of `set -e`, that non-zero exit status in the command substitution makes helm/superset/tests/test-istio.sh terminate immediately at line 154, preventing the subshell EXIT-code propagation check at lines 155-161 and the final pass/fail summary at lines 173-177 from running. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7767ea461e0242e49909ae3e11f0bffd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7767ea461e0242e49909ae3e11f0bffd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** helm/superset/tests/test-istio.sh **Line:** 154:154 **Comment:** *Logic Error: This `grep` is also fatal under `set -e`, so if the trap line format changes or is absent the script exits immediately rather than incrementing `fail` and continuing. Handle missing matches explicitly instead of relying on a command substitution that can hard-stop the run. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41396&comment_hash=0fe227c0488391ab5c971d14801daec7e8dacdf529e2b8bff76a8f768f08032c&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41396&comment_hash=0fe227c0488391ab5c971d14801daec7e8dacdf529e2b8bff76a8f768f08032c&reaction=dislike'>👎</a> ########## helm/superset/tests/test-istio.sh: ########## @@ -0,0 +1,177 @@ +#!/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. +# +# Renders the chart with `helm template` for several `init.istio.*` value +# combinations and asserts that the relevant manifests contain (or omit) +# the expected fields. Intended to be run from the chart directory or via +# `bash helm/superset/tests/test-istio.sh` from the repo root. +# +# Covers the fix for: +# https://github.com/apache/superset/issues/25798 +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CHART_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" + +pass=0 +fail=0 + +assert_contains() { + local label="$1" + local needle="$2" + local haystack="$3" + if grep -qF -- "${needle}" <<<"${haystack}"; then + echo " PASS: ${label}" + pass=$((pass + 1)) + else + echo " FAIL: ${label}" + echo " expected to contain: ${needle}" + fail=$((fail + 1)) + fi +} + +assert_not_contains() { + local label="$1" + local needle="$2" + local haystack="$3" + if ! grep -qF -- "${needle}" <<<"${haystack}"; then + echo " PASS: ${label}" + pass=$((pass + 1)) + else + echo " FAIL: ${label}" + echo " expected NOT to contain: ${needle}" + fail=$((fail + 1)) + fi +} + +render() { + helm template release "${CHART_DIR}" "$@" +} + +extract_init_job() { + awk ' + /^# Source: superset\/templates\/init-job\.yaml/ { capture = 1 } + capture && /^---$/ { capture = 0 } + capture { print } + ' <<<"$1" +} + +extract_config_secret() { + awk ' + /^# Source: superset\/templates\/secret-superset-config\.yaml/ { capture = 1 } + capture && /^---$/ { capture = 0 } + capture { print } + ' <<<"$1" +} + +echo "==> defaults: no istio mitigations applied" +out_default="$(render)" +init_job_default="$(extract_init_job "${out_default}")" +config_default="$(extract_config_secret "${out_default}")" +assert_not_contains "default does not set sidecar.istio.io/inject label" \ + 'sidecar.istio.io/inject' "${init_job_default}" +assert_not_contains "default initscript does not register quitquitquit trap" \ + 'quitquitquit' "${config_default}" + +echo "==> init.istio.disableSidecarInjection=true" +out_disable="$(render --set init.istio.disableSidecarInjection=true)" +init_job_disable="$(extract_init_job "${out_disable}")" +config_disable="$(extract_config_secret "${out_disable}")" +assert_contains "init job sets sidecar.istio.io/inject: \"false\"" \ + 'sidecar.istio.io/inject: "false"' "${init_job_disable}" +assert_not_contains "disableSidecarInjection alone does not add quitquitquit trap" \ + 'quitquitquit' "${config_disable}" + +echo "==> init.istio.terminateSidecarOnExit=true" +out_terminate="$(render --set init.istio.terminateSidecarOnExit=true)" +init_job_terminate="$(extract_init_job "${out_terminate}")" +config_terminate="$(extract_config_secret "${out_terminate}")" +assert_not_contains "terminateSidecarOnExit alone does not add inject label" \ + 'sidecar.istio.io/inject' "${init_job_terminate}" +assert_contains "initscript registers EXIT trap that calls quitquitquit" \ + "trap 'rc=\$?; curl -fsS -m 5 -X POST" "${config_terminate}" +assert_contains "initscript trap targets the configured quit endpoint" \ + 'http://localhost:15020/quitquitquit' "${config_terminate}" +assert_contains "initscript trap binds to the EXIT signal" \ + "' EXIT" "${config_terminate}" + +echo "==> init.istio.quitEndpoint override" +out_endpoint="$(render --set init.istio.terminateSidecarOnExit=true \ + --set init.istio.quitEndpoint=http://127.0.0.1:15020/quitquitquit)" +config_endpoint="$(extract_config_secret "${out_endpoint}")" +assert_contains "trap honours custom quitEndpoint" \ + 'http://127.0.0.1:15020/quitquitquit' "${config_endpoint}" + +echo "==> both options combined" +out_both="$(render --set init.istio.disableSidecarInjection=true \ + --set init.istio.terminateSidecarOnExit=true)" +init_job_both="$(extract_init_job "${out_both}")" +config_both="$(extract_config_secret "${out_both}")" +assert_contains "combined: inject label present" \ + 'sidecar.istio.io/inject: "false"' "${init_job_both}" +assert_contains "combined: trap present" \ + 'quitquitquit' "${config_both}" + +echo "==> existing init.podLabels are preserved alongside istio label" +out_labels="$(render --set init.istio.disableSidecarInjection=true \ + --set init.podLabels.team=data-platform)" +init_job_labels="$(extract_init_job "${out_labels}")" +assert_contains "user-supplied podLabel still rendered" \ + 'team: data-platform' "${init_job_labels}" +assert_contains "istio inject label rendered alongside" \ + 'sidecar.istio.io/inject: "false"' "${init_job_labels}" + +echo "==> init.istio explicitly overridden to null" +out_null_istio="$(render --set init.istio=null)" +init_job_null_istio="$(extract_init_job "${out_null_istio}")" +config_null_istio="$(extract_config_secret "${out_null_istio}")" +assert_not_contains "null init.istio does not set inject label" \ + 'sidecar.istio.io/inject' "${init_job_null_istio}" +assert_not_contains "null init.istio does not register quitquitquit trap" \ + 'quitquitquit' "${config_null_istio}" + +echo "==> EXIT trap propagates the script's exit code, not the notification's" +# The trap's own curl call is best-effort (failures are logged with +# `|| echo ... >&2`, not swallowed with `|| true`) and must not mask a +# failed migration. Extract the two rendered lines and actually run them, +# with curl pointed at a closed local port so the notification itself fails, +# to make sure the wrapped script's real exit code still comes through. +quit_endpoint_line="$(grep -F 'ISTIO_QUIT_ENDPOINT=' <<<"${config_terminate}")" Review Comment: **Suggestion:** With `set -e` enabled, this bare `grep` inside command substitution will terminate the entire test script immediately when the line is missing, skipping the final pass/fail summary and other checks. Make this extraction non-fatal and assert explicitly so failures are reported through the test counters. [logic error] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ⚠️ Istio Helm tests abort without aggregated pass/fail summary. - ⚠️ Later Istio-related assertions are skipped on grep failure. - ⚠️ Debugging template regressions harder due to abrupt exit. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Open helm/superset/tests/test-istio.sh and note `set -euo pipefail` at line 25, which makes any simple-command failure (outside if/while/||/&& contexts) terminate the script. 2. Observe at lines 100-108 that `config_terminate` is populated from `render --set init.istio.terminateSidecarOnExit=true`, and at 103-110 earlier tests assert the presence of the EXIT trap in this rendered config. 3. At line 153, the script performs `quit_endpoint_line="$(grep -F 'ISTIO_QUIT_ENDPOINT=' ...)"` in a bare command substitution; if the Helm template in superset/templates/secret-superset-config.yaml is later changed so that the `ISTIO_QUIT_ENDPOINT=` line is missing from `config_terminate`, this grep exits with status 1. 4. Under `set -e`, the non-zero status from the command substitution causes the script helm/superset/tests/test-istio.sh to terminate immediately at line 153, so the EXIT-code propagation test (lines 155-171) and the final pass/fail summary (lines 173-177) are never executed or printed. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a0ffcb91cda5445f8e9778c8ffe89ab5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a0ffcb91cda5445f8e9778c8ffe89ab5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** helm/superset/tests/test-istio.sh **Line:** 153:153 **Comment:** *Logic Error: With `set -e` enabled, this bare `grep` inside command substitution will terminate the entire test script immediately when the line is missing, skipping the final pass/fail summary and other checks. Make this extraction non-fatal and assert explicitly so failures are reported through the test counters. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41396&comment_hash=cd043b454213ec38fac5c314617675af74bd95f521cae5d21f7c276962035cc5&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41396&comment_hash=cd043b454213ec38fac5c314617675af74bd95f521cae5d21f7c276962035cc5&reaction=dislike'>👎</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
