Skip to content

The Cozystack Kubernetes tests are now POSIX-compatible - #1509

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix/kubernetes-test
Oct 13, 2025
Merged

The Cozystack Kubernetes tests are now POSIX-compatible#1509
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix/kubernetes-test

Conversation

@IvanHunters

@IvanHunters IvanHunters commented Oct 13, 2025

Copy link
Copy Markdown
Collaborator

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.

[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.

What this PR does

Release note

[]

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.

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>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello 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

  • POSIX Compliance: Replaced bash-specific "[[ ... ]]" expressions with POSIX-compliant "case" and "test" constructs in the Kubernetes test script.
  • Test Reliability: Enhanced the reliability of Kubernetes tests by ensuring proper verification of worker node versions and readiness of critical components like CoreDNS, Cilium, ingress-nginx, and vsnap-crd.
  • Shell Compatibility: The tests are now compatible with "/bin/sh", allowing them to run reliably in environments like Bats.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Refactors 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

Cohort / File(s) Summary of Changes
E2E Kubernetes runner script
hack/e2e-apps/run-kubernetes.sh
Switched k8s_version matching from if-patterns to case blocks (outer and inner loops), changed node_ok check to string equality ([ "$node_ok" != true ]), and applied minor whitespace tweaks.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • kvaps
  • lllamnyp
  • klinch0

Poem

I hop through scripts with careful cheer,
Case arms open, patterns clear.
Nodes say “true” or “not today,”
I nibble whitespace on the way.
v1.32, I tip my ear—
Run smooth, dear cluster, never fear. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly states that the Cozystack Kubernetes tests have been made POSIX-compatible, directly reflecting the main change of replacing Bash-specific syntax with POSIX-compliant constructs, and it is clear and concise enough to convey the primary update.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/kubernetes-test

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

@coderabbitai coderabbitai Bot left a comment

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.

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: local is not available in /bin/sh

Dash will error on local. Either drop local or switch the script to Bash. Given the PR goal, drop local.

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 process

No need for bash -c; also ensure we kill the background port-forward to 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: Drop bash -c; use POSIX sh for the wait loop

Keeps 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a19215 and 1a49cbe.

📒 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 check

Using [ "$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: Confirm hr shortname and extend timeout: component names match your HelmRelease templates ({{ .Release.Name }}-cilium|coredns|csi|ingress-nginx|vsnap-crd), but verify kubectl api-resources lists hr. Increase --timeout=1m to 2–5 minutes for initial pulls.


151-153: Verify CRD plural for Kubernetes — couldn’t find a CustomResourceDefinition for kind Kubernetes in the repo; confirm its spec.names.plural matches kuberneteses (apps.cozystack.io) or update the delete command accordingly.

@kvaps Andrei Kvapil (kvaps) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kvaps
Andrei Kvapil (kvaps) merged commit e1e9eef into main Oct 13, 2025
21 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the fix/kubernetes-test branch October 13, 2025 12:59
Andrei Kvapil (kvaps) added a commit that referenced this pull request Oct 13, 2025
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants