Skip to content

add crc cluster install/delete role and gitaction#44

Merged
github-actions[bot] merged 6 commits intomainfrom
crc_install
Jun 17, 2025
Merged

add crc cluster install/delete role and gitaction#44
github-actions[bot] merged 6 commits intomainfrom
crc_install

Conversation

@Jooho
Copy link
Owner

@Jooho Jooho commented Jun 5, 2025

Summary by CodeRabbit

  • New Features

    • Added support for installing and uninstalling OpenShift Local (CRC) clusters, including new configuration options and automated scripts.
    • Introduced end-to-end tests for OpenShift Local cluster lifecycle operations with customizable resource settings.
  • Enhancements

    • Specialized cluster lifecycle test workflows for KIND and prepared for OpenShift Local.
    • Improved configuration flexibility for cluster lifecycle tests and resource allocation.
    • Updated Makefile for more flexible test execution and argument handling.
    • Added new pytest markers for clearer test categorization.
  • Bug Fixes

    • Corrected environment variable assignment for error handling configuration.
  • Style

    • Improved code formatting and readability in scripts and test files.
  • Chores

    • Updated VSCode launch configuration to focus on Python debugging.
    • Removed unused debug log configuration from settings.

Signed-off-by: Jooho Lee <jlee@redhat.com>
@gitguardian
Copy link

gitguardian bot commented Jun 5, 2025

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
17671777 Triggered Generic Password 372801e tests/e2e/cluster-lifecycle/crc_install_delete/conftest.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@coderabbitai
Copy link

coderabbitai bot commented Jun 5, 2025

Walkthrough

This update introduces new roles, scripts, configurations, and end-to-end tests for managing the lifecycle of OpenShift Local (CRC) clusters, alongside enhancements and refinements for KIND cluster workflows. It adds flexible Makefile options, specialized test markers, and improved environment handling, while also updating VSCode debugging settings and internal script logic.

Changes

Files/Paths Change Summary
.github/workflows/e2e-cluster-lifecycle.yml Renamed and specialized KIND cluster lifecycle workflow; added (commented) workflow for OpenShift Local.
.vscode/launch.json Replaced Go debugging config with Python debug/attach configs.
Makefile Added PYTEST_ARGS, made variable quoting consistent, improved e2e-cluster-lifecycle flexibility.
config.yaml Removed show_debug_log config key.
hacks/download-cli.sh Added CRC CLI installation logic; improved KIND install logic.
pytest.ini Renamed marker; added kind and openshift_local markers.
src/cli/logics/component.py Ensured all exported environment variables are strings.
src/commons/python/py_utils.py, tests/e2e/commons/cluster-tests/test_py_utils_e2e.py Reformatted long lines, assertions, and function signatures for readability.
src/commons/scripts/utils.sh Changed debug log logic to use is_positive function.
src/core/initializer.py Fixed environment variable assignments; removed unused debug log config.
src/roles/clusters/kind/install/config.yaml, src/roles/clusters/kind/install/main.sh Added required CLUSTER_TYPE param; updated script to export it and use new error handler.
src/roles/clusters/openshift/crc/crc-install/config.yaml, src/roles/clusters/openshift/crc/crc-install/main.sh Added new role and script for CRC cluster installation and setup.
src/roles/clusters/openshift/crc/crc-uninstall/config.yaml, src/roles/clusters/openshift/crc/crc-uninstall/main.sh Added new role and script for CRC cluster uninstallation and cleanup.
tests/e2e/cluster-lifecycle/crc_install_delete/conftest.py, tests/e2e/cluster-lifecycle/crc_install_delete/test_crc.py Added fixtures and E2E tests for CRC cluster lifecycle (install, stop, delete, cleanup, custom config).
tests/e2e/cluster-lifecycle/kind_install_delete/test_kind.py Added kind marker to KIND cluster lifecycle tests; minor formatting.

Sequence Diagram(s)

