Skip to content

K8s support#58

Merged
pateash merged 32 commits into
mainfrom
k8s-support
Jul 21, 2024
Merged

K8s support#58
pateash merged 32 commits into
mainfrom
k8s-support

Conversation

@pateash

@pateash pateash commented Jul 21, 2024

Copy link
Copy Markdown
Collaborator

Closes #57

@pateash
pateash marked this pull request as ready for review July 21, 2024 14:41
@coderabbitai

coderabbitai Bot commented Jul 21, 2024

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

The recent changes significantly enhance Kubernetes support within the hckr CLI, allowing effective management of contexts, namespaces, and pods via structured commands. Improved documentation and extensive unit tests further bolster reliability and user experience. Additionally, an automated workflow for issue assignment has been implemented, streamlining project management and fostering team efficiency.

Changes

Files Change Summary
.github/workflows/auto-assign.yml, .grazie.en.yaml, Makefile Introduced automation for issue assignment, enforced writing standards, and updated the Makefile for improved sync and run processes.
docs/source/index.rst, docs/source/k8s/*.rst Added comprehensive documentation for Kubernetes-related commands to enhance organization and user accessibility.
src/hckr/cli/__init__.py, src/hckr/cli/k8s/*.py Restructured CLI to integrate and manage Kubernetes commands, improving usability and command organization.
src/hckr/utils/k8s/*.py Introduced utility functions for managing Kubernetes contexts and namespaces, enhancing interaction with Kubernetes resources.
tests/cli/k8s/*.py Developed unit tests for Kubernetes CLI functionalities, covering contexts, namespaces, and pods to ensure reliability.

Assessment against linked issues

Objective Addressed Explanation
Implement Kubernetes support
Ensure CLI functionality
Improve documentation
Enhance testing coverage

Poem

In fields of code, we hop and play,
With Kubernetes here, we brighten the day!
Pods and namespaces dance with glee,
A CLI so spry, just wait and see!
So let's assign and share the fun,
For our project's work is never done! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 21, 2024
@github-actions github-actions Bot added enhancement New feature or request github-actions Changes in CICD tests Changes to test project-config labels Jul 21, 2024

@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: 10

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66d9b0c and 9a8ef97.

Files ignored due to path filters (2)
  • docs/source/_static/logo-extended.png is excluded by !**/*.png, !**/*.png
  • pyproject.toml is excluded by !**/*.toml
Files selected for processing (19)
  • .github/workflows/auto-assign.yml (1 hunks)
  • .grazie.en.yaml (1 hunks)
  • Makefile (2 hunks)
  • docs/source/index.rst (1 hunks)
  • docs/source/k8s/context.rst (1 hunks)
  • docs/source/k8s/index.rst (1 hunks)
  • docs/source/k8s/namespace.rst (1 hunks)
  • docs/source/k8s/pod.rst (1 hunks)
  • src/hckr/cli/init.py (3 hunks)
  • src/hckr/cli/k8s/init.py (1 hunks)
  • src/hckr/cli/k8s/context.py (1 hunks)
  • src/hckr/cli/k8s/namespace.py (1 hunks)
  • src/hckr/cli/k8s/pod.py (1 hunks)
  • src/hckr/utils/CronUtils.py (2 hunks)
  • src/hckr/utils/k8s/K8sUtils.py (1 hunks)
  • src/hckr/utils/k8s/PodUtils.py (1 hunks)
  • tests/cli/k8s/test_context.py (1 hunks)
  • tests/cli/k8s/test_namespace.py (1 hunks)
  • tests/cli/k8s/test_pod.py (1 hunks)
Files skipped from review due to trivial changes (8)
  • .github/workflows/auto-assign.yml
  • .grazie.en.yaml
  • docs/source/index.rst
  • docs/source/k8s/context.rst
  • docs/source/k8s/index.rst
  • docs/source/k8s/namespace.rst
  • docs/source/k8s/pod.rst
  • src/hckr/utils/CronUtils.py
Additional context used
Ruff
src/hckr/cli/k8s/namespace.py

3-3: ...utils.MessageUtils.info imported but unused

Remove unused import: ...utils.MessageUtils.info

(F401)

tests/cli/k8s/test_pod.py

5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

tests/cli/k8s/test_context.py

3-3: unittest.mock.MagicMock imported but unused

