Skip to content

Conversation

@iamayushm
Copy link
Contributor

@iamayushm iamayushm commented Mar 4, 2025

Description

Fixes #

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?


Summary by Bito

This PR introduces helm release linking functionality by adding new REST endpoints and enhancing gRPC protobuf definitions. It extends data structures to support richer information for helm applications, improves validation logic, and refactors error handling mechanisms. These changes streamline helm release management and strengthen overall system reliability.

Copy link
Member

Choose a reason for hiding this comment

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

either move file or new code at new path /pkg/deployment/....

Base automatically changed from link-external-argocd to develop March 7, 2025 12:56
@gitguardian
Copy link

gitguardian bot commented Mar 7, 2025

⚠️ GitGuardian has uncovered 5 secrets 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 secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
15200081 Triggered PGP Private Key e082b02 vendor/github.com/ProtonMail/go-crypto/openpgp/read_write_test_data.go View secret
15200082 Triggered PGP Private Key e082b02 vendor/github.com/ProtonMail/go-crypto/openpgp/read_write_test_data.go View secret
7214865 Triggered PGP Private Key f44a592 vendor/github.com/ProtonMail/go-crypto/openpgp/read_write_test_data.go View secret
15200083 Triggered PGP Private Key f44a592 vendor/github.com/ProtonMail/go-crypto/openpgp/read_write_test_data.go View secret
15200084 Triggered PGP Private Key e082b02 vendor/github.com/ProtonMail/go-crypto/openpgp/read_write_test_data.go 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 secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  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.

@sonarqubecloud
Copy link

@Shivam-nagar23
Copy link
Member

/review

@bito-code-review
Copy link

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
New Feature - New and Enhanced Features

HelmAppService.go - Integrated new service methods including functions for external helm app listing and detailed release retrieval with enhanced logging and error handling.

adapter.go - Introduced utility function 'ConvertClusterBeanToClusterConfig' for consistent mapping between cluster beans and helm configurations.

bean.go - Defined ExternalHelmAppListingResult struct to support extended helm app categorization.

HelmAppRestHandler.go - Added new REST endpoint 'ListHelmApplicationsForEnvironment' with comprehensive request handling and error responses.

HelmAppRouter.go - Configured a new GET route '/external-helm-release' for exposing external helm release details.

PipelineRepository.go - Enhanced pipeline config with added ClusterId and Namespace fields and introduced GetAllAppsByClusterAndDeploymentAppType for advanced retrieval.

Feature Improvement - Enhanced Features and Improvements

applist.pb.go - Integrated new hexadecimal field codes and refined message types for better maintainability.

applist.proto - Added new fields 'releaseStatus' and 'home' to extend the environment details schema.

applist_grpc.pb.go - Refactored multiple gRPC method invocations by replacing hardcoded method strings with constant-based method names across endpoints.

ArgoApplicationServiceExtended.go - Modified initialization and added aCDAuthConfig field for improved authentication configuration.

adapter.go - Updated adapter to include detailed cluster configuration for enriched environment data.

DeploymentPipelineConfigService.go - Enhanced external helm app linking with new validation functions, additional helmAppReadService integration, and updated error handling logic.

adapter.go - Renamed migration validation request to 'NewMigrateExternalAppValidationRequest' to support external helm app linking with helm metadata integration.

ExternalArgoAppLink.go - Added helm release linking functions by introducing HelmReleaseMetadataRequest and related getter methods, and refactored error detail management to support external helm release validations.

Other Improvements - Code Refactoring and Cleanup

DeploymentPipelineRestHandler.go - Renamed validation method for improved clarity in external app link requests.

PipelineConfigRouter.go - Updated route to invoke the new external app link validation handler.

wire_gen.go - Modified code generation command, adjusted import aliases, and updated repository configurations to streamline dependency management.

adapter.go - Updated time parsing logic with improved variable declaration for better error handling.

GitOperationService.go - Removed outdated GetRepoUrlByRepoName method and cleaned up Git operation functions.

TriggerService_ent1.go - Refactored helm history metadata retrieval logic and consolidated cluster configuration conversion in TriggerService.

