Skip to content

Conversation

mohit-nagaraj
Copy link

@mohit-nagaraj mohit-nagaraj commented Jun 7, 2025

Description

This PR fixes #710

Notes for Reviewers

  • io.Copy(buf, tr) needed to be checked for any potential errors that may arise
  • We shuld use logrus.Infof for formatting %v err
  • data, err := os.ReadFile(downloadfilePath) _, err = w.Write(data) the err is being over written here before it was checked so we shud break it into 2 separate checks

there are few more issues caused due to depreciation of the packages:
edit
updated the opa to use 1.x version
removed the deprecated packages in nat.go

Signed commits

  • Yes, I signed my commits.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Hello @mohit-nagaraj, 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!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request to help everyone get up to speed quickly. This PR, titled "fix(app): fixes lint issues", aims to address several linting issues identified in the codebase. According to the description, it partially fixes issue #710. The changes primarily focus on improving error handling in specific areas and correcting logging format usage, as well as updating a dependency.

Highlights

  • Improved Error Handling: Error checks have been added or corrected in converter/tests/helm_test.go for io.Copy and in generators/github/url.go for os.ReadFile before subsequent operations.
  • Logging Format Correction: The logging call in utils/component/generator.go has been updated from logrus.Info to logrus.Infof to correctly format the log message with the provided error.
  • Dependency Update: The go.sum file has been updated to include entries for github.com/meshery/schemas v0.8.22, likely as a result of other changes or dependency resolution during linting fixes.

Changelog

  • converter/tests/helm_test.go
    • Added error check for io.Copy call on line 142.
  • generators/github/url.go
    • Added an error check for os.ReadFile on line 58 before attempting to write the data.
  • go.sum
    • Added entries for github.com/meshery/schemas v0.8.22.
  • utils/component/generator.go
    • Changed logrus.Info to logrus.Infof on line 75 for proper error formatting.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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-code-assist Responds in comments when explicitly tagged, both in issue 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 is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

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.

Copy link
Contributor

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

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 addresses several linting issues as described, specifically focusing on error handling and a minor logging format change. The changes implemented are correct and improve the robustness and clarity of the code in the affected areas. It's good to see these specific issues being tackled.

Summary of Findings

  • Error Handling (io.Copy): Added error checking for io.Copy in the extractManifestFromChart test helper function (medium severity).
  • Error Handling (Overwritten Error): Corrected an issue in GetContent where the error from os.ReadFile was being overwritten by the error from w.Write before being checked. This fix ensures proper error propagation (high severity).
  • Logging Format: Updated logrus.Info to logrus.Infof in IncludeComponentBasedOnGroup for correct formatted logging of errors (low severity - not commented on directly as per review settings).
  • Deprecated Package Usages: The PR description and the provided golangci-lint output indicate several usages of deprecated packages (oras, nats, opa) that are not addressed in this PR. While outside the scope of the current changes, these should be addressed in follow-up PRs to fully resolve the reported lint issues.

Merge Readiness

The code changes in this pull request correctly address the specific error handling and logging issues they target. The fixes are well-implemented and improve the code quality in these areas. The PR description acknowledges that this is a partial fix for the overall linting problem, listing the remaining deprecated package issues. Based on the changes included in this PR, the code is in good shape to be merged. However, it is strongly recommended that follow-up pull requests are created to address the remaining deprecated package usages identified by the linter to fully resolve the linting debt. I am unable to approve the pull request; other reviewers should review and approve this code before merging.

@mohit-nagaraj
Copy link
Author

@vishalvivekm could you suggest the next steps? shall i migrate few of the packges?

@mohit-nagaraj
Copy link
Author

mohit-nagaraj commented Jun 7, 2025

edited:
now its just cause of this 1 file:
broker/nats/nats.go lines 28, 60, 82, 87, 96, 108, 122
issue - nats.EncodedConn and related methods (NewEncodedConn, Close, Publish, etc.) are deprecated.

verifying with tests
they are failing for a whole lot of other reasons

@mohit-nagaraj
Copy link
Author

updating the nats based on this doc
https://pkg.go.dev/github.com/nats-io/nats.go#section-readme

@mohit-nagaraj
Copy link
Author

so the lints are in place, but the workflow will still fail because of the test cases which are failing

@mohit-nagaraj
Copy link
Author

just checked out why one of the testcase is failing,
https://charts.bitnami.com/bitnami/consul
appears this chart has been moved to some other url or something

now we get only oci://registry-1.docker.io/bitnamicharts/consul:11.4.18 from the urls, so theres no direct https url to chart
https://repo.broadcom.com/bitnami-files/index.yaml

@mohit-nagaraj
Copy link
Author