Remove unused import: unittest.mock.MagicMock

(F401)


5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

tests/cli/k8s/test_namespace.py

5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

src/hckr/utils/k8s/PodUtils.py

2-2: re imported but unused

Remove unused import: re

(F401)


15-15: Redefinition of unused logging from line 1

Remove definition: logging

(F811)


91-92: Use a single if statement instead of nested if statements

Combine if statements using and

(SIM102)

Additional comments not posted (28)
src/hckr/cli/k8s/__init__.py (3)

1-1: Import click is correct.

The import statement for the click library is necessary for defining CLI commands.


4-10: Decorator common_k8s_options is well-defined.

The decorator correctly adds a --context option to the decorated function, providing a helpful description.


13-18: Click group k8s is correctly set up.

The k8s Click group is defined with appropriate help text and context settings.

src/hckr/cli/k8s/context.py (2)

6-11: Click group context is correctly set up.

The context Click group is defined with appropriate help text and context settings.


14-29: Command show is well-defined but has an unused import.

The show command correctly lists all contexts using list_contexts. However, the info function is imported but not used.

- info("Listing all contexts")

Likely invalid or redundant comment.

src/hckr/cli/k8s/namespace.py (1)

6-11: Click group namespace is correctly set up.

The namespace Click group is defined with appropriate help text and context settings.

tests/cli/k8s/test_pod.py (1)

15-26: LGTM! Consider adding more tests.

The test method correctly mocks the Kubernetes API, invokes the CLI command, and asserts the output.

However, consider adding tests for other functionalities like delete, logs, etc.

tests/cli/k8s/test_context.py (1)

15-32: LGTM! Consider adding more tests.

The test method correctly mocks the Kubernetes config, invokes the CLI command, and asserts the output.

However, consider adding tests for other functionalities like switching contexts, error handling, etc.

tests/cli/k8s/test_namespace.py (2)

15-25: LGTM! Consider adding more tests.

The test method correctly mocks the Kubernetes API, invokes the CLI command, and asserts the output.

However, consider adding tests for other functionalities like error handling, different contexts, etc.


26-35: LGTM! Consider adding more tests.

The test method correctly mocks the Kubernetes API, invokes the CLI command with a context argument, and asserts the output.

However, consider adding tests for other functionalities like error handling, different contexts, etc.

Makefile (2)

24-24: LGTM! The sync target enhancement is beneficial.

Including fix as a dependency in the sync target ensures that any necessary fixes are applied during synchronization, enhancing the build process.


88-91: LGTM! The run target is a valuable addition.

The run target facilitates local testing by verifying the presence of the hckr command and executing it, streamlining the testing workflow for developers.

src/hckr/utils/k8s/K8sUtils.py (3)

24-39: LGTM! The _human_readable_age function is well-implemented.

The function effectively converts a timestamp to a human-readable age format, handling various time units appropriately.


42-60: LGTM! The list_namespaces function is well-implemented.

The function effectively lists Kubernetes namespaces and displays them using rich, handling context loading and output formatting appropriately.


63-84: LGTM! The list_contexts function is well-implemented.

The function effectively lists Kubernetes contexts and displays them using rich, handling context listing and output formatting appropriately.

src/hckr/cli/__init__.py (4)

9-11: LGTM! The new imports for Kubernetes operations are necessary.

The new imports for Kubernetes operations (context, namespace, pod) are essential for the added functionalities in the CLI.


5-5: LGTM! The removal of the art import is appropriate.

The removal of the art import indicates a shift away from its usage in the CLI, streamlining the import structure.


96-100: LGTM! The new command registrations for Kubernetes operations enhance the CLI.

The new command registrations for Kubernetes operations (k8s, pod, namespace, context) significantly enhance the CLI's capabilities, allowing users to interact with Kubernetes resources directly from the hckr CLI.


Line range hint 36-36:
LGTM! The removal of the art.tprint("hckr") line streamlines the output.

The removal of the art.tprint("hckr") line may streamline the output when the command is invoked without any subcommands, providing a cleaner user experience.

src/hckr/cli/k8s/pod.py (5)

9-14: LGTM!

The pod function is correctly defined as a click group command.


17-56: LGTM!

The show function is well-defined and uses appropriate options and arguments.


59-77: LGTM!

The delete function is well-defined and uses appropriate options and arguments.