wire_gen.go - Updated code generation command, import aliases, and dependency initializations to streamline dependency management.

Other Improvements - Environment Configuration and Documentation Update

env_gen.json - Updated environment JSON configuration with new field REVISION_HISTORY_LIMIT_LINKED_HELM_APP added and deployment config flag changed to true.

env_gen.md - Added documentation row for REVISION_HISTORY_LIMIT_LINKED_HELM_APP reflecting the recent configuration enhancements.

Bug Fix - Bug Fixes and Standardization

InternalErrorCode.go - Modified error code constants; replaced the invalid GitOps repo URL error with GitOpsNotConfigured and adjusted the sequence numbering to maintain consistency.

GitOpsConfigReadService.go - Replaced error code for invalid GitOps repo URL with standardized GitOpsNotConfigured in GitOps config service.

gitOpsValidationService.go - Updated error handling and codes in GitOps validation to provide clearer repository error messages.

GlobalConfig.go - Fixed feature flag evaluation with added nil check and proper return based on configuration.

Copy link

@bito-code-review bito-code-review 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 Agent Run #ed35c6

Actionable Suggestions - 6
  • pkg/cluster/environment/bean/bean.go - 1
    • Missing certificate field population in adapter · Line 39-39
  • pkg/chart/read/ChartReadService.go - 2
  • api/helm-app/service/HelmAppService.go - 2
  • api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go - 1
Review Details
  • Files reviewed - 35 · Commit Range: dcfd98b..82503e6
    • api/helm-app/HelmAppRestHandler.go
    • api/helm-app/HelmAppRouter.go
    • api/helm-app/bean/bean.go
    • api/helm-app/gRPC/applicationClient.go
    • api/helm-app/gRPC/applist.pb.go
    • api/helm-app/gRPC/applist.proto
    • api/helm-app/gRPC/applist_grpc.pb.go
    • api/helm-app/service/HelmAppService.go
    • api/helm-app/service/adapter/adapter.go
    • api/helm-app/service/bean/bean.go
    • api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go
    • api/router/app/pipeline/configure/PipelineConfigRouter.go
    • cmd/external-app/wire_gen.go
    • env_gen.json
    • env_gen.md
    • internal/constants/InternalErrorCode.go
    • internal/sql/repository/pipelineConfig/PipelineRepository.go
    • pkg/app/appDetails/adapter/adapter.go
    • pkg/appStore/installedApp/repository/InstalledAppRepository.go
    • pkg/appStore/installedApp/service/bean/bean.go
    • pkg/argoApplication/ArgoApplicationServiceExtended.go
    • pkg/bean/app.go
    • pkg/chart/read/ChartReadService.go
    • pkg/cluster/environment/adapter/adapter.go
    • pkg/cluster/environment/bean/bean.go
    • pkg/deployment/gitOps/config/GitOpsConfigReadService.go
    • pkg/deployment/gitOps/git/GitOperationService.go
    • pkg/deployment/gitOps/validation/gitOpsValidationService.go
    • pkg/deployment/trigger/devtronApps/TriggerService.go
    • pkg/deployment/trigger/devtronApps/TriggerService_ent1.go
    • pkg/pipeline/DeploymentPipelineConfigService.go
    • pkg/pipeline/adapter/adapter.go
    • pkg/pipeline/bean/ExternalArgoAppLink.go
    • util/GlobalConfig.go
    • wire_gen.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at shivam@devtron.ai.

Documentation & Help

AI Code Review powered by Bito Logo

ClusterToken string `json:"-"`
InsecureSkipTlsVerify bool `json:"-"`
ClusterConfig map[string]string `json:"-"`
ClusterCAData string `json:"-"`

Choose a reason for hiding this comment

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

Missing certificate field population in adapter

The new certificate fields ClusterCAData, ClusterKeyData, and ClusterCertData are added to the struct but the adapter function in pkg/cluster/environment/adapter/adapter.go is not populating these fields from the cluster configuration. This will cause these fields to always be empty even when certificate data is available in the cluster config.