sequenceDiagram
    participant Tester
    participant LoopyCLI
    participant CRCInstallRole
    participant CRCUninstallRole
    participant CRC_CLI
    participant OpenShiftCluster

    Tester->>LoopyCLI: Run install role (crc-install)
    LoopyCLI->>CRCInstallRole: Execute main.sh with env vars
    CRCInstallRole->>CRC_CLI: Check status/setup/start cluster
    CRC_CLI->>OpenShiftCluster: Start/initialize cluster
    CRCInstallRole->>LoopyCLI: Export cluster info to env file

    Tester->>LoopyCLI: Run uninstall role (crc-uninstall)
    LoopyCLI->>CRCUninstallRole: Execute main.sh with env vars
    CRCUninstallRole->>CRC_CLI: Stop/delete/cleanup cluster
    CRC_CLI->>OpenShiftCluster: Stop/delete cluster resources
    CRCUninstallRole->>LoopyCLI: Report operation result
Loading

Possibly related PRs

  • Jooho/loopy#42: Introduces and modifies KIND cluster lifecycle testing roles and workflows, directly connected at the code level.
  • Jooho/loopy#26: Involves codebase restructuring, modularization, and configuration handling, related to the architectural improvements in this PR.

Suggested labels

lgtm

Suggested reviewers

  • github-actions

Poem

In clusters where the rabbits play,
New scripts and roles now lead the way.
KIND and CRC, both in line,
With tests and configs, oh so fine!
Hopping through YAML, bash, and code,
This bunny’s proud of what’s bestowed.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Jooho added 5 commits June 5, 2025 17:51
Signed-off-by: Jooho Lee <jlee@redhat.com>
Signed-off-by: Jooho Lee <jlee@redhat.com>
Signed-off-by: Jooho Lee <jlee@redhat.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🔭 Outside diff range comments (1)
src/roles/clusters/kind/install/main.sh (1)

101-112: Write CLUSTER_TYPE only on success to avoid misleading downstream roles

When result != 0 we intentionally skip writing KUBECONFIG_PATH, yet we still
append CLUSTER_TYPE=kind.
That creates an output file even for failed installs, signalling to subsequent
roles that a cluster exists.

- fi
- echo "CLUSTER_TYPE=kind" >> ${OUTPUT_ENV_FILE}
+    echo "CLUSTER_TYPE=kind" >> ${OUTPUT_ENV_FILE}
+fi

This keeps the semantics: no output file unless the role succeeds.

🧹 Nitpick comments (22)
src/roles/clusters/kind/install/config.yaml (1)

62-64: Terminate file with a newline to satisfy YAML linting

yaml-lint is flagging “no new line character at the end of file”.
Add a trailing newline after line 64 to keep tooling quiet and avoid CI noise.

-    required: true
\ No newline at end of file
+    required: true
+
tests/e2e/cluster-lifecycle/kind_install_delete/test_kind.py (1)

55-57: Minor: keep command array on one line for brevity

The line break isn’t harmful, but you can keep the list compact without
exceeding 120 chars to improve readability.

src/commons/scripts/utils.sh (1)

53-54: Quote variable in command substitution

is_positive consumes its argument as a single word; wrap the variable in
quotes to avoid word-splitting or globbing when SHOW_DEBUG_LOG is unset or
contains spaces.

-if [[ $(is_positive $SHOW_DEBUG_LOG) == "0" ]]; then
+if [[ $(is_positive "$SHOW_DEBUG_LOG") == "0" ]]; then
pytest.ini (1)

30-37: Marker additions are clear but please document them

The new cluster_lifecycle_tests, kind, and openshift_local markers look fine; however, the repo’s CONTRIBUTING/README still only lists the older markers. A quick doc touch-up will save future confusion.

tests/e2e/commons/cluster-tests/test_py_utils_e2e.py (2)

212-214: Prefer boolean truthiness over identity checks

assert retry(...) is False / is True relies on the function returning the literal singleton True/False; if it ever starts returning any truthy/falsy value (e.g. 0/1 or a subclass of bool) these tests will fail for the wrong reason.

Minimal change:

-assert retry(...) is False
+assert not retry(...)

Same for the is True variants.

Also applies to: 244-251, 278-286


297-298: Minor: failure message can be tightened

pytest.fail(f"Cluster command failed: {e.stderr.decode() if e.stderr else str(e)}") is ok, but e.stderr.decode(errors="replace") guards against non-UTF8 bytes. Not blocking.