80-102: LGTM!

The shell function is well-defined and uses appropriate options and arguments.


105-130: LGTM!

The logs function is well-defined and uses appropriate options and arguments.

src/hckr/utils/k8s/PodUtils.py (4)

34-67: LGTM!

The list_pods function is well-defined and uses appropriate methods to fetch and display pod information.


70-81: LGTM!

The delete_pod function is well-defined and handles exceptions appropriately.


84-155: LGTM!

The shell_into_pod function is well-defined and handles input and output streams appropriately.

Tools
Ruff

91-92: Use a single if statement instead of nested if statements

Combine if statements using and

(SIM102)


158-201: LGTM!

The get_pod_logs function is well-defined and handles exceptions appropriately.

Comment thread src/hckr/cli/k8s/context.py
Comment thread src/hckr/cli/k8s/namespace.py Outdated
Comment thread src/hckr/cli/k8s/namespace.py
Comment thread src/hckr/utils/k8s/PodUtils.py
Comment thread tests/cli/k8s/test_pod.py
Comment thread tests/cli/k8s/test_pod.py Outdated
Comment thread src/hckr/utils/k8s/K8sUtils.py
Comment thread src/hckr/utils/k8s/PodUtils.py
Comment thread tests/cli/k8s/test_context.py Outdated
Comment thread tests/cli/k8s/test_namespace.py Outdated

@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

Outside diff range, codebase verification and nitpick comments (3)
tests/cli/k8s/test_context.py (1)

15-32: Ensure assertions are used instead of print statements.

Replace the print statement with an assertion to verify the output.

- print(result.output)
- # self.assertEqual(result.exit_code, 0)
+ self.assertEqual(result.exit_code, 0)
+ self.assertIn("Listing all contexts", result.output)
+ self.assertIn("dev <- active", result.output)
+ self.assertIn("prod", result.output)
tests/cli/k8s/test_namespace.py (2)

15-25: Ensure assertions are used instead of print statements.

Replace the print statement with an assertion to verify the output.

- print(result.output)
+ self.assertEqual(result.exit_code, 0)
+ self.assertIn("Using default context: default", result.output)

26-35: Ensure assertions are used instead of print statements.

Replace the print statement with an assertion to verify the output.

- print(result.output)
+ self.assertEqual(result.exit_code, 0)
+ self.assertIn("Using given context: mycontext", result.output)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9a8ef97 and 673ae27.

Files selected for processing (2)
  • tests/cli/k8s/test_context.py (1 hunks)
  • tests/cli/k8s/test_namespace.py (1 hunks)
Additional context used
Ruff
tests/cli/k8s/test_context.py

3-3: unittest.mock.MagicMock imported but unused

Remove unused import: unittest.mock.MagicMock

(F401)


5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

tests/cli/k8s/test_namespace.py

5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

Additional comments not posted (2)
tests/cli/k8s/test_context.py (1)

3-7: Remove unused imports.

The imports unittest.mock.MagicMock, pyarrow, and pyarrow.parquet are not used in this file.

- from unittest.mock import patch, MagicMock  # type: ignore
- import pyarrow as pa  # type: ignore
- from pyarrow import parquet as pq  # type: ignore
+ from unittest.mock import patch  # type: ignore
Tools
Ruff

3-3: unittest.mock.MagicMock imported but unused

Remove unused import: unittest.mock.MagicMock

(F401)


5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

tests/cli/k8s/test_namespace.py (1)

5-7: Remove unused imports.

The imports pyarrow and pyarrow.parquet are not used in this file.

- import pyarrow as pa  # type: ignore
- from pyarrow import parquet as pq  # type: ignore
Tools
Ruff

5-5: pyarrow imported but unused

Remove unused import: pyarrow

(F401)


7-7: pyarrow.parquet imported but unused

Remove unused import: pyarrow.parquet

(F401)

@github-actions github-actions Bot added the release This will lead to a new release label Jul 21, 2024
@pateash
pateash merged commit 93a177e into main Jul 21, 2024
@pateash
pateash deleted the k8s-support branch July 21, 2024 16:58
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
39.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@pateash
pateash restored the k8s-support branch August 17, 2024 04:50
@pateash
pateash deleted the k8s-support branch August 17, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request github-actions Changes in CICD project-config release This will lead to a new release tests Changes to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

k8s support

1 participant