The Cozystack Kubernetes tests are now POSIX-compatible - #1509
Conversation
This patch replaces bash-specific [[ ... ]] expressions in the run_kubernetes_test function with POSIX-compliant case and test constructs. It ensures that the Kubernetes version on each worker node is verified correctly and that required components (CoreDNS, Cilium, ingress-nginx, vsnap-crd) are ready before proceeding. Now the tests work reliably even when executed with /bin/sh, such as in Bats. ```release-note [tests] Make Kubernetes tests POSIX-compliant and more reliable: verify worker node versions and ensure required releases (CoreDNS, Cilium, ingress-nginx, vsnap-crd) are installed and ready. ``` Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Summary of ChangesHello IvanHunters, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the robustness and portability of the Cozystack Kubernetes end-to-end tests. By refactoring shell script logic to adhere to POSIX standards, the tests can now execute consistently across various shell environments, preventing potential failures due to bash-specific syntax. This change also solidifies the pre-test checks, ensuring that the Kubernetes cluster and its essential components are in a ready state before test execution. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughRefactors version matching in hack/e2e-apps/run-kubernetes.sh from pattern-based if to case statements, adjusts the node readiness check to a string comparison against "true", adds explicit handling for v1.32 variants in inner loops, and makes minor whitespace-only edits. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant S as run-kubernetes.sh
participant VM as Version Matcher (case)
participant NC as Node Readiness Check
U->>S: Execute script
S->>VM: Match k8s_version
alt v1.32* branch
VM-->>S: Handle v1.32 variants
else other versions
VM-->>S: Default handling
end
S->>NC: Evaluate node_ok
alt node_ok != true
NC-->>S: Treat as not ready
S-->>U: Handle not-ready path
else node_ok == true
NC-->>S: Proceed
S-->>U: Continue workflow
end
note over VM,NC: Case-based version logic replaces pattern if<br/>Node readiness uses string comparison
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request successfully improves the POSIX compatibility of the Kubernetes test script. The replacement of the bash-specific [[ ... ]] expression with a case statement and the refactoring of a conditional to use the test command are both correct and enhance the script's portability. The changes align well with the stated goal of ensuring the tests can run reliably with /bin/sh. Overall, this is a good improvement. For future consideration, to fully achieve POSIX compliance, you might want to review the remaining bash -c calls in the script and replace them with sh -c where the executed commands are POSIX-compatible.
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
hack/e2e-apps/run-kubernetes.sh (1)
2-4: Breaks POSIX:localis not available in /bin/shDash will error on
local. Either droplocalor switch the script to Bash. Given the PR goal, droplocal.Apply this diff:
- local version_expr="$1" - local test_name="$2" - local port="$3" + version_expr="$1" + test_name="$2" + port="$3"
🧹 Nitpick comments (3)
hack/e2e-apps/run-kubernetes.sh (3)
89-93: Avoid Bash dependency and clean up port-forward processNo need for
bash -c; also ensure we kill the backgroundport-forwardto avoid leaks/port conflicts.Apply this diff:
- # Set up port forwarding to the Kubernetes API server for a 200 second timeout - bash -c 'timeout 200s kubectl port-forward service/kubernetes-'"${test_name}"' -n tenant-test '"${port}"':6443 > /dev/null 2>&1 &' + # Set up port forwarding to the Kubernetes API server for 200s and ensure cleanup + timeout 200s kubectl port-forward "service/kubernetes-${test_name}" -n tenant-test "${port}":6443 > /dev/null 2>&1 & + pf_pid=$! + trap 'kill "$pf_pid" 2>/dev/null || true' EXIT INT TERM
95-99: Dropbash -c; use POSIX sh for the wait loopKeeps the test runnable under /bin/sh.
- timeout 2m bash -c ' + timeout 2m sh -ec ' until [ "$(kubectl --kubeconfig tenantkubeconfig get nodes -o jsonpath="{.items[*].metadata.name}" | wc -w)" -eq 2 ]; do sleep 3 done '
108-112: Remove noisy TODO echo (logic handled below)This case block is a no-op besides logging; it clutters CI output.
- case "$k8s_version" in - v1.32*) - echo "⚠️ TODO: Temporary stub — allowing nodes with v1.33 while k8s_version is v1.32" - ;; - esac
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
hack/e2e-apps/run-kubernetes.sh(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (7)
hack/e2e-apps/run-kubernetes.sh (7)
139-142: LGTM: POSIX-safe boolean checkUsing
[ "$node_ok" != true ]removes Bash-ism. Looks good.
67-67: No functional change (whitespace). Skipping.
73-73: No functional change (whitespace). Skipping.
76-76: No functional change (whitespace). Skipping.
79-79: No functional change (whitespace). Skipping.
147-149: Confirmhrshortname and extend timeout: component names match your HelmRelease templates ({{ .Release.Name }}-cilium|coredns|csi|ingress-nginx|vsnap-crd), but verifykubectl api-resourceslistshr. Increase--timeout=1mto 2–5 minutes for initial pulls.
151-153: Verify CRD plural for Kubernetes — couldn’t find a CustomResourceDefinition for kindKubernetesin the repo; confirm itsspec.names.pluralmatcheskuberneteses(apps.cozystack.io) or update the delete command accordingly.
This patch replaces bash-specific [[ ... ]] expressions in the run_kubernetes_test function with POSIX-compliant case and test constructs. It ensures that the Kubernetes version on each worker node is verified correctly and that required components (CoreDNS, Cilium, ingress-nginx, vsnap-crd) are ready before proceeding. Now the tests work reliably even when executed with /bin/sh, such as in Bats. ```release-note [tests] Make Kubernetes tests POSIX-compliant and more reliable: verify worker node versions and ensure required releases (CoreDNS, Cilium, ingress-nginx, vsnap-crd) are installed and ready. ``` <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [] ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved Kubernetes version detection to correctly handle 1.32 variants. * Made node readiness checks more reliable to reduce false failures during runs. * **Refactor** * Streamlined version matching logic for clearer, more predictable behavior across releases. * **Style** * Minor formatting cleanups with no functional impact. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This patch replaces bash-specific [[ ... ]] expressions in the run_kubernetes_test function with POSIX-compliant case and test constructs. It ensures that the Kubernetes version on each worker node is verified correctly and that required components (CoreDNS, Cilium, ingress-nginx, vsnap-crd) are ready before proceeding. Now the tests work reliably even when executed with /bin/sh, such as in Bats.
What this PR does
Release note
Summary by CodeRabbit
Bug Fixes
Refactor
Style