hacks/download-cli.sh (1)

182-192: crc install path handling is brittle

tar -xJ produces a versioned directory (crc-linux-<ver>-amd64).
If two different versions exist in /tmp/loopy_temp, the wildcard in

chmod +x crc-linux-*/crc
mv crc-linux-*/crc "${root_directory}/bin/crc"

may expand to two matches and the script aborts. Consider capturing the directory name once:

-curl -L … | tar -xJ
-
-chmod +x crc-linux-*/crc
-mv crc-linux-*/crc "${root_directory}/bin/crc"
-rm -rf "crc-linux-*"
+tmp_dir=$(mktemp -d)
+curl -L … -o "$tmp_dir/crc.tar.xz"
+tar -xJf "$tmp_dir/crc.tar.xz" -C "$tmp_dir"
+crc_path=$(find "$tmp_dir" -type f -name crc | head -n1)
+chmod +x "$crc_path"
+delete_if_exists "${root_directory}/bin/crc"
+mv "$crc_path" "${root_directory}/bin/crc"
+rm -rf "$tmp_dir"

Also, consider adding set -euo pipefail at the top for safer execution.

src/roles/clusters/openshift/crc/crc-uninstall/config.yaml (2)

4-7: Clarify description phrasing

Minor grammar polish will make the description clearer (“This role helps to uninstall …”).


14-16: Remove trailing whitespace & add terminal newline

yaml-lint is already flagging these. Cleaning them up avoids noisy CI failures.

Also applies to: 31-32

tests/e2e/cluster-lifecycle/crc_install_delete/conftest.py (1)

44-50: Sub-process errors should fail the test loudly

When a cleanup command fails you only print a warning; the fixture then silently proceeds, hiding real problems (e.g., leaked VMs). Consider check=True or raising after failed cleanup so CI surfaces the issue.

Makefile (1)

45-50: Shell variable quoting – preserve whitespace in NEW_PYTEST_ARGS

make expands $(NEW_PYTEST_ARGS) before the shell sees it. If the var is unset the condition becomes if [ -n "" ], which is fine, but an empty value explicitly passed (NEW_PYTEST_ARGS="") will still satisfy -n. Usually that’s harmless, but if you need to distinguish unset vs empty, use ${NEW_PYTEST_ARGS+set}. No change required – just flagging the subtlety.

.github/workflows/e2e-cluster-lifecycle.yml (1)

55-55: Trailing whitespace

Yaml-lint flags this; harmless but easy to clean.

src/roles/clusters/openshift/crc/crc-uninstall/main.sh (2)

24-24: Quote the sourced path to avoid word-splitting / globbing

-source $root_directory/src/commons/scripts/utils.sh
+source "$root_directory/src/commons/scripts/utils.sh"

28-30: Unused variable role_name – delete or use it

role_name is parsed but never referenced (SC2034). Remove it or export it for callers.

src/roles/clusters/openshift/crc/crc-install/main.sh (3)

24-24: Quote the sourced utils path

-source $root_directory/src/commons/scripts/utils.sh
+source "$root_directory/src/commons/scripts/utils.sh"

28-30: role_name parsed but never used

Consider removing or exporting it.


78-81: Pull-secret existence check can be simplified & quoted

-if [ ! -f "${PULL_SECRET_PATH}" ] && [ ! -f "$(eval echo ${PULL_SECRET_PATH})" ]; then
-  die "Pull secret file not found at ${PULL_SECRET_PATH}"
-fi
+expanded_secret="$(eval echo "${PULL_SECRET_PATH}")"
+if [ ! -f "$expanded_secret" ]; then
+  die "Pull secret file not found at $expanded_secret"
+fi
src/roles/clusters/openshift/crc/crc-install/config.yaml (3)

19-21: Trailing spaces break YAML linting

Remove the trailing spaces on line 19 to satisfy yamllint.

-      - PULL_SECRET_PATH: Set PULL_SECRET_PATH,if you have a pull secret file(default: ~/pull-secret.txt).
+      - PULL_SECRET_PATH: Set PULL_SECRET_PATH, if you have a pull secret file (default: ~/pull-secret.txt).

