Skip to content

Update default role#45

Merged
Jooho merged 8 commits intomainfrom
update_default_role
Jun 18, 2025
Merged

Update default role#45
Jooho merged 8 commits intomainfrom
update_default_role

Conversation

@Jooho
Copy link
Owner

@Jooho Jooho commented Jun 18, 2025

Summary by CodeRabbit

  • New Features

    • Support for specifying multiple default directories for roles, units, and playbooks.
    • Environment variable expansion is now supported in directory paths.
  • Bug Fixes

    • Improved handling of non-existent directories to prevent errors during initialization.
  • Refactor

    • Configuration keys for default directories are now pluralized and accept lists.
    • Directory structure and test data reorganized for better clarity and flexibility.
  • Tests

    • Updated tests to reflect new pluralized configuration keys and improved directory handling.

Jooho added 8 commits June 5, 2025 17:50
Signed-off-by: Jooho Lee <jlee@redhat.com>
Signed-off-by: Jooho Lee <jlee@redhat.com>
Signed-off-by: Jooho Lee <jlee@redhat.com>
Signed-off-by: Jooho Lee <jlee@redhat.com>
…efault_role

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

gitguardian bot commented Jun 18, 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 18, 2025

Walkthrough

The changes refactor the handling of default component directories in both code and configuration, moving from single string paths to pluralized keys holding lists of directories. Environment variable substitution in paths is now supported. Tests and configuration files are updated to use the new pluralized keys and list structures.

Changes

File(s) Change Summary
src/core/initializer.py Refactored to use pluralized directory keys as lists, added environment variable substitution, updated methods for safer handling.
src/core/internal_config.yaml Changed default directory config keys from singular strings to pluralized lists, supporting multiple directories per component type.
tests/custom-context.json Updated config keys to pluralized list form; reorganized and expanded role, unit, and playbook lists and paths.
tests/fvt/core/test_initizlizer.py Updated test fixture and tests for pluralized directory keys as lists; added mock for directory existence checks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Initializer
    participant OS/Env

    User->>Initializer: initialize()
    Initializer->>OS/Env: Read config (pluralized *_dirs keys)
    loop For each default directory list
        Initializer->>OS/Env: Replace ${VAR} in paths
        Initializer->>OS/Env: Check if directory exists
        alt Directory exists
            Initializer->>Initializer: List components from directory
        else Directory does not exist
            Initializer->>Initializer: Skip directory
        end
    end
    Initializer-->>User: Initialization complete
Loading

Suggested labels

lgtm

Poem

A hop, a skip, through folders anew,
Now lists of paths guide what we do.
Env vars replaced, checks made with care,
Directories plural, found everywhere.
Tests and configs join the parade—
In Loopy’s warren, progress is made! 🐇✨

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

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: 1

🧹 Nitpick comments (4)
src/core/initializer.py (1)

147-166: Minor: simplify replace_env_vars control flow

After the early return inside the str branch, the following elif is unnecessary; convert to if …: return … / if …: return … / return value for clarity.

tests/fvt/core/test_initizlizer.py (2)

105-108: Path building should use os.path.join throughout

config_data["default_roles_dirs"] + "/foo" hard-codes a separator; use os.path.join(config_data["default_roles_dirs"][0], "foo") for portability.


114-122: os.path.exists always-true mock may hide regressions

Returning True for every path means non-existent directories or mistakes in replace_env_vars won’t be caught. Consider restricting the stub to the paths you intend to be valid.

tests/custom-context.json (1)

101-110: Hard-coded absolute paths reduce portability

The pluralised default directory arrays embed user-specific absolute paths. Consider environment variables (already supported by replace_env_vars) or relative paths to keep the sample context repo-agnostic.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fd75e9 and e62a939.