Bitnami (and many other Helm chart publishers) are moving from HTTP(S)-based chart repositories (e.g., https://charts.bitnami.com/bitnami/consul) to OCI-based registries (e.g., oci://registry-1.docker.io/bitnamicharts/consul:11.4.19). This is now the only way to get the latest charts, as confirmed in the Bitnami migration blog.

@mohit-nagaraj
Copy link
Author

package_test.go:37: error while generating components: Get "oci://registry-1.docker.io/bitnamicharts/consul:11.4.19": unsupported protocol scheme "oci"

@mohit-nagaraj
Copy link
Author

last test case which is failing
sanitization_test.go:186: Failed To Identify File as meshery-design , got , errors The file 'valid-design-oci.tar' was not recognized as any of the supported file types [meshery-design k8s-manifest helm-chart docker-compose k8s-kustomize]..Identification attempts and errors:.- Attempted to identify as 'docker-compose': failed to load Docker Compose config: yaml: control characters are not allowed.- Attempted to identify as 'k8s-kustomize': kustomization.yaml not found in extracted directory.- Attempted to identify as 'meshery-design': stat /home/codespace/.meshery/content: no such file or directory.- Attempted to identify as 'k8s-manifest': invalid file extension: .tar, only .yml and .yaml are supported.- Attempted to identify as 'helm-chart': failed to load Helm chart gzip: invalid header

for some reason its not able to locate these files i believe? should investigate this further

@mohit-nagaraj
Copy link
Author

I am not able to find any in this route path for file 'schemas/constructs/v1beta1/designs.json' anyone knows where it has been moved to?

@mohit-nagaraj
Copy link
Author

mohit-nagaraj commented Jun 8, 2025

the original design file wasnt present
however found this file to resemble our PatternFile struct
https://github.com/meshery/schemas/blob/master/schemas/constructs/v1alpha2/design.json
so have taken the from from that place

@mohit-nagaraj mohit-nagaraj force-pushed the master branch 3 times, most recently from 62eb02e to 17aaddc Compare June 15, 2025 14:38
@mohit-nagaraj
Copy link
Author

Just a quick update thought to put it in here
Refactor: Use Interface for NATS Connection

Previously, the Nats struct directly depended on the concrete *nats.Conn type from the NATS library. This tight coupling made it difficult to write effective unit tests, as it was not possible to substitute the real connection with a mock or fake. To address this, I refactored the code to introduce a NatsConn interface, which abstracts only the methods used by our implementation. The Nats struct now depends on this interface, allowing for greater flexibility, easier testing, and improved maintainability.

Test Coverage Improvements

With the introduction of the NatsConn interface, I was able to implement comprehensive unit tests for the NATS broker logic. By providing a mock implementation of the interface, the tests can simulate various scenarios and error conditions without requiring a real NATS server. This ensures that our code is robust and behaves as expected under different circumstances.

Test Cases Added and Coverage

The following test cases were added to ensure high coverage and reliability:

  1. ConnectedEndpoints:
    Verifies that the correct list of endpoints is returned from the connection.

  2. Info:
    Checks the connection information, including the case when the connection is not established.

  3. CloseConnection:
    Ensures the connection is properly drained and closed.

  4. Publish:

    • Tests successful message publishing.
    • Tests error handling for nil messages.
    • Tests error propagation from the underlying connection.
  5. PublishWithChannel:
    Validates that messages sent through a channel are published correctly.

  6. Subscribe:

    • Confirms that subscription logic works and messages are received.
    • Tests error handling when subscription fails.
  7. SubscribeWithChannel:

    • Ensures messages are correctly unmarshaled and sent to the provided channel.
    • Tests error handling for subscription failures.
  8. DeepCopy & DeepCopyObject:
    Verifies that deep copy methods create new, independent instances.

  9. IsEmpty:
    Checks the logic for determining if the Nats struct is empty or uninitialized.

Lmk if i should add/modify something in here

@mohit-nagaraj
Copy link
Author

{
Path: "catalog_data",
Resource: v1alpha1.CatalogData{
PublishedVersion: "v.10.9",
ContentClass: "sdsds",
Compatibility: []v1alpha1.CatalogDataCompatibility{
"kubernetes",
},
PatternCaveats: "NA",
PatternInfo: "NA",
Type: v1alpha1.CatalogDataType("Dployment"),
},
ShouldPass: false,
},

Still getting a error at this case tho, cause i could find something named catalog in v1beta1. (it had in v1beta2 not sure if we can use it cuz it was commited long ago). Have updated the other test case acc to v1beta1 design

@leecalcote
Copy link
Member

Re-running workflows...

@mohit-nagaraj
Copy link
Author

/gemini review

Copy link
Contributor

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

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 addresses several linting issues and updates dependencies, most notably OPA and Helm-related packages. The changes include important correctness fixes, such as proper error handling for I/O operations and fixing an overwritten error variable. The NATS broker implementation has been refactored to remove deprecated components and is now accompanied by unit tests.

Overall, these are valuable fixes, and with the suggested changes, the code quality will be further improved.

@mohit-nagaraj
Copy link
Author

I have updated as suggested by gemini and @Nitish-bot
Could you please take a another look at this? @leecalcote
Thank you

Signed-off-by: Mohit Nagaraj <mohitnagaraj20@gmail.com>
Signed-off-by: Mohit Nagaraj <mohitnagaraj20@gmail.com>
Copy link

stale bot commented Sep 2, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the issue/stale Issue has not had any activity for an extended period of time label Sep 2, 2025
@leecalcote
Copy link
Member

Merge conflicts need to be addressed, @mohit-nagaraj

@stale stale bot removed the issue/stale Issue has not had any activity for an extended period of time label Sep 3, 2025
@mohit-nagaraj
Copy link
Author

Understood

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.

Failing lint jobs

4 participants