13-17: Documentation vs default mismatch for MEMORY

Docstring says default 40000 but the actual default is 10752. Align the two to avoid confusion.


72-74: Cluster type description copy-paste

openshift cluster type (ROSA) is misleading for a local CRC cluster. Replace with “openshift-local”.

tests/e2e/cluster-lifecycle/crc_install_delete/test_crc.py (2)

4-4: Remove unused import time

time is never referenced.

-import time

8-12: Avoid shell=True in helper – injection risk

Since all commands are constant strings, execute without a shell:

-result = subprocess.run(cmd, shell=True, capture_output=True, text=True, env=env)
+result = subprocess.run(cmd, capture_output=True, text=True, env=env, shell=False)

Convert callers to pass the command as a list.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f25141c and c45f3d5.

📒 Files selected for processing (20)
  • .github/workflows/e2e-cluster-lifecycle.yml (3 hunks)
  • .vscode/launch.json (1 hunks)
  • Makefile (2 hunks)
  • config.yaml (0 hunks)
  • hacks/download-cli.sh (1 hunks)
  • pytest.ini (1 hunks)
  • src/cli/logics/component.py (1 hunks)
  • src/commons/python/py_utils.py (11 hunks)
  • src/commons/scripts/utils.sh (1 hunks)
  • src/core/initializer.py (1 hunks)
  • src/roles/clusters/kind/install/config.yaml (1 hunks)
  • src/roles/clusters/kind/install/main.sh (2 hunks)
  • src/roles/clusters/openshift/crc/crc-install/config.yaml (1 hunks)
  • src/roles/clusters/openshift/crc/crc-install/main.sh (1 hunks)
  • src/roles/clusters/openshift/crc/crc-uninstall/config.yaml (1 hunks)
  • src/roles/clusters/openshift/crc/crc-uninstall/main.sh (1 hunks)
  • tests/e2e/cluster-lifecycle/crc_install_delete/conftest.py (1 hunks)
  • tests/e2e/cluster-lifecycle/crc_install_delete/test_crc.py (1 hunks)
  • tests/e2e/cluster-lifecycle/kind_install_delete/test_kind.py (2 hunks)
  • tests/e2e/commons/cluster-tests/test_py_utils_e2e.py (4 hunks)
💤 Files with no reviewable changes (1)
  • config.yaml
🧰 Additional context used
🪛 YAMLlint (1.37.1)
src/roles/clusters/kind/install/config.yaml

[error] 64-64: no new line character at the end of file

(new-line-at-end-of-file)

src/roles/clusters/openshift/crc/crc-uninstall/config.yaml

[error] 16-16: trailing spaces

(trailing-spaces)


[error] 31-31: trailing spaces

(trailing-spaces)


[error] 32-32: no new line character at the end of file

(new-line-at-end-of-file)


[error] 32-32: trailing spaces

(trailing-spaces)

.github/workflows/e2e-cluster-lifecycle.yml

[error] 55-55: trailing spaces

(trailing-spaces)

src/roles/clusters/openshift/crc/crc-install/config.yaml

[error] 19-19: trailing spaces

(trailing-spaces)


[warning] 66-66: wrong indentation: expected 2 but found 4

(indentation)


[warning] 83-83: too many blank lines

(1 > 0) (empty-lines)

🪛 Shellcheck (0.10.0)
src/roles/clusters/openshift/crc/crc-uninstall/main.sh

[warning] 29-29: role_name appears unused. Verify use (or export if used externally).

(SC2034)

src/roles/clusters/openshift/crc/crc-install/main.sh

[warning] 29-29: role_name appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 85-85: Quote this to prevent word splitting.

(SC2046)

🪛 Pylint (3.3.7)
tests/e2e/cluster-lifecycle/crc_install_delete/test_crc.py

[refactor] 167-167: Too few public methods (1/2)

(R0903)

🪛 Ruff (0.11.9)
tests/e2e/cluster-lifecycle/crc_install_delete/test_crc.py

4-4: time imported but unused

Remove unused import: time

(F401)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: kind-cluster-lifecycle-test (3.12)
  • GitHub Check: cluster-test (3.12)
  • GitHub Check: non-cluster-test (3.12)
🔇 Additional comments (9)
src/cli/logics/component.py (1)

464-466: Good defensive fix – explicit string coercion

Converting every value to str() before exporting prevents the accidental
injection of non-string types into os.environ.
Looks ✅ to me.

src/roles/clusters/kind/install/main.sh (1)

34-42: Renamed fataldie matches utils.sh – no issues

utils.sh defines die, so switching to it removes an undefined-function
risk. Implementation looks correct.

tests/e2e/cluster-lifecycle/kind_install_delete/test_kind.py (1)

8-9: Ensure the new marker kind is registered

Pytest will warn/error on unknown markers unless pytest.ini (or
conftest.py) adds:

markers =
    kind: KIND-specific cluster lifecycle tests

Verify that this was added in the same PR; otherwise, add it to
avoid PytestUnknownMarkWarning.

src/core/initializer.py (1)

92-95: Environment variables now properly cast to strings – good catch

Changing the assignment to str(stop_when_failed) brings it in line with the next line and avoids the "TypeError: str expected, not bool" surprises some shells / downstream tools can throw. Nothing else to flag here.

hacks/download-cli.sh (1)

173-180: Re-using helper for kind cleanup is 👍

Switching to delete_if_exists keeps behaviour consistent across installers.

.vscode/launch.json (1)

2-30: VS Code switch to Python debug looks good – ensure debugpy is available

Anyone using this config must have debugpy in the venv. Maybe add a dev-requirements entry or mention it in the README.

src/commons/python/py_utils.py (1)

115-117: Line-wrap only – logic untouched

Looks good; no functional change introduced.

src/roles/clusters/openshift/crc/crc-uninstall/main.sh (1)

40-55: is_positive contract is counter-intuitive – request verification

The script treats “truthy” as the string "0" (see is_positive) and logs “DELETE is set” only when the return value is 0. This is the opposite of Unix exit-code semantics and is easy to mis-read. Please confirm that:

is_positive "1"  ➔ 1
is_positive "0"  ➔ 0   # treated as true

If that is not intentional, flip the comparison.

tests/e2e/cluster-lifecycle/crc_install_delete/test_crc.py (1)

22-33: is_cluster_stopped may raise on absent jq

get_crc_status_json assumes jq exists. If not, the function returns None and later JSON parsing can explode. Handle None explicitly or check for jq before tests.

Comment on lines +22 to +30
input_env:
- name: CLEANUP
description: |
Set CLEANUP to true if you want to stop/cleanup crc cluster (default: false)
default: false
- name: DELETE
description: |
Set DELETE to true if you want to delete crc cluster vm (default: false)
default: false
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

YAML list indentation is invalid – file will not parse

- name: items must be indented two spaces deeper than the input_env: key. Current layout breaks the mapping and will cause the role loader to explode.

22   input_env:
-23   - name: CLEANUP
-24     description: |
-25       Set CLEANUP to true if you want to stop/cleanup crc cluster (default: false)
-26     default: false
-27   - name: DELETE
-28     description: |
-29       Set DELETE to true if you want to delete crc cluster vm (default: false)
-30     default: false
+23     - name: CLEANUP
+24       description: |
+25         Set CLEANUP to true if you want to stop/cleanup crc cluster (default: false)
+26       default: false
+27     - name: DELETE
+28       description: |
+29         Set DELETE to true if you want to delete crc cluster vm (default: false)
+30       default: false
+
+# Add a newline at EOF too
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
input_env:
- name: CLEANUP
description: |
Set CLEANUP to true if you want to stop/cleanup crc cluster (default: false)
default: false
- name: DELETE
description: |
Set DELETE to true if you want to delete crc cluster vm (default: false)
default: false
input_env:
- name: CLEANUP
description: |
Set CLEANUP to true if you want to stop/cleanup crc cluster (default: false)
default: false
- name: DELETE
description: |
Set DELETE to true if you want to delete crc cluster vm (default: false)
default: false
🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-uninstall/config.yaml around lines 22 to
30, the YAML list items under input_env are not indented correctly. Fix the
indentation by adding two spaces before each '- name:' entry so they are
properly nested under the input_env key, ensuring the YAML parses correctly and
the role loader does not fail.