📒 Files selected for processing (4)
  • src/core/initializer.py (2 hunks)
  • src/core/internal_config.yaml (1 hunks)
  • tests/custom-context.json (4 hunks)
  • tests/fvt/core/test_initizlizer.py (2 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
src/core/initializer.py

[refactor] 148-165: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: kind-cluster-lifecycle-test (3.12)
  • GitHub Check: non-cluster-test (3.12)
  • GitHub Check: cluster-test (3.12)
🔇 Additional comments (2)
tests/fvt/core/test_initizlizer.py (1)

93-101: Keep overridden config values as lists

Production code now expects the pluralised keys to be lists; overriding them with a plain string diverges from real-world usage and hides bugs that could appear with multiple directories.

-config_data["default_roles_dirs"] = os.path.join(... )
+config_data["default_roles_dirs"] = [os.path.join(...)]

Apply the same pattern to units & playbooks.

src/core/internal_config.yaml (1)

8-16: Missing in-repo default for units & playbooks?

default_roles_dirs still covers in-tree components (src/roles), but default_units_dirs / default_playbooks_dirs have no equivalent (src/units, src/playbooks).
If in-repo defaults are required, add them to avoid relying solely on ${UNOFFICIAL_COMPONENTS}.

Comment on lines +111 to 130
for key in [
"default_roles_dirs",
"default_units_dirs",
"default_playbooks_dirs",
]:
if key in self.config_data:
# First ensure it's a list
if not isinstance(self.config_data[key], list):
self.config_data[key] = [self.config_data[key]]

# Then replace environment variables in each path
self.config_data[key] = [
self.replace_env_vars(path) for path in self.config_data[key]
]

# Finally add loopy_root_path to each path
self.config_data[key] = [
f"{self.loopy_root_path}/{path}" for path in self.config_data[key]
]

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Absolute-path duplication risk & OS-agnostic join

Blindly prefixing self.loopy_root_path with f"{self.loopy_root_path}/{path}" will corrupt already-absolute paths (e.g. /tmp/foo/repo//tmp/foo) and forces POSIX separators.
Guard with os.path.isabs() and use os.path.join / os.path.normpath instead:

- self.config_data[key] = [
-     f"{self.loopy_root_path}/{path}" for path in self.config_data[key]
- ]
+ self.config_data[key] = [
+     os.path.normpath(
+         os.path.join(self.loopy_root_path, path)
+     )
+     if not os.path.isabs(path) else os.path.normpath(path)
+     for path in self.config_data[key]
+ ]
📝 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
for key in [
"default_roles_dirs",
"default_units_dirs",
"default_playbooks_dirs",
]:
if key in self.config_data:
# First ensure it's a list
if not isinstance(self.config_data[key], list):
self.config_data[key] = [self.config_data[key]]
# Then replace environment variables in each path
self.config_data[key] = [
self.replace_env_vars(path) for path in self.config_data[key]
]
# Finally add loopy_root_path to each path
self.config_data[key] = [
f"{self.loopy_root_path}/{path}" for path in self.config_data[key]
]
for key in [
"default_roles_dirs",
"default_units_dirs",
"default_playbooks_dirs",
]:
if key in self.config_data:
# First ensure it's a list
if not isinstance(self.config_data[key], list):
self.config_data[key] = [self.config_data[key]]
# Then replace environment variables in each path
self.config_data[key] = [
self.replace_env_vars(path) for path in self.config_data[key]
]
# Finally add loopy_root_path to each path
self.config_data[key] = [
os.path.normpath(
os.path.join(self.loopy_root_path, path)
)
if not os.path.isabs(path) else os.path.normpath(path)
for path in self.config_data[key]
]
🤖 Prompt for AI Agents
In src/core/initializer.py around lines 111 to 130, the code prefixes
self.loopy_root_path to each path using string concatenation, which can corrupt
absolute paths and is not OS-agnostic. Fix this by checking if each path is
absolute using os.path.isabs(); if it is not absolute, join it with
self.loopy_root_path using os.path.join, then normalize the result with
os.path.normpath to ensure correct path formatting across OSes.

@Jooho
Copy link
Owner Author

Jooho commented Jun 18, 2025

/lgtm
/approve

@github-actions github-actions bot added the lgtm label Jun 18, 2025
@Jooho Jooho merged commit 49f0be9 into main Jun 18, 2025
7 checks passed
@Jooho Jooho deleted the update_default_role branch June 18, 2025 02:55
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