Skip to content

Commit 9621453

Browse files
feat: deployment config migration (#5368)
* inital commit - deployment config service * wip: migration changes for devtron apps * changes for helm apps * dev testing fixes * wire fix * bulk get function * wip: bulk logic fixes * wip: bulk fixes * feat: Cd pipeline migration sql and query usage update (#5416) * Added sql * removed unused mthod * wip * wip * wip * wip * wip * wip * QUERY : updated GetOfLatestCdWfrByCdPipelineId * QUERY : GetOfLatestInstalledAppVersionHistoryByInstalledAppVersionId * QUERY : fix GetOfLatestCdWfrByCdPipelineId * QUERY : fix GetOfLatestInstalledAppVersionHistoryByInstalledAppVersionId * QUERY : updated GetLatestTriggersOfHelmPipelinesStuckInNonTerminalStatuses * QUERY : updated GetArgoPipelineByArgoAppName * QUERY : updated GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses * QUERY : updated GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelines * QUERY : updated GetAppAndEnvDetailsForDeploymentAppTypePipeline * QUERY : updated FindActiveByEnvIdAndDeploymentType * QUERY : updated GetActiveInstalledAppByEnvIdAndDeploymentType * QUERY : updated GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelinesForAppStore * QUERY : updated GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatusesForAppStore * QUERY : updated GetInstalledAppByInstalledAppVersionId * QUERY : updated GetInstalledAppByAppIdAndDeploymentType * QUERY : updated GetAppAndEnvDetailsForDeploymentAppTypeInstalledApps * QUERY : updated FindLatestByAppIdAndEnvId * QUERY : updated GetInstalledAppByGitRepoUrl * QUERY : updated FindChartByGitRepoUrl * dev testing fixes * QUERY : UPDATED buildAppListingWhereCondition and FIXED deploymentDetailsByAppIdAndEnvId * function for bulk update config * query changes * remaining query changes * PR review changes and logical fixes * nil pointer fix * fix cd pipeline helm app create * dev testing fixes * updating app stages status check * query active check for deployment config * wip * adding flag for migration and removing bulk code * build fix * wip: modifying get function * handling custom gitops case for app clone * handling app clone with custom gitops for system generated url * fix: wrong call for helm app deployment app type change * fix migration function for helm app * wip: updating dc on template update * fix: replacing migrate with get call * fix: wrong call for helm app * minor fixes * renaming chart path * updating deprecated columns * updating dc.active * updating dc.active * fix redirection * removing chart path * updating migration * conditions in patch object * fix error in flag off-> custom-gitops-> app-clone-> deploy-> flag-on-> migrate * wire fix * audit log fix * migation update * reverted 107 sql newline add --------- Co-authored-by: kartik-579 <kartik@devtron.ai> Co-authored-by: kartik-579 <84493919+kartik-579@users.noreply.github.com>
1 parent cf5d60c commit 9621453

File tree

65 files changed

+2076
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2076
-503
lines changed

Wire.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import (
9393
appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
9494
"github.com/devtron-labs/devtron/internal/sql/repository/bulkUpdate"
9595
"github.com/devtron-labs/devtron/internal/sql/repository/chartConfig"
96+
"github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig"
9697
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
9798
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
9899
repository8 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging"
@@ -122,6 +123,7 @@ import (
122123
"github.com/devtron-labs/devtron/pkg/commonService"
123124
delete2 "github.com/devtron-labs/devtron/pkg/delete"
124125
deployment2 "github.com/devtron-labs/devtron/pkg/deployment"
126+
"github.com/devtron-labs/devtron/pkg/deployment/common"
125127
git2 "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git"
126128
"github.com/devtron-labs/devtron/pkg/deployment/manifest/publish"
127129
"github.com/devtron-labs/devtron/pkg/deploymentGroup"
@@ -207,13 +209,13 @@ func InitializeApp() (*App, error) {
207209
wire.Bind(new(gitSensor.Client), new(*gitSensor.ClientImpl)),
208210
// -------
209211
helper.NewAppListingRepositoryQueryBuilder,
210-
// sql.GetConfig,
212+
// sql.GetConfigForDevtronApps,
211213
eClient.GetEventClientConfig,
212214
// sql.NewDbConnection,
213215
// app.GetACDAuthConfig,
214216
util3.GetACDAuthConfig,
215217
connection.SettingsManager,
216-
// auth.GetConfig,
218+
// auth.GetConfigForDevtronApps,
217219

218220
connection.GetConfig,
219221
wire.Bind(new(session2.ServiceClient), new(*middleware.LoginService)),
@@ -434,7 +436,7 @@ func InitializeApp() (*App, error) {
434436
wire.Bind(new(repository2.ServiceClient), new(*repository2.ServiceClientImpl)),
435437
wire.Bind(new(connector.Pump), new(*connector.PumpImpl)),
436438

437-
//app.GetConfig,
439+
//app.GetConfigForDevtronApps,
438440

439441
pipeline.GetEcrConfig,
440442
// otel.NewOtelTracingServiceImpl,
@@ -877,8 +879,8 @@ func InitializeApp() (*App, error) {
877879
wire.Bind(new(repository.UserAttributesRepository), new(*repository.UserAttributesRepositoryImpl)),
878880
pipelineConfig.NewPipelineStatusTimelineRepositoryImpl,
879881
wire.Bind(new(pipelineConfig.PipelineStatusTimelineRepository), new(*pipelineConfig.PipelineStatusTimelineRepositoryImpl)),
880-
wire.Bind(new(pipeline.DeploymentConfigService), new(*pipeline.DeploymentConfigServiceImpl)),
881-
pipeline.NewDeploymentConfigServiceImpl,
882+
wire.Bind(new(pipeline.PipelineDeploymentConfigService), new(*pipeline.PipelineDeploymentConfigServiceImpl)),
883+
pipeline.NewPipelineDeploymentConfigServiceImpl,
882884
pipelineConfig.NewCiTemplateOverrideRepositoryImpl,
883885
wire.Bind(new(pipelineConfig.CiTemplateOverrideRepository), new(*pipelineConfig.CiTemplateOverrideRepositoryImpl)),
884886
pipelineConfig.NewCiBuildConfigRepositoryImpl,
@@ -975,6 +977,12 @@ func InitializeApp() (*App, error) {
975977

976978
cel.NewCELServiceImpl,
977979
wire.Bind(new(cel.EvaluatorService), new(*cel.EvaluatorServiceImpl)),
980+
981+
deploymentConfig.NewRepositoryImpl,
982+
wire.Bind(new(deploymentConfig.Repository), new(*deploymentConfig.RepositoryImpl)),
983+
984+
common.NewDeploymentConfigServiceImpl,
985+
wire.Bind(new(common.DeploymentConfigService), new(*common.DeploymentConfigServiceImpl)),
978986
)
979987
return &App{}, nil
980988
}

api/appStore/InstalledAppRestHandler.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource"
2828
util3 "github.com/devtron-labs/devtron/pkg/appStore/util"
2929
"github.com/devtron-labs/devtron/pkg/bean"
30+
"gopkg.in/go-playground/validator.v9"
3031
"net/http"
3132
"reflect"
3233
"strconv"
@@ -48,14 +49,14 @@ import (
4849
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
4950
"github.com/devtron-labs/devtron/pkg/auth/user"
5051
"github.com/devtron-labs/devtron/pkg/cluster"
52+
bean3 "github.com/devtron-labs/devtron/pkg/deployment/common/bean"
5153
"github.com/devtron-labs/devtron/util"
5254
"github.com/devtron-labs/devtron/util/argo"
5355
"github.com/devtron-labs/devtron/util/rbac"
5456
"github.com/devtron-labs/devtron/util/response"
5557
"github.com/go-pg/pg"
5658
"github.com/gorilla/mux"
5759
"go.uber.org/zap"
58-
"gopkg.in/go-playground/validator.v9"
5960
)
6061

6162
type InstalledAppRestHandler interface {
@@ -744,8 +745,8 @@ func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w htt
744745
resourceTreeAndNotesContainer.ResourceTree = map[string]interface{}{}
745746

746747
if len(installedApp.App.AppName) > 0 && len(installedApp.Environment.Name) > 0 {
747-
err = handler.fetchResourceTree(w, r, &resourceTreeAndNotesContainer, *installedApp, "", "")
748-
if installedApp.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD {
748+
err = handler.fetchResourceTree(w, r, &resourceTreeAndNotesContainer, *installedApp, appDetail.DeploymentConfig, "", "")
749+
if appDetail.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD {
749750
apiError, ok := err.(*util2.ApiError)
750751
if ok && apiError != nil {
751752
if apiError.Code == constants.AppDetailResourceTreeNotFound && installedApp.DeploymentAppDeleteRequest == true {
@@ -868,8 +869,8 @@ func (handler *InstalledAppRestHandlerImpl) FetchResourceTree(w http.ResponseWri
868869
resourceTreeAndNotesContainer.ResourceTree = map[string]interface{}{}
869870

870871
if len(installedApp.App.AppName) > 0 && len(installedApp.Environment.Name) > 0 {
871-
err = handler.fetchResourceTree(w, r, &resourceTreeAndNotesContainer, *installedApp, appDetail.HelmReleaseInstallStatus, appDetail.Status)
872-
if installedApp.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD {
872+
err = handler.fetchResourceTree(w, r, &resourceTreeAndNotesContainer, *installedApp, appDetail.DeploymentConfig, appDetail.HelmReleaseInstallStatus, appDetail.Status)
873+
if appDetail.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD {
873874
//resource tree has been fetched now prepare to sync application deployment status with this resource tree call
874875
handler.syncDeploymentStatusWithResourceTreeCall(appDetail)
875876
apiError, ok := err.(*util2.ApiError)
@@ -960,10 +961,10 @@ func (handler *InstalledAppRestHandlerImpl) FetchResourceTreeForACDApp(w http.Re
960961
common.WriteJsonResp(w, err, appDetail, http.StatusOK)
961962
}
962963

963-
func (handler *InstalledAppRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, resourceTreeAndNotesContainer *bean2.AppDetailsContainer, installedApp repository.InstalledApps, helmReleaseInstallStatus string, status string) error {
964+
func (handler *InstalledAppRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, resourceTreeAndNotesContainer *bean2.AppDetailsContainer, installedApp repository.InstalledApps, deploymentConfig *bean3.DeploymentConfig, helmReleaseInstallStatus string, status string) error {
964965
ctx := r.Context()
965966
cn, _ := w.(http.CloseNotifier)
966-
err := handler.installedAppResourceService.FetchResourceTree(ctx, cn, resourceTreeAndNotesContainer, installedApp, helmReleaseInstallStatus, status)
967+
err := handler.installedAppResourceService.FetchResourceTree(ctx, cn, resourceTreeAndNotesContainer, installedApp, deploymentConfig, helmReleaseInstallStatus, status)
967968
return err
968969
}
969970

api/bean/AppView.go

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package bean
1919
import (
2020
"encoding/json"
2121
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
22+
"github.com/devtron-labs/devtron/pkg/deployment/common/bean"
2223
"time"
2324
)
2425

@@ -141,46 +142,47 @@ type AppEnvironmentContainer struct {
141142
}
142143

143144
type DeploymentDetailContainer struct {
144-
InstalledAppId int `json:"installedAppId,omitempty"`
145-
AppId int `json:"appId,omitempty"`
146-
CdPipelineId int `json:"cdPipelineId,omitempty"`
147-
TriggerType string `json:"triggerType,omitempty"`
148-
ParentEnvironmentName string `json:"parentEnvironmentName"`
149-
AppStoreInstalledAppVersionId int `json:"appStoreInstalledAppVersionId,omitempty"`
150-
AppStoreChartName string `json:"appStoreChartName,omitempty"`
151-
AppStoreChartId int `json:"appStoreChartId,omitempty"`
152-
AppStoreAppName string `json:"appStoreAppName,omitempty"`
153-
AppStoreAppVersion string `json:"appStoreAppVersion,omitempty"`
154-
AppName string `json:"appName"`
155-
EnvironmentId int `json:"environmentId"`
156-
EnvironmentName string `json:"environmentName"`
157-
Namespace string `json:"namespace,omitempty"`
158-
Status string `json:"status,omitempty"`
159-
StatusMessage string `json:"statusMessage,omitempty"`
160-
LastDeployedTime string `json:"lastDeployedTime,omitempty"`
161-
LastDeployedBy string `json:"lastDeployedBy,omitempty"`
162-
MaterialInfo json.RawMessage `json:"materialInfo,omitempty"`
163-
MaterialInfoJsonString string `json:"-"`
164-
ReleaseVersion string `json:"releaseVersion,omitempty"`
165-
Default bool `json:"default,omitempty"`
166-
DataSource string `json:"dataSource,omitempty"`
167-
LastDeployedPipeline string `json:"lastDeployedPipeline,omitempty"`
168-
Deprecated bool `json:"deprecated"`
169-
K8sVersion string `json:"k8sVersion"`
170-
CiArtifactId int `json:"ciArtifactId"`
171-
ParentArtifactId int `json:"parentArtifactId"`
172-
ClusterId int `json:"clusterId"`
173-
DeploymentAppType string `json:"deploymentAppType"`
174-
CiPipelineId int `json:"ciPipelineId,omitempty"`
175-
IsExternalCi bool `json:"externalCi"`
176-
ClusterName string `json:"clusterName,omitempty"`
177-
DockerRegistryId string `json:"dockerRegistryId,omitempty"`
178-
IpsAccessProvided bool `json:"ipsAccessProvided"`
179-
DeploymentAppDeleteRequest bool `json:"deploymentAppDeleteRequest"`
180-
Description string `json:"description" validate:"max=40"`
181-
IsVirtualEnvironment bool `json:"isVirtualEnvironment"`
182-
HelmPackageName string `json:"helmPackageName"`
183-
HelmReleaseInstallStatus string `json:"-"`
145+
InstalledAppId int `json:"installedAppId,omitempty"`
146+
AppId int `json:"appId,omitempty"`
147+
CdPipelineId int `json:"cdPipelineId,omitempty"`
148+
TriggerType string `json:"triggerType,omitempty"`
149+
ParentEnvironmentName string `json:"parentEnvironmentName"`
150+
AppStoreInstalledAppVersionId int `json:"appStoreInstalledAppVersionId,omitempty"`
151+
AppStoreChartName string `json:"appStoreChartName,omitempty"`
152+
AppStoreChartId int `json:"appStoreChartId,omitempty"`
153+
AppStoreAppName string `json:"appStoreAppName,omitempty"`
154+
AppStoreAppVersion string `json:"appStoreAppVersion,omitempty"`
155+
AppName string `json:"appName"`
156+
EnvironmentId int `json:"environmentId"`
157+
EnvironmentName string `json:"environmentName"`
158+
Namespace string `json:"namespace,omitempty"`
159+
Status string `json:"status,omitempty"`
160+
StatusMessage string `json:"statusMessage,omitempty"`
161+
LastDeployedTime string `json:"lastDeployedTime,omitempty"`
162+
LastDeployedBy string `json:"lastDeployedBy,omitempty"`
163+
MaterialInfo json.RawMessage `json:"materialInfo,omitempty"`
164+
MaterialInfoJsonString string `json:"-"`
165+
ReleaseVersion string `json:"releaseVersion,omitempty"`
166+
Default bool `json:"default,omitempty"`
167+
DataSource string `json:"dataSource,omitempty"`
168+
LastDeployedPipeline string `json:"lastDeployedPipeline,omitempty"`
169+
Deprecated bool `json:"deprecated"`
170+
K8sVersion string `json:"k8sVersion"`
171+
CiArtifactId int `json:"ciArtifactId"`
172+
ParentArtifactId int `json:"parentArtifactId"`
173+
ClusterId int `json:"clusterId"`
174+
DeploymentAppType string `json:"deploymentAppType"`
175+
CiPipelineId int `json:"ciPipelineId,omitempty"`
176+
IsExternalCi bool `json:"externalCi"`
177+
ClusterName string `json:"clusterName,omitempty"`
178+
DockerRegistryId string `json:"dockerRegistryId,omitempty"`
179+
IpsAccessProvided bool `json:"ipsAccessProvided"`
180+
DeploymentAppDeleteRequest bool `json:"deploymentAppDeleteRequest"`
181+
Description string `json:"description" validate:"max=40"`
182+
IsVirtualEnvironment bool `json:"isVirtualEnvironment"`
183+
HelmPackageName string `json:"helmPackageName"`
184+
HelmReleaseInstallStatus string `json:"-"`
185+
DeploymentConfig *bean.DeploymentConfig `json:"-"`
184186
}
185187

186188
type AppDetailContainer struct {

api/bean/gitOps/GitOpsConfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ const (
6969
func IsGitOpsRepoNotConfigured(gitRepoUrl string) bool {
7070
return len(gitRepoUrl) == 0 || gitRepoUrl == GIT_REPO_NOT_CONFIGURED
7171
}
72+
73+
func IsGitOpsRepoConfigured(gitRepoUrl string) bool {
74+
return len(gitRepoUrl) != 0 || gitRepoUrl != GIT_REPO_NOT_CONFIGURED
75+
}

api/helm-app/service/HelmAppService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (impl *HelmAppServiceImpl) ListHelmApplications(ctx context.Context, cluste
169169
impl.logger.Errorw("error in fetching helm app list from DB created using cd_pipelines", "clusters", clusterIds, "err", err)
170170
}
171171

172-
// if not hyperion mode, then fetch from installed_apps whose deployment_app_type is helm (as in hyperion mode, these apps should be treated as external-apps)
172+
// if not hyperion mode, then fetch from installed_apps whose deploymentAppType is helm (as in hyperion mode, these apps should be treated as external-apps)
173173
if !util2.IsBaseStack() {
174174
newCtx, span = otel.Tracer("pipelineRepository").Start(newCtx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
175175
start = time.Now()

0 commit comments

Comments
 (0)