Comment on lines +24 to +31
@pytest.fixture()
def role_env(base_env):
"""Fixture providing base environment variables needed for all tests"""
base_env["DELETE"] = "1" # 1 means false in the role
base_env["CLEANUP"] = "1" # 1 means false in the role
base_env["KUBEADMIN_PASSWORD"] = "kubeadmin" # Default CRC admin password
base_env["ADD_CLUSTER_ADMIN_TO_DEVELOPER"] = "1" # 1 means false in the role
return base_env
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid mutating the shared base_env fixture in-place

base_env is session-scoped; changing it here leaks values between independent tests/classes. Work on a copy instead:

-@pytest.fixture()
-def role_env(base_env):
+@pytest.fixture()
+def role_env(base_env):
-    base_env["DELETE"] = "1"
-    base_env["CLEANUP"] = "1"
-    base_env["KUBEADMIN_PASSWORD"] = "kubeadmin"
-    base_env["ADD_CLUSTER_ADMIN_TO_DEVELOPER"] = "1"
-    return base_env
+    env = base_env.copy()
+    env.update(
+        {
+            "DELETE": "1",
+            "CLEANUP": "1",
+            "KUBEADMIN_PASSWORD": "kubeadmin",
+            "ADD_CLUSTER_ADMIN_TO_DEVELOPER": "1",
+        }
+    )
+    return env
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@pytest.fixture()
def role_env(base_env):
"""Fixture providing base environment variables needed for all tests"""
base_env["DELETE"] = "1" # 1 means false in the role
base_env["CLEANUP"] = "1" # 1 means false in the role
base_env["KUBEADMIN_PASSWORD"] = "kubeadmin" # Default CRC admin password
base_env["ADD_CLUSTER_ADMIN_TO_DEVELOPER"] = "1" # 1 means false in the role
return base_env
@pytest.fixture()
def role_env(base_env):
"""Fixture providing base environment variables needed for all tests"""
env = base_env.copy()
env.update(
{
"DELETE": "1",
"CLEANUP": "1",
"KUBEADMIN_PASSWORD": "kubeadmin",
"ADD_CLUSTER_ADMIN_TO_DEVELOPER": "1",
}
)
return env
🤖 Prompt for AI Agents
In tests/e2e/cluster-lifecycle/crc_install_delete/conftest.py around lines 24 to
31, the role_env fixture mutates the shared session-scoped base_env dictionary
in-place, causing state leakage between tests. To fix this, create a copy of
base_env at the start of the fixture and modify the copy instead of the
original. Return the modified copy to ensure isolation between tests.

Comment on lines +24 to 26
if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-life-cycle/kind_install_delete/|default_provided_services/|hacks/|.github/|commons/)'; then
echo "No relevant files changed for KIND cluster-lifecycle-test. Skipping tests but marking success."
exit 0
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Directory glob has a typo – tests will be skipped unintentionally

cluster-life-cyclecluster-lifecycle. The current regex never matches the actual paths, so the workflow always short-circuits.

-  if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-life-cycle/kind_install_delete/|default_provided_services/|hacks/|.github/|commons/)'; then
+  if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-lifecycle/kind_install_delete/|default_provided_services/|hacks/|.github/|commons/)'; then

Make the same correction in the commented-out OpenShift block below.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-life-cycle/kind_install_delete/|default_provided_services/|hacks/|.github/|commons/)'; then
echo "No relevant files changed for KIND cluster-lifecycle-test. Skipping tests but marking success."
exit 0
if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-lifecycle/kind_install_delete/|default_provided_services/|hacks/|.github/|commons/)'; then
echo "No relevant files changed for KIND cluster-lifecycle-test. Skipping tests but marking success."
exit 0
🤖 Prompt for AI Agents
In .github/workflows/e2e-cluster-lifecycle.yml around lines 24 to 26, the
directory glob pattern 'tests/e2e/cluster-life-cycle/kind_install_delete/'
contains a typo with hyphens instead of the correct 'cluster-lifecycle'. Update
the regex to use 'cluster-lifecycle' to correctly match the intended paths and
prevent unintended skipping of tests. Also, locate the commented-out OpenShift
block in the same file and apply the same correction to its directory glob
pattern.