Code suggestion
Check the AI-generated fix before applying
 @@ -34,6 +34,9 @@
  	envBean.InsecureSkipTlsVerify = envModel.Cluster.InsecureSkipTlsVerify
 +	envBean.ClusterCAData = envModel.Cluster.Config[commonBean.CertificateAuthorityData]
 +	envBean.ClusterKeyData = envModel.Cluster.Config[commonBean.TlsKey]
 +	envBean.ClusterCertData = envModel.Cluster.Config[commonBean.CertData]
  }

Code Review Run #ed35c6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

chartRef, err := impl.ChartRefReadService.FindById(latestChart.ChartRefId)
if err != nil {
impl.logger.Errorw("error in finding latest chart by appId", "appId", appId, "err", err)
return nil, nil

Choose a reason for hiding this comment

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

Improper error handling masks failures

Error handling returns nil, nil instead of propagating the actual error. This will mask failures and make debugging difficult. Change to return nil, err to properly propagate errors to callers.

Code suggestion
Check the AI-generated fix before applying
Suggested change
return nil, nil
return nil, err

Code Review Run #ed35c6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

chartRef, err := impl.ChartRefReadService.FindById(latestChart.ChartRefId)
if err != nil {
impl.logger.Errorw("error in finding latest chart by appId", "appId", appId, "err", err)
return nil, nil

Choose a reason for hiding this comment

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

Improper error handling masks failures

Error handling returns nil, nil instead of propagating the actual error. This will mask failures and make debugging difficult. Change to return nil, err to properly propagate errors to callers.

Code suggestion
Check the AI-generated fix before applying
Suggested change
return nil, nil
return nil, err

Code Review Run #ed35c6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

return nil, err
}

cdPipeline := make([]*pipelineConfig.PipelineDeploymentConfigObj, len(cdPipelineDbObj))

Choose a reason for hiding this comment

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

Incorrect slice initialization with append

Slice pre-allocation with append() will create incorrect slice structure. The slice is initialized with length len(cdPipelineDbObj) but then append() adds elements beyond this length, resulting in nil elements at the beginning. Fix: use make([]*pipelineConfig.PipelineDeploymentConfigObj, 0, len(cdPipelineDbObj))

Code suggestion
Check the AI-generated fix before applying
Suggested change
cdPipeline := make([]*pipelineConfig.PipelineDeploymentConfigObj, len(cdPipelineDbObj))
cdPipeline := make([]*pipelineConfig.PipelineDeploymentConfigObj, 0, len(cdPipelineDbObj))

Code Review Run #ed35c6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

return nil, err
}

installedApps := make([]bean3.DeployedInstalledAppInfo, len(installedAppDBObj))

Choose a reason for hiding this comment

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

Incorrect slice initialization with append

Slice pre-allocation with append() will create incorrect slice structure. The slice is initialized with length len(installedAppDBObj) but then append() adds elements beyond this length, resulting in zero-value elements at the beginning. Fix: use make([]bean3.DeployedInstalledAppInfo, 0, len(installedAppDBObj))

Code suggestion
Check the AI-generated fix before applying
Suggested change
installedApps := make([]bean3.DeployedInstalledAppInfo, len(installedAppDBObj))
installedApps := make([]bean3.DeployedInstalledAppInfo, 0, len(installedAppDBObj))

Code Review Run #ed35c6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

} else {
} else if request.DeploymentAppType == util.PIPELINE_DEPLOYMENT_TYPE_HELM {
response := handler.pipelineBuilder.ValidateLinkHelmAppRequest(ctx, &request)
common.WriteJsonResp(w, err, response, http.StatusOK)

Choose a reason for hiding this comment

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

Wrong error variable in success response

The WriteJsonResp call uses the wrong error variable err from the earlier user authentication check instead of nil for a successful validation response. This will cause the API to return an error status even when Helm validation succeeds. Replace err with nil.

Code suggestion
Check the AI-generated fix before applying
Suggested change
common.WriteJsonResp(w, err, response, http.StatusOK)
common.WriteJsonResp(w, nil, response, http.StatusOK)

Code Review Run #ed35c6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants