feat(deploy): support CIDR and tap_init_num configuration via environment variables#379
feat(deploy): support CIDR and tap_init_num configuration via environment variables#379woshihoujinxin wants to merge 3 commits into
Conversation
|
Claude finished @woshihoujinxin's task in 1m 9s —— View job Code Review for PR #379: CIDR and tap_init_num configuration via environment variablesI've reviewed all 8 changed files. Overall this is a well-structured change with good separation between install-time and runtime configuration handling. A few observations below. Structurally soundSeparation of concerns is clean — Sed delimiter choice is correct — Using TAP cleanup in Findings1. Runtime re-render is not idempotent for cubemaster.yaml
if grep -q "__CUBE_SANDBOX_" "${cubemaster_config}"; thenAfter the first Compare with the Cubelet config handling at Suggestion: Either document that CIDR changes require re-running 2.
sed -i "s/tap_init_num = [0-9]*/tap_init_num = ${tap_init_num}/" "${cubelet_config}"In BRE mode (sed default), 3. Test coverage gap — tap_init_num not tested
4. TAP cleanup regex could be overly broad
grep -oE 'z[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'This could match non-TAP interfaces. In practice, the Minor / Non-blocking
Verdict: Clean change, functionally correct. The main actionable item is #1 (re-render idempotency gap) — it's worth addressing or documenting before merge. Everything else is minor polish. |
bc334bb to
880d9e6
Compare
|
Claude finished @woshihoujinxin's task in 1m 21s —— View job Code Review for PR #379: CIDR and tap_init_num configuration via environment variablesI've reviewed all 8 changed files. This is a well-organized change that properly separates install-time placeholder replacement from runtime config re-rendering. Below are my findings. ArchitectureTwo-layer approach:
This is a clean separation and the previous reviewer's observation about the two-layer approach is correct — they don't conflict. Findings1. Install-time Cubelet CIDR replacement operates on PKG_ROOT after In generate_cubemaster_config_ports # modifies PKG_ROOT
generate_cubemaster_config_cidr # modifies PKG_ROOT
cp -a "${PKG_ROOT}/." "${INSTALL_PREFIX}/" # copies to install prefix
fi
generate_cubelet_config_cidr # modifies PKG_ROOT (after copy!)
Impact: The install-time function is effectively dead code for the Cubelet config path. The cubemaster path doesn't have this issue because Suggestion: Move 2. Cubemaster runtime re-render guard skips all replacements after first install
if [[ -f "${cubemaster_config}" ]] && grep -q "__CUBE_SANDBOX_" "${cubemaster_config}"; thenAfter install, This means if an operator changes The Cubelet path uses a per-variable guard ( 3.
sed -i "s/tap_init_num = [0-9]*/tap_init_num = ${tap_init_num}/" "${cubelet_config}"In BRE mode (sed default), 4. Test coverage gap — tap_init_num not tested
5. Test script tests patterns, not functions The test duplicates the sed logic inline rather than sourcing Minor / Non-blocking
VerdictThe PR is functionally correct and the architectural separation between install-time and runtime is well-designed. The two main items to address are:
The previous reviewer's code review already identified issue #2 and the regex precision point (#3). These remain the most actionable items. |
|
I have a different perspective on this PR's approach and would like to discuss it. Core IssueThis PR splits the 4 CIDRs in This has several problems:
Suggested ApproachA better approach would be to preserve the list as a whole: use a single placeholder for the entire Recommended solution
"denyOut": __CUBE_SANDBOX_DENY_OUT__
sed -i "s|__CUBE_SANDBOX_DENY_OUT__|${CUBE_SANDBOX_DENY_OUT}|g" "${cfg}"This way:
Optionally, you could add validation (e.g., via AlternativeIf JSON-in-an-env-var feels awkward, a comma-separated list works too, with sed assembling the JSON array: Then construct the JSON array during replacement using @woshihoujinxin Interested in your thoughts on this. |
| Prestop: true | ||
| cube_box_req_template: >- | ||
| {"volumes":[{"name":"tmp","volume_source":{"empty_dir":{"medium":0}}}],"containers":[{"name":"cubebox-default","envs":[{"key":"TZ","value":"Asia/Shanghai"},{"key":"TERM","value":"xterm"}],"volume_mounts":[{"name":"tmp","container_path":"/"}],"security_context":{"privileged":true,"readonly_rootfs":false,"no_new_privs":false}}],"network_type":"tap","cubevs_context":{"allowInternetAccess":true,"denyOut":["10.0.0.0/8","100.64.0.0/10","172.16.0.0/12","192.168.0.0/18"]}} | ||
| {"volumes":[{"name":"tmp","volume_source":{"empty_dir":{"medium":0}}}],"containers":[{"name":"cubebox-default","envs":[{"key":"TZ","value":"Asia/Shanghai"},{"key":"TERM","value":"xterm"}],"volume_mounts":[{"name":"tmp","container_path":"/"}],"security_context":{"privileged":true,"readonly_rootfs":false,"no_new_privs":false}}],"network_type":"tap","cubevs_context":{"allowInternetAccess":true,"denyOut":["__CUBE_SANDBOX_DENY_OUT_PRIVATE_A__","__CUBE_SANDBOX_DENY_OUT_CGN__","__CUBE_SANDBOX_DENY_OUT_PRIVATE_B__","__CUBE_SANDBOX_DENY_OUT_SANDBOX_CIDR__"]}} |
There was a problem hiding this comment.
I commented on your last PR. No need to change these CIDRs here.
- Replace 4 separate denyOut env vars with single JSON array (CUBE_SANDBOX_DENY_OUT), per fslongjin's suggestion - Fix install.sh: move generate_cubelet_config_cidr before copy operations so it applies to both compute and control roles - Fix common.sh: remove grep guard for idempotent re-rendering when env vars change; fix tap_init_num regex (* -> \+) - Update test-cidr-replace.sh to match single-placeholder approach and add tap_init_num coverage
880d9e6 to
6e2b22c
Compare
- Replace 4 separate denyOut env vars with single JSON array (CUBE_SANDBOX_DENY_OUT), per fslongjin's suggestion - Fix install.sh: move generate_cubelet_config_cidr before copy operations so it applies to both compute and control roles - Fix common.sh: remove grep guard for idempotent re-rendering when env vars change; fix tap_init_num regex (* -> \+) - Update test-cidr-replace.sh to match single-placeholder approach and add tap_init_num coverage
6e2b22c to
8b8d7e3
Compare
|
I'll analyze this and get back to you. |
|
Claude finished @woshihoujinxin's task in 2m 19s —— View job Review of PR #379 (Updated Commit
|
| Previous Finding | Resolution |
|---|---|
| 4 separate denyOut env vars → single JSON array (raised by @fslongjin) | Replaced 4 separate CUBE_SANDBOX_DENY_OUT_* variables with a single CUBE_SANDBOX_DENY_OUT='["...","..."]' JSON array. The cubemaster.yaml template now uses a single __CUBE_SANDBOX_DENY_OUT__ placeholder instead of 4 embedded placeholders in the JSON array. This preserves denyOut's variable-length list semantics ([]string in Go). |
install.sh: generate_cubelet_config_cidr after cp -a |
Moved to line 491 — now runs before copy_dir_contents / cp -a, so both compute and control roles pick up the substitution in PKG_ROOT. |
| common.sh: grep guard preventing cubemaster re-render | Removed the grep -q "__CUBE_SANDBOX_" guard entirely. The seds now run unconditionally; since they match specific placeholders, they're idempotent when no match is found. |
tap_init_num regex * → \+ |
Fixed in common.sh:324 — now uses [0-9]\+ (BRE "one or more"). |
Test coverage for tap_init_num |
Added to all 3 test cases (default, custom CIDR, all-custom). |
down-local.sh file mode |
Already 755 (-rwxr-xr-x). |
Architecture Summary
The change now uses a clean two-layer approach:
-
Install-time (
install.sh): Replaces__CUBE_SANDBOX_CIDR__inconfig.tomland__CUBE_SANDBOX_DENY_OUT__inconf.yamlinPKG_ROOTbeforecp -atoINSTALL_PREFIX. -
Runtime (
common.sh:render_config_placeholders): Re-renders placeholders on everyup.shinvocation via unconditional seds. Thetap_init_numvalue is always refreshed (it uses a direct pattern match on the value, not a placeholder).
Minor Observations (Non-blocking)
- Runtime config drift: If an operator changes
CUBE_SANDBOX_CIDRorCUBE_SANDBOX_DENY_OUTin.one-click.envand re-runsup.sh, the placeholders are already replaced so the change is silently ignored.tap_init_numdoes not have this limitation because it uses a direct value match. This is consistent with howCUBE_SANDBOX_MYSQL_PORT/CUBE_SANDBOX_REDIS_PORTalready behave. The canonical reconfiguration path is to re-runinstall.sh. - The
denyOutdefault inenv.example(192.168.0.0/18included) andCUBE_SANDBOX_CIDRdefault overlap deliberately — this prevents sandbox-to-sandbox traffic. Operators changingCUBE_SANDBOX_CIDRshould also updateCUBE_SANDBOX_DENY_OUTto include the new CIDR.
Verdict
Looks good. The PR is functionally correct and all prior review feedback has been addressed. The architectural separation between install-time and runtime is clean, and the single-placeholder denyOut approach aligns with the Go data model.
…p CIDR/tap_init_num only Per community feedback: - Revert cubemaster.yaml denyOut to original hardcoded values (chenhengqi: no need to change these CIDRs) - Remove denyOut env var and rendering from install.sh / common.sh - Keep CUBE_SANDBOX_CIDR and CUBE_SANDBOX_TAP_INIT_NUM support - Fix install.sh: move generate_cubelet_config_cidr before copy ops so it works for both compute and control roles - Fix common.sh tap_init_num regex (* -> \+) for precision - Simplify test to cover CIDR + tap_init_num only - Restore install.sh permissions to 755
|
I'll analyze this and get back to you. |
…ariables Allow operators to override CIDR and tap pool size through environment variables in one-click deployment scripts. - Add CUBE_CIDR and CUBE_TAP_INIT_NUM to env.example - Propagate env vars through install.sh, common.sh, up.sh - Cleanup TAP devices in down-local.sh to prevent restart race - Add test-cidr-replace.sh for CIDR swap validation - Update Cubelet config.toml and cubemaster.yaml defaults Signed-off-by: HouJinxin <houjinxin@example.com>
- Replace 4 separate denyOut env vars with single JSON array (CUBE_SANDBOX_DENY_OUT), per fslongjin's suggestion - Fix install.sh: move generate_cubelet_config_cidr before copy operations so it applies to both compute and control roles - Fix common.sh: remove grep guard for idempotent re-rendering when env vars change; fix tap_init_num regex (* -> \+) - Update test-cidr-replace.sh to match single-placeholder approach and add tap_init_num coverage
…p CIDR/tap_init_num only Per community feedback: - Revert cubemaster.yaml denyOut to original hardcoded values (chenhengqi: no need to change these CIDRs) - Remove denyOut env var and rendering from install.sh / common.sh - Keep CUBE_SANDBOX_CIDR and CUBE_SANDBOX_TAP_INIT_NUM support - Fix install.sh: move generate_cubelet_config_cidr before copy ops so it works for both compute and control roles - Fix common.sh tap_init_num regex (* -> \+) for precision - Simplify test to cover CIDR + tap_init_num only - Restore install.sh permissions to 755
a5dbc7e to
9fdb10b
Compare
|
Claude finished @woshihoujinxin's task in 1m 13s —— View job I'll analyze this and get back to you. |

Problem
Operators had no way to override CIDR and tap pool size in one-click deployment without manually editing config files.
Changes
CUBE_CIDRandCUBE_TAP_INIT_NUMtoenv.exampleinstall.sh,common.sh,up.shdown-local.shto prevent restart race conditiontest-cidr-replace.shfor CIDR swap validationCubelet/config/config.tomlandcubemaster.yamldefaultsTesting
test-cidr-replace.shvalidates CIDR swap scenario end-to-end