Comment on lines +70 to +76
crc_status=$(crc status 2>&1)
if echo "$crc_status" | grep -iq "Machine does not exist\|crc does not seem to be setup correctly" || [ "$(crc status -o json | jq -r .openshiftStatus)" = "Stopped" ]; then
success "OpenShift local cluster is properly stopped"
else
fail "OpenShift local cluster is not properly stopped"
result=1
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Hard dependency on jq is unchecked

crc status -o json | jq … will fail with “command not found” if jq is absent and will make the script report a running cluster as failed. Add a pre-flight check:

command -v jq >/dev/null || die "jq is required but not installed"
🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-uninstall/main.sh around lines 70 to 76,
the script uses jq without verifying if it is installed, which can cause
failures if jq is missing. Add a pre-flight check before this block using
'command -v jq >/dev/null || die "jq is required but not installed"' to ensure
jq is available and exit with a clear error message if it is not.

Comment on lines +10 to +22
# Traverse up the directory tree to find the .github folder
github_dir="$current_dir"
while [ ! -d "$github_dir/.git" ] && [ "$github_dir" != "/" ]; do
github_dir="$(dirname "$github_dir")"
done

# If the .github folder is found, set root_directory
if [ -d "$github_dir/.git" ]; then
root_directory="$github_dir"
echo "The root directory is: $root_directory"
else
echo "Unable to find .github folder"
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Misleading comment & missing guard when repository root is not found

The comment talks about searching for a “.github” folder while the loop actually looks for .git.
If a .git directory is never found, root_directory is left unset, yet the script continues and source $root_directory/... will expand to an empty path and silently succeed or fail later.

-# Traverse up the directory tree to find the .github folder
+# Traverse up the directory tree to find the repository root (.git)
...
-else
-  echo "Unable to find .github folder"
-fi
+# Abort early when repository root is not located
+else
+  die "Unable to locate repository root (.git); aborting"
+fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Traverse up the directory tree to find the .github folder
github_dir="$current_dir"
while [ ! -d "$github_dir/.git" ] && [ "$github_dir" != "/" ]; do
github_dir="$(dirname "$github_dir")"
done
# If the .github folder is found, set root_directory
if [ -d "$github_dir/.git" ]; then
root_directory="$github_dir"
echo "The root directory is: $root_directory"
else
echo "Unable to find .github folder"
fi
# Traverse up the directory tree to find the repository root (.git)
github_dir="$current_dir"
while [ ! -d "$github_dir/.git" ] && [ "$github_dir" != "/" ]; do
github_dir="$(dirname "$github_dir")"
done
# If the .github folder is found, set root_directory
if [ -d "$github_dir/.git" ]; then
root_directory="$github_dir"
echo "The root directory is: $root_directory"
# Abort early when repository root is not located
else
die "Unable to locate repository root (.git); aborting"
fi
🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-uninstall/main.sh around lines 10 to 22,
update the comment to correctly state that the script is searching for the
".git" directory, not ".github". Add a guard after the search loop to check if
the repository root was found by verifying if root_directory is set; if not,
exit the script with an error message to prevent sourcing from an empty or
invalid path.

Comment on lines +97 to +103
# Verify openshift local cluster is running
if ! retry 60 5 "crc status -o json|jq -r .openshiftStatus | grep -q Running" "Waiting for openshift local cluster to be ready"; then
fail "Openshift local cluster is not running properly after 5 minutes"
result=1
else
success "Openshift local cluster is running properly"
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unverified dependencies: jq, oc, retry

The verify loop depends on these tools/functions but the script only checks for crc. Add explicit checks:

for bin in jq oc; do
  command -v "$bin" >/dev/null || die "$bin not installed"
done

type retry >/dev/null 2>&1 || die "retry helper not sourced"
🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-install/main.sh around lines 97 to 103,
the script uses jq, oc, and the retry function without verifying their
availability. Add explicit checks before the verify loop to ensure jq and oc
binaries are installed using command -v, and confirm the retry function is
sourced by checking its type. If any are missing, terminate the script with a
clear error message.

