Skip to content

Update HPA API Version to v2 #6188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

Mehran-Seifalinia
Copy link
Contributor

@Mehran-Seifalinia Mehran-Seifalinia commented Apr 21, 2025

Proposed changes

This change ensures compatibility with newer Kubernetes versions, prevents deployment failures, and aligns with best practices.
Keeping this outdated API version can lead to errors such as:

  • error: unable to recognize "hpa.yaml": no matches for kind "HorizontalPodAutoscaler" in version "autoscaling/v2beta1"

  • HPA resource not being created or updated during helm install or kubectl apply

Upgrading to autoscaling/v2 ensures compatibility with supported Kubernetes versions, prevents deployment failures, and allows usage of enhanced metric specifications. This change is essential for maintaining long-term cluster compatibility and avoiding runtime issues.

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling when reading and closing proxy files to ensure better reliability and clearer error reporting.

- Replaced the incorrect pattern "nuclei-nvd-%s" with a correct one "nuclei-nvd" in the os.MkdirTemp function call.

NOTE: The incorrect usage of %s in os.MkdirTemp caused it to be ignored, leading to potential issues with naming conventions for temporary directories and confusion in directory structure. The original function attempted to use string interpolation in a context where Go doesn't support it in os.MkdirTemp, which could result in unexpected behavior or errors when the directory name is processed.
- Redefining defaultOpts inside init() could lead to confusion, as it hides the global variable, causing the changes to be applied only within the init() scope and potentially causing unexpected behavior in other parts of the program.
The `autoscaling/v2beta1` API version used in the HPA manifest is deprecated and has been removed in recent Kubernetes versions (1.25+)
@auto-assign auto-assign bot requested a review from dwisiswant0 April 21, 2025 16:16
Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

The update modifies the file handling logic in the proxy component. It removes the use of a deferred file close and instead explicitly closes the file after reading all lines. Additionally, it introduces error handling for both the scanning process and the file closing operation, ensuring that any issues encountered during reading or closing are properly reported.

Changes

File(s) Change Summary
internal/runner/proxy.go Replaced deferred file closing with explicit close after scanning; added error handling for scanner and file closing.

Poem

A file once opened, now closed with care,
No longer left to defer in the air.
Errors are checked, both read and close,
More robust handling, as every bunny knows.
With every hop, we tidy and mend—
Code like a garden, neat to the end! 🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 24311cc and 5f6eee2.

⛔ Files ignored due to path filters (1)
  • helm/templates/hpa.yaml is excluded by !**/*.yaml
📒 Files selected for processing (1)
  • internal/runner/proxy.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (1)
internal/runner/proxy.go (1)

41-50: Improved file handling with proper error checking.

The changes enhance resource management by:

  1. Adding error checking for the scanner operation with scanner.Err()
  2. Explicitly closing the file when scanner errors occur
  3. Adding error checking when closing the file
  4. Replacing implicit deferred file closing with explicit file closure

These improvements prevent potential resource leaks and provide better error reporting for both reading and closing operations.

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

@GeorginaReeder
Copy link

Thanks for your contribution @Mehran-Seifalinia !

- Replaced defer file.Close() inside the loop with an immediate file.Close() after file reading, to prevent file descriptor leaks when processing multiple proxy files.
- Added explicit scanner.Err() check after scanning each file to properly handle and report potential file read errors.
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