Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,20 @@ jq --arg k $expect_k --arg v $expect_v -r '[.Subnets[] | select(any(.Tags[]; .Ke
echo "--------------------------------"

cnt=$(jq --arg k $expect_k --arg v $expect_v -r '[.Subnets[] | select(any(.Tags[]; .Key == $k and .Value == $v))] | length' $out)
expect_cnt=$(echo ${ic_subnets} | wc -w)

# Calculate expected count based on whether Edge Zones are enabled
if [[ ${ENABLE_AWS_EDGE_ZONE:-no} == "yes" ]]; then
# For Edge Zone scenarios, exclude subnets tagged as 'kubernetes.io/cluster/unmanaged:true'
unmanaged_cnt=$(jq -r '[.Subnets[] | select(any(.Tags[]; .Key == "kubernetes.io/cluster/unmanaged" and .Value == "true"))] | length' $out)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Quote variable expansions to prevent word splitting.

Lines 78, 79, and 83 use unquoted variable expansions that could cause word splitting or globbing issues, flagged by Shellcheck SC2086. While unlikely to cause issues in practice (file paths and AWS subnet IDs don't typically contain spaces), quoting is a shell best practice.

🛡️ Proposed fix
-  unmanaged_cnt=$(jq -r '[.Subnets[] | select(any(.Tags[]; .Key == "kubernetes.io/cluster/unmanaged" and .Value == "true"))] | length' $out)
-  total_subnets=$(echo ${ic_subnets} | wc -w)
+  unmanaged_cnt=$(jq -r '[.Subnets[] | select(any(.Tags[]; .Key == "kubernetes.io/cluster/unmanaged" and .Value == "true"))] | length' "$out")
+  total_subnets=$(echo "${ic_subnets}" | wc -w)
   expect_cnt=$((total_subnets - unmanaged_cnt))
   echo "INFO: Edge Zone enabled - total subnets=${total_subnets}, unmanaged subnets=${unmanaged_cnt}, expecting managed subnets=${expect_cnt}"
 else
-  expect_cnt=$(echo ${ic_subnets} | wc -w)
+  expect_cnt=$(echo "${ic_subnets}" | wc -w)
 fi

Also applies to: 79-79, 83-83

🧰 Tools
🪛 Shellcheck (0.11.0)

[info] 78-78: Double quote to prevent globbing and word splitting.

(SC2086)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@ci-operator/step-registry/cucushift/installer/check/aws/custom-vpc/cucushift-installer-check-aws-custom-vpc-commands.sh`
at line 78, The jq invocations use unquoted variable expansions which can cause
word-splitting/globbing (SC2086); update the commands that compute unmanaged_cnt
and the similar expressions on lines 79 and 83 to quote the file/path variable
(e.g., change occurrences of $out to "$out") so the jq arguments are passed as a
single token; locate the three jq calls that reference the shell variable $out
(the one setting unmanaged_cnt and the other two nearby jq uses) and wrap the
expansions in double quotes.

Source: Linters/SAST tools

total_subnets=$(echo ${ic_subnets} | wc -w)
expect_cnt=$((total_subnets - unmanaged_cnt))
echo "INFO: Edge Zone enabled - total subnets=${total_subnets}, unmanaged subnets=${unmanaged_cnt}, expecting managed subnets=${expect_cnt}"
else
expect_cnt=$(echo ${ic_subnets} | wc -w)
fi

if [[ "${cnt}" != "${expect_cnt}" ]]; then
echo "FAIL: check tag $kv_str, found ${cnt}, but expect ${expect_cnt}, please check following subents:"
echo "FAIL: check tag $kv_str, found ${cnt}, but expect ${expect_cnt}, please check following subnets:"
jq --arg k $expect_k --arg v $expect_v -r '[.Subnets[] | select(any(.Tags[]; .Key == $k and .Value == $v) | not) | {subnet: .SubnetId, tags: .Tags}]' $out
ret=$((ret+1))
else
Expand Down