Comment on lines +10 to +22
# Traverse up the directory tree to find the .github folder
github_dir="$current_dir"
while [ ! -d "$github_dir/.git" ] && [ "$github_dir" != "/" ]; do
github_dir="$(dirname "$github_dir")"
done

# If the .github folder is found, set root_directory
if [ -d "$github_dir/.git" ]; then
root_directory="$github_dir"
echo "The root directory is: $root_directory"
else
echo "Unable to find .github folder"
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Same root-directory search issues as uninstall script

Replicate the earlier fix: correct the comment and abort when .git is not found to prevent undefined $root_directory.

🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-install/main.sh around lines 10 to 22,
update the comment to correctly describe searching for the .git folder instead
of .github. Add a check after the search loop to abort the script with an error
message if the .git folder is not found, preventing the use of an undefined
root_directory variable.

Comment on lines +3 to +5
if [[ $DEBUG == "0" ]]; then
set -x
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

set -x leaks secrets when DEBUG==0

Because DEBUG==0 enables tracing, sensitive variables such as KUBEADMIN_PASSWORD and tokens are echoed to the log. Reverse the check or guard secret exports.

🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-install/main.sh around lines 3 to 5, the
current logic enables shell tracing with 'set -x' when DEBUG is 0, which causes
sensitive information like passwords and tokens to be printed in logs. To fix
this, reverse the condition so that 'set -x' is only enabled when DEBUG is not
0, or alternatively, add safeguards to prevent secret variables from being
echoed when tracing is enabled.

Comment on lines +69 to +74
crc config set memory ${MEMORY} >/dev/null 2>&1
crc config set cpus ${CPU} >/dev/null 2>&1
crc config set disk-size ${DISK_SIZE} >/dev/null 2>&1
crc config set kubeadmin-password ${KUBEADMIN_PASSWORD} >/dev/null 2>&1
crc config set enable-cluster-monitoring ${ENABLE_MONITORING} >/dev/null 2>&1
else
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Unquoted variable expansions risk word-splitting

crc config set ... ${MEMORY} etc. are safe, but the pull-secret path is not:

-crc start -p $(eval echo ${PULL_SECRET_PATH})
+crc start -p "$(eval echo "${PULL_SECRET_PATH}")"

Also quote the earlier crc config set values for consistency.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-install/main.sh around lines 69 to 74,
the variable expansions in the crc config set commands are unquoted, risking
word-splitting and errors especially for the pull-secret path. To fix this, add
double quotes around all variable expansions like "${MEMORY}", "${CPU}",
"${DISK_SIZE}", "${KUBEADMIN_PASSWORD}", and "${ENABLE_MONITORING}" to ensure
safe and consistent handling of values.

Comment on lines +66 to +74
- name: CLUSTER_CONSOLE_URL
description: openshift console url

- name: CLUSTER_API_URL
description: openshift api url

- name: CLUSTER_TYPE
description: openshift cluster type (ROSA)

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Indentation off by two spaces – fails strict validators

output_env block is indented by four spaces where two are expected. Fix indentation to avoid tooling issues.

🧰 Tools
🪛 YAMLlint (1.37.1)

[warning] 66-66: wrong indentation: expected 2 but found 4

(indentation)

🤖 Prompt for AI Agents
In src/roles/clusters/openshift/crc/crc-install/config.yaml around lines 66 to
74, the entries under the output_env block are indented by four spaces instead
of the required two spaces. Adjust the indentation of these lines to two spaces
to comply with strict YAML validators and avoid tooling issues.

@Jooho
Copy link
Owner Author

Jooho commented Jun 17, 2025

/lgtm
/approve

@github-actions github-actions bot added the lgtm label Jun 17, 2025
@github-actions github-actions bot merged commit 4fd75e9 into main Jun 17, 2025
8 of 9 checks passed
@Jooho Jooho deleted the crc_install branch June 18, 2025 02:55
@coderabbitai coderabbitai bot mentioned this pull request Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant