diff --git a/Wire.go b/Wire.go index 6e88871c2d4..44587f0bc12 100644 --- a/Wire.go +++ b/Wire.go @@ -122,6 +122,7 @@ import ( "github.com/devtron-labs/devtron/pkg/asyncProvider" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/build" + pipeline6 "github.com/devtron-labs/devtron/pkg/build/pipeline" "github.com/devtron-labs/devtron/pkg/bulkAction" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" @@ -132,6 +133,8 @@ import ( deployment2 "github.com/devtron-labs/devtron/pkg/deployment" "github.com/devtron-labs/devtron/pkg/deployment/common" git2 "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/deployment/manifest/publish" "github.com/devtron-labs/devtron/pkg/deploymentGroup" "github.com/devtron-labs/devtron/pkg/dockerRegistry" @@ -209,7 +212,6 @@ func InitializeApp() (*App, error) { workflow3.WorkflowWireSet, devtronResource.DevtronResourceWireSet, - // -------wireset end ---------- // ------- gitSensor.GetConfig, @@ -819,10 +821,10 @@ func InitializeApp() (*App, error) { wire.Bind(new(history3.PrePostCdScriptHistoryService), new(*history3.PrePostCdScriptHistoryServiceImpl)), history3.NewPrePostCiScriptHistoryServiceImpl, wire.Bind(new(history3.PrePostCiScriptHistoryService), new(*history3.PrePostCiScriptHistoryServiceImpl)), - history3.NewDeploymentTemplateHistoryServiceImpl, - wire.Bind(new(history3.DeploymentTemplateHistoryService), new(*history3.DeploymentTemplateHistoryServiceImpl)), - history3.NewConfigMapHistoryServiceImpl, - wire.Bind(new(history3.ConfigMapHistoryService), new(*history3.ConfigMapHistoryServiceImpl)), + deploymentTemplate.NewDeploymentTemplateHistoryServiceImpl, + wire.Bind(new(deploymentTemplate.DeploymentTemplateHistoryService), new(*deploymentTemplate.DeploymentTemplateHistoryServiceImpl)), + configMapAndSecret.NewConfigMapHistoryServiceImpl, + wire.Bind(new(configMapAndSecret.ConfigMapHistoryService), new(*configMapAndSecret.ConfigMapHistoryServiceImpl)), history3.NewPipelineStrategyHistoryServiceImpl, wire.Bind(new(history3.PipelineStrategyHistoryService), new(*history3.PipelineStrategyHistoryServiceImpl)), history3.NewGitMaterialHistoryServiceImpl, @@ -903,6 +905,8 @@ func InitializeApp() (*App, error) { wire.Bind(new(pipeline.CiBuildConfigService), new(*pipeline.CiBuildConfigServiceImpl)), pipeline.NewCiTemplateServiceImpl, wire.Bind(new(pipeline.CiTemplateService), new(*pipeline.CiTemplateServiceImpl)), + pipeline6.NewCiTemplateReadServiceImpl, + wire.Bind(new(pipeline6.CiTemplateReadService), new(*pipeline6.CiTemplateReadServiceImpl)), router.NewGlobalCMCSRouterImpl, wire.Bind(new(router.GlobalCMCSRouter), new(*router.GlobalCMCSRouterImpl)), restHandler.NewGlobalCMCSRestHandlerImpl, diff --git a/api/appbean/AppDetail.go b/api/appbean/AppDetail.go index 7da09df2529..954c8f03902 100644 --- a/api/appbean/AppDetail.go +++ b/api/appbean/AppDetail.go @@ -19,9 +19,9 @@ package appbean import ( "github.com/devtron-labs/devtron/internal/sql/models" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/chartRepo/repository" "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" ) type AppDetail struct { @@ -62,11 +62,11 @@ type GitMaterial struct { } type DockerConfig struct { - DockerRegistry string `json:"dockerRegistry" validate:"required"` - DockerRepository string `json:"dockerRepository" validate:"required"` - CiBuildConfig *CiPipeline.CiBuildConfigBean `json:"ciBuildConfig"` - DockerBuildConfig *DockerBuildConfig `json:"dockerBuildConfig,omitempty"` // Deprecated, should use CiBuildConfig for development - CheckoutPath string `json:"checkoutPath"` + DockerRegistry string `json:"dockerRegistry" validate:"required"` + DockerRepository string `json:"dockerRepository" validate:"required"` + CiBuildConfig *bean2.CiBuildConfigBean `json:"ciBuildConfig"` + DockerBuildConfig *DockerBuildConfig `json:"dockerBuildConfig,omitempty"` // Deprecated, should use CiBuildConfig for development + CheckoutPath string `json:"checkoutPath"` } type DockerBuildConfig struct { diff --git a/api/k8s/capacity/k8sCapacityRestHandler.go b/api/k8s/capacity/k8sCapacityRestHandler.go index 25e00acf27a..df6daf1ff2f 100644 --- a/api/k8s/capacity/k8sCapacityRestHandler.go +++ b/api/k8s/capacity/k8sCapacityRestHandler.go @@ -103,6 +103,8 @@ func (handler *K8sCapacityRestHandlerImpl) GetClusterListRaw(w http.ResponseWrit Id: cluster.Id, Name: cluster.ClusterName, ErrorInConnection: cluster.ErrorInConnecting, + IsVirtualCluster: cluster.IsVirtualCluster, + IsProd: cluster.IsProd, } clusterDetailList = append(clusterDetailList, clusterDetail) } diff --git a/api/restHandler/CoreAppRestHandler.go b/api/restHandler/CoreAppRestHandler.go index efac7046514..fbd4e987042 100644 --- a/api/restHandler/CoreAppRestHandler.go +++ b/api/restHandler/CoreAppRestHandler.go @@ -22,7 +22,7 @@ import ( "errors" "fmt" app2 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline/configure" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + bean3 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "net/http" "strconv" "strings" @@ -1323,9 +1323,9 @@ func (handler CoreAppRestHandlerImpl) createDockerConfig(appId int, dockerConfig dockerBuildConfig := dockerConfig.DockerBuildConfig if dockerBuildConfig != nil { dockerConfig.CheckoutPath = dockerBuildConfig.GitCheckoutPath - dockerConfig.CiBuildConfig = &CiPipeline.CiBuildConfigBean{ - CiBuildType: CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, - DockerBuildConfig: &CiPipeline.DockerBuildConfig{ + dockerConfig.CiBuildConfig = &bean3.CiBuildConfigBean{ + CiBuildType: bean3.SELF_DOCKERFILE_BUILD_TYPE, + DockerBuildConfig: &bean3.DockerBuildConfig{ DockerfilePath: dockerBuildConfig.DockerfileRelativePath, DockerBuildOptions: dockerBuildConfig.DockerBuildOptions, Args: dockerBuildConfig.Args, @@ -1546,7 +1546,7 @@ func (handler CoreAppRestHandlerImpl) createWorkflows(ctx context.Context, appId //Creating CI pipeline starts ciPipeline, err := handler.createCiPipeline(appId, userId, workflowId, workflow.CiPipeline) if err != nil { - if err.Error() == CiPipeline.PIPELINE_NAME_ALREADY_EXISTS_ERROR { + if err.Error() == bean3.PIPELINE_NAME_ALREADY_EXISTS_ERROR { handler.logger.Errorw("service err, DeleteAppWorkflow ", "err", err) return err, http.StatusBadRequest } @@ -1683,7 +1683,7 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32, ParentCiPipeline: ciPipelineData.ParentCiPipeline, ParentAppId: ciPipelineData.ParentAppId, LinkedCount: ciPipelineData.LinkedCount, - PipelineType: CiPipeline.PipelineType(ciPipelineData.PipelineType), + PipelineType: bean3.PipelineType(ciPipelineData.PipelineType), }, } diff --git a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go index 0a1115a44c0..58c1c03180a 100644 --- a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go +++ b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go @@ -21,13 +21,13 @@ import ( "encoding/json" "errors" "fmt" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "golang.org/x/exp/maps" "io" "net/http" "strconv" "strings" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/util/response/pagination" "github.com/gorilla/schema" @@ -441,8 +441,8 @@ func (handler *PipelineConfigRestHandlerImpl) PatchCiPipelines(w http.ResponseWr ciConfigRequest := bean.CiConfigRequest{} ciConfigRequest.DockerRegistry = emptyDockerRegistry ciConfigRequest.AppId = patchRequest.AppId - ciConfigRequest.CiBuildConfig = &CiPipeline.CiBuildConfigBean{} - ciConfigRequest.CiBuildConfig.CiBuildType = CiPipeline.SKIP_BUILD_TYPE + ciConfigRequest.CiBuildConfig = &bean2.CiBuildConfigBean{} + ciConfigRequest.CiBuildConfig.CiBuildType = bean2.SKIP_BUILD_TYPE ciConfigRequest.UserId = patchRequest.UserId if patchRequest.CiPipeline == nil || patchRequest.CiPipeline.CiMaterial == nil { handler.Logger.Errorw("Invalid patch ci-pipeline request", "request", patchRequest, "err", "invalid CiPipeline data") @@ -463,7 +463,7 @@ func (handler *PipelineConfigRestHandlerImpl) PatchCiPipelines(w http.ResponseWr } createResp, err := handler.pipelineBuilder.PatchCiPipeline(&patchRequest) if err != nil { - if err.Error() == CiPipeline.PIPELINE_NAME_ALREADY_EXISTS_ERROR { + if err.Error() == bean2.PIPELINE_NAME_ALREADY_EXISTS_ERROR { handler.Logger.Errorw("service err, pipeline name already exist ", "err", err) common.WriteJsonResp(w, err, nil, http.StatusBadRequest) return @@ -2254,7 +2254,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetSourceCiDownStreamInfo(w http.R return } - req := &CiPipeline.SourceCiDownStreamFilters{} + req := &bean2.SourceCiDownStreamFilters{} err = decoder.Decode(req, r.URL.Query()) if err != nil { handler.Logger.Errorw("request err, GetSourceCiDownStreamInfo", "err", err, "payload", req) diff --git a/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go b/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go index c0a5b804cc4..ebc96f7d049 100644 --- a/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go +++ b/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go @@ -21,11 +21,11 @@ import ( "context" "encoding/json" "fmt" + bean3 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" - bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "io" "net/http" "strconv" diff --git a/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go b/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go index c0c6699d1ce..7a759af09cf 100644 --- a/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go +++ b/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go @@ -18,6 +18,8 @@ package history import ( "fmt" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "net/http" "strconv" @@ -44,8 +46,8 @@ type PipelineHistoryRestHandlerImpl struct { userAuthService user.UserService enforcer casbin.Enforcer strategyHistoryService history2.PipelineStrategyHistoryService - deploymentTemplateHistoryService history2.DeploymentTemplateHistoryService - configMapHistoryService history2.ConfigMapHistoryService + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService + configMapHistoryService configMapAndSecret.ConfigMapHistoryService prePostCiScriptHistoryService history2.PrePostCiScriptHistoryService prePostCdScriptHistoryService history2.PrePostCdScriptHistoryService enforcerUtil rbac.EnforcerUtil @@ -54,8 +56,8 @@ type PipelineHistoryRestHandlerImpl struct { func NewPipelineHistoryRestHandlerImpl(logger *zap.SugaredLogger, userAuthService user.UserService, enforcer casbin.Enforcer, strategyHistoryService history2.PipelineStrategyHistoryService, - deploymentTemplateHistoryService history2.DeploymentTemplateHistoryService, - configMapHistoryService history2.ConfigMapHistoryService, + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, + configMapHistoryService configMapAndSecret.ConfigMapHistoryService, prePostCiScriptHistoryService history2.PrePostCiScriptHistoryService, prePostCdScriptHistoryService history2.PrePostCdScriptHistoryService, enforcerUtil rbac.EnforcerUtil, diff --git a/client/cron/CiTriggerCron.go b/client/cron/CiTriggerCron.go index 9e841c6d997..c208ff8cc81 100644 --- a/client/cron/CiTriggerCron.go +++ b/client/cron/CiTriggerCron.go @@ -21,8 +21,8 @@ import ( "github.com/caarlos0/env" repository2 "github.com/devtron-labs/devtron/internal/sql/repository" "github.com/devtron-labs/devtron/pkg/bean" + pipelineConfigBean "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline" - pipelineConfigBean "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/repository" repository3 "github.com/devtron-labs/devtron/pkg/plugin/repository" cron2 "github.com/devtron-labs/devtron/util/cron" diff --git a/client/telemetry/TelemetryEventClientExtended.go b/client/telemetry/TelemetryEventClientExtended.go index 782e33cf510..7fd72219818 100644 --- a/client/telemetry/TelemetryEventClientExtended.go +++ b/client/telemetry/TelemetryEventClientExtended.go @@ -20,8 +20,8 @@ import ( "encoding/json" cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier" client "github.com/devtron-labs/devtron/api/helm-app/gRPC" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" cron3 "github.com/devtron-labs/devtron/util/cron" "net/http" "time" @@ -387,16 +387,16 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string) } payload.SelfDockerfileCount = selfDockerfileCount - payload.SelfDockerfileSuccessCount = successCount[CiPipeline.SELF_DOCKERFILE_BUILD_TYPE] - payload.SelfDockerfileFailureCount = failureCount[CiPipeline.SELF_DOCKERFILE_BUILD_TYPE] + payload.SelfDockerfileSuccessCount = successCount[bean.SELF_DOCKERFILE_BUILD_TYPE] + payload.SelfDockerfileFailureCount = failureCount[bean.SELF_DOCKERFILE_BUILD_TYPE] payload.ManagedDockerfileCount = managedDockerfileCount - payload.ManagedDockerfileSuccessCount = successCount[CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE] - payload.ManagedDockerfileFailureCount = failureCount[CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE] + payload.ManagedDockerfileSuccessCount = successCount[bean.MANAGED_DOCKERFILE_BUILD_TYPE] + payload.ManagedDockerfileFailureCount = failureCount[bean.MANAGED_DOCKERFILE_BUILD_TYPE] payload.BuildPackCount = buildpackCount - payload.BuildPackSuccessCount = successCount[CiPipeline.BUILDPACK_BUILD_TYPE] - payload.BuildPackFailureCount = failureCount[CiPipeline.BUILDPACK_BUILD_TYPE] + payload.BuildPackSuccessCount = successCount[bean.BUILDPACK_BUILD_TYPE] + payload.BuildPackFailureCount = failureCount[bean.BUILDPACK_BUILD_TYPE] reqBody, err := json.Marshal(payload) if err != nil { @@ -420,24 +420,24 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string) func (impl *TelemetryEventClientImplExtended) getCiBuildTypeData() (int, int, int) { countByBuildType := impl.ciBuildConfigService.GetCountByBuildType() - return countByBuildType[CiPipeline.SELF_DOCKERFILE_BUILD_TYPE], countByBuildType[CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE], countByBuildType[CiPipeline.BUILDPACK_BUILD_TYPE] + return countByBuildType[bean.SELF_DOCKERFILE_BUILD_TYPE], countByBuildType[bean.MANAGED_DOCKERFILE_BUILD_TYPE], countByBuildType[bean.BUILDPACK_BUILD_TYPE] } -func (impl *TelemetryEventClientImplExtended) getCiBuildTypeVsStatusVsCount() (successCount map[CiPipeline.CiBuildType]int, failureCount map[CiPipeline.CiBuildType]int) { - successCount = make(map[CiPipeline.CiBuildType]int) - failureCount = make(map[CiPipeline.CiBuildType]int) +func (impl *TelemetryEventClientImplExtended) getCiBuildTypeVsStatusVsCount() (successCount map[bean.CiBuildType]int, failureCount map[bean.CiBuildType]int) { + successCount = make(map[bean.CiBuildType]int) + failureCount = make(map[bean.CiBuildType]int) buildTypeAndStatusVsCount := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day() for _, buildTypeCount := range buildTypeAndStatusVsCount { if buildTypeCount == nil { continue } if buildTypeCount.Type == "" { - buildTypeCount.Type = string(CiPipeline.SELF_DOCKERFILE_BUILD_TYPE) + buildTypeCount.Type = string(bean.SELF_DOCKERFILE_BUILD_TYPE) } if buildTypeCount.Status == "Succeeded" { - successCount[CiPipeline.CiBuildType(buildTypeCount.Type)] = buildTypeCount.Count + successCount[bean.CiBuildType(buildTypeCount.Type)] = buildTypeCount.Count } else { - failureCount[CiPipeline.CiBuildType(buildTypeCount.Type)] = buildTypeCount.Count + failureCount[bean.CiBuildType(buildTypeCount.Type)] = buildTypeCount.Count } } return successCount, failureCount diff --git a/cmd/external-app/wire_gen.go b/cmd/external-app/wire_gen.go index 2c4e5a32b02..9aa1485c226 100644 --- a/cmd/external-app/wire_gen.go +++ b/cmd/external-app/wire_gen.go @@ -385,7 +385,7 @@ func InitializeApp() (*App, error) { moduleRestHandlerImpl := module2.NewModuleRestHandlerImpl(sugaredLogger, moduleServiceImpl, userServiceImpl, enforcerImpl, validate) moduleRouterImpl := module2.NewModuleRouterImpl(moduleRestHandlerImpl) serverActionAuditLogRepositoryImpl := server.NewServerActionAuditLogRepositoryImpl(db) - serverServiceImpl := server.NewServerServiceImpl(sugaredLogger, serverActionAuditLogRepositoryImpl, serverDataStoreServerDataStore, serverEnvConfigServerEnvConfig, helmAppServiceImpl, moduleRepositoryImpl) + serverServiceImpl := server.NewServerServiceImpl(sugaredLogger, serverActionAuditLogRepositoryImpl, serverDataStoreServerDataStore, serverEnvConfigServerEnvConfig, helmAppServiceImpl, moduleRepositoryImpl, serverCacheServiceImpl) serverRestHandlerImpl := server2.NewServerRestHandlerImpl(sugaredLogger, serverServiceImpl, userServiceImpl, enforcerImpl, validate) serverRouterImpl := server2.NewServerRouterImpl(serverRestHandlerImpl) apiTokenSecretServiceImpl, err := apiToken.NewApiTokenSecretServiceImpl(sugaredLogger, attributesServiceImpl, apiTokenSecretStore) diff --git a/go.mod b/go.mod index ab7367a2f70..b072072c7c5 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/go-pg/pg v6.15.1+incompatible github.com/go-resty/resty/v2 v2.7.0 github.com/gogo/protobuf v1.3.2 - github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/golang-jwt/jwt/v4 v4.5.1 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.4 github.com/google/cel-go v0.17.8 @@ -90,7 +90,7 @@ require ( k8s.io/client-go v0.29.7 k8s.io/helm v2.12.3+incompatible k8s.io/kubectl v0.29.7 - k8s.io/kubernetes v1.29.6 + k8s.io/kubernetes v1.29.10 k8s.io/metrics v0.29.7 k8s.io/utils v0.0.0-20230726121419-3b25d923346b sigs.k8s.io/yaml v1.4.0 @@ -288,7 +288,7 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect replace ( github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.10 - github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136 + github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241114074942-28eb96763c64 github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 k8s.io/api => k8s.io/api v0.29.7 diff --git a/go.sum b/go.sum index 4577dd412f5..170d467e91a 100644 --- a/go.sum +++ b/go.sum @@ -794,8 +794,8 @@ github.com/devtron-labs/argo-workflows/v3 v3.5.10 h1:6rxQOesOzDz6SgQCMDQNHaehsKF github.com/devtron-labs/argo-workflows/v3 v3.5.10/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA= github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 h1:2+Q7Jdhpo/uMiaQiZZzAh+ZX7wEJIFuMFG6DEiMuo64= github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8/go.mod h1:702R6WIf5y9UzKGoCGxQ+x3l5Ws+l0fXg2xlCpSGFZI= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136 h1:rNGxjU5L6NvObxGMt0+vNFmjkqstm7zDASiS+pakrgQ= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136/go.mod h1:KpKnF4OSpQNDJmb4wVZq3Za88ePBw4xec2GOAGRm5UQ= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241114074942-28eb96763c64 h1:RicDE0aJImRtIJTqcl7ssE8NH1c2xokJClGYfDR8i98= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241114074942-28eb96763c64/go.mod h1:NJSMdv+zTUK3p7rML12RZSeAUKHeLaoY3sR/oK0xhwo= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys= @@ -953,8 +953,9 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= +github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= @@ -2481,8 +2482,8 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/kubectl v0.29.7 h1:D+Jheug9M++zlt67cROZgxaIjrDdLqp9jkW/EYrXAoM= k8s.io/kubectl v0.29.7/go.mod h1:VOEJkcfKTO/X8xSSB6d2JXP/Qni6xtjuI3CUP52T9bM= -k8s.io/kubernetes v1.29.6 h1:jn8kA/oVOAWZOeoorx6xZ4d+KgGp+Evgi90x9bEI/DE= -k8s.io/kubernetes v1.29.6/go.mod h1:28sDhcb87LX5z3GWAKYmLrhrifxi4W9bEWua4DRTIvk= +k8s.io/kubernetes v1.29.10 h1:vlze77k0CbdevTbgliyxpSjfI3bvOUhPEJVSJAEUl5Q= +k8s.io/kubernetes v1.29.10/go.mod h1:L6/pfKQZ6Tv2O8gyT4OxhGZp+nNsjV54xtNodRoup9k= k8s.io/metrics v0.29.7 h1:/oMPdVL7dt+lF8W6lXTg9gIKz1dDKgVBfDnJwgyJrhk= k8s.io/metrics v0.29.7/go.mod h1:5AiYPn1Crd25wtTh7OxHg9Rm2t9THSXJVp3Lb2k7MB8= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= diff --git a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go index 47ab07622ad..4b4a54b96d1 100644 --- a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go @@ -22,7 +22,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/app" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/ciPipeline" "github.com/devtron-labs/devtron/pkg/cluster/repository" - ciPipelineBean "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + "github.com/devtron-labs/devtron/pkg/pipeline/constants" "github.com/devtron-labs/devtron/pkg/sql" "github.com/devtron-labs/devtron/util/response/pagination" "github.com/go-pg/pg" @@ -620,7 +620,7 @@ func (impl *CiPipelineRepositoryImpl) FindLinkedCiCount(ciPipelineId int) (int, pipeline := &CiPipeline{} cnt, err := impl.dbConnection.Model(pipeline). Where("parent_ci_pipeline = ?", ciPipelineId). - Where("ci_pipeline_type != ?", ciPipelineBean.LINKED_CD). + Where("ci_pipeline_type != ?", constants.LINKED_CD). Where("deleted = ?", false). Count() if err == pg.ErrNoRows { @@ -635,7 +635,7 @@ func (impl *CiPipelineRepositoryImpl) GetLinkedCiPipelines(ctx context.Context, var linkedCIPipelines []*CiPipeline err := impl.dbConnection.Model(&linkedCIPipelines). Where("parent_ci_pipeline = ?", ciPipelineId). - Where("ci_pipeline_type != ?", ciPipelineBean.LINKED_CD). + Where("ci_pipeline_type != ?", constants.LINKED_CD). Where("deleted = ?", false). Select() if err != nil { @@ -673,7 +673,7 @@ func (impl *CiPipelineRepositoryImpl) GetDownStreamInfo(ctx context.Context, sou JoinOn("e.active = ?", true). // constrains Where("ci_pipeline.parent_ci_pipeline = ?", sourceCiPipelineId). - Where("ci_pipeline.ci_pipeline_type != ?", ciPipelineBean.LINKED_CD). + Where("ci_pipeline.ci_pipeline_type != ?", constants.LINKED_CD). Where("ci_pipeline.deleted = ?", false) // app name filtering with lower case if len(appNameMatch) != 0 { diff --git a/pkg/appClone/AppCloneService.go b/pkg/appClone/AppCloneService.go index 952d94165af..c77e2220ff4 100644 --- a/pkg/appClone/AppCloneService.go +++ b/pkg/appClone/AppCloneService.go @@ -30,6 +30,7 @@ import ( "github.com/devtron-labs/devtron/pkg/appWorkflow" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/bean" + pipeline2 "github.com/devtron-labs/devtron/pkg/build/pipeline" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/pipeline" @@ -52,7 +53,7 @@ type AppCloneServiceImpl struct { appListingService app.AppListingService propertiesConfigService pipeline.PropertiesConfigService pipelineStageService pipeline.PipelineStageService - ciTemplateService pipeline.CiTemplateService + ciTemplateService pipeline2.CiTemplateReadService appRepository app2.AppRepository ciPipelineRepository pipelineConfig.CiPipelineRepository pipelineRepository pipelineConfig.PipelineRepository @@ -68,7 +69,7 @@ func NewAppCloneServiceImpl(logger *zap.SugaredLogger, appWorkflowService appWorkflow.AppWorkflowService, appListingService app.AppListingService, propertiesConfigService pipeline.PropertiesConfigService, - pipelineStageService pipeline.PipelineStageService, ciTemplateService pipeline.CiTemplateService, + pipelineStageService pipeline.PipelineStageService, ciTemplateService pipeline2.CiTemplateReadService, appRepository app2.AppRepository, ciPipelineRepository pipelineConfig.CiPipelineRepository, pipelineRepository pipelineConfig.PipelineRepository, ciPipelineConfigService pipeline.CiPipelineConfigService, diff --git a/pkg/bean/app.go b/pkg/bean/app.go index 4ac7f16d266..cf1158ea3d5 100644 --- a/pkg/bean/app.go +++ b/pkg/bean/app.go @@ -24,10 +24,10 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/helper" repository2 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + CiPipeline2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/chartRepo/repository" bean3 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean" "github.com/devtron-labs/devtron/pkg/pipeline/bean" - CiPipeline2 "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/repository" "strings" "time" diff --git a/pkg/build/pipeline/CiTemplateReadService.go b/pkg/build/pipeline/CiTemplateReadService.go new file mode 100644 index 00000000000..632b94c46d8 --- /dev/null +++ b/pkg/build/pipeline/CiTemplateReadService.go @@ -0,0 +1,183 @@ +package pipeline + +import ( + "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/internal/util" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" + "github.com/devtron-labs/devtron/pkg/pipeline/adapter" + "github.com/devtron-labs/devtron/pkg/pipeline/types" + "github.com/go-pg/pg" + "go.uber.org/zap" +) + +type CiTemplateReadService interface { + FindByAppId(appId int) (*bean.CiTemplateBean, error) + FindTemplateOverrideByAppId(appId int) ([]*bean.CiTemplateBean, error) + FindTemplateOverrideByCiPipelineIds(ciPipelineIds []int) ([]*bean.CiTemplateBean, error) + FindTemplateOverrideByCiPipelineId(ciPipelineId int) (*bean.CiTemplateBean, error) + GetAppliedDockerConfigForCiPipeline(ciPipelineId, appId int, isOverridden bool) (*types.DockerArtifactStoreBean, error) + GetBaseDockerConfigForCiPipeline(appId int) (*types.DockerArtifactStoreBean, error) + FindByAppIds(appIds []int) (map[int]*bean.CiTemplateBean, error) +} + +type CiTemplateReadServiceImpl struct { + Logger *zap.SugaredLogger + CiTemplateRepository pipelineConfig.CiTemplateRepository + CiTemplateOverrideRepository pipelineConfig.CiTemplateOverrideRepository +} + +func NewCiTemplateReadServiceImpl(logger *zap.SugaredLogger, ciTemplateRepository pipelineConfig.CiTemplateRepository, ciTemplateOverrideRepository pipelineConfig.CiTemplateOverrideRepository) *CiTemplateReadServiceImpl { + return &CiTemplateReadServiceImpl{ + Logger: logger, + CiTemplateRepository: ciTemplateRepository, + CiTemplateOverrideRepository: ciTemplateOverrideRepository, + } +} + +func (impl *CiTemplateReadServiceImpl) FindByAppId(appId int) (ciTemplateBean *bean.CiTemplateBean, err error) { + ciTemplate, err := impl.CiTemplateRepository.FindByAppId(appId) + if err != nil { + return nil, err + } + ciBuildConfig := ciTemplate.CiBuildConfig + ciBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(ciBuildConfig) + if err != nil { + impl.Logger.Errorw("error occurred while converting dbBuildConfig to bean", "ciBuildConfig", + ciBuildConfig, "error", err) + } + if ciBuildConfigBean == nil { + ciBuildConfigBean, err = adapter.OverrideCiBuildConfig(ciTemplate.DockerfilePath, ciTemplate.Args, "", ciTemplate.DockerBuildOptions, ciTemplate.TargetPlatform, nil) + if err != nil { + impl.Logger.Errorw("error occurred while parsing ci build config", "err", err) + } + } + ciBuildConfigBean.GitMaterialId = ciTemplate.GitMaterialId + ciBuildConfigBean.BuildContextGitMaterialId = ciTemplate.BuildContextGitMaterialId + return &bean.CiTemplateBean{ + CiTemplate: ciTemplate, + CiBuildConfig: ciBuildConfigBean, + }, err +} + +func (impl *CiTemplateReadServiceImpl) FindTemplateOverrideByAppId(appId int) (ciTemplateBeans []*bean.CiTemplateBean, err error) { + templateOverrides, err := impl.CiTemplateOverrideRepository.FindByAppId(appId) + if err != nil && err != pg.ErrNoRows { + impl.Logger.Errorw("error in getting ciTemplateOverrides by appId", "err", err, "appId", appId) + return nil, err + } + var templateBeanOverrides []*bean.CiTemplateBean + for _, templateOverride := range templateOverrides { + ciBuildConfigBean, err := impl.extractBuildConfigBean(templateOverride) + if err != nil { + return templateBeanOverrides, err + } + overrideBean := &bean.CiTemplateBean{ + CiTemplateOverride: templateOverride, + CiBuildConfig: ciBuildConfigBean, + } + templateBeanOverrides = append(templateBeanOverrides, overrideBean) + } + return templateBeanOverrides, nil +} + +func (impl *CiTemplateReadServiceImpl) FindTemplateOverrideByCiPipelineIds(ciPipelineIds []int) (ciTemplateBeans []*bean.CiTemplateBean, err error) { + templateOverrides, err := impl.CiTemplateOverrideRepository.FindByCiPipelineIds(ciPipelineIds) + if err != nil && err != pg.ErrNoRows { + impl.Logger.Errorw("error in getting ciTemplateOverrides by appId", "err", err, "ciPipelineIds", ciPipelineIds) + return nil, err + } + var templateBeanOverrides []*bean.CiTemplateBean + for _, templateOverride := range templateOverrides { + ciBuildConfigBean, err := impl.extractBuildConfigBean(templateOverride) + if err != nil { + return templateBeanOverrides, err + } + overrideBean := &bean.CiTemplateBean{ + CiTemplateOverride: templateOverride, + CiBuildConfig: ciBuildConfigBean, + } + templateBeanOverrides = append(templateBeanOverrides, overrideBean) + } + return templateBeanOverrides, nil +} + +func (impl *CiTemplateReadServiceImpl) extractBuildConfigBean(templateOverride *pipelineConfig.CiTemplateOverride) (*bean.CiBuildConfigBean, error) { + ciBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(templateOverride.CiBuildConfig) + if err != nil { + impl.Logger.Errorw("error occurred while converting dbBuildConfig to bean", "ciBuildConfig", + templateOverride.CiBuildConfig, "error", err) + return nil, err + } + if ciBuildConfigBean == nil { + ciBuildConfigBean, err = adapter.OverrideCiBuildConfig(templateOverride.DockerfilePath, "", "", "", "", nil) + if err != nil { + impl.Logger.Errorw("error occurred while parsing ci build config", "err", err) + } + } + ciBuildConfigBean.GitMaterialId = templateOverride.GitMaterialId + ciBuildConfigBean.BuildContextGitMaterialId = templateOverride.BuildContextGitMaterialId + return ciBuildConfigBean, nil +} + +func (impl *CiTemplateReadServiceImpl) FindTemplateOverrideByCiPipelineId(ciPipelineId int) (*bean.CiTemplateBean, error) { + templateOverride, err := impl.CiTemplateOverrideRepository.FindByCiPipelineId(ciPipelineId) + if err != nil && err != pg.ErrNoRows { + impl.Logger.Errorw("error in getting ciTemplateOverrides by ciPipelineId", "err", err, "ciPipelineId", ciPipelineId) + return nil, err + } + ciBuildConfigBean, err := impl.extractBuildConfigBean(templateOverride) + return &bean.CiTemplateBean{CiTemplateOverride: templateOverride, CiBuildConfig: ciBuildConfigBean}, err +} + +func (impl *CiTemplateReadServiceImpl) GetAppliedDockerConfigForCiPipeline(ciPipelineId, appId int, isOverridden bool) (*types.DockerArtifactStoreBean, error) { + if !isOverridden { + return impl.GetBaseDockerConfigForCiPipeline(appId) + } + templateOverride, err := impl.CiTemplateOverrideRepository.FindByCiPipelineId(ciPipelineId) + if err != nil && !util.IsErrNoRows(err) { + impl.Logger.Errorw("error in getting ciTemplateOverrides by ciPipelineId", "err", err, "ciPipelineId", ciPipelineId) + return nil, err + } + if util.IsErrNoRows(err) { + return impl.GetBaseDockerConfigForCiPipeline(appId) + } + return adapter.GetDockerConfigBean(templateOverride.DockerRegistry), nil +} + +func (impl *CiTemplateReadServiceImpl) GetBaseDockerConfigForCiPipeline(appId int) (*types.DockerArtifactStoreBean, error) { + ciTemplate, err := impl.CiTemplateRepository.FindByAppId(appId) + if err != nil { + impl.Logger.Errorw("error in getting ciTemplate by appId", "err", err, "appId", appId) + return nil, err + } + return adapter.GetDockerConfigBean(ciTemplate.DockerRegistry), nil +} + +func (impl *CiTemplateReadServiceImpl) FindByAppIds(appIds []int) (map[int]*bean.CiTemplateBean, error) { + ciTemplates, err := impl.CiTemplateRepository.FindByAppIds(appIds) + if err != nil { + return nil, err + } + ciTemplateMap := make(map[int]*bean.CiTemplateBean) + for _, ciTemplate := range ciTemplates { + ciBuildConfig := ciTemplate.CiBuildConfig + ciBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(ciBuildConfig) + if err != nil { + impl.Logger.Errorw("error occurred while converting dbBuildConfig to bean", "ciBuildConfig", + ciBuildConfig, "error", err) + } + if ciBuildConfigBean == nil { + ciBuildConfigBean, err = adapter.OverrideCiBuildConfig(ciTemplate.DockerfilePath, ciTemplate.Args, "", ciTemplate.DockerBuildOptions, ciTemplate.TargetPlatform, nil) + if err != nil { + impl.Logger.Errorw("error occurred while parsing ci build config", "err", err) + } + } + ciBuildConfigBean.GitMaterialId = ciTemplate.GitMaterialId + ciTemplateBean := &bean.CiTemplateBean{ + CiTemplate: ciTemplate, + CiBuildConfig: ciBuildConfigBean, + } + ciTemplateMap[ciTemplate.AppId] = ciTemplateBean + } + return ciTemplateMap, nil +} diff --git a/pkg/pipeline/bean/CiPipeline/CiBuildConfig.go b/pkg/build/pipeline/bean/CiBuildConfig.go similarity index 97% rename from pkg/pipeline/bean/CiPipeline/CiBuildConfig.go rename to pkg/build/pipeline/bean/CiBuildConfig.go index 0050dc19f3f..34357f5e685 100644 --- a/pkg/pipeline/bean/CiPipeline/CiBuildConfig.go +++ b/pkg/build/pipeline/bean/CiBuildConfig.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package CiPipeline +package bean type CiBuildType string @@ -43,6 +43,10 @@ const ( LINKED_CD PipelineType = "LINKED_CD" ) +func (pType PipelineType) ToString() string { + return string(pType) +} + type CiBuildConfigBean struct { Id int `json:"id"` GitMaterialId int `json:"gitMaterialId,omitempty" validate:"required"` diff --git a/pkg/pipeline/bean/CiTemplateBean.go b/pkg/build/pipeline/bean/CiTemplateBean.go similarity index 88% rename from pkg/pipeline/bean/CiTemplateBean.go rename to pkg/build/pipeline/bean/CiTemplateBean.go index 8463c39e5fa..dfb7065176b 100644 --- a/pkg/pipeline/bean/CiTemplateBean.go +++ b/pkg/build/pipeline/bean/CiTemplateBean.go @@ -18,13 +18,12 @@ package bean import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" ) // todo move to proper place type CiTemplateBean struct { CiTemplate *pipelineConfig.CiTemplate CiTemplateOverride *pipelineConfig.CiTemplateOverride - CiBuildConfig *CiPipeline.CiBuildConfigBean + CiBuildConfig *CiBuildConfigBean UserId int32 } diff --git a/pkg/pipeline/bean/CiPipeline/SourceCiDownStream.go b/pkg/build/pipeline/bean/SourceCiDownStream.go similarity index 98% rename from pkg/pipeline/bean/CiPipeline/SourceCiDownStream.go rename to pkg/build/pipeline/bean/SourceCiDownStream.go index 24dd05e1c87..7c884daa67e 100644 --- a/pkg/pipeline/bean/CiPipeline/SourceCiDownStream.go +++ b/pkg/build/pipeline/bean/SourceCiDownStream.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package CiPipeline +package bean import "github.com/devtron-labs/devtron/util/response/pagination" diff --git a/pkg/bulkAction/BulkUpdateService.go b/pkg/bulkAction/BulkUpdateService.go index 1388a057d3b..846b6b3ce80 100644 --- a/pkg/bulkAction/BulkUpdateService.go +++ b/pkg/bulkAction/BulkUpdateService.go @@ -39,12 +39,13 @@ import ( repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/deployment/deployedApp" bean5 "github.com/devtron-labs/devtron/pkg/deployment/deployedApp/bean" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" bean3 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean" "github.com/devtron-labs/devtron/pkg/eventProcessor/out" "github.com/devtron-labs/devtron/pkg/pipeline" - "github.com/devtron-labs/devtron/pkg/pipeline/history" repository4 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/variables" repository5 "github.com/devtron-labs/devtron/pkg/variables/repository" @@ -84,8 +85,8 @@ type BulkUpdateServiceImpl struct { environmentRepository repository2.EnvironmentRepository pipelineRepository pipelineConfig.PipelineRepository appRepository app.AppRepository - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService - configMapHistoryService history.ConfigMapHistoryService + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService + configMapHistoryService configMapAndSecret.ConfigMapHistoryService pipelineBuilder pipeline.PipelineBuilder enforcerUtil rbac.EnforcerUtil ciHandler pipeline.CiHandler @@ -104,8 +105,8 @@ func NewBulkUpdateServiceImpl(bulkUpdateRepository bulkUpdate.BulkUpdateReposito environmentRepository repository2.EnvironmentRepository, pipelineRepository pipelineConfig.PipelineRepository, appRepository app.AppRepository, - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService, - configMapHistoryService history.ConfigMapHistoryService, + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, + configMapHistoryService configMapAndSecret.ConfigMapHistoryService, pipelineBuilder pipeline.PipelineBuilder, enforcerUtil rbac.EnforcerUtil, ciHandler pipeline.CiHandler, diff --git a/pkg/chart/ChartService.go b/pkg/chart/ChartService.go index edce7ca9581..bdd7d0293a5 100644 --- a/pkg/chart/ChartService.go +++ b/pkg/chart/ChartService.go @@ -33,9 +33,9 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics/bean" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" chartRefBean "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/sql" "github.com/devtron-labs/devtron/pkg/variables" variablesRepository "github.com/devtron-labs/devtron/pkg/variables/repository" @@ -82,7 +82,7 @@ type ChartServiceImpl struct { envOverrideRepository chartConfig.EnvConfigOverrideRepository pipelineConfigRepository chartConfig.PipelineConfigRepository environmentRepository repository4.EnvironmentRepository - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService scopedVariableManager variables.ScopedVariableManager deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService chartRefService chartRef.ChartRefService @@ -99,7 +99,7 @@ func NewChartServiceImpl(chartRepository chartRepoRepository.ChartRepository, envOverrideRepository chartConfig.EnvConfigOverrideRepository, pipelineConfigRepository chartConfig.PipelineConfigRepository, environmentRepository repository4.EnvironmentRepository, - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService, + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, scopedVariableManager variables.ScopedVariableManager, deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService, chartRefService chartRef.ChartRefService, diff --git a/pkg/chartRepo/ChartRepositoryService.go b/pkg/chartRepo/ChartRepositoryService.go index 52e54534249..fd42187b2d2 100644 --- a/pkg/chartRepo/ChartRepositoryService.go +++ b/pkg/chartRepo/ChartRepositoryService.go @@ -725,7 +725,7 @@ func (impl *ChartRepositoryServiceImpl) TriggerChartSyncManual(chartProviderConf defaultClusterConfig := defaultClusterBean.GetClusterConfig() - manualAppSyncJobByteArr := manualAppSyncJobByteArr(impl.serverEnvConfig.AppSyncImage, impl.serverEnvConfig.AppSyncJobResourcesObj, impl.serverEnvConfig.AppSyncServiceAccount, chartProviderConfig,impl.serverEnvConfig.ParallelismLimitForTagProcessing) + manualAppSyncJobByteArr := manualAppSyncJobByteArr(impl.serverEnvConfig.AppSyncImage, impl.serverEnvConfig.AppSyncJobResourcesObj, impl.serverEnvConfig.AppSyncServiceAccount, chartProviderConfig, impl.serverEnvConfig.ParallelismLimitForTagProcessing) err = impl.K8sUtil.DeleteAndCreateJob(manualAppSyncJobByteArr, impl.aCDAuthConfig.ACDConfigMapNamespace, defaultClusterConfig) if err != nil { impl.logger.Errorw("DeleteAndCreateJob err, TriggerChartSyncManual", "err", err) diff --git a/pkg/cluster/ClusterService.go b/pkg/cluster/ClusterService.go index 5417c69eaed..5020147437c 100644 --- a/pkg/cluster/ClusterService.go +++ b/pkg/cluster/ClusterService.go @@ -90,6 +90,7 @@ type ClusterBean struct { IsCdArgoSetup bool `json:"isCdArgoSetup"` IsVirtualCluster bool `json:"isVirtualCluster"` ClusterUpdated bool `json:"clusterUpdated"` + IsProd bool `json:"isProd"` } func GetClusterBean(model repository.Cluster) ClusterBean { @@ -106,6 +107,7 @@ func GetClusterBean(model repository.Cluster) ClusterBean { bean.InsecureSkipTLSVerify = model.InsecureSkipTlsVerify bean.IsVirtualCluster = model.IsVirtualCluster bean.ErrorInConnecting = model.ErrorInConnecting + bean.IsProd = model.IsProd bean.PrometheusAuth = &PrometheusAuth{ UserName: model.PUserName, Password: model.PPassword, @@ -241,6 +243,7 @@ func (impl *ClusterServiceImpl) ConvertClusterBeanToCluster(clusterBean *Cluster model.Config = clusterBean.Config model.PrometheusEndpoint = clusterBean.PrometheusUrl model.InsecureSkipTlsVerify = clusterBean.InsecureSkipTLSVerify + model.IsProd = clusterBean.IsProd if clusterBean.PrometheusAuth != nil { model.PUserName = clusterBean.PrometheusAuth.UserName @@ -374,7 +377,6 @@ func (impl *ClusterServiceImpl) FindOneActive(clusterName string) (*ClusterBean, } bean := GetClusterBean(*model) return &bean, nil - } func (impl *ClusterServiceImpl) FindAllWithoutConfig() ([]*ClusterBean, error) { @@ -516,6 +518,7 @@ func (impl *ClusterServiceImpl) Update(ctx context.Context, bean *ClusterBean, u model.ClusterName = bean.ClusterName model.ServerUrl = bean.ServerUrl model.InsecureSkipTlsVerify = bean.InsecureSkipTLSVerify + model.IsProd = bean.IsProd model.PrometheusEndpoint = bean.PrometheusUrl if bean.PrometheusAuth != nil { @@ -646,7 +649,7 @@ func (impl *ClusterServiceImpl) FindAllForAutoComplete() ([]ClusterBean, error) } func (impl *ClusterServiceImpl) CreateGrafanaDataSource(clusterBean *ClusterBean, env *repository.Environment) (int, error) { - impl.logger.Errorw("CreateGrafanaDataSource not inplementd in ClusterServiceImpl") + impl.logger.Errorw("CreateGrafanaDataSource not implemented in ClusterServiceImpl") return 0, fmt.Errorf("method not implemented") } @@ -752,7 +755,13 @@ func (impl *ClusterServiceImpl) FindAllNamespacesByUserIdAndClusterId(userId int } namespaceListGroupByCLuster := impl.K8sInformerFactory.GetLatestNamespaceListGroupByCLuster() namespaces := namespaceListGroupByCLuster[clusterBean.ClusterName] - + if len(namespaces) == 0 { + // TODO: Verify if this is a valid scenario, if yes, then handle it + // ideally, all clusters should have at least one `default` namespace + // this is a fallback scenario, for handling the namespace informer failure at start up... + impl.logger.Warnw("no namespaces found for cluster", "clusterName", clusterBean.ClusterName) + impl.SyncNsInformer(clusterBean) + } if isActionUserSuperAdmin { for namespace, value := range namespaces { if value { diff --git a/pkg/cluster/repository/ClusterRepository.go b/pkg/cluster/repository/ClusterRepository.go index 16c5febb5af..541c4485f6c 100644 --- a/pkg/cluster/repository/ClusterRepository.go +++ b/pkg/cluster/repository/ClusterRepository.go @@ -42,6 +42,7 @@ type Cluster struct { ErrorInConnecting string `sql:"error_in_connecting"` IsVirtualCluster bool `sql:"is_virtual_cluster"` InsecureSkipTlsVerify bool `sql:"insecure_skip_tls_verify"` + IsProd bool `sql:"is_prod"` sql.AuditLog } diff --git a/pkg/configDiff/DeploymentConfigurationService.go b/pkg/configDiff/DeploymentConfigurationService.go index 160e620df23..6e671bac097 100644 --- a/pkg/configDiff/DeploymentConfigurationService.go +++ b/pkg/configDiff/DeploymentConfigurationService.go @@ -15,12 +15,14 @@ import ( bean2 "github.com/devtron-labs/devtron/pkg/configDiff/bean" "github.com/devtron-labs/devtron/pkg/configDiff/helper" "github.com/devtron-labs/devtron/pkg/configDiff/utils" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + read2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/pkg/generateManifest" "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/history" repository3 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/resourceQualifiers" "github.com/devtron-labs/devtron/pkg/variables" @@ -40,22 +42,23 @@ type DeploymentConfigurationService interface { } type DeploymentConfigurationServiceImpl struct { - logger *zap.SugaredLogger - configMapService pipeline.ConfigMapService - appRepository appRepository.AppRepository - environmentRepository repository.EnvironmentRepository - chartService chartService.ChartService - deploymentTemplateService generateManifest.DeploymentTemplateService - deploymentTemplateHistoryRepository repository3.DeploymentTemplateHistoryRepository - pipelineStrategyHistoryRepository repository3.PipelineStrategyHistoryRepository - configMapHistoryRepository repository3.ConfigMapHistoryRepository - scopedVariableManager variables.ScopedVariableCMCSManager - configMapRepository chartConfig.ConfigMapRepository - deploymentConfigService pipeline.PipelineDeploymentConfigService - chartRefService chartRef.ChartRefService - pipelineRepository pipelineConfig.PipelineRepository - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService - configMapHistoryService history.ConfigMapHistoryService + logger *zap.SugaredLogger + configMapService pipeline.ConfigMapService + appRepository appRepository.AppRepository + environmentRepository repository.EnvironmentRepository + chartService chartService.ChartService + deploymentTemplateService generateManifest.DeploymentTemplateService + deploymentTemplateHistoryRepository repository3.DeploymentTemplateHistoryRepository + pipelineStrategyHistoryRepository repository3.PipelineStrategyHistoryRepository + configMapHistoryRepository repository3.ConfigMapHistoryRepository + scopedVariableManager variables.ScopedVariableCMCSManager + configMapRepository chartConfig.ConfigMapRepository + deploymentConfigService pipeline.PipelineDeploymentConfigService + chartRefService chartRef.ChartRefService + pipelineRepository pipelineConfig.PipelineRepository + configMapHistoryService configMapAndSecret.ConfigMapHistoryService + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService + configMapHistoryReadService read2.ConfigMapHistoryReadService } func NewDeploymentConfigurationServiceImpl(logger *zap.SugaredLogger, @@ -72,26 +75,28 @@ func NewDeploymentConfigurationServiceImpl(logger *zap.SugaredLogger, deploymentConfigService pipeline.PipelineDeploymentConfigService, chartRefService chartRef.ChartRefService, pipelineRepository pipelineConfig.PipelineRepository, - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService, - configMapHistoryService history.ConfigMapHistoryService, + configMapHistoryService configMapAndSecret.ConfigMapHistoryService, + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService, + configMapHistoryReadService read2.ConfigMapHistoryReadService, ) (*DeploymentConfigurationServiceImpl, error) { deploymentConfigurationService := &DeploymentConfigurationServiceImpl{ - logger: logger, - configMapService: configMapService, - appRepository: appRepository, - environmentRepository: environmentRepository, - chartService: chartService, - deploymentTemplateService: deploymentTemplateService, - deploymentTemplateHistoryRepository: deploymentTemplateHistoryRepository, - pipelineStrategyHistoryRepository: pipelineStrategyHistoryRepository, - configMapHistoryRepository: configMapHistoryRepository, - scopedVariableManager: scopedVariableManager, - configMapRepository: configMapRepository, - deploymentConfigService: deploymentConfigService, - chartRefService: chartRefService, - pipelineRepository: pipelineRepository, - deploymentTemplateHistoryService: deploymentTemplateHistoryService, - configMapHistoryService: configMapHistoryService, + logger: logger, + configMapService: configMapService, + appRepository: appRepository, + environmentRepository: environmentRepository, + chartService: chartService, + deploymentTemplateService: deploymentTemplateService, + deploymentTemplateHistoryRepository: deploymentTemplateHistoryRepository, + pipelineStrategyHistoryRepository: pipelineStrategyHistoryRepository, + configMapHistoryRepository: configMapHistoryRepository, + scopedVariableManager: scopedVariableManager, + configMapRepository: configMapRepository, + deploymentConfigService: deploymentConfigService, + chartRefService: chartRefService, + pipelineRepository: pipelineRepository, + configMapHistoryService: configMapHistoryService, + deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, + configMapHistoryReadService: configMapHistoryReadService, } return deploymentConfigurationService, nil @@ -375,13 +380,13 @@ func (impl *DeploymentConfigurationServiceImpl) getCmCsDataForPreviousDeployment configDataDto := &bean2.DeploymentAndCmCsConfigDto{} - deplTemplateHistory, err := impl.deploymentTemplateHistoryService.GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId) + deplTemplateHistory, err := impl.deploymentTemplateHistoryReadService.GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId) if err != nil { impl.logger.Errorw("error in getting deployment template history", "err", err, "deploymentTemplateHistoryId", deploymentTemplateHistoryId, "pipelineId", pipelineId) return nil, err } - secretConfigData, cmConfigData, err := impl.configMapHistoryService.GetConfigmapHistoryDataByDeployedOnAndPipelineId(ctx, pipelineId, deplTemplateHistory.DeployedOn, userHasAdminAccess) + secretConfigData, cmConfigData, err := impl.configMapHistoryReadService.GetConfigmapHistoryDataByDeployedOnAndPipelineId(ctx, pipelineId, deplTemplateHistory.DeployedOn, userHasAdminAccess) if err != nil { impl.logger.Errorw("error in getting secretData and cmData", "err", err, "deploymentTemplateHistoryId", deploymentTemplateHistoryId, "pipelineId", pipelineId) return nil, err @@ -393,7 +398,7 @@ func (impl *DeploymentConfigurationServiceImpl) getCmCsDataForPreviousDeployment func (impl *DeploymentConfigurationServiceImpl) getPipelineStrategyForPreviousDeployments(ctx context.Context, deploymentTemplateHistoryId, pipelineId int) (*bean2.DeploymentAndCmCsConfig, error) { pipelineStrategyJson := json.RawMessage{} pipelineConfig := bean2.NewDeploymentAndCmCsConfig() - deplTemplateHistory, err := impl.deploymentTemplateHistoryService.GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId) + deplTemplateHistory, err := impl.deploymentTemplateHistoryReadService.GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId) if err != nil { impl.logger.Errorw("error in getting deployment template history", "deploymentTemplateHistoryId", deploymentTemplateHistoryId, "pipelineId", pipelineId, "err", err) return nil, err diff --git a/pkg/deployment/manifest/configMapAndSecret/ConfigMapHistoryService.go b/pkg/deployment/manifest/configMapAndSecret/ConfigMapHistoryService.go new file mode 100644 index 00000000000..2cdfc0bf115 --- /dev/null +++ b/pkg/deployment/manifest/configMapAndSecret/ConfigMapHistoryService.go @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2024. Devtron Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package configMapAndSecret + +import ( + "encoding/json" + "time" + + "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" + "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/pkg/auth/user" + "github.com/devtron-labs/devtron/pkg/bean" + "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" + "github.com/devtron-labs/devtron/pkg/sql" + "github.com/devtron-labs/devtron/pkg/variables" + "github.com/go-pg/pg" + "go.uber.org/zap" +) + +type ConfigMapHistoryService interface { + CreateHistoryFromAppLevelConfig(appLevelConfig *chartConfig.ConfigMapAppModel, configType repository.ConfigType) error + CreateHistoryFromEnvLevelConfig(envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType) error + CreateCMCSHistoryForDeploymentTrigger(pipeline *pipelineConfig.Pipeline, deployedOn time.Time, deployedBy int32) (int, int, error) + MergeAppLevelAndEnvLevelConfigs(appLevelConfig *chartConfig.ConfigMapAppModel, envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType, configMapSecretNames []string) (string, error) +} + +type ConfigMapHistoryServiceImpl struct { + logger *zap.SugaredLogger + configMapHistoryRepository repository.ConfigMapHistoryRepository + pipelineRepository pipelineConfig.PipelineRepository + configMapRepository chartConfig.ConfigMapRepository + userService user.UserService + scopedVariableManager variables.ScopedVariableCMCSManager +} + +func NewConfigMapHistoryServiceImpl(logger *zap.SugaredLogger, + configMapHistoryRepository repository.ConfigMapHistoryRepository, + pipelineRepository pipelineConfig.PipelineRepository, + configMapRepository chartConfig.ConfigMapRepository, + userService user.UserService, + scopedVariableManager variables.ScopedVariableCMCSManager, +) *ConfigMapHistoryServiceImpl { + return &ConfigMapHistoryServiceImpl{ + logger: logger, + configMapHistoryRepository: configMapHistoryRepository, + pipelineRepository: pipelineRepository, + configMapRepository: configMapRepository, + userService: userService, + scopedVariableManager: scopedVariableManager, + } +} + +func (impl ConfigMapHistoryServiceImpl) CreateHistoryFromAppLevelConfig(appLevelConfig *chartConfig.ConfigMapAppModel, configType repository.ConfigType) error { + pipelines, err := impl.pipelineRepository.FindActiveByAppId(appLevelConfig.AppId) + if err != nil { + impl.logger.Errorw("err in getting pipelines, CreateHistoryFromAppLevelConfig", "err", err, "appLevelConfig", appLevelConfig) + return err + } + //creating history for global + configData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, nil, configType, nil) + if err != nil { + impl.logger.Errorw("err in merging app and env level configs", "err", err) + return err + } + historyModel := &repository.ConfigmapAndSecretHistory{ + AppId: appLevelConfig.AppId, + DataType: configType, + Deployed: false, + Data: configData, + AuditLog: sql.AuditLog{ + CreatedBy: appLevelConfig.CreatedBy, + CreatedOn: appLevelConfig.CreatedOn, + UpdatedBy: appLevelConfig.UpdatedBy, + UpdatedOn: appLevelConfig.UpdatedOn, + }, + } + _, err = impl.configMapHistoryRepository.CreateHistory(nil, historyModel) + if err != nil { + impl.logger.Errorw("error in creating new entry for CM/CS history", "historyModel", historyModel) + return err + } + for _, pipeline := range pipelines { + envLevelConfig, err := impl.configMapRepository.GetByAppIdAndEnvIdEnvLevel(pipeline.AppId, pipeline.EnvironmentId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("err in getting env level config", "err", err, "appId", appLevelConfig.AppId) + return err + } + configData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, configType, nil) + if err != nil { + impl.logger.Errorw("err in merging app and env level configs", "err", err) + return err + } + historyModel := &repository.ConfigmapAndSecretHistory{ + AppId: appLevelConfig.AppId, + PipelineId: pipeline.Id, + DataType: configType, + Deployed: false, + Data: configData, + AuditLog: sql.AuditLog{ + CreatedBy: appLevelConfig.CreatedBy, + CreatedOn: appLevelConfig.CreatedOn, + UpdatedBy: appLevelConfig.UpdatedBy, + UpdatedOn: appLevelConfig.UpdatedOn, + }, + } + _, err = impl.configMapHistoryRepository.CreateHistory(nil, historyModel) + if err != nil { + impl.logger.Errorw("error in creating new entry for CM/CS history", "historyModel", historyModel) + return err + } + } + + return nil +} + +func (impl ConfigMapHistoryServiceImpl) CreateHistoryFromEnvLevelConfig(envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType) error { + pipelines, err := impl.pipelineRepository.FindActiveByAppIdAndEnvironmentId(envLevelConfig.AppId, envLevelConfig.EnvironmentId) + if err != nil { + impl.logger.Errorw("err in getting pipelines, CreateHistoryFromEnvLevelConfig", "err", err, "envLevelConfig", envLevelConfig) + return err + } + appLevelConfig, err := impl.configMapRepository.GetByAppIdAppLevel(envLevelConfig.AppId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("err in getting app level config", "err", err, "appId", envLevelConfig.AppId) + return err + } + for _, pipeline := range pipelines { + configData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, configType, nil) + if err != nil { + impl.logger.Errorw("err in merging app and env level configs", "err", err) + return err + } + historyModel := &repository.ConfigmapAndSecretHistory{ + AppId: envLevelConfig.AppId, + PipelineId: pipeline.Id, + DataType: configType, + Deployed: false, + Data: configData, + AuditLog: sql.AuditLog{ + CreatedBy: envLevelConfig.CreatedBy, + CreatedOn: envLevelConfig.CreatedOn, + UpdatedBy: envLevelConfig.UpdatedBy, + UpdatedOn: envLevelConfig.UpdatedOn, + }, + } + _, err = impl.configMapHistoryRepository.CreateHistory(nil, historyModel) + if err != nil { + impl.logger.Errorw("error in creating new entry for CM/CS history", "historyModel", historyModel) + return err + } + } + return nil +} + +func (impl ConfigMapHistoryServiceImpl) CreateCMCSHistoryForDeploymentTrigger(pipeline *pipelineConfig.Pipeline, deployedOn time.Time, deployedBy int32) (int, int, error) { + //creating history for configmaps, secrets(if any) + appLevelConfig, err := impl.configMapRepository.GetByAppIdAppLevel(pipeline.AppId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("err in getting app level config", "err", err, "appId", pipeline.AppId) + return 0, 0, err + } + envLevelConfig, err := impl.configMapRepository.GetByAppIdAndEnvIdEnvLevel(pipeline.AppId, pipeline.EnvironmentId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("err in getting env level config", "err", err, "appId", pipeline.AppId) + return 0, 0, err + } + configMapData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, repository.CONFIGMAP_TYPE, nil) + if err != nil { + impl.logger.Errorw("err in merging app and env level configs", "err", err) + return 0, 0, err + } + historyModelForCM := repository.ConfigmapAndSecretHistory{ + AppId: pipeline.AppId, + PipelineId: pipeline.Id, + DataType: repository.CONFIGMAP_TYPE, + Deployed: true, + DeployedBy: deployedBy, + DeployedOn: deployedOn, + Data: configMapData, + AuditLog: sql.AuditLog{ + CreatedBy: deployedBy, + CreatedOn: deployedOn, + UpdatedBy: deployedBy, + UpdatedOn: deployedOn, + }, + } + + tx, err := impl.configMapHistoryRepository.StartTx() + if err != nil { + impl.logger.Errorw("error in starting transaction to create new cm/cs history", "error", err) + return 0, 0, err + } + defer impl.configMapHistoryRepository.RollbackTx(tx) + cmHistory, err := impl.configMapHistoryRepository.CreateHistory(tx, &historyModelForCM) + if err != nil { + impl.logger.Errorw("error in creating new entry for cm history", "historyModel", historyModelForCM) + return 0, 0, err + } + secretData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, repository.SECRET_TYPE, nil) + if err != nil { + impl.logger.Errorw("err in merging app and env level configs", "err", err) + return 0, 0, err + } + historyModelForCS := historyModelForCM + historyModelForCS.DataType = repository.SECRET_TYPE + historyModelForCS.Data = secretData + historyModelForCS.Id = 0 + csHistory, err := impl.configMapHistoryRepository.CreateHistory(tx, &historyModelForCS) + if err != nil { + impl.logger.Errorw("error in creating new entry for secret history", "historyModel", historyModelForCS) + return 0, 0, err + } + err = impl.configMapHistoryRepository.CommitTx(tx) + if err != nil { + impl.logger.Errorw("error in committing transaction to create new cm/cs history", "error", err) + return 0, 0, err + } + return cmHistory.Id, csHistory.Id, nil +} + +func (impl ConfigMapHistoryServiceImpl) MergeAppLevelAndEnvLevelConfigs(appLevelConfig *chartConfig.ConfigMapAppModel, envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType, configMapSecretNames []string) (string, error) { + var err error + var appLevelConfigData []*bean.ConfigData + var envLevelConfigData []*bean.ConfigData + if configType == repository.CONFIGMAP_TYPE { + var configDataAppLevel string + var configDataEnvLevel string + if appLevelConfig != nil { + configDataAppLevel = appLevelConfig.ConfigMapData + } + if envLevelConfig != nil { + configDataEnvLevel = envLevelConfig.ConfigMapData + } + configListAppLevel := &bean.ConfigList{} + if len(configDataAppLevel) > 0 { + err = json.Unmarshal([]byte(configDataAppLevel), configListAppLevel) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return "", err + } + } + configListEnvLevel := &bean.ConfigList{} + if len(configDataEnvLevel) > 0 { + err = json.Unmarshal([]byte(configDataEnvLevel), configListEnvLevel) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return "", err + } + } + appLevelConfigData = configListAppLevel.ConfigData + envLevelConfigData = configListEnvLevel.ConfigData + } else if configType == repository.SECRET_TYPE { + var secretDataAppLevel string + var secretDataEnvLevel string + if appLevelConfig != nil { + secretDataAppLevel = appLevelConfig.SecretData + } + if envLevelConfig != nil { + secretDataEnvLevel = envLevelConfig.SecretData + } + secretListAppLevel := &bean.SecretList{} + if len(secretDataAppLevel) > 0 { + err = json.Unmarshal([]byte(secretDataAppLevel), secretListAppLevel) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return "", err + } + } + secretListEnvLevel := &bean.SecretList{} + if len(secretDataEnvLevel) > 0 { + err = json.Unmarshal([]byte(secretDataEnvLevel), secretListEnvLevel) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return "", err + } + } + appLevelConfigData = secretListAppLevel.ConfigData + envLevelConfigData = secretListEnvLevel.ConfigData + } + + var finalConfigs []*bean.ConfigData + envLevelConfigs := make(map[string]bool) + filterNameMap := make(map[string]bool) + for _, name := range configMapSecretNames { + filterNameMap[name] = true + } + //if filter name map is not empty, to add configs by filtering names + //if filter name map is empty, adding all env level configs to final configs + for _, item := range envLevelConfigData { + if _, ok := filterNameMap[item.Name]; ok || len(filterNameMap) == 0 { + //adding all env configs whose name is in filter name map + envLevelConfigs[item.Name] = true + finalConfigs = append(finalConfigs, item) + } + } + for _, item := range appLevelConfigData { + //if filter name map is not empty, adding all global configs which are not present in env level and are present in filter name map to final configs + //if filter name map is empty,adding all global configs which are not present in env level to final configs + if _, ok := envLevelConfigs[item.Name]; !ok { + if _, ok = filterNameMap[item.Name]; ok || len(filterNameMap) == 0 { + finalConfigs = append(finalConfigs, item) + } + } + } + var finalConfigDataByte []byte + if configType == repository.CONFIGMAP_TYPE { + var finalConfigList bean.ConfigList + finalConfigList.ConfigData = finalConfigs + finalConfigDataByte, err = json.Marshal(finalConfigList) + if err != nil { + impl.logger.Errorw("error in marshaling config", "err", err) + return "", err + } + } else if configType == repository.SECRET_TYPE { + var finalConfigList bean.SecretList + finalConfigList.ConfigData = finalConfigs + finalConfigDataByte, err = json.Marshal(finalConfigList) + if err != nil { + impl.logger.Errorw("error in marshaling config", "err", err) + return "", err + } + } + return string(finalConfigDataByte), err +} diff --git a/pkg/deployment/manifest/configMapAndSecret/read/ConfigMapHistoryReadService.go b/pkg/deployment/manifest/configMapAndSecret/read/ConfigMapHistoryReadService.go new file mode 100644 index 00000000000..6f981eabd94 --- /dev/null +++ b/pkg/deployment/manifest/configMapAndSecret/read/ConfigMapHistoryReadService.go @@ -0,0 +1,490 @@ +package read + +import ( + "context" + "encoding/json" + "errors" + bean2 "github.com/devtron-labs/devtron/pkg/bean" + "github.com/devtron-labs/devtron/pkg/configDiff/adaptor" + bean3 "github.com/devtron-labs/devtron/pkg/configDiff/bean" + "github.com/devtron-labs/devtron/pkg/configDiff/utils" + "github.com/devtron-labs/devtron/pkg/pipeline/adapter" + bean4 "github.com/devtron-labs/devtron/pkg/pipeline/bean" + "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" + "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" + "github.com/devtron-labs/devtron/pkg/variables" + "github.com/devtron-labs/devtron/util" + "github.com/go-pg/pg" + "go.uber.org/zap" + "time" +) + +type ConfigMapHistoryReadService interface { + GetHistoryForDeployedCMCSById(ctx context.Context, id, pipelineId int, configType repository.ConfigType, componentName string, userHasAdminAccess bool) (*bean.HistoryDetailDto, error) + GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId int, configType repository.ConfigType) (history *repository.ConfigmapAndSecretHistory, exists bool, cmCsNames []string, err error) + GetDeployedHistoryList(pipelineId, baseConfigId int, configType repository.ConfigType, componentName string) ([]*bean.DeployedHistoryComponentMetadataDto, error) + CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (cmId int, csId int, exists bool, err error) + GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, configType repository.ConfigType, userHasAdminAccess bool) ([]*bean.ComponentLevelHistoryDetailDto, error) + ConvertConfigDataToComponentLevelDto(config *bean2.ConfigData, configType repository.ConfigType, userHasAdminAccess bool) (*bean.ComponentLevelHistoryDetailDto, error) + GetConfigmapHistoryDataByDeployedOnAndPipelineId(ctx context.Context, pipelineId int, deployedOn time.Time, userHasAdminAccess bool) (*bean3.DeploymentAndCmCsConfig, *bean3.DeploymentAndCmCsConfig, error) +} + +type ConfigMapHistoryReadServiceImpl struct { + logger *zap.SugaredLogger + configMapHistoryRepository repository.ConfigMapHistoryRepository + scopedVariableManager variables.ScopedVariableCMCSManager +} + +func NewConfigMapHistoryReadService( + logger *zap.SugaredLogger, + configMapHistoryRepository repository.ConfigMapHistoryRepository, + scopedVariableManager variables.ScopedVariableCMCSManager, +) *ConfigMapHistoryReadServiceImpl { + return &ConfigMapHistoryReadServiceImpl{ + logger: logger, + configMapHistoryRepository: configMapHistoryRepository, + scopedVariableManager: scopedVariableManager, + } +} + +func (impl *ConfigMapHistoryReadServiceImpl) GetHistoryForDeployedCMCSById(ctx context.Context, id, pipelineId int, configType repository.ConfigType, componentName string, userHasAdminAccess bool) (*bean.HistoryDetailDto, error) { + history, err := impl.configMapHistoryRepository.GetHistoryForDeployedCMCSById(id, pipelineId, configType) + if err != nil { + impl.logger.Errorw("error in getting histories for cm/cs", "err", err, "id", id, "pipelineId", pipelineId) + return nil, err + } + var configData []*bean2.ConfigData + var configList bean2.ConfigList + var secretList bean2.SecretList + if configType == repository.CONFIGMAP_TYPE { + configList = bean2.ConfigList{} + if len(history.Data) > 0 { + err := json.Unmarshal([]byte(history.Data), &configList) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return nil, err + } + } + configData = configList.ConfigData + } else if configType == repository.SECRET_TYPE { + secretList = bean2.SecretList{} + if len(history.Data) > 0 { + err := json.Unmarshal([]byte(history.Data), &secretList) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return nil, err + } + } + configData = secretList.ConfigData + + } + + variableSnapshotMap, resolvedTemplate, err := impl.scopedVariableManager.ResolveCMCSHistoryDto(ctx, configType, configList, history, componentName, secretList) + if err != nil { + return nil, err + } + + config := &bean2.ConfigData{} + for _, data := range configData { + if data.Name == componentName { + config = data + break + } + } + historyDto := &bean.HistoryDetailDto{ + Type: config.Type, + External: &config.External, + MountPath: config.MountPath, + SubPath: &config.SubPath, + FilePermission: config.FilePermission, + CodeEditorValue: &bean.HistoryDetailConfig{ + DisplayName: bean.DataDisplayName, + Value: string(config.Data), + VariableSnapshot: variableSnapshotMap, + ResolvedValue: resolvedTemplate, + }, + SecretViewAccess: userHasAdminAccess, + } + if configType == repository.SECRET_TYPE { + if config.Data != nil { + if !userHasAdminAccess { + //removing keys and sending + resultMap := make(map[string]string) + resultMapFinal := make(map[string]string) + err = json.Unmarshal(config.Data, &resultMap) + if err != nil { + impl.logger.Warnw("unmarshal failed", "error", err) + } + for key, _ := range resultMap { + //hard-coding values to show them as hidden to user + resultMapFinal[key] = "*****" + } + resultByte, err := json.Marshal(resultMapFinal) + if err != nil { + impl.logger.Errorw("error while marshaling request", "err", err) + return nil, err + } + historyDto.CodeEditorValue.Value = string(resultByte) + } + } + historyDto.ExternalSecretType = config.ExternalSecretType + historyDto.RoleARN = config.RoleARN + historyDto.ESOSubPath = config.ESOSubPath + if config.External { + if config.ExternalSecretType == util.KubernetesSecret { + externalSecretData, err := json.Marshal(config.ExternalSecret) + if err != nil { + impl.logger.Errorw("error in marshaling external secret data", "err", err) + } + if len(externalSecretData) > 0 { + historyDto.CodeEditorValue.DisplayName = bean.ExternalSecretDisplayName + historyDto.CodeEditorValue.Value = string(externalSecretData) + } + } else if config.IsESOExternalSecretType() { + externalSecretDataBytes, jErr := json.Marshal(config.ESOSecretData) + if jErr != nil { + impl.logger.Errorw("error in marshaling eso secret data", "esoSecretData", config.ESOSecretData, "err", jErr) + return nil, jErr + } + if len(externalSecretDataBytes) > 0 { + historyDto.CodeEditorValue.DisplayName = bean.ESOSecretDataDisplayName + historyDto.CodeEditorValue.Value = string(externalSecretDataBytes) + } + } + } + } + return historyDto, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId int, configType repository.ConfigType) (history *repository.ConfigmapAndSecretHistory, exists bool, cmCsNames []string, err error) { + impl.logger.Debugw("received request, CheckIfHistoryExistsForPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) + //checking if history exists for pipelineId and wfrId + history, err = impl.configMapHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId, configType) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return history, false, cmCsNames, err + } else if err == pg.ErrNoRows { + return history, false, cmCsNames, nil + } + var configData []*bean2.ConfigData + if configType == repository.CONFIGMAP_TYPE { + configList := bean2.ConfigList{} + if len(history.Data) > 0 { + err = json.Unmarshal([]byte(history.Data), &configList) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return history, false, cmCsNames, err + } + } + configData = configList.ConfigData + } else if configType == repository.SECRET_TYPE { + secretList := bean2.SecretList{} + if len(history.Data) > 0 { + err = json.Unmarshal([]byte(history.Data), &secretList) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return history, false, cmCsNames, err + } + } + configData = secretList.ConfigData + } + for _, data := range configData { + cmCsNames = append(cmCsNames, data.Name) + } + if len(configData) == 0 { + return history, false, cmCsNames, nil + } + + return history, true, cmCsNames, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) GetDeployedHistoryList(pipelineId, baseConfigId int, configType repository.ConfigType, componentName string) ([]*bean.DeployedHistoryComponentMetadataDto, error) { + impl.logger.Debugw("received request, GetDeployedHistoryList", "pipelineId", pipelineId, "baseConfigId", baseConfigId) + + //checking if history exists for pipelineId and wfrId + histories, err := impl.configMapHistoryRepository.GetDeployedHistoryList(pipelineId, baseConfigId, configType, componentName) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in getting history list for pipelineId and baseConfigId", "err", err, "pipelineId", pipelineId) + return nil, err + } + var historyList []*bean.DeployedHistoryComponentMetadataDto + for _, history := range histories { + historyList = append(historyList, &bean.DeployedHistoryComponentMetadataDto{ + Id: history.Id, + DeployedOn: history.DeployedOn, + DeployedBy: history.DeployedByEmailId, + DeploymentStatus: history.DeploymentStatus, + }) + } + return historyList, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (cmId int, csId int, exists bool, err error) { + cmHistory, cmErr := impl.configMapHistoryRepository.GetDeployedHistoryForPipelineIdOnTime(pipelineId, deployedOn, repository.SECRET_TYPE) + if cmErr != nil && !errors.Is(cmErr, pg.ErrNoRows) { + impl.logger.Errorw("error in checking if config map history exists for pipelineId and deployedOn", "err", cmErr, "pipelineId", pipelineId, "deployedOn", deployedOn) + return cmId, csId, exists, cmErr + } + if cmErr == nil { + cmId = cmHistory.Id + } + csHistory, csErr := impl.configMapHistoryRepository.GetDeployedHistoryForPipelineIdOnTime(pipelineId, deployedOn, repository.SECRET_TYPE) + if csErr != nil && !errors.Is(csErr, pg.ErrNoRows) { + impl.logger.Errorw("error in checking if secret history exists for pipelineId and deployedOn", "err", csErr, "pipelineId", pipelineId, "deployedOn", deployedOn) + return cmId, csId, exists, csErr + } + if csErr == nil { + csId = csHistory.Id + } + if cmErr == nil && csErr == nil { + exists = true + } + return cmId, csId, exists, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, configType repository.ConfigType, userHasAdminAccess bool) ([]*bean.ComponentLevelHistoryDetailDto, error) { + history, err := impl.configMapHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId, configType) + if err != nil { + impl.logger.Errorw("error in getting histories for cm/cs", "err", err, "wfrId", wfrId, "pipelineId", pipelineId) + return nil, err + } + var configData []*bean2.ConfigData + var configList bean2.ConfigList + var secretList bean2.SecretList + if err != nil { + return nil, err + } + if configType == repository.CONFIGMAP_TYPE { + configList = bean2.ConfigList{} + if len(history.Data) > 0 { + err := json.Unmarshal([]byte(history.Data), &configList) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return nil, err + } + } + configData = configList.ConfigData + } else if configType == repository.SECRET_TYPE { + secretList = bean2.SecretList{} + if len(history.Data) > 0 { + err := json.Unmarshal([]byte(history.Data), &secretList) + if err != nil { + impl.logger.Debugw("error while Unmarshal", "err", err) + return nil, err + } + } + configData = secretList.ConfigData + } + resolvedDataMap, variableSnapshotMap, err := impl.scopedVariableManager.GetResolvedCMCSHistoryDtos(ctx, configType, configList, history, secretList) + if err != nil { + return nil, err + } + + var componentLevelHistoryData []*bean.ComponentLevelHistoryDetailDto + for _, config := range configData { + componentLevelData, err := impl.ConvertConfigDataToComponentLevelDto(config, configType, userHasAdminAccess) + if err != nil { + impl.logger.Errorw("error in converting data to componentLevelData", "err", err) + } + componentLevelData.HistoryConfig.CodeEditorValue.VariableSnapshot = variableSnapshotMap[config.Name] + componentLevelData.HistoryConfig.CodeEditorValue.ResolvedValue = string(resolvedDataMap[config.Name].Data) + componentLevelHistoryData = append(componentLevelHistoryData, componentLevelData) + } + return componentLevelHistoryData, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) ConvertConfigDataToComponentLevelDto(config *bean2.ConfigData, configType repository.ConfigType, userHasAdminAccess bool) (*bean.ComponentLevelHistoryDetailDto, error) { + historyDto := &bean.HistoryDetailDto{ + Type: config.Type, + External: &config.External, + MountPath: config.MountPath, + SubPath: &config.SubPath, + FilePermission: config.FilePermission, + CodeEditorValue: &bean.HistoryDetailConfig{ + DisplayName: bean.DataDisplayName, + Value: string(config.Data), + }, + } + var err error + if configType == repository.SECRET_TYPE { + if config.Data != nil { + if !userHasAdminAccess { + //removing keys and sending + resultMap := make(map[string]string) + resultMapFinal := make(map[string]string) + err = json.Unmarshal(config.Data, &resultMap) + if err != nil { + impl.logger.Warnw("unmarshal failed", "error", err) + return nil, err + } + for key, _ := range resultMap { + //hard-coding values to show them as hidden to user + resultMapFinal[key] = "*****" + } + resultByte, err := json.Marshal(resultMapFinal) + if err != nil { + impl.logger.Errorw("error while marshaling request", "err", err) + return nil, err + } + historyDto.CodeEditorValue.Value = string(resultByte) + } + } + historyDto.ExternalSecretType = config.ExternalSecretType + historyDto.RoleARN = config.RoleARN + historyDto.ESOSubPath = config.ESOSubPath + if config.External { + var externalSecretData []byte + displayName := historyDto.CodeEditorValue.DisplayName + if config.IsESOExternalSecretType() { + displayName = bean.ESOSecretDataDisplayName + externalSecretData, err = json.Marshal(config.ESOSecretData) + if err != nil { + impl.logger.Errorw("error in marshaling external secret data", "err", err) + return nil, err + } + } else { + displayName = bean.ExternalSecretDisplayName + externalSecretData, err = json.Marshal(config.ExternalSecret) + if err != nil { + impl.logger.Errorw("error in marshaling external secret data", "err", err) + return nil, err + } + } + if len(externalSecretData) > 0 { + historyDto.CodeEditorValue.DisplayName = displayName + historyDto.CodeEditorValue.Value = string(externalSecretData) + } + } + } + componentLevelData := &bean.ComponentLevelHistoryDetailDto{ + ComponentName: config.Name, + HistoryConfig: historyDto, + } + return componentLevelData, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) GetConfigmapHistoryDataByDeployedOnAndPipelineId(ctx context.Context, pipelineId int, deployedOn time.Time, userHasAdminAccess bool) (*bean3.DeploymentAndCmCsConfig, *bean3.DeploymentAndCmCsConfig, error) { + secretConfigData, err := impl.getResolvedConfigData(ctx, pipelineId, deployedOn, repository.SECRET_TYPE, userHasAdminAccess) + if err != nil { + impl.logger.Errorw("error in getting resolved secret config data in case of previous deployments ", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) + return nil, nil, err + } + cmConfigData, err := impl.getResolvedConfigData(ctx, pipelineId, deployedOn, repository.CONFIGMAP_TYPE, userHasAdminAccess) + if err != nil { + impl.logger.Errorw("error in getting resolved cm config data in case of previous deployments ", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) + return nil, nil, err + } + + return secretConfigData, cmConfigData, nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) getResolvedConfigData(ctx context.Context, pipelineId int, deployedOn time.Time, configType repository.ConfigType, userHasAdminAccess bool) (*bean3.DeploymentAndCmCsConfig, error) { + configsList := &bean4.ConfigsList{} + secretsList := &bean4.SecretsList{} + var err error + history, err := impl.configMapHistoryRepository.GetDeployedHistoryByPipelineIdAndDeployedOn(pipelineId, deployedOn, configType) + if err != nil { + impl.logger.Errorw("error in getting deployed history by pipeline id and deployed on", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) + return nil, err + } + if configType == repository.SECRET_TYPE { + _, secretsList, err = impl.getConfigDataRequestForHistory(history) + if err != nil { + impl.logger.Errorw("error in getting config data request for history", "err", err) + return nil, err + } + } else if configType == repository.CONFIGMAP_TYPE { + configsList, _, err = impl.getConfigDataRequestForHistory(history) + if err != nil { + impl.logger.Errorw("error in getting config data request for history", "cmCsHistory", history, "err", err) + return nil, err + } + } + + resolvedDataMap, variableSnapshotMap, err := impl.scopedVariableManager.GetResolvedCMCSHistoryDtos(ctx, configType, adaptor.ReverseConfigListConvertor(*configsList), history, adaptor.ReverseSecretListConvertor(*secretsList)) + if err != nil { + return nil, err + } + resolvedConfigDataList := make([]*bean4.ConfigData, 0, len(resolvedDataMap)) + for _, resolvedConfigData := range resolvedDataMap { + resolvedConfigDataList = append(resolvedConfigDataList, adapter.ConvertConfigDataToPipelineConfigData(&resolvedConfigData)) + } + configDataReq := &bean4.ConfigDataRequest{} + var resourceType bean4.ResourceType + if configType == repository.SECRET_TYPE { + impl.encodeSecretDataFromNonAdminUsers(secretsList.ConfigData, userHasAdminAccess) + impl.encodeSecretDataFromNonAdminUsers(resolvedConfigDataList, userHasAdminAccess) + configDataReq.ConfigData = secretsList.ConfigData + resourceType = bean4.CS + } else if configType == repository.CONFIGMAP_TYPE { + configDataReq.ConfigData = configsList.ConfigData + resourceType = bean4.CM + } + + configDataJson, err := utils.ConvertToJsonRawMessage(configDataReq) + if err != nil { + impl.logger.Errorw("getCmCsPublishedConfigResponse, error in converting config data to json raw message", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) + return nil, err + } + resolvedConfigDataReq := &bean4.ConfigDataRequest{ConfigData: resolvedConfigDataList} + resolvedConfigDataString, err := utils.ConvertToString(resolvedConfigDataReq) + if err != nil { + impl.logger.Errorw("getCmCsPublishedConfigResponse, error in converting config data to json raw message", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) + return nil, err + } + resolvedConfigDataStringJson, err := utils.ConvertToJsonRawMessage(resolvedConfigDataString) + if err != nil { + impl.logger.Errorw("getCmCsPublishedConfigResponse, error in ConvertToJsonRawMessage for resolvedJson", "resolvedJson", resolvedConfigDataStringJson, "err", err) + return nil, err + } + return bean3.NewDeploymentAndCmCsConfig().WithConfigData(configDataJson).WithResourceType(resourceType). + WithVariableSnapshot(variableSnapshotMap).WithResolvedValue(resolvedConfigDataStringJson), nil +} + +func (impl *ConfigMapHistoryReadServiceImpl) encodeSecretDataFromNonAdminUsers(configDataList []*bean4.ConfigData, userHasAdminAccess bool) { + for _, config := range configDataList { + if config.Data != nil { + if !userHasAdminAccess { + //removing keys and sending + resultMap := make(map[string]string) + resultMapFinal := make(map[string]string) + err := json.Unmarshal(config.Data, &resultMap) + if err != nil { + impl.logger.Errorw("unmarshal failed", "error", err) + return + } + for key, _ := range resultMap { + //hard-coding values to show them as hidden to user + resultMapFinal[key] = "*****" + } + config.Data, err = utils.ConvertToJsonRawMessage(resultMapFinal) + if err != nil { + impl.logger.Errorw("error while marshaling request", "err", err) + return + } + } + } + } +} + +func (impl *ConfigMapHistoryReadServiceImpl) getConfigDataRequestForHistory(history *repository.ConfigmapAndSecretHistory) (*bean4.ConfigsList, *bean4.SecretsList, error) { + + configsList := &bean4.ConfigsList{} + secretsList := &bean4.SecretsList{} + if history.IsConfigmapHistorySecretType() { + err := json.Unmarshal([]byte(history.Data), secretsList) + if err != nil { + impl.logger.Errorw("error while Unmarshal in secret history data", "error", err) + return configsList, secretsList, err + } + return configsList, secretsList, nil + } else if history.IsConfigmapHistoryConfigMapType() { + err := json.Unmarshal([]byte(history.Data), configsList) + if err != nil { + impl.logger.Errorw("error while Unmarshal in config history data", "historyData", history.Data, "error", err) + return configsList, secretsList, err + } + return configsList, secretsList, nil + } + return configsList, secretsList, nil +} diff --git a/pkg/deployment/manifest/configMapAndSecret/wire_configMapAndSecret.go b/pkg/deployment/manifest/configMapAndSecret/wire_configMapAndSecret.go new file mode 100644 index 00000000000..1a99ba27fe2 --- /dev/null +++ b/pkg/deployment/manifest/configMapAndSecret/wire_configMapAndSecret.go @@ -0,0 +1,11 @@ +package configMapAndSecret + +import ( + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" + "github.com/google/wire" +) + +var ConfigMapAndSecretWireSet = wire.NewSet( + read.NewConfigMapHistoryReadService, + wire.Bind(new(read.ConfigMapHistoryReadService), new(*read.ConfigMapHistoryReadServiceImpl)), +) diff --git a/pkg/pipeline/history/DeploymentTemplateHistoryService.go b/pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go similarity index 54% rename from pkg/pipeline/history/DeploymentTemplateHistoryService.go rename to pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go index d2eac61f809..ef0042390c7 100644 --- a/pkg/pipeline/history/DeploymentTemplateHistoryService.go +++ b/pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go @@ -14,11 +14,9 @@ * limitations under the License. */ -package history +package deploymentTemplate import ( - "context" - "errors" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" "time" @@ -30,9 +28,6 @@ import ( "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" "github.com/devtron-labs/devtron/pkg/variables" - "github.com/devtron-labs/devtron/pkg/variables/parsers" - repository6 "github.com/devtron-labs/devtron/pkg/variables/repository" - "github.com/devtron-labs/devtron/util" "github.com/go-pg/pg" "go.uber.org/zap" ) @@ -41,17 +36,6 @@ type DeploymentTemplateHistoryService interface { CreateDeploymentTemplateHistoryFromGlobalTemplate(chart *chartRepoRepository.Chart, tx *pg.Tx, IsAppMetricsEnabled bool) error CreateDeploymentTemplateHistoryFromEnvOverrideTemplate(envOverride *chartConfig.EnvConfigOverride, tx *pg.Tx, IsAppMetricsEnabled bool, pipelineId int) error CreateDeploymentTemplateHistoryForDeploymentTrigger(pipeline *pipelineConfig.Pipeline, envOverride *chartConfig.EnvConfigOverride, renderedImageTemplate string, deployedOn time.Time, deployedBy int32) (*repository.DeploymentTemplateHistory, error) - GetDeploymentDetailsForDeployedTemplateHistory(pipelineId, offset, limit int) ([]*DeploymentTemplateHistoryDto, error) - - GetHistoryForDeployedTemplateById(ctx context.Context, id int, pipelineId int) (*HistoryDetailDto, error) - CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId int) (historyId int, exists bool, err error) - CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (deploymentTemplateHistoryId int, exists bool, err error) - GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*DeployedHistoryComponentMetadataDto, error) - - // used for rollback - GetDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*HistoryDetailDto, error) - - GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId int) (*repository.DeploymentTemplateHistory, error) } type DeploymentTemplateHistoryServiceImpl struct { @@ -249,172 +233,3 @@ func (impl DeploymentTemplateHistoryServiceImpl) CreateDeploymentTemplateHistory } return history, nil } - -func (impl DeploymentTemplateHistoryServiceImpl) GetDeploymentDetailsForDeployedTemplateHistory(pipelineId, offset, limit int) ([]*DeploymentTemplateHistoryDto, error) { - histories, err := impl.deploymentTemplateHistoryRepository.GetDeploymentDetailsForDeployedTemplateHistory(pipelineId, offset, limit) - if err != nil { - impl.logger.Errorw("error in getting deployment template history", "err", err, "pipelineId", pipelineId) - return nil, err - } - //getting wfrList for status of history - wfrList, err := impl.cdWorkflowRepository.FindCdWorkflowMetaByPipelineId(pipelineId, offset, limit) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting ") - return nil, err - } - deploymentTimeStatusMap := make(map[time.Time]int) - for index, wfr := range wfrList { - deploymentTimeStatusMap[wfr.StartedOn] = index - } - var historiesDto []*DeploymentTemplateHistoryDto - for _, history := range histories { - if wfrIndex, ok := deploymentTimeStatusMap[history.DeployedOn]; ok { - userEmailId, err := impl.userService.GetActiveEmailById(history.DeployedBy) - if err != nil { - impl.logger.Errorw("unable to find user email by id", "err", err, "id", history.DeployedBy) - return nil, err - } - historyDto := &DeploymentTemplateHistoryDto{ - Id: history.Id, - AppId: history.AppId, - PipelineId: history.PipelineId, - Deployed: history.Deployed, - DeployedOn: history.DeployedOn, - DeployedBy: history.DeployedBy, - EmailId: userEmailId, - DeploymentStatus: wfrList[wfrIndex].Status, - WfrId: wfrList[wfrIndex].Id, - WorkflowType: string(wfrList[wfrIndex].WorkflowType), - } - historiesDto = append(historiesDto, historyDto) - } - } - return historiesDto, nil -} - -func (impl DeploymentTemplateHistoryServiceImpl) CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId int) (historyId int, exists bool, err error) { - impl.logger.Debugw("received request, CheckIfHistoryExistsForPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) - - //checking if history exists for pipelineId and wfrId - history, err := impl.deploymentTemplateHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return 0, false, err - } else if err == pg.ErrNoRows { - return 0, false, nil - } - return history.Id, true, nil -} - -func (impl DeploymentTemplateHistoryServiceImpl) GetDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*HistoryDetailDto, error) { - impl.logger.Debugw("received request, GetDeployedHistoryByPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) - - //checking if history exists for pipelineId and wfrId - history, err := impl.deploymentTemplateHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId) - if err != nil { - impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - - isSuperAdmin, err := util.GetIsSuperAdminFromContext(ctx) - if err != nil { - return nil, err - } - reference := repository6.HistoryReference{ - HistoryReferenceId: history.Id, - HistoryReferenceType: repository6.HistoryReferenceTypeDeploymentTemplate, - } - variableSnapshotMap, resolvedTemplate, err := impl.scopedVariableManager.GetVariableSnapshotAndResolveTemplate(history.Template, parsers.JsonVariableTemplate, reference, isSuperAdmin, false) - if err != nil { - impl.logger.Errorw("error while resolving template from history", "err", err, "wfrId", wfrId, "pipelineID", pipelineId) - } - - historyDto := &HistoryDetailDto{ - TemplateName: history.TemplateName, - TemplateVersion: history.TemplateVersion, - IsAppMetricsEnabled: &history.IsAppMetricsEnabled, - CodeEditorValue: &HistoryDetailConfig{ - DisplayName: "values.yaml", - Value: history.Template, - VariableSnapshot: variableSnapshotMap, - ResolvedValue: resolvedTemplate, - }, - } - return historyDto, nil -} - -func (impl DeploymentTemplateHistoryServiceImpl) GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*DeployedHistoryComponentMetadataDto, error) { - impl.logger.Debugw("received request, GetDeployedHistoryList", "pipelineId", pipelineId, "baseConfigId", baseConfigId) - - //checking if history exists for pipelineId and wfrId - histories, err := impl.deploymentTemplateHistoryRepository.GetDeployedHistoryList(pipelineId, baseConfigId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting history list for pipelineId and baseConfigId", "err", err, "pipelineId", pipelineId) - return nil, err - } - var historyList []*DeployedHistoryComponentMetadataDto - for _, history := range histories { - historyList = append(historyList, &DeployedHistoryComponentMetadataDto{ - Id: history.Id, - DeployedOn: history.DeployedOn, - DeployedBy: history.DeployedByEmailId, - DeploymentStatus: history.DeploymentStatus, - }) - } - return historyList, nil -} - -func (impl DeploymentTemplateHistoryServiceImpl) GetHistoryForDeployedTemplateById(ctx context.Context, id int, pipelineId int) (*HistoryDetailDto, error) { - history, err := impl.deploymentTemplateHistoryRepository.GetHistoryForDeployedTemplateById(id, pipelineId) - if err != nil { - impl.logger.Errorw("error in getting deployment template history", "err", err, "id", id, "pipelineId", pipelineId) - return nil, err - } - - isSuperAdmin, err := util.GetIsSuperAdminFromContext(ctx) - if err != nil { - return nil, err - } - reference := repository6.HistoryReference{ - HistoryReferenceId: history.Id, - HistoryReferenceType: repository6.HistoryReferenceTypeDeploymentTemplate, - } - variableSnapshotMap, resolvedTemplate, err := impl.scopedVariableManager.GetVariableSnapshotAndResolveTemplate(history.Template, parsers.JsonVariableTemplate, reference, isSuperAdmin, false) - if err != nil { - impl.logger.Errorw("error while resolving template from history", "err", err, "id", id, "pipelineID", pipelineId) - } - historyDto := &HistoryDetailDto{ - TemplateName: history.TemplateName, - TemplateVersion: history.TemplateVersion, - IsAppMetricsEnabled: &history.IsAppMetricsEnabled, - CodeEditorValue: &HistoryDetailConfig{ - DisplayName: "values.yaml", - Value: history.Template, - VariableSnapshot: variableSnapshotMap, - ResolvedValue: resolvedTemplate, - }, - } - return historyDto, nil -} - -func (impl DeploymentTemplateHistoryServiceImpl) CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (deploymentTemplateHistoryId int, exists bool, err error) { - history, err := impl.deploymentTemplateHistoryRepository.GetDeployedHistoryForPipelineIdOnTime(pipelineId, deployedOn) - if err != nil && !errors.Is(err, pg.ErrNoRows) { - impl.logger.Errorw("error in checking if history exists for pipelineId and deployedOn", "err", err, "pipelineId", pipelineId, "deployedOn", deployedOn) - return deploymentTemplateHistoryId, exists, err - } else if errors.Is(err, pg.ErrNoRows) { - return deploymentTemplateHistoryId, exists, nil - } - deploymentTemplateHistoryId = history.Id - exists = true - return deploymentTemplateHistoryId, exists, err -} - -func (impl DeploymentTemplateHistoryServiceImpl) GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId int) (*repository.DeploymentTemplateHistory, error) { - history, err := impl.deploymentTemplateHistoryRepository.GetHistoryForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId) - if err != nil { - impl.logger.Errorw("error in getting deployment template history", "err", err, "deploymentTemplateHistoryId", deploymentTemplateHistoryId, "pipelineId", pipelineId) - return nil, err - } - return history, nil -} diff --git a/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go b/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go new file mode 100644 index 00000000000..e8233417816 --- /dev/null +++ b/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go @@ -0,0 +1,150 @@ +package read + +import ( + "context" + "errors" + "github.com/devtron-labs/devtron/pkg/pipeline/history/adaptors" + "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" + repository2 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" + "github.com/devtron-labs/devtron/pkg/variables" + "github.com/devtron-labs/devtron/pkg/variables/parsers" + "github.com/devtron-labs/devtron/pkg/variables/repository" + "github.com/devtron-labs/devtron/util" + "github.com/go-pg/pg" + "go.uber.org/zap" + "time" +) + +type DeploymentTemplateHistoryReadService interface { + GetHistoryForDeployedTemplateById(ctx context.Context, id int, pipelineId int) (*bean.HistoryDetailDto, error) + CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId int) (historyId int, exists bool, err error) + CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (deploymentTemplateHistoryId int, exists bool, err error) + GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*bean.DeployedHistoryComponentMetadataDto, error) + // used for rollback + GetDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*bean.HistoryDetailDto, error) + + GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId int) (*repository2.DeploymentTemplateHistory, error) +} + +type DeploymentTemplateHistoryReadServiceImpl struct { + logger *zap.SugaredLogger + deploymentTemplateHistoryRepository repository2.DeploymentTemplateHistoryRepository + scopedVariableManager variables.ScopedVariableManager +} + +func NewDeploymentTemplateHistoryReadServiceImpl( + logger *zap.SugaredLogger, + deploymentTemplateHistoryRepository repository2.DeploymentTemplateHistoryRepository, + scopedVariableManager variables.ScopedVariableManager, +) *DeploymentTemplateHistoryReadServiceImpl { + return &DeploymentTemplateHistoryReadServiceImpl{ + logger: logger, + deploymentTemplateHistoryRepository: deploymentTemplateHistoryRepository, + scopedVariableManager: scopedVariableManager, + } +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetHistoryForDeployedTemplateById(ctx context.Context, id int, pipelineId int) (*bean.HistoryDetailDto, error) { + history, err := impl.deploymentTemplateHistoryRepository.GetHistoryForDeployedTemplateById(id, pipelineId) + if err != nil { + impl.logger.Errorw("error in getting deployment template history", "err", err, "id", id, "pipelineId", pipelineId) + return nil, err + } + + isSuperAdmin, err := util.GetIsSuperAdminFromContext(ctx) + if err != nil { + return nil, err + } + reference := repository.HistoryReference{ + HistoryReferenceId: history.Id, + HistoryReferenceType: repository.HistoryReferenceTypeDeploymentTemplate, + } + variableSnapshotMap, resolvedTemplate, err := impl.scopedVariableManager.GetVariableSnapshotAndResolveTemplate(history.Template, parsers.JsonVariableTemplate, reference, isSuperAdmin, false) + if err != nil { + impl.logger.Errorw("error while resolving template from history", "err", err, "id", id, "pipelineID", pipelineId) + } + return adaptors.GetHistoryDetailDto(history, variableSnapshotMap, resolvedTemplate), nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId int) (historyId int, exists bool, err error) { + impl.logger.Debugw("received request, CheckIfHistoryExistsForPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) + + //checking if history exists for pipelineId and wfrId + history, err := impl.deploymentTemplateHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return 0, false, err + } else if err == pg.ErrNoRows { + return 0, false, nil + } + return history.Id, true, nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*bean.HistoryDetailDto, error) { + impl.logger.Debugw("received request, GetDeployedHistoryByPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) + + //checking if history exists for pipelineId and wfrId + history, err := impl.deploymentTemplateHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId) + if err != nil { + impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + + isSuperAdmin, err := util.GetIsSuperAdminFromContext(ctx) + if err != nil { + return nil, err + } + reference := repository.HistoryReference{ + HistoryReferenceId: history.Id, + HistoryReferenceType: repository.HistoryReferenceTypeDeploymentTemplate, + } + variableSnapshotMap, resolvedTemplate, err := impl.scopedVariableManager.GetVariableSnapshotAndResolveTemplate(history.Template, parsers.JsonVariableTemplate, reference, isSuperAdmin, false) + if err != nil { + impl.logger.Errorw("error while resolving template from history", "err", err, "wfrId", wfrId, "pipelineID", pipelineId) + } + + return adaptors.GetHistoryDetailDto(history, variableSnapshotMap, resolvedTemplate), nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (deploymentTemplateHistoryId int, exists bool, err error) { + history, err := impl.deploymentTemplateHistoryRepository.GetDeployedHistoryForPipelineIdOnTime(pipelineId, deployedOn) + if err != nil && !errors.Is(err, pg.ErrNoRows) { + impl.logger.Errorw("error in checking if history exists for pipelineId and deployedOn", "err", err, "pipelineId", pipelineId, "deployedOn", deployedOn) + return deploymentTemplateHistoryId, exists, err + } else if errors.Is(err, pg.ErrNoRows) { + return deploymentTemplateHistoryId, exists, nil + } + deploymentTemplateHistoryId = history.Id + exists = true + return deploymentTemplateHistoryId, exists, err +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId int) (*repository2.DeploymentTemplateHistory, error) { + history, err := impl.deploymentTemplateHistoryRepository.GetHistoryForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId) + if err != nil { + impl.logger.Errorw("error in getting deployment template history", "err", err, "deploymentTemplateHistoryId", deploymentTemplateHistoryId, "pipelineId", pipelineId) + return nil, err + } + return history, nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*bean.DeployedHistoryComponentMetadataDto, error) { + impl.logger.Debugw("received request, GetDeployedHistoryList", "pipelineId", pipelineId, "baseConfigId", baseConfigId) + + //checking if history exists for pipelineId and wfrId + histories, err := impl.deploymentTemplateHistoryRepository.GetDeployedHistoryList(pipelineId, baseConfigId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in getting history list for pipelineId and baseConfigId", "err", err, "pipelineId", pipelineId) + return nil, err + } + var historyList []*bean.DeployedHistoryComponentMetadataDto + for _, history := range histories { + historyList = append(historyList, &bean.DeployedHistoryComponentMetadataDto{ + Id: history.Id, + DeployedOn: history.DeployedOn, + DeployedBy: history.DeployedByEmailId, + DeploymentStatus: history.DeploymentStatus, + }) + } + return historyList, nil +} diff --git a/pkg/deployment/manifest/deploymentTemplate/wire_deploymentTemplate.go b/pkg/deployment/manifest/deploymentTemplate/wire_deploymentTemplate.go index 5e102adbb0c..67ec97adb95 100644 --- a/pkg/deployment/manifest/deploymentTemplate/wire_deploymentTemplate.go +++ b/pkg/deployment/manifest/deploymentTemplate/wire_deploymentTemplate.go @@ -18,6 +18,7 @@ package deploymentTemplate import ( "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/google/wire" ) @@ -28,4 +29,6 @@ var DeploymentTemplateWireSet = wire.NewSet( wire.Bind(new(DeploymentTemplateValidationService), new(*DeploymentTemplateValidationServiceImpl)), chartRef.NewChartRefServiceImpl, wire.Bind(new(chartRef.ChartRefService), new(*chartRef.ChartRefServiceImpl)), + read.NewDeploymentTemplateHistoryReadServiceImpl, + wire.Bind(new(read.DeploymentTemplateHistoryReadService), new(*read.DeploymentTemplateHistoryReadServiceImpl)), ) diff --git a/pkg/deployment/manifest/wire_deployment_manifest.go b/pkg/deployment/manifest/wire_deployment_manifest.go index 2500a5092a8..4a48b1f4d84 100644 --- a/pkg/deployment/manifest/wire_deployment_manifest.go +++ b/pkg/deployment/manifest/wire_deployment_manifest.go @@ -17,6 +17,7 @@ package manifest import ( + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/google/wire" @@ -25,6 +26,7 @@ import ( var DeploymentManifestWireSet = wire.NewSet( deployedAppMetrics.AppMetricsWireSet, deploymentTemplate.DeploymentTemplateWireSet, + configMapAndSecret.ConfigMapAndSecretWireSet, NewManifestCreationServiceImpl, wire.Bind(new(ManifestCreationService), new(*ManifestCreationServiceImpl)), diff --git a/pkg/deployment/trigger/devtronApps/PreStageTriggerService.go b/pkg/deployment/trigger/devtronApps/PreStageTriggerService.go index 33e47e6b1a9..d8cda2ab63c 100644 --- a/pkg/deployment/trigger/devtronApps/PreStageTriggerService.go +++ b/pkg/deployment/trigger/devtronApps/PreStageTriggerService.go @@ -29,6 +29,7 @@ import ( "github.com/devtron-labs/devtron/internal/util" bean6 "github.com/devtron-labs/devtron/pkg/attributes/bean" bean4 "github.com/devtron-labs/devtron/pkg/bean" + bean7 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository" bean5 "github.com/devtron-labs/devtron/pkg/deployment/common/bean" adapter2 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/adapter" @@ -37,7 +38,6 @@ import ( "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" pipelineConfigBean "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" repository3 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/pipeline/types" "github.com/devtron-labs/devtron/pkg/plugin" @@ -493,7 +493,7 @@ func (impl *TriggerServiceImpl) buildWFRequest(runner *pipelineConfig.CdWorkflow return nil, err } ciProjectDetail.CommitTime = commitTime.Format(bean4.LayoutRFC3339) - } else if ciPipeline.PipelineType == string(CiPipeline.CI_JOB) { + } else if ciPipeline.PipelineType == string(bean7.CI_JOB) { // This has been done to resolve unmarshalling issue in ci-runner, in case of no commit time(eg- polling container images) ciProjectDetail.CommitTime = time.Time{}.Format(bean4.LayoutRFC3339) } else { diff --git a/pkg/deployment/trigger/devtronApps/TriggerService.go b/pkg/deployment/trigger/devtronApps/TriggerService.go index a4ffae1c152..56199aa17bb 100644 --- a/pkg/deployment/trigger/devtronApps/TriggerService.go +++ b/pkg/deployment/trigger/devtronApps/TriggerService.go @@ -51,6 +51,7 @@ import ( "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/auth/user" bean2 "github.com/devtron-labs/devtron/pkg/bean" + pipeline2 "github.com/devtron-labs/devtron/pkg/build/pipeline" chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/deployment/common" @@ -157,7 +158,7 @@ type TriggerServiceImpl struct { cdWorkflowRepository pipelineConfig.CdWorkflowRepository ciWorkflowRepository pipelineConfig.CiWorkflowRepository ciArtifactRepository repository3.CiArtifactRepository - ciTemplateService pipeline.CiTemplateService + ciTemplateService pipeline2.CiTemplateReadService materialRepository pipelineConfig.MaterialRepository appLabelRepository pipelineConfig.AppLabelRepository ciPipelineRepository pipelineConfig.CiPipelineRepository @@ -214,7 +215,7 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger, cdWorkflowRepository pipelineConfig.CdWorkflowRepository, ciWorkflowRepository pipelineConfig.CiWorkflowRepository, ciArtifactRepository repository3.CiArtifactRepository, - ciTemplateService pipeline.CiTemplateService, + ciTemplateService pipeline2.CiTemplateReadService, materialRepository pipelineConfig.MaterialRepository, appLabelRepository pipelineConfig.AppLabelRepository, ciPipelineRepository pipelineConfig.CiPipelineRepository, diff --git a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go index 31090d42b8a..5069e26a650 100644 --- a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go +++ b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go @@ -6,12 +6,13 @@ import ( "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history" + bean2 "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" "go.uber.org/zap" ) type DeploymentHistoryService interface { GetCdPipelineDeploymentHistory(req *historyBean.CdPipelineDeploymentHistoryListReq) (resp historyBean.DeploymentHistoryResp, err error) - GetCdPipelineDeploymentHistoryConfigList(req *historyBean.CdPipelineDeploymentHistoryConfigListReq) (resp []*history.DeployedHistoryComponentMetadataDto, err error) + GetCdPipelineDeploymentHistoryConfigList(req *historyBean.CdPipelineDeploymentHistoryConfigListReq) (resp []*bean2.DeployedHistoryComponentMetadataDto, err error) } type DeploymentHistoryServiceImpl struct { @@ -62,7 +63,7 @@ func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistory(req *hi return resp, nil } -func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistoryConfigList(req *historyBean.CdPipelineDeploymentHistoryConfigListReq) (resp []*history.DeployedHistoryComponentMetadataDto, err error) { +func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistoryConfigList(req *historyBean.CdPipelineDeploymentHistoryConfigListReq) (resp []*bean2.DeployedHistoryComponentMetadataDto, err error) { res, err := impl.deployedConfigurationHistoryService.GetDeployedHistoryComponentList(req.PipelineId, req.BaseConfigurationId, req.HistoryComponent, req.HistoryComponentName) if err != nil { impl.logger.Errorw("service err, GetDeployedHistoryComponentList", "err", err, "pipelineId", req.PipelineId) diff --git a/pkg/generateManifest/DeploymentTemplateService.go b/pkg/generateManifest/DeploymentTemplateService.go index 1b8dadb6aff..3a939b38573 100644 --- a/pkg/generateManifest/DeploymentTemplateService.go +++ b/pkg/generateManifest/DeploymentTemplateService.go @@ -35,10 +35,10 @@ import ( chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" repository3 "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" bean2 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean" k8s2 "github.com/devtron-labs/devtron/pkg/k8s" "github.com/devtron-labs/devtron/pkg/pipeline" - "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/resourceQualifiers" "github.com/devtron-labs/devtron/pkg/variables" "github.com/devtron-labs/devtron/pkg/variables/parsers" @@ -57,6 +57,7 @@ import ( "sync" ) +// TODO: Prakash, move this interface to pkg/deployment/manifest/deploymentTemplate, both are same type DeploymentTemplateService interface { FetchDeploymentsWithChartRefs(appId int, envId int) ([]*repository.DeploymentTemplateComparisonMetadata, error) GetDeploymentTemplate(ctx context.Context, request DeploymentTemplateRequest) (DeploymentTemplateResponse, error) @@ -66,25 +67,25 @@ type DeploymentTemplateService interface { ResolveTemplateVariables(ctx context.Context, values string, request DeploymentTemplateRequest) (string, map[string]string, error) } type DeploymentTemplateServiceImpl struct { - Logger *zap.SugaredLogger - chartService chart.ChartService - appListingService app.AppListingService - deploymentTemplateRepository repository.DeploymentTemplateRepository - helmAppService client.HelmAppService - chartTemplateServiceImpl util.ChartTemplateService - K8sUtil *k8s.K8sServiceImpl - helmAppClient gRPC.HelmAppClient - propertiesConfigService pipeline.PropertiesConfigService - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService - environmentRepository repository3.EnvironmentRepository - appRepository appRepository.AppRepository - scopedVariableManager variables.ScopedVariableManager - chartRefService chartRef.ChartRefService - pipelineOverrideRepository chartConfig.PipelineOverrideRepository - pipelineRepository pipelineConfig.PipelineRepository - chartRepository chartRepoRepository.ChartRepository - restartWorkloadConfig *RestartWorkloadConfig - mergeUtil *util.MergeUtil + Logger *zap.SugaredLogger + chartService chart.ChartService + appListingService app.AppListingService + deploymentTemplateRepository repository.DeploymentTemplateRepository + helmAppService client.HelmAppService + chartTemplateServiceImpl util.ChartTemplateService + K8sUtil *k8s.K8sServiceImpl + helmAppClient gRPC.HelmAppClient + propertiesConfigService pipeline.PropertiesConfigService + environmentRepository repository3.EnvironmentRepository + appRepository appRepository.AppRepository + scopedVariableManager variables.ScopedVariableManager + chartRefService chartRef.ChartRefService + pipelineOverrideRepository chartConfig.PipelineOverrideRepository + pipelineRepository pipelineConfig.PipelineRepository + chartRepository chartRepoRepository.ChartRepository + restartWorkloadConfig *RestartWorkloadConfig + mergeUtil *util.MergeUtil + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService } func GetRestartWorkloadConfig() (*RestartWorkloadConfig, error) { @@ -101,7 +102,6 @@ func NewDeploymentTemplateServiceImpl(Logger *zap.SugaredLogger, chartService ch helmAppClient gRPC.HelmAppClient, K8sUtil *k8s.K8sServiceImpl, propertiesConfigService pipeline.PropertiesConfigService, - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService, environmentRepository repository3.EnvironmentRepository, appRepository appRepository.AppRepository, scopedVariableManager variables.ScopedVariableManager, @@ -110,26 +110,27 @@ func NewDeploymentTemplateServiceImpl(Logger *zap.SugaredLogger, chartService ch chartRepository chartRepoRepository.ChartRepository, pipelineRepository pipelineConfig.PipelineRepository, mergeUtil *util.MergeUtil, + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService, ) (*DeploymentTemplateServiceImpl, error) { deploymentTemplateServiceImpl := &DeploymentTemplateServiceImpl{ - Logger: Logger, - chartService: chartService, - appListingService: appListingService, - deploymentTemplateRepository: deploymentTemplateRepository, - helmAppService: helmAppService, - chartTemplateServiceImpl: chartTemplateServiceImpl, - K8sUtil: K8sUtil, - helmAppClient: helmAppClient, - propertiesConfigService: propertiesConfigService, - deploymentTemplateHistoryService: deploymentTemplateHistoryService, - environmentRepository: environmentRepository, - appRepository: appRepository, - scopedVariableManager: scopedVariableManager, - chartRefService: chartRefService, - pipelineOverrideRepository: pipelineOverrideRepository, - chartRepository: chartRepository, - pipelineRepository: pipelineRepository, - mergeUtil: mergeUtil, + Logger: Logger, + chartService: chartService, + appListingService: appListingService, + deploymentTemplateRepository: deploymentTemplateRepository, + helmAppService: helmAppService, + chartTemplateServiceImpl: chartTemplateServiceImpl, + K8sUtil: K8sUtil, + helmAppClient: helmAppClient, + propertiesConfigService: propertiesConfigService, + environmentRepository: environmentRepository, + appRepository: appRepository, + scopedVariableManager: scopedVariableManager, + chartRefService: chartRefService, + pipelineOverrideRepository: pipelineOverrideRepository, + chartRepository: chartRepository, + pipelineRepository: pipelineRepository, + mergeUtil: mergeUtil, + deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, } cfg, err := GetRestartWorkloadConfig() if err != nil { @@ -360,7 +361,7 @@ func (impl DeploymentTemplateServiceImpl) fetchResolvedTemplateForPublishedEnvs( } func (impl DeploymentTemplateServiceImpl) fetchTemplateForDeployedEnv(ctx context.Context, request DeploymentTemplateRequest) (*DeploymentTemplateResponse, error) { - historyObject, err := impl.deploymentTemplateHistoryService.GetHistoryForDeployedTemplateById(ctx, request.DeploymentTemplateHistoryId, request.PipelineId) + historyObject, err := impl.deploymentTemplateHistoryReadService.GetHistoryForDeployedTemplateById(ctx, request.DeploymentTemplateHistoryId, request.PipelineId) if err != nil { impl.Logger.Errorw("error in getting deployment template history", "err", err, "id", request.DeploymentTemplateHistoryId, "pipelineId", request.PipelineId) return nil, err diff --git a/pkg/k8s/capacity/bean/bean.go b/pkg/k8s/capacity/bean/bean.go index b790eabf01f..5d2146142ef 100644 --- a/pkg/k8s/capacity/bean/bean.go +++ b/pkg/k8s/capacity/bean/bean.go @@ -82,6 +82,8 @@ type ClusterCapacityDetail struct { ServerVersion string `json:"serverVersion,omitempty"` Cpu *ResourceDetailObject `json:"cpu"` Memory *ResourceDetailObject `json:"memory"` + IsVirtualCluster bool `json:"isVirtualCluster"` + IsProd bool `json:"isProd"` } type NodeCapacityDetail struct { diff --git a/pkg/k8s/capacity/k8sCapacityService.go b/pkg/k8s/capacity/k8sCapacityService.go index 7768f810f50..a60e6fe0599 100644 --- a/pkg/k8s/capacity/k8sCapacityService.go +++ b/pkg/k8s/capacity/k8sCapacityService.go @@ -96,6 +96,8 @@ func (impl *K8sCapacityServiceImpl) GetClusterCapacityDetailList(ctx context.Con } clusterCapacityDetail.Id = cluster.Id clusterCapacityDetail.Name = cluster.ClusterName + clusterCapacityDetail.IsVirtualCluster = cluster.IsVirtualCluster + clusterCapacityDetail.IsProd = cluster.IsProd clustersDetails = append(clustersDetails, clusterCapacityDetail) } return clustersDetails, nil @@ -140,6 +142,7 @@ func (impl *K8sCapacityServiceImpl) GetClusterCapacityDetail(ctx context.Context return nil, err } } + clusterDetail.IsProd = cluster.IsProd return clusterDetail, nil } diff --git a/pkg/module/ModuleCacheService.go b/pkg/module/ModuleCacheService.go index 76f3a58df55..57f45922d67 100644 --- a/pkg/module/ModuleCacheService.go +++ b/pkg/module/ModuleCacheService.go @@ -77,23 +77,6 @@ func NewModuleCacheServiceImpl(logger *zap.SugaredLogger, K8sUtil *k8s.K8sServic return nil, err } - // if old installation (i.e. project was created more than 1 hour ago then insert rest entries) - teamId := 1 - team, err := teamService.FetchOne(teamId) - if err != nil { - log.Println("Error while getting team.", "teamId", teamId, "err", err) - return nil, err - } - - // insert first release components if this was old release and user installed full mode at that time - if time.Now().After(team.CreatedOn.Add(1 * time.Hour)) { - for _, supportedModuleName := range SupportedModuleNamesListFirstReleaseExcludingCicd { - err = impl.updateModuleToInstalled(supportedModuleName) - if err != nil { - return nil, err - } - } - } } } diff --git a/pkg/pipeline/AppArtifactManager.go b/pkg/pipeline/AppArtifactManager.go index 088cef8b585..29306dfa4e7 100644 --- a/pkg/pipeline/AppArtifactManager.go +++ b/pkg/pipeline/AppArtifactManager.go @@ -18,6 +18,7 @@ package pipeline import ( argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean" + "github.com/devtron-labs/devtron/pkg/build/pipeline" pipelineBean "github.com/devtron-labs/devtron/pkg/pipeline/bean" "sort" "strings" @@ -59,7 +60,7 @@ type AppArtifactManagerImpl struct { cdPipelineConfigService CdPipelineConfigService dockerArtifactRegistry dockerArtifactStoreRegistry.DockerArtifactStoreRepository CiPipelineRepository pipelineConfig.CiPipelineRepository - ciTemplateService CiTemplateService + ciTemplateService pipeline.CiTemplateReadService } func NewAppArtifactManagerImpl( @@ -73,7 +74,7 @@ func NewAppArtifactManagerImpl( cdPipelineConfigService CdPipelineConfigService, dockerArtifactRegistry dockerArtifactStoreRegistry.DockerArtifactStoreRepository, CiPipelineRepository pipelineConfig.CiPipelineRepository, - ciTemplateService CiTemplateService) *AppArtifactManagerImpl { + ciTemplateService pipeline.CiTemplateReadService) *AppArtifactManagerImpl { cdConfig, err := types.GetCdConfig() if err != nil { return nil diff --git a/pkg/pipeline/BuildPipelineConfigService.go b/pkg/pipeline/BuildPipelineConfigService.go index 225fb5f3152..8eb463d3eba 100644 --- a/pkg/pipeline/BuildPipelineConfigService.go +++ b/pkg/pipeline/BuildPipelineConfigService.go @@ -30,8 +30,9 @@ import ( "github.com/devtron-labs/devtron/pkg/attributes" bean2 "github.com/devtron-labs/devtron/pkg/attributes/bean" "github.com/devtron-labs/devtron/pkg/bean" + "github.com/devtron-labs/devtron/pkg/build/pipeline" + bean3 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" pipelineConfigBean "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/pipeline/repository" "github.com/devtron-labs/devtron/pkg/pipeline/types" @@ -114,6 +115,7 @@ type CiPipelineConfigService interface { type CiPipelineConfigServiceImpl struct { logger *zap.SugaredLogger ciTemplateService CiTemplateService + ciTemplateReadService pipeline.CiTemplateReadService materialRepo pipelineConfig.MaterialRepository ciPipelineRepository pipelineConfig.CiPipelineRepository ciConfig *types.CiCdConfig @@ -153,6 +155,7 @@ func NewCiPipelineConfigServiceImpl(logger *zap.SugaredLogger, pipelineStageService PipelineStageService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, ciTemplateService CiTemplateService, + ciTemplateReadService pipeline.CiTemplateReadService, ciTemplateOverrideRepository pipelineConfig.CiTemplateOverrideRepository, CiTemplateHistoryService history.CiTemplateHistoryService, enforcerUtil rbac.EnforcerUtil, @@ -183,6 +186,7 @@ func NewCiPipelineConfigServiceImpl(logger *zap.SugaredLogger, pipelineStageService: pipelineStageService, ciPipelineMaterialRepository: ciPipelineMaterialRepository, ciTemplateService: ciTemplateService, + ciTemplateReadService: ciTemplateReadService, ciTemplateOverrideRepository: ciTemplateOverrideRepository, CiTemplateHistoryService: CiTemplateHistoryService, enforcerUtil: enforcerUtil, @@ -199,7 +203,7 @@ func NewCiPipelineConfigServiceImpl(logger *zap.SugaredLogger, func (impl *CiPipelineConfigServiceImpl) getCiTemplateVariablesByAppIds(appIds []int) (map[int]*bean.CiConfigRequest, error) { ciConfigMap := make(map[int]*bean.CiConfigRequest) - ciTemplateMap, err := impl.ciTemplateService.FindByAppIds(appIds) + ciTemplateMap, err := impl.ciTemplateReadService.FindByAppIds(appIds) if err != nil && !errors.IsNotFound(err) { impl.logger.Errorw("error in fetching ci pipeline", "appIds", appIds, "err", err) return nil, err @@ -287,17 +291,17 @@ func (impl *CiPipelineConfigServiceImpl) patchCiPipelineUpdateSource(baseCiConfi } // updating PipelineType from db if not present in request if modifiedCiPipeline.PipelineType == "" { - if CiPipeline.PipelineType(pipeline.PipelineType) != "" { - modifiedCiPipeline.PipelineType = CiPipeline.PipelineType(pipeline.PipelineType) + if bean3.PipelineType(pipeline.PipelineType) != "" { + modifiedCiPipeline.PipelineType = bean3.PipelineType(pipeline.PipelineType) } else { // updating default pipelineType if not present in request - modifiedCiPipeline.PipelineType = CiPipeline.DefaultPipelineType + modifiedCiPipeline.PipelineType = bean3.DefaultPipelineType } } if !modifiedCiPipeline.PipelineType.IsValidPipelineType() { impl.logger.Debugw(" Invalid PipelineType", "PipelineType", modifiedCiPipeline.PipelineType) - errorMessage := fmt.Sprintf(CiPipeline.PIPELINE_TYPE_IS_NOT_VALID, modifiedCiPipeline.Name) + errorMessage := fmt.Sprintf(bean3.PIPELINE_TYPE_IS_NOT_VALID, modifiedCiPipeline.Name) return nil, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage(errorMessage).WithUserMessage(errorMessage) } cannotUpdate := false @@ -434,7 +438,7 @@ func (impl *CiPipelineConfigServiceImpl) buildExternalCiWebhookSchema() map[stri } func (impl *CiPipelineConfigServiceImpl) getCiTemplateVariables(appId int) (ciConfig *bean.CiConfigRequest, err error) { - ciTemplateBean, err := impl.ciTemplateService.FindByAppId(appId) + ciTemplateBean, err := impl.ciTemplateReadService.FindByAppId(appId) if err != nil && !errors.IsNotFound(err) { impl.logger.Errorw("error in fetching ci pipeline", "appId", appId, "err", err) return nil, err @@ -525,8 +529,8 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipeline(appId int) (ciConfig *bea } } //map of ciPipelineId and their templateOverrideConfig - ciOverrideTemplateMap := make(map[int]*pipelineConfigBean.CiTemplateBean) - ciTemplateBeanOverrides, err := impl.ciTemplateService.FindTemplateOverrideByAppId(appId) + ciOverrideTemplateMap := make(map[int]*bean3.CiTemplateBean) + ciTemplateBeanOverrides, err := impl.ciTemplateReadService.FindTemplateOverrideByAppId(appId) if err != nil { return nil, err } @@ -591,7 +595,7 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipeline(appId int) (ciConfig *bea AfterDockerBuildScripts: afterDockerBuildScripts, ScanEnabled: pipeline.ScanEnabled, IsDockerConfigOverridden: pipeline.IsDockerConfigOverridden, - PipelineType: CiPipeline.PipelineType(pipeline.PipelineType), + PipelineType: bean3.PipelineType(pipeline.PipelineType), } ciEnvMapping, err := impl.ciPipelineRepository.FindCiEnvMappingByCiPipelineId(pipeline.Id) if err != nil && err != pg.ErrNoRows { @@ -735,7 +739,7 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipelineById(pipelineId int) (ciPi AfterDockerBuildScripts: afterDockerBuildScripts, ScanEnabled: pipeline.ScanEnabled, IsDockerConfigOverridden: pipeline.IsDockerConfigOverridden, - PipelineType: CiPipeline.PipelineType(pipeline.PipelineType), + PipelineType: bean3.PipelineType(pipeline.PipelineType), } customTag, err := impl.customTagService.GetActiveCustomTagByEntityKeyAndValue(pipelineConfigBean.EntityTypeCiPipelineId, strconv.Itoa(pipeline.Id)) if err != nil && err != pg.ErrNoRows { @@ -757,7 +761,7 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipelineById(pipelineId int) (ciPi ciPipeline.EnvironmentId = ciEnvMapping.EnvironmentId } if !ciPipeline.IsExternal && ciPipeline.IsDockerConfigOverridden { - ciTemplateBean, err := impl.ciTemplateService.FindTemplateOverrideByCiPipelineId(ciPipeline.Id) + ciTemplateBean, err := impl.ciTemplateReadService.FindTemplateOverrideByCiPipelineId(ciPipeline.Id) if err != nil { return nil, err } @@ -834,8 +838,8 @@ func (impl *CiPipelineConfigServiceImpl) GetTriggerViewCiPipeline(appId int) (*b return nil, err } - ciOverrideTemplateMap := make(map[int]*pipelineConfigBean.CiTemplateBean) - ciTemplateBeanOverrides, err := impl.ciTemplateService.FindTemplateOverrideByAppId(appId) + ciOverrideTemplateMap := make(map[int]*bean3.CiTemplateBean) + ciTemplateBeanOverrides, err := impl.ciTemplateReadService.FindTemplateOverrideByAppId(appId) if err != nil { return nil, err } @@ -859,7 +863,7 @@ func (impl *CiPipelineConfigServiceImpl) GetTriggerViewCiPipeline(appId int) (*b ParentCiPipeline: pipeline.ParentCiPipeline, ScanEnabled: pipeline.ScanEnabled, IsDockerConfigOverridden: pipeline.IsDockerConfigOverridden, - PipelineType: CiPipeline.PipelineType(pipeline.PipelineType), + PipelineType: bean3.PipelineType(pipeline.PipelineType), } if ciTemplateBean, ok := ciOverrideTemplateMap[pipeline.Id]; ok { templateOverride := ciTemplateBean.CiTemplateOverride @@ -1192,7 +1196,7 @@ func (impl *CiPipelineConfigServiceImpl) UpdateCiTemplate(updateRequest *bean.Ci } ciBuildConfig.Id = originalCiBuildConfig.Id - ciTemplateBean := &pipelineConfigBean.CiTemplateBean{ + ciTemplateBean := &bean3.CiTemplateBean{ CiTemplate: ciTemplate, CiBuildConfig: ciBuildConfig, UserId: updateRequest.UserId, @@ -1225,7 +1229,7 @@ func (impl *CiPipelineConfigServiceImpl) UpdateCiTemplate(updateRequest *bean.Ci } for _, ciTemplateOverride := range ciTemplateOverrides { if _, ok := ciPipelineIdsMap[ciTemplateOverride.CiPipelineId]; ok { - if ciPipelineIdsMap[ciTemplateOverride.CiPipelineId].PipelineType == string(CiPipeline.CI_JOB) { + if ciPipelineIdsMap[ciTemplateOverride.CiPipelineId].PipelineType == string(bean3.CI_JOB) { ciTemplateOverride.DockerRepository = updateRequest.DockerRepository ciTemplateOverride.DockerRegistryId = updateRequest.DockerRegistry _, err = impl.ciTemplateOverrideRepository.Update(ciTemplateOverride) @@ -1257,7 +1261,7 @@ func (impl *CiPipelineConfigServiceImpl) handlePipelineCreate(request *bean.CiPa if pipelineExists { err = &utils.ApiError{Code: "400", HttpStatusCode: 400, UserMessage: "pipeline name already exist"} impl.logger.Errorw("pipeline name already exist", "err", err, "patch cipipeline name", request.CiPipeline.Name) - return nil, fmt.Errorf(CiPipeline.PIPELINE_NAME_ALREADY_EXISTS_ERROR) + return nil, fmt.Errorf(bean3.PIPELINE_NAME_ALREADY_EXISTS_ERROR) } if request.IsSwitchCiPipelineRequest() { @@ -1281,17 +1285,17 @@ func (impl *CiPipelineConfigServiceImpl) PatchCiPipeline(request *bean.CiPatchRe impl.logger.Errorw("err in fetching template for pipeline patch, ", "err", err, "appId", request.AppId) return nil, err } - if request.CiPipeline.PipelineType == CiPipeline.CI_JOB { + if request.CiPipeline.PipelineType == bean3.CI_JOB { request.CiPipeline.IsDockerConfigOverridden = true request.CiPipeline.DockerConfigOverride = bean.DockerConfigOverride{ DockerRegistry: ciConfig.DockerRegistry, DockerRepository: ciConfig.DockerRepository, - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean3.CiBuildConfigBean{ Id: 0, GitMaterialId: request.CiPipeline.CiMaterial[0].GitMaterialId, BuildContextGitMaterialId: request.CiPipeline.CiMaterial[0].GitMaterialId, UseRootBuildContext: false, - CiBuildType: CiPipeline.SKIP_BUILD_TYPE, + CiBuildType: bean3.SKIP_BUILD_TYPE, DockerBuildConfig: nil, BuildPackConfig: nil, }, @@ -1411,7 +1415,7 @@ func (impl *CiPipelineConfigServiceImpl) CreateCiPipeline(createRequest *bean.Ci ciTemplate.DockerRepository = createRequest.DockerRepository } - ciTemplateBean := &pipelineConfigBean.CiTemplateBean{ + ciTemplateBean := &bean3.CiTemplateBean{ CiTemplate: ciTemplate, CiBuildConfig: createRequest.CiBuildConfig, } @@ -1474,15 +1478,15 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipelineMin(appId int, envIds []in var ciPipelineResp []*bean.CiPipelineMin for _, pipeline := range pipelines { parentCiPipeline := pipelineConfig.CiPipeline{} - pipelineType := CiPipeline.CI_BUILD + pipelineType := bean3.CI_BUILD if pipelineParentCiMap[pipeline.Id] != nil { parentCiPipeline = *pipelineParentCiMap[pipeline.Id] - pipelineType = CiPipeline.LINKED + pipelineType = bean3.LINKED } else if pipeline.IsExternal == true { - pipelineType = CiPipeline.EXTERNAL - } else if pipeline.PipelineType == string(CiPipeline.CI_JOB) { - pipelineType = CiPipeline.CI_JOB + pipelineType = bean3.EXTERNAL + } else if pipeline.PipelineType == string(bean3.CI_JOB) { + pipelineType = bean3.CI_JOB } ciPipeline := &bean.CiPipelineMin{ @@ -1659,13 +1663,13 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipelineByEnvironment(request reso } _, span = otel.Tracer("orchestrator").Start(request.Ctx, "ciHandler.FindTemplateOverrideByCiPipelineIds") - ciTemplateBeanOverrides, err := impl.ciTemplateService.FindTemplateOverrideByCiPipelineIds(ciPipelineIds) + ciTemplateBeanOverrides, err := impl.ciTemplateReadService.FindTemplateOverrideByCiPipelineIds(ciPipelineIds) span.End() if err != nil { impl.logger.Errorw("error in fetching templates override", "appIds", appIds, "err", err) return nil, err } - ciOverrideTemplateMap := make(map[int]*pipelineConfigBean.CiTemplateBean) + ciOverrideTemplateMap := make(map[int]*bean3.CiTemplateBean) for _, templateBeanOverride := range ciTemplateBeanOverrides { ciTemplateOverride := templateBeanOverride.CiTemplateOverride ciOverrideTemplateMap[ciTemplateOverride.CiPipelineId] = templateBeanOverride @@ -1699,7 +1703,7 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipelineByEnvironment(request reso ExternalCiConfig: externalCiConfig, ScanEnabled: pipeline.ScanEnabled, IsDockerConfigOverridden: pipeline.IsDockerConfigOverridden, - PipelineType: CiPipeline.PipelineType(pipeline.PipelineType), + PipelineType: bean3.PipelineType(pipeline.PipelineType), } parentPipelineAppId, ok := pipelineIdVsAppId[parentCiPipelineId] if ok { diff --git a/pkg/pipeline/BuildPipelineSwitchService.go b/pkg/pipeline/BuildPipelineSwitchService.go index 42d2197a8d5..e36627dcc49 100644 --- a/pkg/pipeline/BuildPipelineSwitchService.go +++ b/pkg/pipeline/BuildPipelineSwitchService.go @@ -21,8 +21,8 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/internal/util" "github.com/devtron-labs/devtron/pkg/bean" + pipelineConfigBean "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - pipelineConfigBean "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/history" repository4 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" diff --git a/pkg/pipeline/CiBuildConfigService.go b/pkg/pipeline/CiBuildConfigService.go index 43414beb7dc..c29d99fc605 100644 --- a/pkg/pipeline/CiBuildConfigService.go +++ b/pkg/pipeline/CiBuildConfigService.go @@ -19,17 +19,17 @@ package pipeline import ( "errors" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "go.uber.org/zap" "time" ) type CiBuildConfigService interface { - Save(templateId int, overrideTemplateId int, ciBuildConfigBean *CiPipeline.CiBuildConfigBean, userId int32) error - UpdateOrSave(templateId int, overrideTemplateId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) (*CiPipeline.CiBuildConfigBean, error) + Save(templateId int, overrideTemplateId int, ciBuildConfigBean *bean.CiBuildConfigBean, userId int32) error + UpdateOrSave(templateId int, overrideTemplateId int, ciBuildConfig *bean.CiBuildConfigBean, userId int32) (*bean.CiBuildConfigBean, error) Delete(ciBuildConfigId int) error - GetCountByBuildType() map[CiPipeline.CiBuildType]int + GetCountByBuildType() map[bean.CiBuildType]int } type CiBuildConfigServiceImpl struct { @@ -44,7 +44,7 @@ func NewCiBuildConfigServiceImpl(logger *zap.SugaredLogger, ciBuildConfigReposit } } -func (impl *CiBuildConfigServiceImpl) Save(templateId int, overrideTemplateId int, ciBuildConfigBean *CiPipeline.CiBuildConfigBean, userId int32) error { +func (impl *CiBuildConfigServiceImpl) Save(templateId int, overrideTemplateId int, ciBuildConfigBean *bean.CiBuildConfigBean, userId int32) error { ciBuildConfigEntity, err := adapter.ConvertBuildConfigBeanToDbEntity(templateId, overrideTemplateId, ciBuildConfigBean, userId) if err != nil { impl.Logger.Errorw("error occurred while converting build config to db entity", "templateId", templateId, @@ -62,7 +62,7 @@ func (impl *CiBuildConfigServiceImpl) Save(templateId int, overrideTemplateId in return nil } -func (impl *CiBuildConfigServiceImpl) UpdateOrSave(templateId int, overrideTemplateId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) (*CiPipeline.CiBuildConfigBean, error) { +func (impl *CiBuildConfigServiceImpl) UpdateOrSave(templateId int, overrideTemplateId int, ciBuildConfig *bean.CiBuildConfigBean, userId int32) (*bean.CiBuildConfigBean, error) { if ciBuildConfig == nil { impl.Logger.Warnw("not updating build config as object is empty", "ciBuildConfig", ciBuildConfig) return nil, nil @@ -92,14 +92,14 @@ func (impl *CiBuildConfigServiceImpl) Delete(ciBuildConfigId int) error { return impl.CiBuildConfigRepository.Delete(ciBuildConfigId) } -func (impl *CiBuildConfigServiceImpl) GetCountByBuildType() map[CiPipeline.CiBuildType]int { - result := make(map[CiPipeline.CiBuildType]int) +func (impl *CiBuildConfigServiceImpl) GetCountByBuildType() map[bean.CiBuildType]int { + result := make(map[bean.CiBuildType]int) buildTypeVsCount, err := impl.CiBuildConfigRepository.GetCountByBuildType() if err != nil { return result } for buildType, count := range buildTypeVsCount { - result[CiPipeline.CiBuildType(buildType)] = count + result[bean.CiBuildType(buildType)] = count } return result } diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index d5834cbf30b..8aea7805ec2 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -26,6 +26,8 @@ import ( "errors" "fmt" attributesBean "github.com/devtron-labs/devtron/pkg/attributes/bean" + "github.com/devtron-labs/devtron/pkg/build/pipeline" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/deployment/common" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/plugin" @@ -38,7 +40,6 @@ import ( "time" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/util/response/pagination" "go.opentelemetry.io/otel" @@ -91,7 +92,7 @@ type CiCdPipelineOrchestrator interface { PatchMaterialValue(createRequest *bean.CiPipeline, userId int32, oldPipeline *pipelineConfig.CiPipeline) (*bean.CiPipeline, error) PatchCiMaterialSource(ciPipeline *bean.CiMaterialPatchRequest, userId int32) (*bean.CiMaterialPatchRequest, error) PatchCiMaterialSourceValue(patchRequest *bean.CiMaterialValuePatchRequest, userId int32, value string, token string, checkAppSpecificAccess func(token, action string, appId int) (bool, error)) (*pipelineConfig.CiPipelineMaterial, error) - CreateCiTemplateBean(ciPipelineId int, dockerRegistryId string, dockerRepository string, gitMaterialId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) pipelineConfigBean.CiTemplateBean + CreateCiTemplateBean(ciPipelineId int, dockerRegistryId string, dockerRepository string, gitMaterialId int, ciBuildConfig *bean2.CiBuildConfigBean, userId int32) bean2.CiTemplateBean UpdateCiPipelineMaterials(materialsUpdate []*pipelineConfig.CiPipelineMaterial) error PipelineExists(name string) (bool, error) GetCdPipelinesForApp(appId int) (cdPipelines *bean.CdPipelines, err error) @@ -103,8 +104,8 @@ type CiCdPipelineOrchestrator interface { CreateEcrRepo(dockerRepository, AWSRegion, AWSAccessKeyId, AWSSecretAccessKey string) error GetCdPipelinesForEnv(envId int, requestedAppIds []int) (cdPipelines *bean.CdPipelines, err error) AddPipelineToTemplate(createRequest *bean.CiConfigRequest, isSwitchCiPipelineRequest bool) (resp *bean.CiConfigRequest, err error) - GetSourceCiDownStreamFilters(ctx context.Context, sourceCiPipelineId int) (*CiPipeline.SourceCiDownStreamEnv, error) - GetSourceCiDownStreamInfo(ctx context.Context, sourceCIPipeline int, req *CiPipeline.SourceCiDownStreamFilters) (pagination.PaginatedResponse[CiPipeline.SourceCiDownStreamResponse], error) + GetSourceCiDownStreamFilters(ctx context.Context, sourceCiPipelineId int) (*bean2.SourceCiDownStreamEnv, error) + GetSourceCiDownStreamInfo(ctx context.Context, sourceCIPipeline int, req *bean2.SourceCiDownStreamFilters) (pagination.PaginatedResponse[bean2.SourceCiDownStreamResponse], error) GetGitCommitEnvVarDataForCICDStage(gitTriggers map[int]pipelineConfig.GitCommit) (map[string]string, *gitSensor.WebhookAndCiData, error) } @@ -125,6 +126,7 @@ type CiCdPipelineOrchestratorImpl struct { userAuthService user.UserAuthService prePostCdScriptHistoryService history3.PrePostCdScriptHistoryService pipelineStageService PipelineStageService + ciTemplateReadService pipeline.CiTemplateReadService ciTemplateService CiTemplateService gitMaterialHistoryService history3.GitMaterialHistoryService ciPipelineHistoryService history3.CiPipelineHistoryService @@ -157,6 +159,7 @@ func NewCiCdPipelineOrchestrator( pipelineStageService PipelineStageService, gitMaterialHistoryService history3.GitMaterialHistoryService, ciPipelineHistoryService history3.CiPipelineHistoryService, + ciTemplateReadService pipeline.CiTemplateReadService, ciTemplateService CiTemplateService, dockerArtifactStoreRepository dockerRegistryRepository.DockerArtifactStoreRepository, CiArtifactRepository repository.CiArtifactRepository, @@ -301,7 +304,7 @@ func (impl CiCdPipelineOrchestratorImpl) validateCiPipelineMaterial(ciPipelineMa func (impl CiCdPipelineOrchestratorImpl) getSkipMessage(ciPipeline *pipelineConfig.CiPipeline) string { switch ciPipeline.PipelineType { - case string(CiPipeline.LINKED_CD): + case string(bean2.LINKED_CD): return "“Sync with Environment”" default: return "“Linked Build Pipeline”" @@ -564,7 +567,7 @@ func (impl CiCdPipelineOrchestratorImpl) PatchMaterialValue(createRequest *bean. } if !createRequest.IsExternal && createRequest.IsDockerConfigOverridden { //get override - savedTemplateOverrideBean, err := impl.ciTemplateService.FindTemplateOverrideByCiPipelineId(createRequest.Id) + savedTemplateOverrideBean, err := impl.ciTemplateReadService.FindTemplateOverrideByCiPipelineId(createRequest.Id) if err != nil && err != pg.ErrNoRows { impl.logger.Errorw("error in getting templateOverride by ciPipelineId", "err", err, "ciPipelineId", createRequest.Id) return nil, err @@ -597,7 +600,7 @@ func (impl CiCdPipelineOrchestratorImpl) PatchMaterialValue(createRequest *bean. templateOverrideReq.Id = savedTemplateOverride.Id templateOverrideReq.CreatedOn = savedTemplateOverride.CreatedOn templateOverrideReq.CreatedBy = savedTemplateOverride.CreatedBy - ciTemplateBean := &pipelineConfigBean.CiTemplateBean{ + ciTemplateBean := &bean2.CiTemplateBean{ CiTemplateOverride: templateOverrideReq, CiBuildConfig: ciBuildConfigBean, UserId: userId, @@ -614,7 +617,7 @@ func (impl CiCdPipelineOrchestratorImpl) PatchMaterialValue(createRequest *bean. } } else { - ciTemplateBean := &pipelineConfigBean.CiTemplateBean{ + ciTemplateBean := &bean2.CiTemplateBean{ CiTemplateOverride: templateOverrideReq, CiBuildConfig: ciBuildConfigBean, UserId: userId, @@ -632,7 +635,7 @@ func (impl CiCdPipelineOrchestratorImpl) PatchMaterialValue(createRequest *bean. } } else { - ciTemplateBean := &pipelineConfigBean.CiTemplateBean{ + ciTemplateBean := &bean2.CiTemplateBean{ CiTemplateOverride: &pipelineConfig.CiTemplateOverride{}, CiBuildConfig: nil, UserId: userId, @@ -836,8 +839,8 @@ func (impl CiCdPipelineOrchestratorImpl) DeleteCiPipelineAndCiEnvMappings(tx *pg return err } -func (impl CiCdPipelineOrchestratorImpl) CreateCiTemplateBean(ciPipelineId int, dockerRegistryId string, dockerRepository string, gitMaterialId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) pipelineConfigBean.CiTemplateBean { - CiTemplateBean := pipelineConfigBean.CiTemplateBean{ +func (impl CiCdPipelineOrchestratorImpl) CreateCiTemplateBean(ciPipelineId int, dockerRegistryId string, dockerRepository string, gitMaterialId int, ciBuildConfig *bean2.CiBuildConfigBean, userId int32) bean2.CiTemplateBean { + CiTemplateBean := bean2.CiTemplateBean{ CiTemplate: nil, CiTemplateOverride: &pipelineConfig.CiTemplateOverride{ CiPipelineId: ciPipelineId, @@ -860,10 +863,10 @@ func (impl CiCdPipelineOrchestratorImpl) CreateCiTemplateBean(ciPipelineId int, } func (impl CiCdPipelineOrchestratorImpl) SaveHistoryOfBaseTemplate(userId int32, pipeline *pipelineConfig.CiPipeline, materials []*pipelineConfig.CiPipelineMaterial) error { - CiTemplateBean := pipelineConfigBean.CiTemplateBean{ + CiTemplateBean := bean2.CiTemplateBean{ CiTemplate: nil, CiTemplateOverride: &pipelineConfig.CiTemplateOverride{}, - CiBuildConfig: &CiPipeline.CiBuildConfigBean{}, + CiBuildConfig: &bean2.CiBuildConfigBean{}, UserId: userId, } err := impl.ciPipelineHistoryService.SaveHistory(pipeline, materials, &CiTemplateBean, repository4.TRIGGER_DELETE) @@ -982,6 +985,9 @@ func (impl CiCdPipelineOrchestratorImpl) CreateCiConf(createRequest *bean.CiConf var pipelineMaterials []*pipelineConfig.CiPipelineMaterial for _, r := range ciPipeline.CiMaterial { + if ciPipeline.PipelineType == bean2.LINKED_CD { + continue + } material := &pipelineConfig.CiPipelineMaterial{ GitMaterialId: r.GitMaterialId, ScmId: r.ScmId, @@ -1066,7 +1072,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateCiConf(createRequest *bean.CiConf } } - ciTemplateBean := &pipelineConfigBean.CiTemplateBean{} + ciTemplateBean := &bean2.CiTemplateBean{} if ciPipeline.IsDockerConfigOverridden { //creating template override templateOverride := &pipelineConfig.CiTemplateOverride{ @@ -1084,7 +1090,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateCiConf(createRequest *bean.CiConf UpdatedOn: time.Now(), }, } - ciTemplateBean = &pipelineConfigBean.CiTemplateBean{ + ciTemplateBean = &bean2.CiTemplateBean{ CiTemplateOverride: templateOverride, CiBuildConfig: ciPipeline.DockerConfigOverride.CiBuildConfig, UserId: createRequest.UserId, @@ -1506,7 +1512,7 @@ func (impl CiCdPipelineOrchestratorImpl) createAppGroup(name, description string displayName := name appName := name if appType == helper.Job { - appName = name + "-" + util2.Generate(8) + "J" + CiPipeline.UniquePlaceHolderForAppName + appName = name + "-" + util2.Generate(8) + "J" + bean2.UniquePlaceHolderForAppName } pg := &app2.App{ Active: true, @@ -2193,7 +2199,7 @@ func (impl CiCdPipelineOrchestratorImpl) AddPipelineToTemplate(createRequest *be for _, ciPipeline := range createRequest.CiPipelines { if !ciPipeline.PipelineType.IsValidPipelineType() { impl.logger.Debugw(" Invalid PipelineType", "ciPipeline.PipelineType", ciPipeline.PipelineType) - errorMessage := fmt.Sprintf(CiPipeline.PIPELINE_TYPE_IS_NOT_VALID, ciPipeline.PipelineType) + errorMessage := fmt.Sprintf(bean2.PIPELINE_TYPE_IS_NOT_VALID, ciPipeline.PipelineType) return nil, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage(errorMessage).WithUserMessage(errorMessage) } } @@ -2239,24 +2245,24 @@ func (impl CiCdPipelineOrchestratorImpl) AddPipelineToTemplate(createRequest *be return createRequest, err } -func (impl CiCdPipelineOrchestratorImpl) GetSourceCiDownStreamFilters(ctx context.Context, sourceCiPipelineId int) (*CiPipeline.SourceCiDownStreamEnv, error) { +func (impl CiCdPipelineOrchestratorImpl) GetSourceCiDownStreamFilters(ctx context.Context, sourceCiPipelineId int) (*bean2.SourceCiDownStreamEnv, error) { ctx, span := otel.Tracer("orchestrator").Start(ctx, "GetSourceCiDownStreamFilters") defer span.End() linkedCiPipelines, err := impl.ciPipelineRepository.GetLinkedCiPipelines(ctx, sourceCiPipelineId) if err != nil { impl.logger.Errorw("error in getting linked Ci pipelines for given source Ci pipeline Id ", "sourceCiPipelineId", sourceCiPipelineId, "err", err) - return &CiPipeline.SourceCiDownStreamEnv{ + return &bean2.SourceCiDownStreamEnv{ EnvNames: []string{}, }, err } envNames, err := impl.getAttachedEnvNamesByCiIds(ctx, linkedCiPipelines) if err != nil { impl.logger.Errorw("error in fetching environment names for linked Ci pipelines", "linkedCiPipelines", linkedCiPipelines, "err", err) - return &CiPipeline.SourceCiDownStreamEnv{ + return &bean2.SourceCiDownStreamEnv{ EnvNames: []string{}, }, err } - res := &CiPipeline.SourceCiDownStreamEnv{ + res := &bean2.SourceCiDownStreamEnv{ EnvNames: envNames, } return res, nil @@ -2290,10 +2296,10 @@ func (impl CiCdPipelineOrchestratorImpl) getAttachedEnvNamesByCiIds(ctx context. return envNames, nil } -func (impl CiCdPipelineOrchestratorImpl) GetSourceCiDownStreamInfo(ctx context.Context, sourceCIPipeline int, req *CiPipeline.SourceCiDownStreamFilters) (pagination.PaginatedResponse[CiPipeline.SourceCiDownStreamResponse], error) { +func (impl CiCdPipelineOrchestratorImpl) GetSourceCiDownStreamInfo(ctx context.Context, sourceCIPipeline int, req *bean2.SourceCiDownStreamFilters) (pagination.PaginatedResponse[bean2.SourceCiDownStreamResponse], error) { ctx, span := otel.Tracer("orchestrator").Start(ctx, "GetSourceCiDownStreamInfo") defer span.End() - response := pagination.NewPaginatedResponse[CiPipeline.SourceCiDownStreamResponse]() + response := pagination.NewPaginatedResponse[bean2.SourceCiDownStreamResponse]() queryReq := &pagination.RepositoryRequest{ Order: req.SortOrder, SortBy: req.SortBy, diff --git a/pkg/pipeline/CiHandler.go b/pkg/pipeline/CiHandler.go index 7061494328a..140698181b4 100644 --- a/pkg/pipeline/CiHandler.go +++ b/pkg/pipeline/CiHandler.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/devtron-labs/common-lib/utils/workFlow" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" + bean4 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" util3 "github.com/devtron-labs/devtron/pkg/pipeline/util" "io/ioutil" "net/http" @@ -265,10 +266,11 @@ func (impl *CiHandlerImpl) HandleCIWebhook(gitCiTriggerRequest bean.GitCiTrigger impl.Logger.Debugw("HandleCIWebhook for material ", "material", gitCiTriggerRequest.CiPipelineMaterial) ciPipeline, err := impl.GetCiPipeline(gitCiTriggerRequest.CiPipelineMaterial.Id) if err != nil { + impl.Logger.Errorw("err in getting ci_pipeline by ciPipelineMaterialId", "ciPipelineMaterialId", gitCiTriggerRequest.CiPipelineMaterial.Id, "err", err) return 0, err } - if ciPipeline.IsManual { - impl.Logger.Debugw("not handling manual pipeline", "pipelineId", ciPipeline.Id) + if ciPipeline.IsManual || ciPipeline.PipelineType == bean4.LINKED_CD.ToString() { + impl.Logger.Debugw("not handling for manual pipeline or in case of linked cd", "pipelineId", ciPipeline.Id) return 0, err } diff --git a/pkg/pipeline/CiLogService.go b/pkg/pipeline/CiLogService.go index 7d0d7302703..6ad0752f5c4 100644 --- a/pkg/pipeline/CiLogService.go +++ b/pkg/pipeline/CiLogService.go @@ -20,7 +20,7 @@ import ( "context" blob_storage "github.com/devtron-labs/common-lib/blob-storage" "github.com/devtron-labs/common-lib/utils/k8s" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/types" "go.uber.org/zap" "io" @@ -66,7 +66,7 @@ func (impl *CiLogServiceImpl) FetchRunningWorkflowLogs(ciLogRequest types.BuildL return nil, nil, err } } - req := impl.k8sUtil.GetLogsForAPod(kubeClient, ciLogRequest.Namespace, ciLogRequest.PodName, CiPipeline.Main, true) + req := impl.k8sUtil.GetLogsForAPod(kubeClient, ciLogRequest.Namespace, ciLogRequest.PodName, bean.Main, true) podLogs, err := req.Stream(context.Background()) if err != nil { impl.logger.Errorw("error in opening stream", "name", ciLogRequest.PodName, "err", err) diff --git a/pkg/pipeline/CiMaterialConfigService.go b/pkg/pipeline/CiMaterialConfigService.go index 742c1f636eb..3fe371aa150 100644 --- a/pkg/pipeline/CiMaterialConfigService.go +++ b/pkg/pipeline/CiMaterialConfigService.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/bean" + "github.com/devtron-labs/devtron/pkg/build/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/sql" "github.com/go-pg/pg" @@ -46,7 +47,7 @@ type CiMaterialConfigService interface { type CiMaterialConfigServiceImpl struct { logger *zap.SugaredLogger materialRepo pipelineConfig.MaterialRepository - ciTemplateService CiTemplateService + ciTemplateService pipeline.CiTemplateReadService ciCdPipelineOrchestrator CiCdPipelineOrchestrator ciPipelineRepository pipelineConfig.CiPipelineRepository gitMaterialHistoryService history.GitMaterialHistoryService @@ -58,7 +59,7 @@ type CiMaterialConfigServiceImpl struct { func NewCiMaterialConfigServiceImpl( logger *zap.SugaredLogger, materialRepo pipelineConfig.MaterialRepository, - ciTemplateService CiTemplateService, + ciTemplateService pipeline.CiTemplateReadService, ciCdPipelineOrchestrator CiCdPipelineOrchestrator, ciPipelineRepository pipelineConfig.CiPipelineRepository, gitMaterialHistoryService history.GitMaterialHistoryService, diff --git a/pkg/pipeline/CiService.go b/pkg/pipeline/CiService.go index 70c5464f442..d34e1f4b5ee 100644 --- a/pkg/pipeline/CiService.go +++ b/pkg/pipeline/CiService.go @@ -26,9 +26,10 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" "github.com/devtron-labs/devtron/pkg/attributes" bean4 "github.com/devtron-labs/devtron/pkg/attributes/bean" + "github.com/devtron-labs/devtron/pkg/build/pipeline" + bean5 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/infraConfig" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/infraProviders" bean2 "github.com/devtron-labs/devtron/pkg/plugin/bean" "maps" @@ -87,7 +88,7 @@ type CiServiceImpl struct { ciArtifactRepository repository5.CiArtifactRepository pipelineStageService PipelineStageService userService user.UserService - ciTemplateService CiTemplateService + ciTemplateService pipeline.CiTemplateReadService appCrudOperationService app.AppCrudOperationService envRepository repository1.EnvironmentRepository appRepository appRepository.AppRepository @@ -110,7 +111,7 @@ func NewCiServiceImpl(Logger *zap.SugaredLogger, workflowService WorkflowService ciArtifactRepository repository5.CiArtifactRepository, pipelineStageService PipelineStageService, userService user.UserService, - ciTemplateService CiTemplateService, appCrudOperationService app.AppCrudOperationService, envRepository repository1.EnvironmentRepository, appRepository appRepository.AppRepository, + ciTemplateService pipeline.CiTemplateReadService, appCrudOperationService app.AppCrudOperationService, envRepository repository1.EnvironmentRepository, appRepository appRepository.AppRepository, scopedVariableManager variables.ScopedVariableManager, customTagService CustomTagService, pluginInputVariableParser PluginInputVariableParser, @@ -171,12 +172,12 @@ func (impl *CiServiceImpl) GetCiMaterials(pipelineId int, ciMaterials []*pipelin func (impl *CiServiceImpl) handleRuntimeParamsValidations(trigger types.Trigger, ciMaterials []*pipelineConfig.CiPipelineMaterial, workflowRequest *types.WorkflowRequest) error { // externalCi artifact is meant only for CI_JOB - if trigger.PipelineType != string(CiPipeline.CI_JOB) { + if trigger.PipelineType != string(bean5.CI_JOB) { return nil } // checking if user has given run time parameters for externalCiArtifact, if given then sending git material to Ci-Runner - externalCiArtifact, exists := trigger.ExtraEnvironmentVariables[CiPipeline.ExtraEnvVarExternalCiArtifactKey] + externalCiArtifact, exists := trigger.ExtraEnvironmentVariables[bean5.ExtraEnvVarExternalCiArtifactKey] // validate externalCiArtifact as docker image if exists { externalCiArtifact = strings.TrimSpace(externalCiArtifact) @@ -201,11 +202,11 @@ func (impl *CiServiceImpl) handleRuntimeParamsValidations(trigger types.Trigger, } - trigger.ExtraEnvironmentVariables[CiPipeline.ExtraEnvVarExternalCiArtifactKey] = externalCiArtifact + trigger.ExtraEnvironmentVariables[bean5.ExtraEnvVarExternalCiArtifactKey] = externalCiArtifact var artifactExists bool var err error - if trigger.ExtraEnvironmentVariables[CiPipeline.ExtraEnvVarImageDigestKey] == "" { + if trigger.ExtraEnvironmentVariables[bean5.ExtraEnvVarImageDigestKey] == "" { artifactExists, err = impl.ciArtifactRepository.IfArtifactExistByImage(externalCiArtifact, trigger.PipelineId) if err != nil { impl.Logger.Errorw("error in fetching ci artifact", "err", err) @@ -216,7 +217,7 @@ func (impl *CiServiceImpl) handleRuntimeParamsValidations(trigger types.Trigger, return fmt.Errorf("ci artifact already exists with same image name") } } else { - artifactExists, err = impl.ciArtifactRepository.IfArtifactExistByImageDigest(trigger.ExtraEnvironmentVariables[CiPipeline.ExtraEnvVarImageDigestKey], externalCiArtifact, trigger.PipelineId) + artifactExists, err = impl.ciArtifactRepository.IfArtifactExistByImageDigest(trigger.ExtraEnvironmentVariables[bean5.ExtraEnvVarImageDigestKey], externalCiArtifact, trigger.PipelineId) if err != nil { impl.Logger.Errorw("error in fetching ci artifact", "err", err) return err @@ -229,7 +230,7 @@ func (impl *CiServiceImpl) handleRuntimeParamsValidations(trigger types.Trigger, } } - if trigger.PipelineType == string(CiPipeline.CI_JOB) && len(ciMaterials) != 0 && !exists && externalCiArtifact == "" { + if trigger.PipelineType == string(bean5.CI_JOB) && len(ciMaterials) != 0 && !exists && externalCiArtifact == "" { ciMaterials[0].GitMaterial = nil ciMaterials[0].GitMaterialId = 0 } @@ -621,7 +622,7 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig. var dockerfilePath string var dockerRepository string var checkoutPath string - var ciBuildConfigBean *CiPipeline.CiBuildConfigBean + var ciBuildConfigBean *bean5.CiBuildConfigBean dockerRegistry := &repository3.DockerArtifactStore{} ciBaseBuildConfigEntity := ciTemplate.CiBuildConfig ciBaseBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(ciBaseBuildConfigEntity) @@ -734,13 +735,13 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig. ciBuildConfigBean.PipelineType = trigger.PipelineType - if ciBuildConfigBean.CiBuildType == CiPipeline.SELF_DOCKERFILE_BUILD_TYPE || ciBuildConfigBean.CiBuildType == CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE { + if ciBuildConfigBean.CiBuildType == bean5.SELF_DOCKERFILE_BUILD_TYPE || ciBuildConfigBean.CiBuildType == bean5.MANAGED_DOCKERFILE_BUILD_TYPE { ciBuildConfigBean.DockerBuildConfig.BuildContext = filepath.Join(buildContextCheckoutPath, ciBuildConfigBean.DockerBuildConfig.BuildContext) dockerBuildConfig := ciBuildConfigBean.DockerBuildConfig dockerfilePath = filepath.Join(checkoutPath, dockerBuildConfig.DockerfilePath) dockerBuildConfig.DockerfilePath = dockerfilePath checkoutPath = dockerfilePath[:strings.LastIndex(dockerfilePath, "/")+1] - } else if ciBuildConfigBean.CiBuildType == CiPipeline.BUILDPACK_BUILD_TYPE { + } else if ciBuildConfigBean.CiBuildType == bean5.BUILDPACK_BUILD_TYPE { buildPackConfig := ciBuildConfigBean.BuildPackConfig checkoutPath = filepath.Join(checkoutPath, buildPackConfig.ProjectPath) } @@ -803,7 +804,7 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig. if pipeline.App.AppType == helper.Job { workflowRequest.AppName = pipeline.App.DisplayName } - if trigger.PipelineType == string(CiPipeline.CI_JOB) { + if trigger.PipelineType == string(bean5.CI_JOB) { workflowRequest.IgnoreDockerCachePush = impl.config.SkipCiJobBuildCachePushPull workflowRequest.IgnoreDockerCachePull = impl.config.SkipCiJobBuildCachePushPull } diff --git a/pkg/pipeline/CiTemplateService.go b/pkg/pipeline/CiTemplateService.go index dbca6f96d41..620b2c05e36 100644 --- a/pkg/pipeline/CiTemplateService.go +++ b/pkg/pipeline/CiTemplateService.go @@ -18,25 +18,13 @@ package pipeline import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" - "github.com/devtron-labs/devtron/internal/util" - "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" - "github.com/devtron-labs/devtron/pkg/pipeline/types" - "github.com/go-pg/pg" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "go.uber.org/zap" ) type CiTemplateService interface { Save(ciTemplateBean *bean.CiTemplateBean) error - FindByAppId(appId int) (ciTemplateBean *bean.CiTemplateBean, err error) - FindTemplateOverrideByAppId(appId int) (ciTemplateBeans []*bean.CiTemplateBean, err error) - FindTemplateOverrideByCiPipelineIds(ciPipelineIds []int) (ciTemplateBeans []*bean.CiTemplateBean, err error) - FindTemplateOverrideByCiPipelineId(ciPipelineId int) (*bean.CiTemplateBean, error) - GetAppliedDockerConfigForCiPipeline(ciPipelineId, appId int, isOverridden bool) (*types.DockerArtifactStoreBean, error) - GetBaseDockerConfigForCiPipeline(appId int) (*types.DockerArtifactStoreBean, error) Update(ciTemplateBean *bean.CiTemplateBean) error - FindByAppIds(appIds []int) (map[int]*bean.CiTemplateBean, error) } type CiTemplateServiceImpl struct { Logger *zap.SugaredLogger @@ -88,125 +76,6 @@ func (impl CiTemplateServiceImpl) Save(ciTemplateBean *bean.CiTemplateBean) erro return err } -func (impl CiTemplateServiceImpl) FindByAppId(appId int) (ciTemplateBean *bean.CiTemplateBean, err error) { - ciTemplate, err := impl.CiTemplateRepository.FindByAppId(appId) - if err != nil { - return nil, err - } - ciBuildConfig := ciTemplate.CiBuildConfig - ciBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(ciBuildConfig) - if err != nil { - impl.Logger.Errorw("error occurred while converting dbBuildConfig to bean", "ciBuildConfig", - ciBuildConfig, "error", err) - } - if ciBuildConfigBean == nil { - ciBuildConfigBean, err = adapter.OverrideCiBuildConfig(ciTemplate.DockerfilePath, ciTemplate.Args, "", ciTemplate.DockerBuildOptions, ciTemplate.TargetPlatform, nil) - if err != nil { - impl.Logger.Errorw("error occurred while parsing ci build config", "err", err) - } - } - ciBuildConfigBean.GitMaterialId = ciTemplate.GitMaterialId - ciBuildConfigBean.BuildContextGitMaterialId = ciTemplate.BuildContextGitMaterialId - return &bean.CiTemplateBean{ - CiTemplate: ciTemplate, - CiBuildConfig: ciBuildConfigBean, - }, err -} - -func (impl CiTemplateServiceImpl) FindTemplateOverrideByAppId(appId int) (ciTemplateBeans []*bean.CiTemplateBean, err error) { - templateOverrides, err := impl.CiTemplateOverrideRepository.FindByAppId(appId) - if err != nil && err != pg.ErrNoRows { - impl.Logger.Errorw("error in getting ciTemplateOverrides by appId", "err", err, "appId", appId) - return nil, err - } - var templateBeanOverrides []*bean.CiTemplateBean - for _, templateOverride := range templateOverrides { - ciBuildConfigBean, err := impl.extractBuildConfigBean(templateOverride) - if err != nil { - return templateBeanOverrides, err - } - overrideBean := &bean.CiTemplateBean{ - CiTemplateOverride: templateOverride, - CiBuildConfig: ciBuildConfigBean, - } - templateBeanOverrides = append(templateBeanOverrides, overrideBean) - } - return templateBeanOverrides, nil -} - -func (impl CiTemplateServiceImpl) FindTemplateOverrideByCiPipelineIds(ciPipelineIds []int) (ciTemplateBeans []*bean.CiTemplateBean, err error) { - templateOverrides, err := impl.CiTemplateOverrideRepository.FindByCiPipelineIds(ciPipelineIds) - if err != nil && err != pg.ErrNoRows { - impl.Logger.Errorw("error in getting ciTemplateOverrides by appId", "err", err, "ciPipelineIds", ciPipelineIds) - return nil, err - } - var templateBeanOverrides []*bean.CiTemplateBean - for _, templateOverride := range templateOverrides { - ciBuildConfigBean, err := impl.extractBuildConfigBean(templateOverride) - if err != nil { - return templateBeanOverrides, err - } - overrideBean := &bean.CiTemplateBean{ - CiTemplateOverride: templateOverride, - CiBuildConfig: ciBuildConfigBean, - } - templateBeanOverrides = append(templateBeanOverrides, overrideBean) - } - return templateBeanOverrides, nil -} - -func (impl CiTemplateServiceImpl) extractBuildConfigBean(templateOverride *pipelineConfig.CiTemplateOverride) (*CiPipeline.CiBuildConfigBean, error) { - ciBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(templateOverride.CiBuildConfig) - if err != nil { - impl.Logger.Errorw("error occurred while converting dbBuildConfig to bean", "ciBuildConfig", - templateOverride.CiBuildConfig, "error", err) - return nil, err - } - if ciBuildConfigBean == nil { - ciBuildConfigBean, err = adapter.OverrideCiBuildConfig(templateOverride.DockerfilePath, "", "", "", "", nil) - if err != nil { - impl.Logger.Errorw("error occurred while parsing ci build config", "err", err) - } - } - ciBuildConfigBean.GitMaterialId = templateOverride.GitMaterialId - ciBuildConfigBean.BuildContextGitMaterialId = templateOverride.BuildContextGitMaterialId - return ciBuildConfigBean, nil -} - -func (impl CiTemplateServiceImpl) FindTemplateOverrideByCiPipelineId(ciPipelineId int) (*bean.CiTemplateBean, error) { - templateOverride, err := impl.CiTemplateOverrideRepository.FindByCiPipelineId(ciPipelineId) - if err != nil && err != pg.ErrNoRows { - impl.Logger.Errorw("error in getting ciTemplateOverrides by ciPipelineId", "err", err, "ciPipelineId", ciPipelineId) - return nil, err - } - ciBuildConfigBean, err := impl.extractBuildConfigBean(templateOverride) - return &bean.CiTemplateBean{CiTemplateOverride: templateOverride, CiBuildConfig: ciBuildConfigBean}, err -} - -func (impl CiTemplateServiceImpl) GetAppliedDockerConfigForCiPipeline(ciPipelineId, appId int, isOverridden bool) (*types.DockerArtifactStoreBean, error) { - if !isOverridden { - return impl.GetBaseDockerConfigForCiPipeline(appId) - } - templateOverride, err := impl.CiTemplateOverrideRepository.FindByCiPipelineId(ciPipelineId) - if err != nil && !util.IsErrNoRows(err) { - impl.Logger.Errorw("error in getting ciTemplateOverrides by ciPipelineId", "err", err, "ciPipelineId", ciPipelineId) - return nil, err - } - if util.IsErrNoRows(err) { - return impl.GetBaseDockerConfigForCiPipeline(appId) - } - return adapter.GetDockerConfigBean(templateOverride.DockerRegistry), nil -} - -func (impl CiTemplateServiceImpl) GetBaseDockerConfigForCiPipeline(appId int) (*types.DockerArtifactStoreBean, error) { - ciTemplate, err := impl.CiTemplateRepository.FindByAppId(appId) - if err != nil { - impl.Logger.Errorw("error in getting ciTemplate by appId", "err", err, "appId", appId) - return nil, err - } - return adapter.GetDockerConfigBean(ciTemplate.DockerRegistry), nil -} - func (impl CiTemplateServiceImpl) Update(ciTemplateBean *bean.CiTemplateBean) error { ciTemplate := ciTemplateBean.CiTemplate ciTemplateOverride := ciTemplateBean.CiTemplateOverride @@ -239,32 +108,3 @@ func (impl CiTemplateServiceImpl) Update(ciTemplateBean *bean.CiTemplateBean) er } return err } - -func (impl CiTemplateServiceImpl) FindByAppIds(appIds []int) (map[int]*bean.CiTemplateBean, error) { - ciTemplates, err := impl.CiTemplateRepository.FindByAppIds(appIds) - if err != nil { - return nil, err - } - ciTemplateMap := make(map[int]*bean.CiTemplateBean) - for _, ciTemplate := range ciTemplates { - ciBuildConfig := ciTemplate.CiBuildConfig - ciBuildConfigBean, err := adapter.ConvertDbBuildConfigToBean(ciBuildConfig) - if err != nil { - impl.Logger.Errorw("error occurred while converting dbBuildConfig to bean", "ciBuildConfig", - ciBuildConfig, "error", err) - } - if ciBuildConfigBean == nil { - ciBuildConfigBean, err = adapter.OverrideCiBuildConfig(ciTemplate.DockerfilePath, ciTemplate.Args, "", ciTemplate.DockerBuildOptions, ciTemplate.TargetPlatform, nil) - if err != nil { - impl.Logger.Errorw("error occurred while parsing ci build config", "err", err) - } - } - ciBuildConfigBean.GitMaterialId = ciTemplate.GitMaterialId - ciTemplateBean := &bean.CiTemplateBean{ - CiTemplate: ciTemplate, - CiBuildConfig: ciBuildConfigBean, - } - ciTemplateMap[ciTemplate.AppId] = ciTemplateBean - } - return ciTemplateMap, nil -} diff --git a/pkg/pipeline/CiTemplateService_test.go b/pkg/pipeline/CiTemplateService_test.go index 5da6f28542e..0a8f984610d 100644 --- a/pkg/pipeline/CiTemplateService_test.go +++ b/pkg/pipeline/CiTemplateService_test.go @@ -1,17 +1,5 @@ /* * Copyright (c) 2024. Devtron Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package pipeline @@ -22,8 +10,8 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/mocks" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/internal/util" - "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + "github.com/devtron-labs/devtron/pkg/build/pipeline" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" pipelineMocks "github.com/devtron-labs/devtron/pkg/pipeline/mocks" "github.com/devtron-labs/devtron/pkg/sql" "github.com/stretchr/testify/assert" @@ -44,17 +32,17 @@ func TestCiTemplateService(t *testing.T) { templateDbEntity := &pipelineConfig.CiTemplate{ Id: 1, CiBuildConfig: &pipelineConfig.CiBuildConfig{ - Type: string(CiPipeline.BUILDPACK_BUILD_TYPE), + Type: string(bean2.BUILDPACK_BUILD_TYPE), BuildMetadata: "{\"BuilderId\":\"" + builderId + "\"}", }, } ciTemplateRepositoryMocked.On("FindByAppId", 1).Return(templateDbEntity, nil) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, nil, ciTemplateRepositoryMocked, nil) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, ciTemplateRepositoryMocked, nil) templateBean, err := ciTemplateServiceImpl.FindByAppId(1) template := templateBean.CiTemplate assert.Equal(t, template.Id, templateDbEntity.Id) assert.NotNil(t, templateBean.CiBuildConfig) - assert.Equal(t, CiPipeline.BUILDPACK_BUILD_TYPE, templateBean.CiBuildConfig.CiBuildType) + assert.Equal(t, bean2.BUILDPACK_BUILD_TYPE, templateBean.CiBuildConfig.CiBuildType) assert.Equal(t, builderId, templateBean.CiBuildConfig.BuildPackConfig.BuilderId) }) @@ -74,14 +62,14 @@ func TestCiTemplateService(t *testing.T) { Args: "{\"" + argsKey + "\":\"" + argsValue + "\"}", } mockCiTemplateRepository.On("FindByAppId", 1).Return(templateDbEntity, nil) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, nil, mockCiTemplateRepository, nil) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, mockCiTemplateRepository, nil) templateBean, err := ciTemplateServiceImpl.FindByAppId(1) template := templateBean.CiTemplate assert.Equal(t, template.Id, templateDbEntity.Id) assert.Equal(t, template.TargetPlatform, templateDbEntity.TargetPlatform) assert.Nil(t, template.CiBuildConfig) ciBuildConfig := templateBean.CiBuildConfig - assert.Equal(t, CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, ciBuildConfig.CiBuildType) + assert.Equal(t, bean2.SELF_DOCKERFILE_BUILD_TYPE, ciBuildConfig.CiBuildType) assert.NotNil(t, ciBuildConfig.DockerBuildConfig) assert.Equal(t, templateDbEntity.TargetPlatform, ciBuildConfig.DockerBuildConfig.TargetPlatform) args := ciBuildConfig.DockerBuildConfig.Args @@ -101,8 +89,8 @@ func TestCiTemplateService(t *testing.T) { notPlatform := "linux/arm64" gitMaterialId := 2 ciBuildConfigId := 3 - managedDockerfileBuildType := CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE - buildConfigMetadata := &CiPipeline.DockerBuildConfig{ + managedDockerfileBuildType := bean2.MANAGED_DOCKERFILE_BUILD_TYPE + buildConfigMetadata := &bean2.DockerBuildConfig{ DockerfileContent: dockerfileContent, TargetPlatform: targetPlatform, } @@ -119,7 +107,7 @@ func TestCiTemplateService(t *testing.T) { }, } mockCiTemplateRepository.On("FindByAppId", 1).Return(templateDbEntity, nil) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, nil, mockCiTemplateRepository, nil) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, mockCiTemplateRepository, nil) templateBean, err := ciTemplateServiceImpl.FindByAppId(1) ciTemplateEntity := templateBean.CiTemplate ciBuildConfig := templateBean.CiBuildConfig @@ -152,7 +140,7 @@ func TestCiTemplateService(t *testing.T) { DockerfilePath: "Dockerfile_ea", }} mockedCiTemplateOverrideRepository.On("FindByAppId", appId).Return(mockedTemplateOverrides, nil) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, nil, nil, mockedCiTemplateOverrideRepository) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, nil, mockedCiTemplateOverrideRepository) templateBeans, err := ciTemplateServiceImpl.FindTemplateOverrideByAppId(appId) assert.Nil(t, err) assert.Equal(t, len(mockedTemplateOverrides), len(templateBeans)) @@ -164,7 +152,7 @@ func TestCiTemplateService(t *testing.T) { assert.Equal(t, mockedTemplateOverride.Id, templateOverride.Id) assert.Equal(t, mockedTemplateOverride.GitMaterialId, templateOverride.GitMaterialId) assert.Equal(t, mockedTemplateOverride.CiPipelineId, templateOverride.CiPipelineId) - assert.Equal(t, CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, ciBuildConfig.CiBuildType) + assert.Equal(t, bean2.SELF_DOCKERFILE_BUILD_TYPE, ciBuildConfig.CiBuildType) assert.Nil(t, ciBuildConfig.BuildPackConfig) assert.Empty(t, ciBuildConfig.DockerBuildConfig.DockerBuildOptions, "docker build options not supported in pipeline override") assert.Equal(t, mockedTemplateOverride.DockerfilePath, ciBuildConfig.DockerBuildConfig.DockerfilePath) @@ -182,7 +170,7 @@ func TestCiTemplateService(t *testing.T) { CiPipelineId: 2, GitMaterialId: 3, CiBuildConfig: &pipelineConfig.CiBuildConfig{ - Type: string(CiPipeline.BUILDPACK_BUILD_TYPE), + Type: string(bean2.BUILDPACK_BUILD_TYPE), BuildMetadata: "{\"BuilderId\":\"" + builderId1 + "\"}", }, }, { @@ -190,12 +178,12 @@ func TestCiTemplateService(t *testing.T) { CiPipelineId: 3, GitMaterialId: 3, CiBuildConfig: &pipelineConfig.CiBuildConfig{ - Type: string(CiPipeline.BUILDPACK_BUILD_TYPE), + Type: string(bean2.BUILDPACK_BUILD_TYPE), BuildMetadata: "{\"BuilderId\":\"" + builderId1 + "\"}", }, }} mockedCiTemplateOverrideRepository.On("FindByAppId", appId).Return(mockedTemplateOverrides, nil) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, nil, nil, mockedCiTemplateOverrideRepository) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, nil, mockedCiTemplateOverrideRepository) templateBeans, err := ciTemplateServiceImpl.FindTemplateOverrideByAppId(appId) assert.Nil(t, err) assert.Equal(t, len(mockedTemplateOverrides), len(templateBeans)) @@ -207,7 +195,7 @@ func TestCiTemplateService(t *testing.T) { assert.Equal(t, mockedTemplateOverride.Id, templateOverride.Id) assert.Equal(t, mockedTemplateOverride.GitMaterialId, templateOverride.GitMaterialId) assert.Equal(t, mockedTemplateOverride.CiPipelineId, templateOverride.CiPipelineId) - assert.Equal(t, CiPipeline.BUILDPACK_BUILD_TYPE, ciBuildConfig.CiBuildType) + assert.Equal(t, bean2.BUILDPACK_BUILD_TYPE, ciBuildConfig.CiBuildType) assert.Nil(t, ciBuildConfig.DockerBuildConfig) assert.NotNil(t, ciBuildConfig.BuildPackConfig) assert.Equal(t, builderId1, ciBuildConfig.BuildPackConfig.BuilderId) @@ -222,7 +210,7 @@ func TestCiTemplateService(t *testing.T) { dockerfileContent := "FROM node:9\r\n\r\nWORKDIR /app\r\n\r\nRUN npm install -g contentful-cli\r\n\r\nCOPY package.json .\r\nRUN npm install\r\n\r\nCOPY . .\r\n\r\nUSER node\r\nEXPOSE 3000\r\n\r\nCMD [\"npm\", \"run\", \"start:dev\"]" targetPlatform := "linux/amd64" builderId := "sample-builder" - buildConfigMetadata := &CiPipeline.DockerBuildConfig{ + buildConfigMetadata := &bean2.DockerBuildConfig{ DockerfileContent: dockerfileContent, TargetPlatform: targetPlatform, } @@ -233,7 +221,7 @@ func TestCiTemplateService(t *testing.T) { CiPipelineId: 2, GitMaterialId: 3, CiBuildConfig: &pipelineConfig.CiBuildConfig{ - Type: string(CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE), + Type: string(bean2.MANAGED_DOCKERFILE_BUILD_TYPE), BuildMetadata: string(buildMetadata), }, }, { @@ -241,12 +229,12 @@ func TestCiTemplateService(t *testing.T) { CiPipelineId: 3, GitMaterialId: 3, CiBuildConfig: &pipelineConfig.CiBuildConfig{ - Type: string(CiPipeline.BUILDPACK_BUILD_TYPE), + Type: string(bean2.BUILDPACK_BUILD_TYPE), BuildMetadata: "{\"BuilderId\":\"" + builderId + "\"}", }, }} mockedCiTemplateOverrideRepository.On("FindByAppId", appId).Return(mockedTemplateOverrides, nil) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, nil, nil, mockedCiTemplateOverrideRepository) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, nil, mockedCiTemplateOverrideRepository) templateBeans, err := ciTemplateServiceImpl.FindTemplateOverrideByAppId(appId) assert.Nil(t, err) assert.Equal(t, len(mockedTemplateOverrides), len(templateBeans)) @@ -258,13 +246,13 @@ func TestCiTemplateService(t *testing.T) { assert.Equal(t, mockedTemplateOverride.Id, templateOverride.Id) assert.Equal(t, mockedTemplateOverride.GitMaterialId, templateOverride.GitMaterialId) assert.Equal(t, mockedTemplateOverride.CiPipelineId, templateOverride.CiPipelineId) - if ciBuildConfig.CiBuildType == CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE { - assert.Equal(t, CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE, ciBuildConfig.CiBuildType) + if ciBuildConfig.CiBuildType == bean2.MANAGED_DOCKERFILE_BUILD_TYPE { + assert.Equal(t, bean2.MANAGED_DOCKERFILE_BUILD_TYPE, ciBuildConfig.CiBuildType) assert.Nil(t, ciBuildConfig.BuildPackConfig) assert.NotNil(t, ciBuildConfig.DockerBuildConfig) assert.Equal(t, dockerfileContent, ciBuildConfig.DockerBuildConfig.DockerfileContent) - } else if ciBuildConfig.CiBuildType == CiPipeline.BUILDPACK_BUILD_TYPE { - assert.Equal(t, CiPipeline.BUILDPACK_BUILD_TYPE, ciBuildConfig.CiBuildType) + } else if ciBuildConfig.CiBuildType == bean2.BUILDPACK_BUILD_TYPE { + assert.Equal(t, bean2.BUILDPACK_BUILD_TYPE, ciBuildConfig.CiBuildType) assert.Nil(t, ciBuildConfig.DockerBuildConfig) assert.NotNil(t, ciBuildConfig.BuildPackConfig) assert.Equal(t, builderId, ciBuildConfig.BuildPackConfig.BuilderId) @@ -278,7 +266,7 @@ func TestCiTemplateService(t *testing.T) { mockedCiTemplateOverrideRepository := mocks.NewCiTemplateOverrideRepository(t) mockedBuildConfigService := pipelineMocks.NewCiBuildConfigService(t) ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, mockedBuildConfigService, nil, mockedCiTemplateOverrideRepository) - mockedCiTemplateBean := &bean.CiTemplateBean{} + mockedCiTemplateBean := &bean2.CiTemplateBean{} materialId := 3 mockedTemplateOverrideId := 1 mockedCiBuildConfigId := 5 @@ -286,11 +274,11 @@ func TestCiTemplateService(t *testing.T) { mockedCiTemplateBean.CiTemplateOverride = mockedTemplateOverride dockerBuildOptions := map[string]string{} dockerBuildOptions["volume"] = "abcd:defg" - mockedCiTemplateBean.CiBuildConfig = &CiPipeline.CiBuildConfigBean{ + mockedCiTemplateBean.CiBuildConfig = &bean2.CiBuildConfigBean{ Id: mockedCiBuildConfigId, GitMaterialId: materialId, - CiBuildType: CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, - DockerBuildConfig: &CiPipeline.DockerBuildConfig{DockerfilePath: "Dockerfile", TargetPlatform: "linux/amd64", DockerBuildOptions: dockerBuildOptions}, + CiBuildType: bean2.SELF_DOCKERFILE_BUILD_TYPE, + DockerBuildConfig: &bean2.DockerBuildConfig{DockerfilePath: "Dockerfile", TargetPlatform: "linux/amd64", DockerBuildOptions: dockerBuildOptions}, } mockedUserId := int32(4) mockedCiTemplateBean.UserId = mockedUserId @@ -302,7 +290,7 @@ func TestCiTemplateService(t *testing.T) { mockedBuildConfigService.On("UpdateOrSave", mock.AnythingOfType("int"), mock.AnythingOfType("int"), mock.AnythingOfType("*bean.CiBuildConfigBean"), mock.AnythingOfType("int32")). Return( - func(templateId int, overrideTemplateId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) *CiPipeline.CiBuildConfigBean { + func(templateId int, overrideTemplateId int, ciBuildConfig *bean2.CiBuildConfigBean, userId int32) *bean2.CiBuildConfigBean { assert.Equal(t, 0, templateId) assert.Equal(t, mockedTemplateOverrideId, overrideTemplateId) assert.Equal(t, mockedUserId, userId) @@ -323,7 +311,7 @@ func TestCiTemplateService(t *testing.T) { mockedCiTemplateRepository := mocks.NewCiTemplateRepository(t) mockedBuildConfigService := pipelineMocks.NewCiBuildConfigService(t) ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, mockedBuildConfigService, mockedCiTemplateRepository, nil) - mockedCiTemplateBean := &bean.CiTemplateBean{} + mockedCiTemplateBean := &bean2.CiTemplateBean{} materialId := 3 mockedTemplateId := 1 mockedCiBuildConfigId := 5 @@ -331,11 +319,11 @@ func TestCiTemplateService(t *testing.T) { mockedCiTemplateBean.CiTemplate = mockedTemplate dockerBuildOptions := map[string]string{} dockerBuildOptions["volume"] = "abcd:defg" - mockedCiTemplateBean.CiBuildConfig = &CiPipeline.CiBuildConfigBean{ + mockedCiTemplateBean.CiBuildConfig = &bean2.CiBuildConfigBean{ Id: mockedCiBuildConfigId, GitMaterialId: materialId, - CiBuildType: CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, - DockerBuildConfig: &CiPipeline.DockerBuildConfig{DockerfilePath: "Dockerfile", TargetPlatform: "linux/amd64", DockerBuildOptions: dockerBuildOptions}, + CiBuildType: bean2.SELF_DOCKERFILE_BUILD_TYPE, + DockerBuildConfig: &bean2.DockerBuildConfig{DockerfilePath: "Dockerfile", TargetPlatform: "linux/amd64", DockerBuildOptions: dockerBuildOptions}, } mockedUserId := int32(4) mockedCiTemplateBean.UserId = mockedUserId @@ -347,7 +335,7 @@ func TestCiTemplateService(t *testing.T) { mockedBuildConfigService.On("UpdateOrSave", mock.AnythingOfType("int"), mock.AnythingOfType("int"), mock.AnythingOfType("*bean.CiBuildConfigBean"), mock.AnythingOfType("int32")). Return( - func(templateId int, overrideTemplateId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) *CiPipeline.CiBuildConfigBean { + func(templateId int, overrideTemplateId int, ciBuildConfig *bean2.CiBuildConfigBean, userId int32) *bean2.CiBuildConfigBean { assert.Equal(t, 0, overrideTemplateId) assert.Equal(t, mockedTemplateId, templateId) assert.Equal(t, mockedUserId, userId) @@ -367,7 +355,7 @@ func TestCiTemplateService(t *testing.T) { mockedCiTemplateRepository := mocks.NewCiTemplateRepository(t) mockedBuildConfigService := pipelineMocks.NewCiBuildConfigService(t) ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, mockedBuildConfigService, mockedCiTemplateRepository, nil) - mockedCiTemplateBean := &bean.CiTemplateBean{} + mockedCiTemplateBean := &bean2.CiTemplateBean{} materialId := 3 mockedTemplateId := 7 mockedCiBuildConfigId := 6 @@ -375,18 +363,18 @@ func TestCiTemplateService(t *testing.T) { mockedCiTemplateBean.CiTemplate = mockedTemplate dockerBuildOptions := map[string]string{} dockerBuildOptions["volume"] = "abcd:defg" - mockedCiTemplateBean.CiBuildConfig = &CiPipeline.CiBuildConfigBean{ + mockedCiTemplateBean.CiBuildConfig = &bean2.CiBuildConfigBean{ Id: 0, GitMaterialId: materialId, - CiBuildType: CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, - DockerBuildConfig: &CiPipeline.DockerBuildConfig{DockerfilePath: "Dockerfile", TargetPlatform: "linux/amd64", DockerBuildOptions: dockerBuildOptions}, + CiBuildType: bean2.SELF_DOCKERFILE_BUILD_TYPE, + DockerBuildConfig: &bean2.DockerBuildConfig{DockerfilePath: "Dockerfile", TargetPlatform: "linux/amd64", DockerBuildOptions: dockerBuildOptions}, } mockedUserId := int32(4) mockedCiTemplateBean.UserId = mockedUserId mockedBuildConfigService.On("Save", mock.AnythingOfType("int"), mock.AnythingOfType("int"), mock.AnythingOfType("*bean.CiBuildConfigBean"), mock.AnythingOfType("int32")). Return( - func(templateId int, overrideTemplateId int, ciBuildConfig *CiPipeline.CiBuildConfigBean, userId int32) error { + func(templateId int, overrideTemplateId int, ciBuildConfig *bean2.CiBuildConfigBean, userId int32) error { assert.Equal(t, 0, overrideTemplateId) assert.Equal(t, mockedTemplate.Id, templateId) assert.Equal(t, mockedUserId, userId) @@ -417,10 +405,11 @@ func TestCiTemplateService(t *testing.T) { ciBuildConfigServiceImpl := NewCiBuildConfigServiceImpl(sugaredLogger, ciBuildConfigRepositoryImpl) ciTemplateRepositoryImpl := pipelineConfig.NewCiTemplateRepositoryImpl(db, sugaredLogger) ciTemplateOverrideRepositoryImpl := pipelineConfig.NewCiTemplateOverrideRepositoryImpl(db, sugaredLogger) + ciTemplateReadServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, ciBuildConfigServiceImpl, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) - _, err = ciTemplateServiceImpl.FindTemplateOverrideByCiPipelineId(1) + _, err = ciTemplateReadServiceImpl.FindTemplateOverrideByCiPipelineId(1) appId := 1 - ciTemplateBean, err := ciTemplateServiceImpl.FindByAppId(appId) + ciTemplateBean, err := ciTemplateReadServiceImpl.FindByAppId(appId) assert.True(t, err == nil, err) assert.True(t, ciTemplateBean != nil, ciTemplateBean) assert.True(t, ciTemplateBean.CiTemplate != nil) @@ -429,11 +418,11 @@ func TestCiTemplateService(t *testing.T) { ciBuildConfig := ciTemplateBean.CiBuildConfig - buildPackConfig := &CiPipeline.BuildPackConfig{ + buildPackConfig := &bean2.BuildPackConfig{ BuilderId: "gcr.io/buildpacks/builder:v1", } //buildPackConfig.BuilderId = "heroku/buildpacks:20" - ciBuildConfig.CiBuildType = CiPipeline.BUILDPACK_BUILD_TYPE + ciBuildConfig.CiBuildType = bean2.BUILDPACK_BUILD_TYPE ciBuildConfig.BuildPackConfig = buildPackConfig //args := make(map[string]string) @@ -459,11 +448,9 @@ func TestCiTemplateService(t *testing.T) { config, err := sql.GetConfig() assert.True(t, err == nil, err) db, err := sql.NewDbConnection(config, sugaredLogger) - ciBuildConfigRepositoryImpl := pipelineConfig.NewCiBuildConfigRepositoryImpl(db, sugaredLogger) - ciBuildConfigServiceImpl := NewCiBuildConfigServiceImpl(sugaredLogger, ciBuildConfigRepositoryImpl) ciTemplateRepositoryImpl := pipelineConfig.NewCiTemplateRepositoryImpl(db, sugaredLogger) ciTemplateOverrideRepositoryImpl := pipelineConfig.NewCiTemplateOverrideRepositoryImpl(db, sugaredLogger) - ciTemplateServiceImpl := NewCiTemplateServiceImpl(sugaredLogger, ciBuildConfigServiceImpl, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) + ciTemplateServiceImpl := pipeline.NewCiTemplateReadServiceImpl(sugaredLogger, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) appId := 7 templateBeans, _ := ciTemplateServiceImpl.FindTemplateOverrideByAppId(appId) for _, templateBean := range templateBeans { diff --git a/pkg/pipeline/ConfigMapService.go b/pkg/pipeline/ConfigMapService.go index bbfb74148bf..d13083d6888 100644 --- a/pkg/pipeline/ConfigMapService.go +++ b/pkg/pipeline/ConfigMapService.go @@ -26,8 +26,8 @@ import ( chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/commonService" + history2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" "github.com/devtron-labs/devtron/pkg/pipeline/bean" - history2 "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" "github.com/devtron-labs/devtron/pkg/variables" diff --git a/pkg/pipeline/DeploymentConfigService.go b/pkg/pipeline/DeploymentConfigService.go index bb35e4fc41d..03cb75fa477 100644 --- a/pkg/pipeline/DeploymentConfigService.go +++ b/pkg/pipeline/DeploymentConfigService.go @@ -23,9 +23,10 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/bean" chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" - "github.com/devtron-labs/devtron/pkg/pipeline/history" + bean2 "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" repository2 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/resourceQualifiers" "github.com/devtron-labs/devtron/pkg/variables" @@ -37,9 +38,9 @@ import ( ) type PipelineDeploymentConfigService interface { - GetLatestDeploymentConfigurationByPipelineId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*history.AllDeploymentConfigurationDetail, error) + GetLatestDeploymentConfigurationByPipelineId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean2.AllDeploymentConfigurationDetail, error) GetMergedCMCSConfigMap(appLevelConfig, envLevelConfig string, configType repository2.ConfigType) (map[string]*bean.ConfigData, error) - GetLatestPipelineStrategyConfig(pipeline *pipelineConfig.Pipeline) (*history.HistoryDetailDto, error) + GetLatestPipelineStrategyConfig(pipeline *pipelineConfig.Pipeline) (*bean2.HistoryDetailDto, error) } type PipelineDeploymentConfigServiceImpl struct { @@ -49,10 +50,10 @@ type PipelineDeploymentConfigServiceImpl struct { pipelineRepository pipelineConfig.PipelineRepository pipelineConfigRepository chartConfig.PipelineConfigRepository configMapRepository chartConfig.ConfigMapRepository - configMapHistoryService history.ConfigMapHistoryService scopedVariableManager variables.ScopedVariableCMCSManager deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService chartRefService chartRef.ChartRefService + configMapHistoryReadService read.ConfigMapHistoryReadService } func NewPipelineDeploymentConfigServiceImpl(logger *zap.SugaredLogger, @@ -61,10 +62,11 @@ func NewPipelineDeploymentConfigServiceImpl(logger *zap.SugaredLogger, pipelineRepository pipelineConfig.PipelineRepository, pipelineConfigRepository chartConfig.PipelineConfigRepository, configMapRepository chartConfig.ConfigMapRepository, - configMapHistoryService history.ConfigMapHistoryService, scopedVariableManager variables.ScopedVariableCMCSManager, deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService, - chartRefService chartRef.ChartRefService) *PipelineDeploymentConfigServiceImpl { + chartRefService chartRef.ChartRefService, + configMapHistoryReadService read.ConfigMapHistoryReadService, +) *PipelineDeploymentConfigServiceImpl { return &PipelineDeploymentConfigServiceImpl{ logger: logger, envConfigOverrideRepository: envConfigOverrideRepository, @@ -72,15 +74,15 @@ func NewPipelineDeploymentConfigServiceImpl(logger *zap.SugaredLogger, pipelineRepository: pipelineRepository, pipelineConfigRepository: pipelineConfigRepository, configMapRepository: configMapRepository, - configMapHistoryService: configMapHistoryService, scopedVariableManager: scopedVariableManager, deployedAppMetricsService: deployedAppMetricsService, chartRefService: chartRefService, + configMapHistoryReadService: configMapHistoryReadService, } } -func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentConfigurationByPipelineId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*history.AllDeploymentConfigurationDetail, error) { - configResp := &history.AllDeploymentConfigurationDetail{} +func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentConfigurationByPipelineId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean2.AllDeploymentConfigurationDetail, error) { + configResp := &bean2.AllDeploymentConfigurationDetail{} pipeline, err := impl.pipelineRepository.FindById(pipelineId) if err != nil { impl.logger.Errorw("error in getting pipeline by id", "err", err, "id", pipelineId) @@ -111,7 +113,7 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentConfiguratio return configResp, nil } -func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentTemplateConfig(ctx context.Context, pipeline *pipelineConfig.Pipeline) (*history.HistoryDetailDto, error) { +func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentTemplateConfig(ctx context.Context, pipeline *pipelineConfig.Pipeline) (*bean2.HistoryDetailDto, error) { isAppMetricsEnabled, err := impl.deployedAppMetricsService.GetMetricsFlagForAPipelineByAppIdAndEnvId(pipeline.AppId, pipeline.EnvironmentId) if err != nil { impl.logger.Errorw("error, GetMetricsFlagForAPipelineByAppIdAndEnvId", "err", err, "appId", pipeline.AppId, "envId", pipeline.EnvironmentId) @@ -123,7 +125,7 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentTemplateConf return nil, err } impl.logger.Infow("received override chart", "envConfigOverride", envOverride) - deploymentTemplateConfig := &history.HistoryDetailDto{} + deploymentTemplateConfig := &bean2.HistoryDetailDto{} if envOverride != nil && envOverride.Id > 0 && envOverride.IsOverride { if envOverride.Chart != nil { chartRefDto, err := impl.chartRefService.FindById(envOverride.Chart.ChartRefId) @@ -149,11 +151,11 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentTemplateConf impl.logger.Errorw("could not resolve template", "err", err, "envOverrideId", envOverride.Id, "scope", scope, "pipelineId", pipeline.Id) } - deploymentTemplateConfig = &history.HistoryDetailDto{ + deploymentTemplateConfig = &bean2.HistoryDetailDto{ TemplateName: envOverride.Chart.ChartName, TemplateVersion: chartRefDto.Version, IsAppMetricsEnabled: &isAppMetricsEnabled, - CodeEditorValue: &history.HistoryDetailConfig{ + CodeEditorValue: &bean2.HistoryDetailConfig{ DisplayName: "values.yaml", Value: envOverride.EnvOverrideValues, VariableSnapshot: scopedVariablesMap, @@ -190,11 +192,11 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentTemplateConf if err != nil { impl.logger.Errorw("could not resolve template", "err", err, "chartId", chart.Id, "scope", scope, "pipelineId", pipeline.Id) } - deploymentTemplateConfig = &history.HistoryDetailDto{ + deploymentTemplateConfig = &bean2.HistoryDetailDto{ TemplateName: chart.ChartName, TemplateVersion: chartRefDto.Version, IsAppMetricsEnabled: &isAppMetricsEnabled, - CodeEditorValue: &history.HistoryDetailConfig{ + CodeEditorValue: &bean2.HistoryDetailConfig{ DisplayName: "values.yaml", Value: chart.GlobalOverride, VariableSnapshot: scopedVariablesMap, @@ -205,17 +207,17 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestDeploymentTemplateConf return deploymentTemplateConfig, nil } -func (impl *PipelineDeploymentConfigServiceImpl) GetLatestPipelineStrategyConfig(pipeline *pipelineConfig.Pipeline) (*history.HistoryDetailDto, error) { +func (impl *PipelineDeploymentConfigServiceImpl) GetLatestPipelineStrategyConfig(pipeline *pipelineConfig.Pipeline) (*bean2.HistoryDetailDto, error) { pipelineStrategy, err := impl.pipelineConfigRepository.GetDefaultStrategyByPipelineId(pipeline.Id) if err != nil { impl.logger.Errorw("error in getting default pipelineStrategy by pipelineId", "err", err, "pipelineId", pipeline.Id) return nil, err } - pipelineStrategyConfig := &history.HistoryDetailDto{ + pipelineStrategyConfig := &bean2.HistoryDetailDto{ Strategy: string(pipelineStrategy.Strategy), PipelineTriggerType: pipeline.TriggerType, - CodeEditorValue: &history.HistoryDetailConfig{ + CodeEditorValue: &bean2.HistoryDetailConfig{ DisplayName: "Strategy configuration", Value: pipelineStrategy.Config, }, @@ -223,7 +225,7 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestPipelineStrategyConfig return pipelineStrategyConfig, nil } -func (impl *PipelineDeploymentConfigServiceImpl) GetLatestCMCSConfig(ctx context.Context, pipeline *pipelineConfig.Pipeline, userHasAdminAccess bool) ([]*history.ComponentLevelHistoryDetailDto, []*history.ComponentLevelHistoryDetailDto, error) { +func (impl *PipelineDeploymentConfigServiceImpl) GetLatestCMCSConfig(ctx context.Context, pipeline *pipelineConfig.Pipeline, userHasAdminAccess bool) ([]*bean2.ComponentLevelHistoryDetailDto, []*bean2.ComponentLevelHistoryDetailDto, error) { configAppLevel, err := impl.configMapRepository.GetByAppIdAppLevel(pipeline.AppId) if err != nil && pg.ErrNoRows != err { @@ -269,9 +271,9 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestCMCSConfig(ctx context return nil, nil, err } - var cmConfigsDto []*history.ComponentLevelHistoryDetailDto + var cmConfigsDto []*bean2.ComponentLevelHistoryDetailDto for _, data := range mergedConfigMap { - convertedData, err := impl.configMapHistoryService.ConvertConfigDataToComponentLevelDto(data, repository2.CONFIGMAP_TYPE, userHasAdminAccess) + convertedData, err := impl.configMapHistoryReadService.ConvertConfigDataToComponentLevelDto(data, repository2.CONFIGMAP_TYPE, userHasAdminAccess) if err != nil { impl.logger.Errorw("error in converting cmConfig to componentLevelData", "err", err) return nil, nil, err @@ -281,9 +283,9 @@ func (impl *PipelineDeploymentConfigServiceImpl) GetLatestCMCSConfig(ctx context cmConfigsDto = append(cmConfigsDto, convertedData) } - var secretConfigsDto []*history.ComponentLevelHistoryDetailDto + var secretConfigsDto []*bean2.ComponentLevelHistoryDetailDto for _, data := range mergedSecret { - convertedData, err := impl.configMapHistoryService.ConvertConfigDataToComponentLevelDto(data, repository2.SECRET_TYPE, userHasAdminAccess) + convertedData, err := impl.configMapHistoryReadService.ConvertConfigDataToComponentLevelDto(data, repository2.SECRET_TYPE, userHasAdminAccess) if err != nil { impl.logger.Errorw("error in converting secretConfig to componentLevelData", "err", err) return nil, nil, err diff --git a/pkg/pipeline/DeploymentPipelineConfigService.go b/pkg/pipeline/DeploymentPipelineConfigService.go index cc4c4a39fa1..3b8d2ff9918 100644 --- a/pkg/pipeline/DeploymentPipelineConfigService.go +++ b/pkg/pipeline/DeploymentPipelineConfigService.go @@ -50,6 +50,7 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" config2 "github.com/devtron-labs/devtron/pkg/deployment/providerConfig" clientErrors "github.com/devtron-labs/devtron/pkg/errors" "github.com/devtron-labs/devtron/pkg/eventProcessor/out" @@ -145,7 +146,7 @@ type CdPipelineConfigServiceImpl struct { chartRepository chartRepoRepository.ChartRepository resourceGroupService resourceGroup2.ResourceGroupService propertiesConfigService PropertiesConfigService - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService scopedVariableManager variables.ScopedVariableManager deploymentConfig *util2.DeploymentServiceTypeConfig application application.ServiceClient @@ -173,7 +174,7 @@ func NewCdPipelineConfigServiceImpl(logger *zap.SugaredLogger, pipelineRepositor enforcerUtil rbac.EnforcerUtil, pipelineStrategyHistoryService history.PipelineStrategyHistoryService, chartRepository chartRepoRepository.ChartRepository, resourceGroupService resourceGroup2.ResourceGroupService, propertiesConfigService PropertiesConfigService, - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService, + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, scopedVariableManager variables.ScopedVariableManager, envVariables *util2.EnvironmentVariables, application application.ServiceClient, customTagService CustomTagService, ciPipelineConfigService CiPipelineConfigService, buildPipelineSwitchService BuildPipelineSwitchService, diff --git a/pkg/pipeline/PropertiesConfig.go b/pkg/pipeline/PropertiesConfig.go index ad4e2806d67..0bdcc882e61 100644 --- a/pkg/pipeline/PropertiesConfig.go +++ b/pkg/pipeline/PropertiesConfig.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" bean2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics/bean" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/pipeline/bean" "github.com/devtron-labs/devtron/pkg/variables" repository5 "github.com/devtron-labs/devtron/pkg/variables/repository" @@ -29,7 +30,6 @@ import ( chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository" - "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/sql" "github.com/devtron-labs/devtron/internal/sql/models" @@ -59,7 +59,7 @@ type PropertiesConfigServiceImpl struct { envConfigRepo chartConfig.EnvConfigOverrideRepository chartRepo chartRepoRepository.ChartRepository environmentRepository repository2.EnvironmentRepository - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService scopedVariableManager variables.ScopedVariableManager deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService } @@ -68,7 +68,7 @@ func NewPropertiesConfigServiceImpl(logger *zap.SugaredLogger, envConfigRepo chartConfig.EnvConfigOverrideRepository, chartRepo chartRepoRepository.ChartRepository, environmentRepository repository2.EnvironmentRepository, - deploymentTemplateHistoryService history.DeploymentTemplateHistoryService, + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, scopedVariableManager variables.ScopedVariableManager, deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService) *PropertiesConfigServiceImpl { return &PropertiesConfigServiceImpl{ diff --git a/pkg/pipeline/WorkflowService.go b/pkg/pipeline/WorkflowService.go index c51b74b0181..0fb168022ef 100644 --- a/pkg/pipeline/WorkflowService.go +++ b/pkg/pipeline/WorkflowService.go @@ -28,11 +28,11 @@ import ( "github.com/devtron-labs/devtron/api/bean" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" "github.com/devtron-labs/devtron/pkg/app" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/infraConfig" k8s2 "github.com/devtron-labs/devtron/pkg/k8s" bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/executors" "github.com/devtron-labs/devtron/pkg/pipeline/infraProviders" "github.com/devtron-labs/devtron/pkg/pipeline/types" @@ -186,7 +186,7 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W func (impl *WorkflowServiceImpl) shouldAddExistingCmCsInWorkflow(workflowRequest *types.WorkflowRequest) bool { // CmCs are not added for CI_JOB if IgnoreCmCsInCiJob is true - if workflowRequest.CiPipelineType == string(CiPipeline.CI_JOB) && impl.ciCdConfig.IgnoreCmCsInCiJob { + if workflowRequest.CiPipelineType == string(bean2.CI_JOB) && impl.ciCdConfig.IgnoreCmCsInCiJob { return false } return true diff --git a/pkg/pipeline/WorkflowServiceIT_test.go b/pkg/pipeline/WorkflowServiceIT_test.go index ece775c66d1..8eedae4a907 100644 --- a/pkg/pipeline/WorkflowServiceIT_test.go +++ b/pkg/pipeline/WorkflowServiceIT_test.go @@ -27,6 +27,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" "github.com/devtron-labs/devtron/internal/util" "github.com/devtron-labs/devtron/pkg/app" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" "github.com/devtron-labs/devtron/pkg/cluster" repository3 "github.com/devtron-labs/devtron/pkg/cluster/repository" @@ -34,7 +35,6 @@ import ( k8s2 "github.com/devtron-labs/devtron/pkg/k8s" "github.com/devtron-labs/devtron/pkg/k8s/informer" bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/executors" "github.com/devtron-labs/devtron/pkg/pipeline/types" "github.com/stretchr/testify/assert" @@ -170,13 +170,13 @@ func TestWorkflowServiceImpl_SubmitWorkflow(t *testing.T) { RefPlugins: nil, AppName: "app", TriggerByAuthor: "admin", - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean.CiBuildConfigBean{ Id: 1, GitMaterialId: 0, BuildContextGitMaterialId: 1, UseRootBuildContext: true, CiBuildType: "self-dockerfile-build", - DockerBuildConfig: &CiPipeline.DockerBuildConfig{ + DockerBuildConfig: &bean.DockerBuildConfig{ DockerfilePath: "Dockerfile", DockerfileContent: "", Args: nil, @@ -306,13 +306,13 @@ func TestWorkflowServiceImpl_SubmitWorkflow(t *testing.T) { RefPlugins: nil, AppName: "app", TriggerByAuthor: "admin", - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean.CiBuildConfigBean{ Id: 1, GitMaterialId: 0, BuildContextGitMaterialId: 1, UseRootBuildContext: true, CiBuildType: "self-dockerfile-build", - DockerBuildConfig: &CiPipeline.DockerBuildConfig{ + DockerBuildConfig: &bean.DockerBuildConfig{ DockerfilePath: "Dockerfile", DockerfileContent: "", Args: nil, @@ -485,7 +485,7 @@ func TestWorkflowServiceImpl_SubmitWorkflow(t *testing.T) { RefPlugins: nil, AppName: "job/f1851uikJ", TriggerByAuthor: "admin", - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean.CiBuildConfigBean{ Id: 2, GitMaterialId: 0, BuildContextGitMaterialId: 0, @@ -682,7 +682,7 @@ func TestWorkflowServiceImpl_SubmitWorkflow(t *testing.T) { RefPlugins: nil, AppName: "", TriggerByAuthor: "admin", - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean.CiBuildConfigBean{ Id: 2, GitMaterialId: 0, BuildContextGitMaterialId: 0, diff --git a/pkg/pipeline/adapter/adapter.go b/pkg/pipeline/adapter/adapter.go index e587a119bc4..e0a6ac8c19a 100644 --- a/pkg/pipeline/adapter/adapter.go +++ b/pkg/pipeline/adapter/adapter.go @@ -22,8 +22,8 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/ciPipeline" "github.com/devtron-labs/devtron/pkg/bean" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" pipelineConfigBean "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/types" "github.com/devtron-labs/devtron/pkg/sql" "time" @@ -57,16 +57,16 @@ func UpdateRegistryDetailsToWrfReq(cdStageWorkflowRequest *types.WorkflowRequest cdStageWorkflowRequest.DockerRegistryId = dockerRegistry.Id } -func ConvertBuildConfigBeanToDbEntity(templateId int, overrideTemplateId int, ciBuildConfigBean *CiPipeline.CiBuildConfigBean, userId int32) (*pipelineConfig.CiBuildConfig, error) { +func ConvertBuildConfigBeanToDbEntity(templateId int, overrideTemplateId int, ciBuildConfigBean *bean2.CiBuildConfigBean, userId int32) (*pipelineConfig.CiBuildConfig, error) { buildMetadata := "" ciBuildType := ciBuildConfigBean.CiBuildType - if ciBuildType == CiPipeline.BUILDPACK_BUILD_TYPE { + if ciBuildType == bean2.BUILDPACK_BUILD_TYPE { buildPackConfigMetadataBytes, err := json.Marshal(ciBuildConfigBean.BuildPackConfig) if err != nil { return nil, err } buildMetadata = string(buildPackConfigMetadataBytes) - } else if ciBuildType == CiPipeline.SELF_DOCKERFILE_BUILD_TYPE || ciBuildType == CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE { + } else if ciBuildType == bean2.SELF_DOCKERFILE_BUILD_TYPE || ciBuildType == bean2.MANAGED_DOCKERFILE_BUILD_TYPE { dockerBuildMetadataBytes, err := json.Marshal(ciBuildConfigBean.DockerBuildConfig) if err != nil { return nil, err @@ -85,20 +85,20 @@ func ConvertBuildConfigBeanToDbEntity(templateId int, overrideTemplateId int, ci return ciBuildConfigEntity, nil } -func ConvertDbBuildConfigToBean(dbBuildConfig *pipelineConfig.CiBuildConfig) (*CiPipeline.CiBuildConfigBean, error) { - var buildPackConfig *CiPipeline.BuildPackConfig - var dockerBuildConfig *CiPipeline.DockerBuildConfig +func ConvertDbBuildConfigToBean(dbBuildConfig *pipelineConfig.CiBuildConfig) (*bean2.CiBuildConfigBean, error) { + var buildPackConfig *bean2.BuildPackConfig + var dockerBuildConfig *bean2.DockerBuildConfig var err error if dbBuildConfig == nil { return nil, nil } - ciBuildType := CiPipeline.CiBuildType(dbBuildConfig.Type) - if ciBuildType == CiPipeline.BUILDPACK_BUILD_TYPE { + ciBuildType := bean2.CiBuildType(dbBuildConfig.Type) + if ciBuildType == bean2.BUILDPACK_BUILD_TYPE { buildPackConfig, err = convertMetadataToBuildPackConfig(dbBuildConfig.BuildMetadata) if err != nil { return nil, err } - } else if ciBuildType == CiPipeline.SELF_DOCKERFILE_BUILD_TYPE || ciBuildType == CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE { + } else if ciBuildType == bean2.SELF_DOCKERFILE_BUILD_TYPE || ciBuildType == bean2.MANAGED_DOCKERFILE_BUILD_TYPE { dockerBuildConfig, err = convertMetadataToDockerBuildConfig(dbBuildConfig.BuildMetadata) if err != nil { return nil, err @@ -109,7 +109,7 @@ func ConvertDbBuildConfigToBean(dbBuildConfig *pipelineConfig.CiBuildConfig) (*C if dbBuildConfig.UseRootContext == nil || *(dbBuildConfig.UseRootContext) { useRootBuildContext = true } - ciBuildConfigBean := &CiPipeline.CiBuildConfigBean{ + ciBuildConfigBean := &bean2.CiBuildConfigBean{ Id: dbBuildConfig.Id, CiBuildType: ciBuildType, BuildPackConfig: buildPackConfig, @@ -119,19 +119,19 @@ func ConvertDbBuildConfigToBean(dbBuildConfig *pipelineConfig.CiBuildConfig) (*C return ciBuildConfigBean, nil } -func convertMetadataToBuildPackConfig(buildConfMetadata string) (*CiPipeline.BuildPackConfig, error) { - buildPackConfig := &CiPipeline.BuildPackConfig{} +func convertMetadataToBuildPackConfig(buildConfMetadata string) (*bean2.BuildPackConfig, error) { + buildPackConfig := &bean2.BuildPackConfig{} err := json.Unmarshal([]byte(buildConfMetadata), buildPackConfig) return buildPackConfig, err } -func convertMetadataToDockerBuildConfig(dockerBuildMetadata string) (*CiPipeline.DockerBuildConfig, error) { - dockerBuildConfig := &CiPipeline.DockerBuildConfig{} +func convertMetadataToDockerBuildConfig(dockerBuildMetadata string) (*bean2.DockerBuildConfig, error) { + dockerBuildConfig := &bean2.DockerBuildConfig{} err := json.Unmarshal([]byte(dockerBuildMetadata), dockerBuildConfig) return dockerBuildConfig, err } -func OverrideCiBuildConfig(dockerfilePath string, oldArgs string, ciLevelArgs string, dockerBuildOptions string, targetPlatform string, ciBuildConfigBean *CiPipeline.CiBuildConfigBean) (*CiPipeline.CiBuildConfigBean, error) { +func OverrideCiBuildConfig(dockerfilePath string, oldArgs string, ciLevelArgs string, dockerBuildOptions string, targetPlatform string, ciBuildConfigBean *bean2.CiBuildConfigBean) (*bean2.CiBuildConfigBean, error) { oldDockerArgs := map[string]string{} ciLevelDockerArgs := map[string]string{} dockerBuildOptionsMap := map[string]string{} @@ -153,9 +153,9 @@ func OverrideCiBuildConfig(dockerfilePath string, oldArgs string, ciLevelArgs st //no entry found in ci_build_config table, construct with requested data if ciBuildConfigBean == nil { dockerArgs := mergeMap(oldDockerArgs, ciLevelDockerArgs) - ciBuildConfigBean = &CiPipeline.CiBuildConfigBean{ - CiBuildType: CiPipeline.SELF_DOCKERFILE_BUILD_TYPE, - DockerBuildConfig: &CiPipeline.DockerBuildConfig{ + ciBuildConfigBean = &bean2.CiBuildConfigBean{ + CiBuildType: bean2.SELF_DOCKERFILE_BUILD_TYPE, + DockerBuildConfig: &bean2.DockerBuildConfig{ DockerfilePath: dockerfilePath, Args: dockerArgs, TargetPlatform: targetPlatform, @@ -165,7 +165,7 @@ func OverrideCiBuildConfig(dockerfilePath string, oldArgs string, ciLevelArgs st //setting true as default UseRootBuildContext: true, } - } else if ciBuildConfigBean.CiBuildType == CiPipeline.SELF_DOCKERFILE_BUILD_TYPE || ciBuildConfigBean.CiBuildType == CiPipeline.MANAGED_DOCKERFILE_BUILD_TYPE { + } else if ciBuildConfigBean.CiBuildType == bean2.SELF_DOCKERFILE_BUILD_TYPE || ciBuildConfigBean.CiBuildType == bean2.MANAGED_DOCKERFILE_BUILD_TYPE { dockerBuildConfig := ciBuildConfigBean.DockerBuildConfig dockerArgs := mergeMap(dockerBuildConfig.Args, ciLevelDockerArgs) //dockerBuildConfig.DockerfilePath = dockerfilePath @@ -187,29 +187,29 @@ func mergeMap(oldDockerArgs map[string]string, ciLevelDockerArgs map[string]stri // IsLinkedCD will return if the pipelineConfig.CiPipeline is a Linked CD func IsLinkedCD(ci pipelineConfig.CiPipeline) bool { - return ci.ParentCiPipeline != 0 && ci.PipelineType == string(CiPipeline.LINKED_CD) + return ci.ParentCiPipeline != 0 && ci.PipelineType == string(bean2.LINKED_CD) } // IsLinkedCI will return if the pipelineConfig.CiPipeline is a Linked CI func IsLinkedCI(ci pipelineConfig.CiPipeline) bool { return ci.ParentCiPipeline != 0 && - ci.PipelineType == string(CiPipeline.LINKED) + ci.PipelineType == string(bean2.LINKED) } // IsCIJob will return if the pipelineConfig.CiPipeline is a CI JOB func IsCIJob(ci pipelineConfig.CiPipeline) bool { - return ci.PipelineType == string(CiPipeline.CI_JOB) + return ci.PipelineType == string(bean2.CI_JOB) } // GetSourceCiDownStreamResponse will take the models []bean.LinkedCIDetails and []pipelineConfig.CdWorkflowRunner (for last deployment status) and generate the []CiPipeline.SourceCiDownStreamResponse -func GetSourceCiDownStreamResponse(linkedCIDetails []ciPipeline.LinkedCIDetails, latestWfrs ...pipelineConfig.CdWorkflowRunner) []CiPipeline.SourceCiDownStreamResponse { - response := make([]CiPipeline.SourceCiDownStreamResponse, 0) +func GetSourceCiDownStreamResponse(linkedCIDetails []ciPipeline.LinkedCIDetails, latestWfrs ...pipelineConfig.CdWorkflowRunner) []bean2.SourceCiDownStreamResponse { + response := make([]bean2.SourceCiDownStreamResponse, 0) cdWfrStatusMap := make(map[int]string) for _, latestWfr := range latestWfrs { cdWfrStatusMap[latestWfr.CdWorkflow.PipelineId] = latestWfr.Status } for _, item := range linkedCIDetails { - linkedCIDetailsRes := CiPipeline.SourceCiDownStreamResponse{ + linkedCIDetailsRes := bean2.SourceCiDownStreamResponse{ AppName: item.AppName, AppId: item.AppId, } diff --git a/pkg/pipeline/constants/constants.go b/pkg/pipeline/constants/constants.go new file mode 100644 index 00000000000..ea0c661fdac --- /dev/null +++ b/pkg/pipeline/constants/constants.go @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024. Devtron Inc. + */ + +package constants + +const CDPipelineNotFoundErr = "cd pipeline not found" +const CiPipelineNotFoundErr = "ci pipeline not found" + +type PipelineType string + +// default PipelineType +const DefaultPipelineType = CI_BUILD + +const ( + CI_BUILD PipelineType = "CI_BUILD" + LINKED PipelineType = "LINKED" + EXTERNAL PipelineType = "EXTERNAL" + CI_JOB PipelineType = "CI_JOB" + LINKED_CD PipelineType = "LINKED_CD" +) + +type PatchPipelineActionResponse string + +const ( + PATCH_PIPELINE_ACTION_CREATED PatchPipelineActionResponse = "created" + PATCH_PIPELINE_ACTION_UPDATED PatchPipelineActionResponse = "updated" + PATCH_PIPELINE_ACTION_DELETED PatchPipelineActionResponse = "deleted" + PATCH_PIPELINE_ACTION_IGNORED PatchPipelineActionResponse = "ignored" + PATCH_PIPELINE_ACTION_ERRORED PatchPipelineActionResponse = "errored" + PATCH_PIPELINE_ACTION_NOT_APPLICABLE PatchPipelineActionResponse = "N/A" +) + +func (r PipelineType) ToString() string { + return string(r) +} + +func (pType PipelineType) IsValidPipelineType() bool { + switch pType { + case CI_BUILD, LINKED, EXTERNAL, CI_JOB, LINKED_CD: + return true + default: + return false + } +} + +const ( + UNIQUE_DEPLOYMENT_APP_NAME = "unique_deployment_app_name" +) + +const ( + ExtraEnvVarExternalCiArtifactKey = "externalCiArtifact" + ExtraEnvVarImageDigestKey = "imageDigest" +) diff --git a/pkg/pipeline/history/CiPipelineHistoryService.go b/pkg/pipeline/history/CiPipelineHistoryService.go index 838e614999a..ee3a9e22fb1 100644 --- a/pkg/pipeline/history/CiPipelineHistoryService.go +++ b/pkg/pipeline/history/CiPipelineHistoryService.go @@ -19,8 +19,8 @@ package history import ( "encoding/json" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - "github.com/devtron-labs/devtron/pkg/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" "github.com/go-pg/pg" diff --git a/pkg/pipeline/history/CiPipelineHistoryService_test.go b/pkg/pipeline/history/CiPipelineHistoryService_test.go index f963e34f79f..c6c27afb3d3 100644 --- a/pkg/pipeline/history/CiPipelineHistoryService_test.go +++ b/pkg/pipeline/history/CiPipelineHistoryService_test.go @@ -21,8 +21,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" mocks2 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/mocks" "github.com/devtron-labs/devtron/internal/util" - bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository/mocks" "github.com/devtron-labs/devtron/pkg/sql" @@ -92,11 +91,11 @@ func TestCiPipelineHistoryService(t *testing.T) { DockerRegistry: nil, CiBuildConfig: nil, }, - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean2.CiBuildConfigBean{ Id: 20, GitMaterialId: 22, CiBuildType: "self-dockerfile-build", - DockerBuildConfig: &CiPipeline.DockerBuildConfig{DockerfileContent: ""}, + DockerBuildConfig: &bean2.DockerBuildConfig{DockerfileContent: ""}, BuildPackConfig: nil, }, UserId: 0, diff --git a/pkg/pipeline/history/ConfigMapHistoryService.go b/pkg/pipeline/history/ConfigMapHistoryService.go deleted file mode 100644 index 107f486dea4..00000000000 --- a/pkg/pipeline/history/ConfigMapHistoryService.go +++ /dev/null @@ -1,826 +0,0 @@ -/* - * Copyright (c) 2024. Devtron Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package history - -import ( - "context" - "encoding/json" - "errors" - "github.com/devtron-labs/devtron/pkg/configDiff/adaptor" - bean2 "github.com/devtron-labs/devtron/pkg/configDiff/bean" - "github.com/devtron-labs/devtron/pkg/configDiff/utils" - "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean" - globalUtil "github.com/devtron-labs/devtron/util" - "time" - - "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" - "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" - "github.com/devtron-labs/devtron/pkg/auth/user" - "github.com/devtron-labs/devtron/pkg/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" - "github.com/devtron-labs/devtron/pkg/sql" - "github.com/devtron-labs/devtron/pkg/variables" - "github.com/go-pg/pg" - "go.uber.org/zap" -) - -type ConfigMapHistoryService interface { - CreateHistoryFromAppLevelConfig(appLevelConfig *chartConfig.ConfigMapAppModel, configType repository.ConfigType) error - CreateHistoryFromEnvLevelConfig(envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType) error - CreateCMCSHistoryForDeploymentTrigger(pipeline *pipelineConfig.Pipeline, deployedOn time.Time, deployedBy int32) (int, int, error) - MergeAppLevelAndEnvLevelConfigs(appLevelConfig *chartConfig.ConfigMapAppModel, envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType, configMapSecretNames []string) (string, error) - GetDeploymentDetailsForDeployedCMCSHistory(pipelineId int, configType repository.ConfigType) ([]*ConfigMapAndSecretHistoryDto, error) - - GetHistoryForDeployedCMCSById(ctx context.Context, id, pipelineId int, configType repository.ConfigType, componentName string, userHasAdminAccess bool) (*HistoryDetailDto, error) - GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId int, configType repository.ConfigType) (history *repository.ConfigmapAndSecretHistory, exists bool, cmCsNames []string, err error) - GetDeployedHistoryList(pipelineId, baseConfigId int, configType repository.ConfigType, componentName string) ([]*DeployedHistoryComponentMetadataDto, error) - - CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (cmId int, csId int, exists bool, err error) - GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, configType repository.ConfigType, userHasAdminAccess bool) ([]*ComponentLevelHistoryDetailDto, error) - ConvertConfigDataToComponentLevelDto(config *bean.ConfigData, configType repository.ConfigType, userHasAdminAccess bool) (*ComponentLevelHistoryDetailDto, error) - - GetConfigmapHistoryDataByDeployedOnAndPipelineId(ctx context.Context, pipelineId int, deployedOn time.Time, userHasAdminAccess bool) (*bean2.DeploymentAndCmCsConfig, *bean2.DeploymentAndCmCsConfig, error) -} - -type ConfigMapHistoryServiceImpl struct { - logger *zap.SugaredLogger - configMapHistoryRepository repository.ConfigMapHistoryRepository - pipelineRepository pipelineConfig.PipelineRepository - configMapRepository chartConfig.ConfigMapRepository - userService user.UserService - scopedVariableManager variables.ScopedVariableCMCSManager -} - -func NewConfigMapHistoryServiceImpl(logger *zap.SugaredLogger, - configMapHistoryRepository repository.ConfigMapHistoryRepository, - pipelineRepository pipelineConfig.PipelineRepository, - configMapRepository chartConfig.ConfigMapRepository, - userService user.UserService, - scopedVariableManager variables.ScopedVariableCMCSManager, -) *ConfigMapHistoryServiceImpl { - return &ConfigMapHistoryServiceImpl{ - logger: logger, - configMapHistoryRepository: configMapHistoryRepository, - pipelineRepository: pipelineRepository, - configMapRepository: configMapRepository, - userService: userService, - scopedVariableManager: scopedVariableManager, - } -} - -func (impl ConfigMapHistoryServiceImpl) CreateHistoryFromAppLevelConfig(appLevelConfig *chartConfig.ConfigMapAppModel, configType repository.ConfigType) error { - pipelines, err := impl.pipelineRepository.FindActiveByAppId(appLevelConfig.AppId) - if err != nil { - impl.logger.Errorw("err in getting pipelines, CreateHistoryFromAppLevelConfig", "err", err, "appLevelConfig", appLevelConfig) - return err - } - //creating history for global - configData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, nil, configType, nil) - if err != nil { - impl.logger.Errorw("err in merging app and env level configs", "err", err) - return err - } - historyModel := &repository.ConfigmapAndSecretHistory{ - AppId: appLevelConfig.AppId, - DataType: configType, - Deployed: false, - Data: configData, - AuditLog: sql.AuditLog{ - CreatedBy: appLevelConfig.CreatedBy, - CreatedOn: appLevelConfig.CreatedOn, - UpdatedBy: appLevelConfig.UpdatedBy, - UpdatedOn: appLevelConfig.UpdatedOn, - }, - } - _, err = impl.configMapHistoryRepository.CreateHistory(nil, historyModel) - if err != nil { - impl.logger.Errorw("error in creating new entry for CM/CS history", "historyModel", historyModel) - return err - } - for _, pipeline := range pipelines { - envLevelConfig, err := impl.configMapRepository.GetByAppIdAndEnvIdEnvLevel(pipeline.AppId, pipeline.EnvironmentId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("err in getting env level config", "err", err, "appId", appLevelConfig.AppId) - return err - } - configData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, configType, nil) - if err != nil { - impl.logger.Errorw("err in merging app and env level configs", "err", err) - return err - } - historyModel := &repository.ConfigmapAndSecretHistory{ - AppId: appLevelConfig.AppId, - PipelineId: pipeline.Id, - DataType: configType, - Deployed: false, - Data: configData, - AuditLog: sql.AuditLog{ - CreatedBy: appLevelConfig.CreatedBy, - CreatedOn: appLevelConfig.CreatedOn, - UpdatedBy: appLevelConfig.UpdatedBy, - UpdatedOn: appLevelConfig.UpdatedOn, - }, - } - _, err = impl.configMapHistoryRepository.CreateHistory(nil, historyModel) - if err != nil { - impl.logger.Errorw("error in creating new entry for CM/CS history", "historyModel", historyModel) - return err - } - } - - return nil -} - -func (impl ConfigMapHistoryServiceImpl) CreateHistoryFromEnvLevelConfig(envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType) error { - pipelines, err := impl.pipelineRepository.FindActiveByAppIdAndEnvironmentId(envLevelConfig.AppId, envLevelConfig.EnvironmentId) - if err != nil { - impl.logger.Errorw("err in getting pipelines, CreateHistoryFromEnvLevelConfig", "err", err, "envLevelConfig", envLevelConfig) - return err - } - appLevelConfig, err := impl.configMapRepository.GetByAppIdAppLevel(envLevelConfig.AppId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("err in getting app level config", "err", err, "appId", envLevelConfig.AppId) - return err - } - for _, pipeline := range pipelines { - configData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, configType, nil) - if err != nil { - impl.logger.Errorw("err in merging app and env level configs", "err", err) - return err - } - historyModel := &repository.ConfigmapAndSecretHistory{ - AppId: envLevelConfig.AppId, - PipelineId: pipeline.Id, - DataType: configType, - Deployed: false, - Data: configData, - AuditLog: sql.AuditLog{ - CreatedBy: envLevelConfig.CreatedBy, - CreatedOn: envLevelConfig.CreatedOn, - UpdatedBy: envLevelConfig.UpdatedBy, - UpdatedOn: envLevelConfig.UpdatedOn, - }, - } - _, err = impl.configMapHistoryRepository.CreateHistory(nil, historyModel) - if err != nil { - impl.logger.Errorw("error in creating new entry for CM/CS history", "historyModel", historyModel) - return err - } - } - return nil -} - -func (impl ConfigMapHistoryServiceImpl) CreateCMCSHistoryForDeploymentTrigger(pipeline *pipelineConfig.Pipeline, deployedOn time.Time, deployedBy int32) (int, int, error) { - //creating history for configmaps, secrets(if any) - appLevelConfig, err := impl.configMapRepository.GetByAppIdAppLevel(pipeline.AppId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("err in getting app level config", "err", err, "appId", pipeline.AppId) - return 0, 0, err - } - envLevelConfig, err := impl.configMapRepository.GetByAppIdAndEnvIdEnvLevel(pipeline.AppId, pipeline.EnvironmentId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("err in getting env level config", "err", err, "appId", pipeline.AppId) - return 0, 0, err - } - configMapData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, repository.CONFIGMAP_TYPE, nil) - if err != nil { - impl.logger.Errorw("err in merging app and env level configs", "err", err) - return 0, 0, err - } - historyModelForCM := repository.ConfigmapAndSecretHistory{ - AppId: pipeline.AppId, - PipelineId: pipeline.Id, - DataType: repository.CONFIGMAP_TYPE, - Deployed: true, - DeployedBy: deployedBy, - DeployedOn: deployedOn, - Data: configMapData, - AuditLog: sql.AuditLog{ - CreatedBy: deployedBy, - CreatedOn: deployedOn, - UpdatedBy: deployedBy, - UpdatedOn: deployedOn, - }, - } - - tx, err := impl.configMapHistoryRepository.StartTx() - if err != nil { - impl.logger.Errorw("error in starting transaction to create new cm/cs history", "error", err) - return 0, 0, err - } - defer impl.configMapHistoryRepository.RollbackTx(tx) - cmHistory, err := impl.configMapHistoryRepository.CreateHistory(tx, &historyModelForCM) - if err != nil { - impl.logger.Errorw("error in creating new entry for cm history", "historyModel", historyModelForCM) - return 0, 0, err - } - secretData, err := impl.MergeAppLevelAndEnvLevelConfigs(appLevelConfig, envLevelConfig, repository.SECRET_TYPE, nil) - if err != nil { - impl.logger.Errorw("err in merging app and env level configs", "err", err) - return 0, 0, err - } - historyModelForCS := historyModelForCM - historyModelForCS.DataType = repository.SECRET_TYPE - historyModelForCS.Data = secretData - historyModelForCS.Id = 0 - csHistory, err := impl.configMapHistoryRepository.CreateHistory(tx, &historyModelForCS) - if err != nil { - impl.logger.Errorw("error in creating new entry for secret history", "historyModel", historyModelForCS) - return 0, 0, err - } - err = impl.configMapHistoryRepository.CommitTx(tx) - if err != nil { - impl.logger.Errorw("error in committing transaction to create new cm/cs history", "error", err) - return 0, 0, err - } - return cmHistory.Id, csHistory.Id, nil -} - -func (impl ConfigMapHistoryServiceImpl) MergeAppLevelAndEnvLevelConfigs(appLevelConfig *chartConfig.ConfigMapAppModel, envLevelConfig *chartConfig.ConfigMapEnvModel, configType repository.ConfigType, configMapSecretNames []string) (string, error) { - var err error - var appLevelConfigData []*bean.ConfigData - var envLevelConfigData []*bean.ConfigData - if configType == repository.CONFIGMAP_TYPE { - var configDataAppLevel string - var configDataEnvLevel string - if appLevelConfig != nil { - configDataAppLevel = appLevelConfig.ConfigMapData - } - if envLevelConfig != nil { - configDataEnvLevel = envLevelConfig.ConfigMapData - } - configListAppLevel := &bean.ConfigList{} - if len(configDataAppLevel) > 0 { - err = json.Unmarshal([]byte(configDataAppLevel), configListAppLevel) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return "", err - } - } - configListEnvLevel := &bean.ConfigList{} - if len(configDataEnvLevel) > 0 { - err = json.Unmarshal([]byte(configDataEnvLevel), configListEnvLevel) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return "", err - } - } - appLevelConfigData = configListAppLevel.ConfigData - envLevelConfigData = configListEnvLevel.ConfigData - } else if configType == repository.SECRET_TYPE { - var secretDataAppLevel string - var secretDataEnvLevel string - if appLevelConfig != nil { - secretDataAppLevel = appLevelConfig.SecretData - } - if envLevelConfig != nil { - secretDataEnvLevel = envLevelConfig.SecretData - } - secretListAppLevel := &bean.SecretList{} - if len(secretDataAppLevel) > 0 { - err = json.Unmarshal([]byte(secretDataAppLevel), secretListAppLevel) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return "", err - } - } - secretListEnvLevel := &bean.SecretList{} - if len(secretDataEnvLevel) > 0 { - err = json.Unmarshal([]byte(secretDataEnvLevel), secretListEnvLevel) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return "", err - } - } - appLevelConfigData = secretListAppLevel.ConfigData - envLevelConfigData = secretListEnvLevel.ConfigData - } - - var finalConfigs []*bean.ConfigData - envLevelConfigs := make(map[string]bool) - filterNameMap := make(map[string]bool) - for _, name := range configMapSecretNames { - filterNameMap[name] = true - } - //if filter name map is not empty, to add configs by filtering names - //if filter name map is empty, adding all env level configs to final configs - for _, item := range envLevelConfigData { - if _, ok := filterNameMap[item.Name]; ok || len(filterNameMap) == 0 { - //adding all env configs whose name is in filter name map - envLevelConfigs[item.Name] = true - finalConfigs = append(finalConfigs, item) - } - } - for _, item := range appLevelConfigData { - //if filter name map is not empty, adding all global configs which are not present in env level and are present in filter name map to final configs - //if filter name map is empty,adding all global configs which are not present in env level to final configs - if _, ok := envLevelConfigs[item.Name]; !ok { - if _, ok = filterNameMap[item.Name]; ok || len(filterNameMap) == 0 { - finalConfigs = append(finalConfigs, item) - } - } - } - var finalConfigDataByte []byte - if configType == repository.CONFIGMAP_TYPE { - var finalConfigList bean.ConfigList - finalConfigList.ConfigData = finalConfigs - finalConfigDataByte, err = json.Marshal(finalConfigList) - if err != nil { - impl.logger.Errorw("error in marshaling config", "err", err) - return "", err - } - } else if configType == repository.SECRET_TYPE { - var finalConfigList bean.SecretList - finalConfigList.ConfigData = finalConfigs - finalConfigDataByte, err = json.Marshal(finalConfigList) - if err != nil { - impl.logger.Errorw("error in marshaling config", "err", err) - return "", err - } - } - return string(finalConfigDataByte), err -} - -func (impl ConfigMapHistoryServiceImpl) GetDeploymentDetailsForDeployedCMCSHistory(pipelineId int, configType repository.ConfigType) ([]*ConfigMapAndSecretHistoryDto, error) { - histories, err := impl.configMapHistoryRepository.GetDeploymentDetailsForDeployedCMCSHistory(pipelineId, configType) - if err != nil { - impl.logger.Errorw("error in getting histories for cm/cs", "err", err, "pipelineId", pipelineId) - return nil, err - } - var historiesDto []*ConfigMapAndSecretHistoryDto - for _, history := range histories { - userEmailId, err := impl.userService.GetActiveEmailById(history.DeployedBy) - if err != nil { - impl.logger.Errorw("unable to find user email by id", "err", err, "id", history.DeployedBy) - return nil, err - } - historyDto := &ConfigMapAndSecretHistoryDto{ - Id: history.Id, - AppId: history.AppId, - PipelineId: history.PipelineId, - Deployed: history.Deployed, - DeployedOn: history.DeployedOn, - DeployedBy: history.DeployedBy, - EmailId: userEmailId, - } - historiesDto = append(historiesDto, historyDto) - } - return historiesDto, nil -} - -func (impl ConfigMapHistoryServiceImpl) GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId int, configType repository.ConfigType) (history *repository.ConfigmapAndSecretHistory, exists bool, cmCsNames []string, err error) { - impl.logger.Debugw("received request, CheckIfHistoryExistsForPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) - //checking if history exists for pipelineId and wfrId - history, err = impl.configMapHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId, configType) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return history, false, cmCsNames, err - } else if err == pg.ErrNoRows { - return history, false, cmCsNames, nil - } - var configData []*bean.ConfigData - if configType == repository.CONFIGMAP_TYPE { - configList := bean.ConfigList{} - if len(history.Data) > 0 { - err = json.Unmarshal([]byte(history.Data), &configList) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return history, false, cmCsNames, err - } - } - configData = configList.ConfigData - } else if configType == repository.SECRET_TYPE { - secretList := bean.SecretList{} - if len(history.Data) > 0 { - err = json.Unmarshal([]byte(history.Data), &secretList) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return history, false, cmCsNames, err - } - } - configData = secretList.ConfigData - } - for _, data := range configData { - cmCsNames = append(cmCsNames, data.Name) - } - if len(configData) == 0 { - return history, false, cmCsNames, nil - } - - return history, true, cmCsNames, nil -} - -func (impl ConfigMapHistoryServiceImpl) GetDeployedHistoryList(pipelineId, baseConfigId int, configType repository.ConfigType, componentName string) ([]*DeployedHistoryComponentMetadataDto, error) { - impl.logger.Debugw("received request, GetDeployedHistoryList", "pipelineId", pipelineId, "baseConfigId", baseConfigId) - - //checking if history exists for pipelineId and wfrId - histories, err := impl.configMapHistoryRepository.GetDeployedHistoryList(pipelineId, baseConfigId, configType, componentName) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting history list for pipelineId and baseConfigId", "err", err, "pipelineId", pipelineId) - return nil, err - } - var historyList []*DeployedHistoryComponentMetadataDto - for _, history := range histories { - historyList = append(historyList, &DeployedHistoryComponentMetadataDto{ - Id: history.Id, - DeployedOn: history.DeployedOn, - DeployedBy: history.DeployedByEmailId, - DeploymentStatus: history.DeploymentStatus, - }) - } - return historyList, nil -} - -func (impl ConfigMapHistoryServiceImpl) GetHistoryForDeployedCMCSById(ctx context.Context, id, pipelineId int, configType repository.ConfigType, componentName string, userHasAdminAccess bool) (*HistoryDetailDto, error) { - history, err := impl.configMapHistoryRepository.GetHistoryForDeployedCMCSById(id, pipelineId, configType) - if err != nil { - impl.logger.Errorw("error in getting histories for cm/cs", "err", err, "id", id, "pipelineId", pipelineId) - return nil, err - } - var configData []*bean.ConfigData - var configList bean.ConfigList - var secretList bean.SecretList - if configType == repository.CONFIGMAP_TYPE { - configList = bean.ConfigList{} - if len(history.Data) > 0 { - err := json.Unmarshal([]byte(history.Data), &configList) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return nil, err - } - } - configData = configList.ConfigData - } else if configType == repository.SECRET_TYPE { - secretList = bean.SecretList{} - if len(history.Data) > 0 { - err := json.Unmarshal([]byte(history.Data), &secretList) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return nil, err - } - } - configData = secretList.ConfigData - - } - - variableSnapshotMap, resolvedTemplate, err := impl.scopedVariableManager.ResolveCMCSHistoryDto(ctx, configType, configList, history, componentName, secretList) - if err != nil { - return nil, err - } - - config := &bean.ConfigData{} - for _, data := range configData { - if data.Name == componentName { - config = data - break - } - } - historyDto := &HistoryDetailDto{ - Type: config.Type, - External: &config.External, - MountPath: config.MountPath, - SubPath: &config.SubPath, - FilePermission: config.FilePermission, - CodeEditorValue: &HistoryDetailConfig{ - DisplayName: DataDisplayName, - Value: string(config.Data), - VariableSnapshot: variableSnapshotMap, - ResolvedValue: resolvedTemplate, - }, - SecretViewAccess: userHasAdminAccess, - } - if configType == repository.SECRET_TYPE { - if config.Data != nil { - if !userHasAdminAccess { - //removing keys and sending - resultMap := make(map[string]string) - resultMapFinal := make(map[string]string) - err = json.Unmarshal(config.Data, &resultMap) - if err != nil { - impl.logger.Warnw("unmarshal failed", "error", err) - } - for key, _ := range resultMap { - //hard-coding values to show them as hidden to user - resultMapFinal[key] = "*****" - } - resultByte, err := json.Marshal(resultMapFinal) - if err != nil { - impl.logger.Errorw("error while marshaling request", "err", err) - return nil, err - } - historyDto.CodeEditorValue.Value = string(resultByte) - } - } - historyDto.ExternalSecretType = config.ExternalSecretType - historyDto.RoleARN = config.RoleARN - historyDto.ESOSubPath = config.ESOSubPath - if config.External { - if config.ExternalSecretType == globalUtil.KubernetesSecret { - externalSecretData, err := json.Marshal(config.ExternalSecret) - if err != nil { - impl.logger.Errorw("error in marshaling external secret data", "err", err) - } - if len(externalSecretData) > 0 { - historyDto.CodeEditorValue.DisplayName = ExternalSecretDisplayName - historyDto.CodeEditorValue.Value = string(externalSecretData) - } - } else if config.IsESOExternalSecretType() { - externalSecretDataBytes, jErr := json.Marshal(config.ESOSecretData) - if jErr != nil { - impl.logger.Errorw("error in marshaling eso secret data", "esoSecretData", config.ESOSecretData, "err", jErr) - return nil, jErr - } - if len(externalSecretDataBytes) > 0 { - historyDto.CodeEditorValue.DisplayName = ESOSecretDataDisplayName - historyDto.CodeEditorValue.Value = string(externalSecretDataBytes) - } - } - } - } - return historyDto, nil -} - -func (impl ConfigMapHistoryServiceImpl) GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, configType repository.ConfigType, userHasAdminAccess bool) ([]*ComponentLevelHistoryDetailDto, error) { - history, err := impl.configMapHistoryRepository.GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId, configType) - if err != nil { - impl.logger.Errorw("error in getting histories for cm/cs", "err", err, "wfrId", wfrId, "pipelineId", pipelineId) - return nil, err - } - var configData []*bean.ConfigData - var configList bean.ConfigList - var secretList bean.SecretList - if err != nil { - return nil, err - } - if configType == repository.CONFIGMAP_TYPE { - configList = bean.ConfigList{} - if len(history.Data) > 0 { - err := json.Unmarshal([]byte(history.Data), &configList) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return nil, err - } - } - configData = configList.ConfigData - } else if configType == repository.SECRET_TYPE { - secretList = bean.SecretList{} - if len(history.Data) > 0 { - err := json.Unmarshal([]byte(history.Data), &secretList) - if err != nil { - impl.logger.Debugw("error while Unmarshal", "err", err) - return nil, err - } - } - configData = secretList.ConfigData - } - resolvedDataMap, variableSnapshotMap, err := impl.scopedVariableManager.GetResolvedCMCSHistoryDtos(ctx, configType, configList, history, secretList) - if err != nil { - return nil, err - } - - var componentLevelHistoryData []*ComponentLevelHistoryDetailDto - for _, config := range configData { - componentLevelData, err := impl.ConvertConfigDataToComponentLevelDto(config, configType, userHasAdminAccess) - if err != nil { - impl.logger.Errorw("error in converting data to componentLevelData", "err", err) - } - componentLevelData.HistoryConfig.CodeEditorValue.VariableSnapshot = variableSnapshotMap[config.Name] - componentLevelData.HistoryConfig.CodeEditorValue.ResolvedValue = string(resolvedDataMap[config.Name].Data) - componentLevelHistoryData = append(componentLevelHistoryData, componentLevelData) - } - return componentLevelHistoryData, nil -} - -func (impl ConfigMapHistoryServiceImpl) ConvertConfigDataToComponentLevelDto(config *bean.ConfigData, configType repository.ConfigType, userHasAdminAccess bool) (*ComponentLevelHistoryDetailDto, error) { - historyDto := &HistoryDetailDto{ - Type: config.Type, - External: &config.External, - MountPath: config.MountPath, - SubPath: &config.SubPath, - FilePermission: config.FilePermission, - CodeEditorValue: &HistoryDetailConfig{ - DisplayName: DataDisplayName, - Value: string(config.Data), - }, - } - var err error - if configType == repository.SECRET_TYPE { - if config.Data != nil { - if !userHasAdminAccess { - //removing keys and sending - resultMap := make(map[string]string) - resultMapFinal := make(map[string]string) - err = json.Unmarshal(config.Data, &resultMap) - if err != nil { - impl.logger.Warnw("unmarshal failed", "error", err) - return nil, err - } - for key, _ := range resultMap { - //hard-coding values to show them as hidden to user - resultMapFinal[key] = "*****" - } - resultByte, err := json.Marshal(resultMapFinal) - if err != nil { - impl.logger.Errorw("error while marshaling request", "err", err) - return nil, err - } - historyDto.CodeEditorValue.Value = string(resultByte) - } - } - historyDto.ExternalSecretType = config.ExternalSecretType - historyDto.RoleARN = config.RoleARN - historyDto.ESOSubPath = config.ESOSubPath - if config.External { - var externalSecretData []byte - displayName := historyDto.CodeEditorValue.DisplayName - if config.IsESOExternalSecretType() { - displayName = ESOSecretDataDisplayName - externalSecretData, err = json.Marshal(config.ESOSecretData) - if err != nil { - impl.logger.Errorw("error in marshaling external secret data", "err", err) - return nil, err - } - } else { - displayName = ExternalSecretDisplayName - externalSecretData, err = json.Marshal(config.ExternalSecret) - if err != nil { - impl.logger.Errorw("error in marshaling external secret data", "err", err) - return nil, err - } - } - if len(externalSecretData) > 0 { - historyDto.CodeEditorValue.DisplayName = displayName - historyDto.CodeEditorValue.Value = string(externalSecretData) - } - } - } - componentLevelData := &ComponentLevelHistoryDetailDto{ - ComponentName: config.Name, - HistoryConfig: historyDto, - } - return componentLevelData, nil -} - -func (impl ConfigMapHistoryServiceImpl) CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (cmId int, csId int, exists bool, err error) { - cmHistory, cmErr := impl.configMapHistoryRepository.GetDeployedHistoryForPipelineIdOnTime(pipelineId, deployedOn, repository.SECRET_TYPE) - if cmErr != nil && !errors.Is(cmErr, pg.ErrNoRows) { - impl.logger.Errorw("error in checking if config map history exists for pipelineId and deployedOn", "err", cmErr, "pipelineId", pipelineId, "deployedOn", deployedOn) - return cmId, csId, exists, cmErr - } - if cmErr == nil { - cmId = cmHistory.Id - } - csHistory, csErr := impl.configMapHistoryRepository.GetDeployedHistoryForPipelineIdOnTime(pipelineId, deployedOn, repository.SECRET_TYPE) - if csErr != nil && !errors.Is(csErr, pg.ErrNoRows) { - impl.logger.Errorw("error in checking if secret history exists for pipelineId and deployedOn", "err", csErr, "pipelineId", pipelineId, "deployedOn", deployedOn) - return cmId, csId, exists, csErr - } - if csErr == nil { - csId = csHistory.Id - } - if cmErr == nil && csErr == nil { - exists = true - } - return cmId, csId, exists, nil -} - -func (impl ConfigMapHistoryServiceImpl) GetConfigmapHistoryDataByDeployedOnAndPipelineId(ctx context.Context, pipelineId int, deployedOn time.Time, userHasAdminAccess bool) (*bean2.DeploymentAndCmCsConfig, *bean2.DeploymentAndCmCsConfig, error) { - secretConfigData, err := impl.getResolvedConfigData(ctx, pipelineId, deployedOn, repository.SECRET_TYPE, userHasAdminAccess) - if err != nil { - impl.logger.Errorw("error in getting resolved secret config data in case of previous deployments ", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) - return nil, nil, err - } - cmConfigData, err := impl.getResolvedConfigData(ctx, pipelineId, deployedOn, repository.CONFIGMAP_TYPE, userHasAdminAccess) - if err != nil { - impl.logger.Errorw("error in getting resolved cm config data in case of previous deployments ", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) - return nil, nil, err - } - - return secretConfigData, cmConfigData, nil -} - -func (impl *ConfigMapHistoryServiceImpl) getResolvedConfigData(ctx context.Context, pipelineId int, deployedOn time.Time, configType repository.ConfigType, userHasAdminAccess bool) (*bean2.DeploymentAndCmCsConfig, error) { - configsList := &bean3.ConfigsList{} - secretsList := &bean3.SecretsList{} - var err error - history, err := impl.configMapHistoryRepository.GetDeployedHistoryByPipelineIdAndDeployedOn(pipelineId, deployedOn, configType) - if err != nil { - impl.logger.Errorw("error in getting deployed history by pipeline id and deployed on", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) - return nil, err - } - if configType == repository.SECRET_TYPE { - _, secretsList, err = impl.getConfigDataRequestForHistory(history) - if err != nil { - impl.logger.Errorw("error in getting config data request for history", "err", err) - return nil, err - } - } else if configType == repository.CONFIGMAP_TYPE { - configsList, _, err = impl.getConfigDataRequestForHistory(history) - if err != nil { - impl.logger.Errorw("error in getting config data request for history", "cmCsHistory", history, "err", err) - return nil, err - } - } - - resolvedDataMap, variableSnapshotMap, err := impl.scopedVariableManager.GetResolvedCMCSHistoryDtos(ctx, configType, adaptor.ReverseConfigListConvertor(*configsList), history, adaptor.ReverseSecretListConvertor(*secretsList)) - if err != nil { - return nil, err - } - resolvedConfigDataList := make([]*bean3.ConfigData, 0, len(resolvedDataMap)) - for _, resolvedConfigData := range resolvedDataMap { - resolvedConfigDataList = append(resolvedConfigDataList, adapter.ConvertConfigDataToPipelineConfigData(&resolvedConfigData)) - } - configDataReq := &bean3.ConfigDataRequest{} - var resourceType bean3.ResourceType - if configType == repository.SECRET_TYPE { - impl.encodeSecretDataFromNonAdminUsers(secretsList.ConfigData, userHasAdminAccess) - impl.encodeSecretDataFromNonAdminUsers(resolvedConfigDataList, userHasAdminAccess) - configDataReq.ConfigData = secretsList.ConfigData - resourceType = bean3.CS - } else if configType == repository.CONFIGMAP_TYPE { - configDataReq.ConfigData = configsList.ConfigData - resourceType = bean3.CM - } - - configDataJson, err := utils.ConvertToJsonRawMessage(configDataReq) - if err != nil { - impl.logger.Errorw("getCmCsPublishedConfigResponse, error in converting config data to json raw message", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) - return nil, err - } - resolvedConfigDataReq := &bean3.ConfigDataRequest{ConfigData: resolvedConfigDataList} - resolvedConfigDataString, err := utils.ConvertToString(resolvedConfigDataReq) - if err != nil { - impl.logger.Errorw("getCmCsPublishedConfigResponse, error in converting config data to json raw message", "pipelineId", pipelineId, "deployedOn", deployedOn, "err", err) - return nil, err - } - resolvedConfigDataStringJson, err := utils.ConvertToJsonRawMessage(resolvedConfigDataString) - if err != nil { - impl.logger.Errorw("getCmCsPublishedConfigResponse, error in ConvertToJsonRawMessage for resolvedJson", "resolvedJson", resolvedConfigDataStringJson, "err", err) - return nil, err - } - return bean2.NewDeploymentAndCmCsConfig().WithConfigData(configDataJson).WithResourceType(resourceType). - WithVariableSnapshot(variableSnapshotMap).WithResolvedValue(resolvedConfigDataStringJson), nil -} - -func (impl *ConfigMapHistoryServiceImpl) encodeSecretDataFromNonAdminUsers(configDataList []*bean3.ConfigData, userHasAdminAccess bool) { - for _, config := range configDataList { - if config.Data != nil { - if !userHasAdminAccess { - //removing keys and sending - resultMap := make(map[string]string) - resultMapFinal := make(map[string]string) - err := json.Unmarshal(config.Data, &resultMap) - if err != nil { - impl.logger.Errorw("unmarshal failed", "error", err) - return - } - for key, _ := range resultMap { - //hard-coding values to show them as hidden to user - resultMapFinal[key] = "*****" - } - config.Data, err = utils.ConvertToJsonRawMessage(resultMapFinal) - if err != nil { - impl.logger.Errorw("error while marshaling request", "err", err) - return - } - } - } - } -} - -func (impl ConfigMapHistoryServiceImpl) getConfigDataRequestForHistory(history *repository.ConfigmapAndSecretHistory) (*bean3.ConfigsList, *bean3.SecretsList, error) { - - configsList := &bean3.ConfigsList{} - secretsList := &bean3.SecretsList{} - if history.IsConfigmapHistorySecretType() { - err := json.Unmarshal([]byte(history.Data), secretsList) - if err != nil { - impl.logger.Errorw("error while Unmarshal in secret history data", "error", err) - return configsList, secretsList, err - } - return configsList, secretsList, nil - } else if history.IsConfigmapHistoryConfigMapType() { - err := json.Unmarshal([]byte(history.Data), configsList) - if err != nil { - impl.logger.Errorw("error while Unmarshal in config history data", "historyData", history.Data, "error", err) - return configsList, secretsList, err - } - return configsList, secretsList, nil - } - return configsList, secretsList, nil -} diff --git a/pkg/pipeline/history/DeployedConfigurationHistoryService.go b/pkg/pipeline/history/DeployedConfigurationHistoryService.go index 241574a2f18..22cf93e5a0f 100644 --- a/pkg/pipeline/history/DeployedConfigurationHistoryService.go +++ b/pkg/pipeline/history/DeployedConfigurationHistoryService.go @@ -21,6 +21,11 @@ import ( "errors" "fmt" "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + read2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" + bean2 "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" "github.com/devtron-labs/devtron/pkg/variables" repository5 "github.com/devtron-labs/devtron/pkg/variables/repository" util4 "github.com/devtron-labs/devtron/util" @@ -36,48 +41,56 @@ import ( "go.uber.org/zap" ) +// TODO: Prakash, merge this interface with interface in deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go and extract out read logic in read repo type DeployedConfigurationHistoryService interface { //TODO: rethink if the below method right at this place CreateHistoriesForDeploymentTrigger(ctx context.Context, pipeline *pipelineConfig.Pipeline, strategy *chartConfig.PipelineStrategy, envOverride *chartConfig.EnvConfigOverride, deployedOn time.Time, deployedBy int32) error - GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*DeploymentConfigurationDto, error) - GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*DeployedHistoryComponentMetadataDto, error) - GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*HistoryDetailDto, error) - GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*AllDeploymentConfigurationDetail, error) - GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*AllDeploymentConfigurationDetail, error) + GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*bean2.DeploymentConfigurationDto, error) + GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*bean2.DeployedHistoryComponentMetadataDto, error) + GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*bean2.HistoryDetailDto, error) + GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean2.AllDeploymentConfigurationDetail, error) + GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*bean2.AllDeploymentConfigurationDetail, error) GetLatestDeployedArtifactByPipelineId(pipelineId int) (*repository2.CiArtifact, error) } type DeployedConfigurationHistoryServiceImpl struct { - logger *zap.SugaredLogger - userService user.UserService - deploymentTemplateHistoryService DeploymentTemplateHistoryService - strategyHistoryService PipelineStrategyHistoryService - configMapHistoryService ConfigMapHistoryService - cdWorkflowRepository pipelineConfig.CdWorkflowRepository - scopedVariableManager variables.ScopedVariableCMCSManager + logger *zap.SugaredLogger + userService user.UserService + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService + strategyHistoryService PipelineStrategyHistoryService + configMapHistoryService configMapAndSecret.ConfigMapHistoryService + cdWorkflowRepository pipelineConfig.CdWorkflowRepository + scopedVariableManager variables.ScopedVariableCMCSManager + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService + configMapHistoryReadService read2.ConfigMapHistoryReadService } func NewDeployedConfigurationHistoryServiceImpl(logger *zap.SugaredLogger, - userService user.UserService, deploymentTemplateHistoryService DeploymentTemplateHistoryService, - strategyHistoryService PipelineStrategyHistoryService, configMapHistoryService ConfigMapHistoryService, + userService user.UserService, deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, + strategyHistoryService PipelineStrategyHistoryService, configMapHistoryService configMapAndSecret.ConfigMapHistoryService, cdWorkflowRepository pipelineConfig.CdWorkflowRepository, - scopedVariableManager variables.ScopedVariableCMCSManager) *DeployedConfigurationHistoryServiceImpl { + scopedVariableManager variables.ScopedVariableCMCSManager, + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService, + configMapHistoryReadService read2.ConfigMapHistoryReadService, +) *DeployedConfigurationHistoryServiceImpl { return &DeployedConfigurationHistoryServiceImpl{ - logger: logger, - userService: userService, - deploymentTemplateHistoryService: deploymentTemplateHistoryService, - strategyHistoryService: strategyHistoryService, - configMapHistoryService: configMapHistoryService, - cdWorkflowRepository: cdWorkflowRepository, - scopedVariableManager: scopedVariableManager, + logger: logger, + userService: userService, + deploymentTemplateHistoryService: deploymentTemplateHistoryService, + strategyHistoryService: strategyHistoryService, + configMapHistoryService: configMapHistoryService, + cdWorkflowRepository: cdWorkflowRepository, + scopedVariableManager: scopedVariableManager, + deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, + configMapHistoryReadService: configMapHistoryReadService, } } func (impl *DeployedConfigurationHistoryServiceImpl) CreateHistoriesForDeploymentTrigger(ctx context.Context, pipeline *pipelineConfig.Pipeline, strategy *chartConfig.PipelineStrategy, envOverride *chartConfig.EnvConfigOverride, deployedOn time.Time, deployedBy int32) error { _, span := otel.Tracer("orchestrator").Start(ctx, "DeployedConfigurationHistoryServiceImpl.CreateHistoriesForDeploymentTrigger") defer span.End() - deploymentTemplateHistoryId, templateHistoryExists, err := impl.deploymentTemplateHistoryService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) + deploymentTemplateHistoryId, templateHistoryExists, err := impl.deploymentTemplateHistoryReadService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) if err != nil { impl.logger.Errorw("error in checking if deployment template history exists for deployment trigger", "err", err) return err @@ -91,7 +104,7 @@ func (impl *DeployedConfigurationHistoryServiceImpl) CreateHistoriesForDeploymen } deploymentTemplateHistoryId = deploymentTemplateHistory.Id } - cmId, csId, cmCsHistoryExists, err := impl.configMapHistoryService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) + cmId, csId, cmCsHistoryExists, err := impl.configMapHistoryReadService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) if err != nil { impl.logger.Errorw("error in checking if config map/ secrete history exists for deployment trigger", "err", err) return err @@ -142,19 +155,19 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetLatestDeployedArtifactBy return wfr.CdWorkflow.CiArtifact, nil } -func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*DeploymentConfigurationDto, error) { +func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*bean2.DeploymentConfigurationDto, error) { newCtx, span := otel.Tracer("orchestrator").Start(ctx, "DeployedConfigurationHistoryServiceImpl.GetDeployedConfigurationByWfrId") defer span.End() - var deployedConfigurations []*DeploymentConfigurationDto + var deployedConfigurations []*bean2.DeploymentConfigurationDto //checking if deployment template configuration for this pipelineId and wfrId exists or not - templateHistoryId, exists, err := impl.deploymentTemplateHistoryService.CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId) + templateHistoryId, exists, err := impl.deploymentTemplateHistoryReadService.CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId) if err != nil { impl.logger.Errorw("error in checking if history exists for deployment template", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } - deploymentTemplateConfiguration := &DeploymentConfigurationDto{ - Name: DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT, + deploymentTemplateConfiguration := &bean2.DeploymentConfigurationDto{ + Name: bean2.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT, } if exists { deploymentTemplateConfiguration.Id = templateHistoryId @@ -168,8 +181,8 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedConfigurationByW impl.logger.Errorw("error in checking if history exists for pipeline strategy", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } - pipelineStrategyConfiguration := &DeploymentConfigurationDto{ - Name: PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT, + pipelineStrategyConfiguration := &bean2.DeploymentConfigurationDto{ + Name: bean2.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT, } if exists { pipelineStrategyConfiguration.Id = strategyHistoryId @@ -177,30 +190,30 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedConfigurationByW } //checking if configmap history data exists and get its details - configmapHistory, exists, names, err := impl.configMapHistoryService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository.CONFIGMAP_TYPE) + configmapHistory, exists, names, err := impl.configMapHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository.CONFIGMAP_TYPE) if err != nil { impl.logger.Errorw("error in checking if history exists for configmap", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } if exists { - configmapConfiguration := &DeploymentConfigurationDto{ + configmapConfiguration := &bean2.DeploymentConfigurationDto{ Id: configmapHistory.Id, - Name: CONFIGMAP_TYPE_HISTORY_COMPONENT, + Name: bean2.CONFIGMAP_TYPE_HISTORY_COMPONENT, ChildComponentNames: names, } deployedConfigurations = append(deployedConfigurations, configmapConfiguration) } //checking if secret history data exists and get its details - secretHistory, exists, names, err := impl.configMapHistoryService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository.SECRET_TYPE) + secretHistory, exists, names, err := impl.configMapHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository.SECRET_TYPE) if err != nil { impl.logger.Errorw("error in checking if history exists for secret", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } if exists { - secretConfiguration := &DeploymentConfigurationDto{ + secretConfiguration := &bean2.DeploymentConfigurationDto{ Id: secretHistory.Id, - Name: SECRET_TYPE_HISTORY_COMPONENT, + Name: bean2.SECRET_TYPE_HISTORY_COMPONENT, ChildComponentNames: names, } deployedConfigurations = append(deployedConfigurations, secretConfiguration) @@ -208,17 +221,17 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedConfigurationByW return deployedConfigurations, nil } -func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*DeployedHistoryComponentMetadataDto, error) { - var historyList []*DeployedHistoryComponentMetadataDto +func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*bean2.DeployedHistoryComponentMetadataDto, error) { + var historyList []*bean2.DeployedHistoryComponentMetadataDto var err error - if historyComponent == string(DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.deploymentTemplateHistoryService.GetDeployedHistoryList(pipelineId, baseConfigId) - } else if historyComponent == string(PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { + if historyComponent == string(bean2.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.deploymentTemplateHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId) + } else if historyComponent == string(bean2.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { historyList, err = impl.strategyHistoryService.GetDeployedHistoryList(pipelineId, baseConfigId) - } else if historyComponent == string(CONFIGMAP_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.configMapHistoryService.GetDeployedHistoryList(pipelineId, baseConfigId, repository.CONFIGMAP_TYPE, historyComponentName) - } else if historyComponent == string(SECRET_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.configMapHistoryService.GetDeployedHistoryList(pipelineId, baseConfigId, repository.SECRET_TYPE, historyComponentName) + } else if historyComponent == string(bean2.CONFIGMAP_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.configMapHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId, repository.CONFIGMAP_TYPE, historyComponentName) + } else if historyComponent == string(bean2.SECRET_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.configMapHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId, repository.SECRET_TYPE, historyComponentName) } else { return nil, errors.New(fmt.Sprintf("history of %s not supported", historyComponent)) } @@ -229,17 +242,17 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponent return historyList, nil } -func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*HistoryDetailDto, error) { - history := &HistoryDetailDto{} +func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*bean2.HistoryDetailDto, error) { + history := &bean2.HistoryDetailDto{} var err error - if historyComponent == string(DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { - history, err = impl.deploymentTemplateHistoryService.GetHistoryForDeployedTemplateById(ctx, id, pipelineId) - } else if historyComponent == string(PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { + if historyComponent == string(bean2.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { + history, err = impl.deploymentTemplateHistoryReadService.GetHistoryForDeployedTemplateById(ctx, id, pipelineId) + } else if historyComponent == string(bean2.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { history, err = impl.strategyHistoryService.GetHistoryForDeployedStrategyById(id, pipelineId) - } else if historyComponent == string(CONFIGMAP_TYPE_HISTORY_COMPONENT) { - history, err = impl.configMapHistoryService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository.CONFIGMAP_TYPE, historyComponentName, userHasAdminAccess) - } else if historyComponent == string(SECRET_TYPE_HISTORY_COMPONENT) { - history, err = impl.configMapHistoryService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository.SECRET_TYPE, historyComponentName, userHasAdminAccess) + } else if historyComponent == string(bean2.CONFIGMAP_TYPE_HISTORY_COMPONENT) { + history, err = impl.configMapHistoryReadService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository.CONFIGMAP_TYPE, historyComponentName, userHasAdminAccess) + } else if historyComponent == string(bean2.SECRET_TYPE_HISTORY_COMPONENT) { + history, err = impl.configMapHistoryReadService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository.SECRET_TYPE, historyComponentName, userHasAdminAccess) } else { return nil, errors.New(fmt.Sprintf("history of %s not supported", historyComponent)) } @@ -250,7 +263,7 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponent return history, nil } -func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*AllDeploymentConfigurationDetail, error) { +func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean2.AllDeploymentConfigurationDetail, error) { //getting latest wfr from pipelineId wfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean.CD_WORKFLOW_TYPE_DEPLOY) if err != nil { @@ -265,21 +278,21 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfiguration deployedConfig.WfrId = wfr.Id return deployedConfig, nil } -func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*AllDeploymentConfigurationDetail, error) { +func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*bean2.AllDeploymentConfigurationDetail, error) { //getting history of deployment template for latest deployment - deploymentTemplateHistory, err := impl.deploymentTemplateHistoryService.GetDeployedHistoryByPipelineIdAndWfrId(ctx, pipelineId, wfrId) + deploymentTemplateHistory, err := impl.deploymentTemplateHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(ctx, pipelineId, wfrId) if err != nil && err != pg.ErrNoRows { impl.logger.Errorw("error in getting deployment template history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } //getting history of config map for latest deployment - configMapHistory, err := impl.configMapHistoryService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository.CONFIGMAP_TYPE, userHasAdminAccess) + configMapHistory, err := impl.configMapHistoryReadService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository.CONFIGMAP_TYPE, userHasAdminAccess) if err != nil && err != pg.ErrNoRows { impl.logger.Errorw("error in getting config map history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } //getting history of secret for latest deployment - secretHistory, err := impl.configMapHistoryService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository.SECRET_TYPE, userHasAdminAccess) + secretHistory, err := impl.configMapHistoryReadService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository.SECRET_TYPE, userHasAdminAccess) if err != nil && err != pg.ErrNoRows { impl.logger.Errorw("error in getting secret history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err @@ -290,7 +303,7 @@ func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfiguration impl.logger.Errorw("error in getting strategy history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } - allDeploymentConfigurationHistoryDetail := &AllDeploymentConfigurationDetail{ + allDeploymentConfigurationHistoryDetail := &bean2.AllDeploymentConfigurationDetail{ DeploymentTemplateConfig: deploymentTemplateHistory, ConfigMapConfig: configMapHistory, SecretConfig: secretHistory, diff --git a/pkg/pipeline/history/PipelineStrategyHistoryService.go b/pkg/pipeline/history/PipelineStrategyHistoryService.go index 91378aca5f4..5a6c4809375 100644 --- a/pkg/pipeline/history/PipelineStrategyHistoryService.go +++ b/pkg/pipeline/history/PipelineStrategyHistoryService.go @@ -19,6 +19,7 @@ package history import ( "context" "errors" + "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" "go.opentelemetry.io/otel" "time" @@ -34,13 +35,13 @@ import ( type PipelineStrategyHistoryService interface { CreatePipelineStrategyHistory(pipelineStrategy *chartConfig.PipelineStrategy, pipelineTriggerType pipelineConfig.TriggerType, tx *pg.Tx) (historyModel *repository.PipelineStrategyHistory, err error) CreateStrategyHistoryForDeploymentTrigger(strategy *chartConfig.PipelineStrategy, deployedOn time.Time, deployedBy int32, pipelineTriggerType pipelineConfig.TriggerType) error - GetDeploymentDetailsForDeployedStrategyHistory(pipelineId int) ([]*PipelineStrategyHistoryDto, error) + GetDeploymentDetailsForDeployedStrategyHistory(pipelineId int) ([]*bean.PipelineStrategyHistoryDto, error) - GetHistoryForDeployedStrategyById(id, pipelineId int) (*HistoryDetailDto, error) + GetHistoryForDeployedStrategyById(id, pipelineId int) (*bean.HistoryDetailDto, error) CheckIfHistoryExistsForPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (historyId int, exists bool, err error) CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (exists bool, err error) - GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*DeployedHistoryComponentMetadataDto, error) - GetLatestDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*HistoryDetailDto, error) + GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*bean.DeployedHistoryComponentMetadataDto, error) + GetLatestDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*bean.HistoryDetailDto, error) } type PipelineStrategyHistoryServiceImpl struct { @@ -113,20 +114,20 @@ func (impl PipelineStrategyHistoryServiceImpl) CreateStrategyHistoryForDeploymen return err } -func (impl PipelineStrategyHistoryServiceImpl) GetDeploymentDetailsForDeployedStrategyHistory(pipelineId int) ([]*PipelineStrategyHistoryDto, error) { +func (impl PipelineStrategyHistoryServiceImpl) GetDeploymentDetailsForDeployedStrategyHistory(pipelineId int) ([]*bean.PipelineStrategyHistoryDto, error) { histories, err := impl.pipelineStrategyHistoryRepository.GetDeploymentDetailsForDeployedStrategyHistory(pipelineId) if err != nil { impl.logger.Errorw("error in getting history for strategy", "err", err, "pipelineId", pipelineId) return nil, err } - var historiesDto []*PipelineStrategyHistoryDto + var historiesDto []*bean.PipelineStrategyHistoryDto for _, history := range histories { emailId, err := impl.userService.GetActiveEmailById(history.DeployedBy) if err != nil { impl.logger.Errorw("unable to find user email by id", "err", err, "userId", history.DeployedBy) return nil, err } - historyDto := &PipelineStrategyHistoryDto{ + historyDto := &bean.PipelineStrategyHistoryDto{ Id: history.Id, PipelineId: history.PipelineId, Deployed: history.Deployed, @@ -154,7 +155,7 @@ func (impl PipelineStrategyHistoryServiceImpl) CheckIfHistoryExistsForPipelineId return history.Id, true, nil } -func (impl PipelineStrategyHistoryServiceImpl) GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*DeployedHistoryComponentMetadataDto, error) { +func (impl PipelineStrategyHistoryServiceImpl) GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*bean.DeployedHistoryComponentMetadataDto, error) { impl.logger.Debugw("received request, GetDeployedHistoryList", "pipelineId", pipelineId, "baseConfigId", baseConfigId) //checking if history exists for pipelineId and wfrId @@ -163,9 +164,9 @@ func (impl PipelineStrategyHistoryServiceImpl) GetDeployedHistoryList(pipelineId impl.logger.Errorw("error in getting history list for pipelineId and baseConfigId", "err", err, "pipelineId", pipelineId) return nil, err } - var historyList []*DeployedHistoryComponentMetadataDto + var historyList []*bean.DeployedHistoryComponentMetadataDto for _, history := range histories { - historyList = append(historyList, &DeployedHistoryComponentMetadataDto{ + historyList = append(historyList, &bean.DeployedHistoryComponentMetadataDto{ Id: history.Id, DeployedOn: history.DeployedOn, DeployedBy: history.DeployedByEmailId, @@ -175,15 +176,15 @@ func (impl PipelineStrategyHistoryServiceImpl) GetDeployedHistoryList(pipelineId return historyList, nil } -func (impl PipelineStrategyHistoryServiceImpl) GetHistoryForDeployedStrategyById(id, pipelineId int) (*HistoryDetailDto, error) { +func (impl PipelineStrategyHistoryServiceImpl) GetHistoryForDeployedStrategyById(id, pipelineId int) (*bean.HistoryDetailDto, error) { history, err := impl.pipelineStrategyHistoryRepository.GetHistoryForDeployedStrategyById(id, pipelineId) if err != nil { impl.logger.Errorw("error in getting history for strategy", "err", err, "id", id, "pipelineId", pipelineId) return nil, err } - historyDto := &HistoryDetailDto{ + historyDto := &bean.HistoryDetailDto{ Strategy: string(history.Strategy), - CodeEditorValue: &HistoryDetailConfig{ + CodeEditorValue: &bean.HistoryDetailConfig{ DisplayName: "Strategy configuration", Value: history.Config, }, @@ -194,7 +195,7 @@ func (impl PipelineStrategyHistoryServiceImpl) GetHistoryForDeployedStrategyById return historyDto, nil } -func (impl PipelineStrategyHistoryServiceImpl) GetLatestDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*HistoryDetailDto, error) { +func (impl PipelineStrategyHistoryServiceImpl) GetLatestDeployedHistoryByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int) (*bean.HistoryDetailDto, error) { impl.logger.Debugw("received request, GetLatestDeployedHistoryByPipelineIdAndWfrId", "pipelineId", pipelineId, "wfrId", wfrId) newCtx, span := otel.Tracer("orchestrator").Start(ctx, "PipelineStrategyHistoryServiceImpl.GetLatestDeployedHistoryByPipelineIdAndWfrId") defer span.End() @@ -204,9 +205,9 @@ func (impl PipelineStrategyHistoryServiceImpl) GetLatestDeployedHistoryByPipelin impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) return nil, err } - historyDto := &HistoryDetailDto{ + historyDto := &bean.HistoryDetailDto{ Strategy: string(history.Strategy), - CodeEditorValue: &HistoryDetailConfig{ + CodeEditorValue: &bean.HistoryDetailConfig{ DisplayName: "Strategy configuration", Value: history.Config, }, diff --git a/pkg/pipeline/history/PrePostCdScriptHistoryService.go b/pkg/pipeline/history/PrePostCdScriptHistoryService.go index 2b4e3acdf4a..9ca898a9219 100644 --- a/pkg/pipeline/history/PrePostCdScriptHistoryService.go +++ b/pkg/pipeline/history/PrePostCdScriptHistoryService.go @@ -21,6 +21,8 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/bean" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + bean2 "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" "github.com/go-pg/pg" @@ -30,18 +32,18 @@ import ( type PrePostCdScriptHistoryService interface { CreatePrePostCdScriptHistory(pipeline *pipelineConfig.Pipeline, tx *pg.Tx, stage repository.CdStageType, deployed bool, deployedBy int32, deployedOn time.Time) error - GetHistoryForDeployedPrePostCdScript(pipelineId int, stage repository.CdStageType) ([]*PrePostCdScriptHistoryDto, error) + GetHistoryForDeployedPrePostCdScript(pipelineId int, stage repository.CdStageType) ([]*bean2.PrePostCdScriptHistoryDto, error) } type PrePostCdScriptHistoryServiceImpl struct { logger *zap.SugaredLogger prePostCdScriptHistoryRepository repository.PrePostCdScriptHistoryRepository configMapRepository chartConfig.ConfigMapRepository - configMapHistoryService ConfigMapHistoryService + configMapHistoryService configMapAndSecret.ConfigMapHistoryService } func NewPrePostCdScriptHistoryServiceImpl(logger *zap.SugaredLogger, prePostCdScriptHistoryRepository repository.PrePostCdScriptHistoryRepository, - configMapRepository chartConfig.ConfigMapRepository, configMapHistoryService ConfigMapHistoryService) *PrePostCdScriptHistoryServiceImpl { + configMapRepository chartConfig.ConfigMapRepository, configMapHistoryService configMapAndSecret.ConfigMapHistoryService) *PrePostCdScriptHistoryServiceImpl { return &PrePostCdScriptHistoryServiceImpl{ logger: logger, prePostCdScriptHistoryRepository: prePostCdScriptHistoryRepository, @@ -95,13 +97,13 @@ func (impl PrePostCdScriptHistoryServiceImpl) CreatePrePostCdScriptHistory(pipel return nil } -func (impl PrePostCdScriptHistoryServiceImpl) GetHistoryForDeployedPrePostCdScript(pipelineId int, stage repository.CdStageType) ([]*PrePostCdScriptHistoryDto, error) { +func (impl PrePostCdScriptHistoryServiceImpl) GetHistoryForDeployedPrePostCdScript(pipelineId int, stage repository.CdStageType) ([]*bean2.PrePostCdScriptHistoryDto, error) { histories, err := impl.prePostCdScriptHistoryRepository.GetHistoryForDeployedPrePostScriptByStage(pipelineId, stage) if err != nil { impl.logger.Errorw("error in getting pre/post cd script history", "err", err, "pipelineId", pipelineId) return nil, err } - var historiesDto []*PrePostCdScriptHistoryDto + var historiesDto []*bean2.PrePostCdScriptHistoryDto for _, history := range histories { configMapList := bean.ConfigList{} if len(history.ConfigMapData) > 0 { @@ -119,7 +121,7 @@ func (impl PrePostCdScriptHistoryServiceImpl) GetHistoryForDeployedPrePostCdScri return nil, err } } - var configMapSecretNames PrePostStageConfigMapSecretNames + var configMapSecretNames bean2.PrePostStageConfigMapSecretNames if history.ConfigMapSecretNames != "" { err = json.Unmarshal([]byte(history.ConfigMapSecretNames), &configMapSecretNames) if err != nil { @@ -128,7 +130,7 @@ func (impl PrePostCdScriptHistoryServiceImpl) GetHistoryForDeployedPrePostCdScri } } - historyDto := &PrePostCdScriptHistoryDto{ + historyDto := &bean2.PrePostCdScriptHistoryDto{ Id: history.Id, PipelineId: history.PipelineId, Script: history.Script, @@ -148,7 +150,7 @@ func (impl PrePostCdScriptHistoryServiceImpl) GetHistoryForDeployedPrePostCdScri } func (impl PrePostCdScriptHistoryServiceImpl) GetConfigMapSecretData(pipeline *pipelineConfig.Pipeline, stage repository.CdStageType) (configMapData, secretData string, err error) { - var configMapSecretNames PrePostStageConfigMapSecretNames + var configMapSecretNames bean2.PrePostStageConfigMapSecretNames if stage == repository.PRE_CD_TYPE { if pipeline.PreStageConfigMapSecretNames != "" { err = json.Unmarshal([]byte(pipeline.PreStageConfigMapSecretNames), &configMapSecretNames) diff --git a/pkg/pipeline/history/adaptors/adaptor.go b/pkg/pipeline/history/adaptors/adaptor.go new file mode 100644 index 00000000000..35ed4398c9d --- /dev/null +++ b/pkg/pipeline/history/adaptors/adaptor.go @@ -0,0 +1,23 @@ +package adaptors + +import ( + "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" + "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" +) + +func GetHistoryDetailDto(history *repository.DeploymentTemplateHistory, variableSnapshotMap map[string]string, resolvedTemplate string) *bean.HistoryDetailDto { + if history == nil { + return &bean.HistoryDetailDto{} + } + return &bean.HistoryDetailDto{ + TemplateName: history.TemplateName, + TemplateVersion: history.TemplateVersion, + IsAppMetricsEnabled: &history.IsAppMetricsEnabled, + CodeEditorValue: &bean.HistoryDetailConfig{ + DisplayName: "values.yaml", + Value: history.Template, + VariableSnapshot: variableSnapshotMap, + ResolvedValue: resolvedTemplate, + }, + } +} diff --git a/pkg/pipeline/history/bean.go b/pkg/pipeline/history/bean/bean.go similarity index 99% rename from pkg/pipeline/history/bean.go rename to pkg/pipeline/history/bean/bean.go index 61b6e10a99c..7799216bcfc 100644 --- a/pkg/pipeline/history/bean.go +++ b/pkg/pipeline/history/bean/bean.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package history +package bean import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" diff --git a/pkg/pipeline/history/ciTemplateHistoryService.go b/pkg/pipeline/history/ciTemplateHistoryService.go index 32bf6823fff..568ab8e48ed 100644 --- a/pkg/pipeline/history/ciTemplateHistoryService.go +++ b/pkg/pipeline/history/ciTemplateHistoryService.go @@ -17,8 +17,8 @@ package history import ( + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/adapter" - "github.com/devtron-labs/devtron/pkg/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" "go.uber.org/zap" diff --git a/pkg/pipeline/history/ciTemplateHistoryService_test.go b/pkg/pipeline/history/ciTemplateHistoryService_test.go index 48f1e71d462..207710eabf7 100644 --- a/pkg/pipeline/history/ciTemplateHistoryService_test.go +++ b/pkg/pipeline/history/ciTemplateHistoryService_test.go @@ -19,8 +19,7 @@ package history import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/internal/util" - bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository/mocks" "github.com/devtron-labs/devtron/pkg/sql" @@ -88,11 +87,11 @@ func TestCiTemplateHistoryService(t *testing.T) { CiBuildConfig: nil, }, CiTemplateOverride: nil, - CiBuildConfig: &CiPipeline.CiBuildConfigBean{ + CiBuildConfig: &bean2.CiBuildConfigBean{ Id: 20, GitMaterialId: 22, CiBuildType: "self-dockerfile-build", - DockerBuildConfig: &CiPipeline.DockerBuildConfig{DockerfileContent: ""}, + DockerBuildConfig: &bean2.DockerBuildConfig{DockerfileContent: ""}, BuildPackConfig: nil, }, UserId: 0, diff --git a/pkg/pipeline/history/mocks/ConfigMapHistoryService.go b/pkg/pipeline/history/mocks/ConfigMapHistoryService.go index 1ed6150ba60..5db7eb396be 100644 --- a/pkg/pipeline/history/mocks/ConfigMapHistoryService.go +++ b/pkg/pipeline/history/mocks/ConfigMapHistoryService.go @@ -5,7 +5,7 @@ package mocks import ( chartConfig "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" "github.com/devtron-labs/devtron/pkg/bean" - history "github.com/devtron-labs/devtron/pkg/pipeline/history" + history "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" mock "github.com/stretchr/testify/mock" diff --git a/pkg/pipeline/history/repository/DeploymentTemplateHistoryRepository.go b/pkg/pipeline/history/repository/DeploymentTemplateHistoryRepository.go index bc1ef73c0da..1ce547851c3 100644 --- a/pkg/pipeline/history/repository/DeploymentTemplateHistoryRepository.go +++ b/pkg/pipeline/history/repository/DeploymentTemplateHistoryRepository.go @@ -27,7 +27,6 @@ type DeploymentTemplateHistoryRepository interface { CreateHistory(chart *DeploymentTemplateHistory) (*DeploymentTemplateHistory, error) CreateHistoryWithTxn(chart *DeploymentTemplateHistory, tx *pg.Tx) (*DeploymentTemplateHistory, error) GetHistoryForDeployedTemplateById(id, pipelineId int) (*DeploymentTemplateHistory, error) - GetDeploymentDetailsForDeployedTemplateHistory(pipelineId, offset, limit int) ([]*DeploymentTemplateHistory, error) GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId int) (*DeploymentTemplateHistory, error) GetDeployedHistoryForPipelineIdOnTime(pipelineId int, deployedOn time.Time) (*DeploymentTemplateHistory, error) GetDeployedHistoryList(pipelineId, baseConfigId int) ([]*DeploymentTemplateHistory, error) @@ -92,18 +91,6 @@ func (impl DeploymentTemplateHistoryRepositoryImpl) GetHistoryForDeployedTemplat return &history, nil } -func (impl DeploymentTemplateHistoryRepositoryImpl) GetDeploymentDetailsForDeployedTemplateHistory(pipelineId, offset, limit int) ([]*DeploymentTemplateHistory, error) { - var histories []*DeploymentTemplateHistory - err := impl.dbConnection.Model(&histories).Where("pipeline_id = ?", pipelineId). - Where("deployed = ?", true). - Offset(offset).Limit(limit).Select() - if err != nil { - impl.logger.Errorw("error in getting deployment template history", "err", err) - return histories, err - } - return histories, nil -} - func (impl DeploymentTemplateHistoryRepositoryImpl) GetHistoryByPipelineIdAndWfrId(pipelineId, wfrId int) (*DeploymentTemplateHistory, error) { var history DeploymentTemplateHistory err := impl.dbConnection.Model(&history).Join("INNER JOIN cd_workflow_runner cwr ON cwr.started_on = deployment_template_history.deployed_on"). diff --git a/pkg/pipeline/history/wire_history.go b/pkg/pipeline/history/wire_history.go new file mode 100644 index 00000000000..3374a3cd2e6 --- /dev/null +++ b/pkg/pipeline/history/wire_history.go @@ -0,0 +1,7 @@ +package history + +import ( + "github.com/google/wire" +) + +var AllHistoryWireSet = wire.NewSet() diff --git a/pkg/pipeline/mocks/CiBuildConfigService.go b/pkg/pipeline/mocks/CiBuildConfigService.go index dfc4f017216..57b96cf3a80 100644 --- a/pkg/pipeline/mocks/CiBuildConfigService.go +++ b/pkg/pipeline/mocks/CiBuildConfigService.go @@ -3,7 +3,7 @@ package mocks import ( - bean "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" + "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" mock "github.com/stretchr/testify/mock" ) diff --git a/pkg/pipeline/types/Workflow.go b/pkg/pipeline/types/Workflow.go index 1f9f3704b6b..5a0c8a38c65 100644 --- a/pkg/pipeline/types/Workflow.go +++ b/pkg/pipeline/types/Workflow.go @@ -29,10 +29,10 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" bean2 "github.com/devtron-labs/devtron/pkg/bean" + bean5 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/infraConfig" "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" bean4 "github.com/devtron-labs/devtron/pkg/plugin/bean" "github.com/devtron-labs/devtron/pkg/resourceQualifiers" "k8s.io/api/core/v1" @@ -100,7 +100,7 @@ type WorkflowRequest struct { RefPlugins []*bean.RefPluginObject `json:"refPlugins"` AppName string `json:"appName"` TriggerByAuthor string `json:"triggerByAuthor"` - CiBuildConfig *CiPipeline.CiBuildConfigBean `json:"ciBuildConfig"` + CiBuildConfig *bean5.CiBuildConfigBean `json:"ciBuildConfig"` CiBuildDockerMtuValue int `json:"ciBuildDockerMtuValue"` IgnoreDockerCachePush bool `json:"ignoreDockerCachePush"` IgnoreDockerCachePull bool `json:"ignoreDockerCachePull"` diff --git a/pkg/server/ServerCacheService.go b/pkg/server/ServerCacheService.go index cfcd43bd6c2..b70d18a4b23 100644 --- a/pkg/server/ServerCacheService.go +++ b/pkg/server/ServerCacheService.go @@ -53,6 +53,16 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve return impl, nil } + err := impl.UpdateServerEnvAndDataStore() + if err != nil { + logger.Errorw("error encountered in updating UpdateServerEnvAndDataStore", "error", err) + return nil, err + } + + return impl, nil +} + +func (impl *ServerCacheServiceImpl) UpdateServerEnvAndDataStore() error { // devtron helm release identifier appIdentifier := bean.AppIdentifier{ ClusterId: 1, @@ -63,7 +73,8 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve // check if the release is installed or not isDevtronHelmReleaseInstalled, err := impl.helmAppService.IsReleaseInstalled(context.Background(), &appIdentifier) if err != nil { - logger.Errorw("not able to check if the devtron helm release exists or not.", "error", err) + impl.logger.Errorw("not able to check if the devtron helm release exists or not.", "error", err) + impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease = err // return nil, err // not returning the error as it will bring down orchestrator } @@ -71,25 +82,24 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve // if not installed, treat it as OSS kubectl user // if installed, treat it as OSS helm user and fetch current version if isDevtronHelmReleaseInstalled { - serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssHelm + impl.serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssHelm // fetch current version from helm release releaseInfo, err := impl.helmAppService.GetValuesYaml(context.Background(), &appIdentifier) if err != nil { log.Println("got error in fetching devtron helm release values.", "error", err) - return nil, err + return err } currentVersion := gjson.Get(releaseInfo.GetMergedValues(), impl.serverEnvConfig.DevtronVersionIdentifierInHelmValues).String() if len(currentVersion) == 0 { log.Println("current devtron version found empty") - return nil, err + return err } // store current version in-memory impl.serverDataStore.CurrentVersion = currentVersion } else { - serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssKubectl + impl.serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssKubectl } - - return impl, nil + return nil } diff --git a/pkg/server/ServerService.go b/pkg/server/ServerService.go index ade41755566..12c278d7efc 100644 --- a/pkg/server/ServerService.go +++ b/pkg/server/ServerService.go @@ -44,10 +44,12 @@ type ServerServiceImpl struct { serverEnvConfig *serverEnvConfig.ServerEnvConfig helmAppService client.HelmAppService moduleRepository moduleRepo.ModuleRepository + serverCacheService *ServerCacheServiceImpl } func NewServerServiceImpl(logger *zap.SugaredLogger, serverActionAuditLogRepository ServerActionAuditLogRepository, - serverDataStore *serverDataStore.ServerDataStore, serverEnvConfig *serverEnvConfig.ServerEnvConfig, helmAppService client.HelmAppService, moduleRepository moduleRepo.ModuleRepository) *ServerServiceImpl { + serverDataStore *serverDataStore.ServerDataStore, serverEnvConfig *serverEnvConfig.ServerEnvConfig, helmAppService client.HelmAppService, moduleRepository moduleRepo.ModuleRepository, + serverCacheService *ServerCacheServiceImpl) *ServerServiceImpl { return &ServerServiceImpl{ logger: logger, serverActionAuditLogRepository: serverActionAuditLogRepository, @@ -55,12 +57,27 @@ func NewServerServiceImpl(logger *zap.SugaredLogger, serverActionAuditLogReposit serverEnvConfig: serverEnvConfig, helmAppService: helmAppService, moduleRepository: moduleRepository, + serverCacheService: serverCacheService, } } func (impl ServerServiceImpl) GetServerInfo(showServerStatus bool) (*serverBean.ServerInfoDto, error) { impl.logger.Debug("getting server info") - + if impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease != nil || impl.serverDataStore.CurrentVersion == "" { + // if on initialisation any error have occurred, have captured that error and retry mechanism is done here, possible scenario is migration did not complete but devtron pod came up so values set would not be correct. + impl.logger.Debug("error encountered on getting devtron helm release, now retrying", "err", impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease) + err := impl.serverCacheService.UpdateServerEnvAndDataStore() + if err != nil || impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease != nil { + var errToReturn error + if err != nil { + errToReturn = err + } else { + errToReturn = impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease + } + impl.logger.Errorw("error encountered in GetServerInfo", "err", errToReturn) + return nil, errToReturn + } + } serverInfoDto := &serverBean.ServerInfoDto{ CurrentVersion: impl.serverDataStore.CurrentVersion, ReleaseName: impl.serverEnvConfig.DevtronHelmReleaseName, diff --git a/pkg/server/config/ServerEnvConfig.go b/pkg/server/config/ServerEnvConfig.go index f1339afacb7..4b4b9083654 100644 --- a/pkg/server/config/ServerEnvConfig.go +++ b/pkg/server/config/ServerEnvConfig.go @@ -22,24 +22,25 @@ import ( ) type ServerEnvConfig struct { - DevtronInstallationType string `env:"DEVTRON_INSTALLATION_TYPE"` - InstallerCrdObjectGroupName string `env:"INSTALLER_CRD_OBJECT_GROUP_NAME" envDefault:"installer.devtron.ai"` - InstallerCrdObjectVersion string `env:"INSTALLER_CRD_OBJECT_VERSION" envDefault:"v1alpha1"` - InstallerCrdObjectResource string `env:"INSTALLER_CRD_OBJECT_RESOURCE" envDefault:"installers"` - InstallerCrdNamespace string `env:"INSTALLER_CRD_NAMESPACE" envDefault:"devtroncd"` - DevtronHelmRepoName string `env:"DEVTRON_HELM_REPO_NAME" envDefault:"devtron"` - DevtronHelmRepoUrl string `env:"DEVTRON_HELM_REPO_URL" envDefault:"https://helm.devtron.ai"` - DevtronHelmReleaseName string `env:"DEVTRON_HELM_RELEASE_NAME" envDefault:"devtron"` - DevtronHelmReleaseNamespace string `env:"DEVTRON_HELM_RELEASE_NAMESPACE" envDefault:"devtroncd"` - DevtronHelmReleaseChartName string `env:"DEVTRON_HELM_RELEASE_CHART_NAME" envDefault:"devtron-operator"` - DevtronVersionIdentifierInHelmValues string `env:"DEVTRON_VERSION_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.release"` - DevtronModulesIdentifierInHelmValues string `env:"DEVTRON_MODULES_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.modules"` - DevtronBomUrl string `env:"DEVTRON_BOM_URL" envDefault:"https://raw.githubusercontent.com/devtron-labs/devtron/%s/charts/devtron/devtron-bom.yaml"` - AppSyncImage string `env:"APP_SYNC_IMAGE" envDefault:"quay.io/devtron/chart-sync:1227622d-132-3775"` - AppSyncServiceAccount string `env:"APP_SYNC_SERVICE_ACCOUNT" envDefault:"chart-sync"` - AppSyncJobResourcesObj string `env:"APP_SYNC_JOB_RESOURCES_OBJ"` - ModuleMetaDataApiUrl string `env:"MODULE_METADATA_API_URL" envDefault:"https://api.devtron.ai/module?name=%s"` - ParallelismLimitForTagProcessing int `env:"PARALLELISM_LIMIT_FOR_TAG_PROCESSING"` + DevtronInstallationType string `env:"DEVTRON_INSTALLATION_TYPE"` + InstallerCrdObjectGroupName string `env:"INSTALLER_CRD_OBJECT_GROUP_NAME" envDefault:"installer.devtron.ai"` + InstallerCrdObjectVersion string `env:"INSTALLER_CRD_OBJECT_VERSION" envDefault:"v1alpha1"` + InstallerCrdObjectResource string `env:"INSTALLER_CRD_OBJECT_RESOURCE" envDefault:"installers"` + InstallerCrdNamespace string `env:"INSTALLER_CRD_NAMESPACE" envDefault:"devtroncd"` + DevtronHelmRepoName string `env:"DEVTRON_HELM_REPO_NAME" envDefault:"devtron"` + DevtronHelmRepoUrl string `env:"DEVTRON_HELM_REPO_URL" envDefault:"https://helm.devtron.ai"` + DevtronHelmReleaseName string `env:"DEVTRON_HELM_RELEASE_NAME" envDefault:"devtron"` + DevtronHelmReleaseNamespace string `env:"DEVTRON_HELM_RELEASE_NAMESPACE" envDefault:"devtroncd"` + DevtronHelmReleaseChartName string `env:"DEVTRON_HELM_RELEASE_CHART_NAME" envDefault:"devtron-operator"` + DevtronVersionIdentifierInHelmValues string `env:"DEVTRON_VERSION_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.release"` + DevtronModulesIdentifierInHelmValues string `env:"DEVTRON_MODULES_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.modules"` + DevtronBomUrl string `env:"DEVTRON_BOM_URL" envDefault:"https://raw.githubusercontent.com/devtron-labs/devtron/%s/charts/devtron/devtron-bom.yaml"` + AppSyncImage string `env:"APP_SYNC_IMAGE" envDefault:"quay.io/devtron/chart-sync:1227622d-132-3775"` + AppSyncServiceAccount string `env:"APP_SYNC_SERVICE_ACCOUNT" envDefault:"chart-sync"` + AppSyncJobResourcesObj string `env:"APP_SYNC_JOB_RESOURCES_OBJ"` + ModuleMetaDataApiUrl string `env:"MODULE_METADATA_API_URL" envDefault:"https://api.devtron.ai/module?name=%s"` + ParallelismLimitForTagProcessing int `env:"PARALLELISM_LIMIT_FOR_TAG_PROCESSING"` + ErrorEncounteredOnGettingDevtronHelmRelease error } func ParseServerEnvConfig() (*ServerEnvConfig, error) { diff --git a/pkg/workflow/dag/WorkflowDagExecutor.go b/pkg/workflow/dag/WorkflowDagExecutor.go index 849c5d9e1b3..3f973e26f0f 100644 --- a/pkg/workflow/dag/WorkflowDagExecutor.go +++ b/pkg/workflow/dag/WorkflowDagExecutor.go @@ -34,6 +34,7 @@ import ( cdWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" "github.com/devtron-labs/devtron/pkg/app/status" "github.com/devtron-labs/devtron/pkg/build/artifacts" + bean5 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean" common2 "github.com/devtron-labs/devtron/pkg/deployment/common" "github.com/devtron-labs/devtron/pkg/deployment/manifest" "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps" @@ -42,7 +43,6 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/userDeploymentRequest/service" eventProcessorBean "github.com/devtron-labs/devtron/pkg/eventProcessor/bean" "github.com/devtron-labs/devtron/pkg/pipeline" - "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" "github.com/devtron-labs/devtron/pkg/pipeline/executors" repository2 "github.com/devtron-labs/devtron/pkg/plugin/repository" "github.com/devtron-labs/devtron/pkg/sql" @@ -769,7 +769,7 @@ func (impl *WorkflowDagExecutorImpl) HandleCiSuccessEvent(triggerContext trigger var pluginArtifacts []*repository.CiArtifact for registry, artifacts := range request.PluginRegistryArtifactDetails { for _, image := range artifacts { - if pipelineModal.PipelineType == string(CiPipeline.CI_JOB) && image == "" { + if pipelineModal.PipelineType == string(bean5.CI_JOB) && image == "" { continue } pluginArtifact := &repository.CiArtifact{ diff --git a/scripts/sql/29902300_mandatory_plugin_v2.down.sql b/scripts/sql/29902300_mandatory_plugin_v2.down.sql new file mode 100644 index 00000000000..ea9b85910d6 --- /dev/null +++ b/scripts/sql/29902300_mandatory_plugin_v2.down.sql @@ -0,0 +1,55 @@ +BEGIN; +--- +--- Drop all the resource qualifier mappings related to plugin policy version 2. +--- +DELETE FROM resource_qualifier_mapping + WHERE resource_type = 9 + AND resource_id IN ( + SELECT id + FROM resource_qualifier_mapping_criteria + WHERE policy_type = 'plugin' + AND version = 'v1' + ) +; + +--- +--- Drop all the criteria mappings related to plugin policy version 2. +--- +DELETE FROM resource_qualifier_mapping_criteria + WHERE policy_type = 'plugin' + AND version = 'v1'; + +--- +--- Drop the global policy history related to plugin policy version 2. +--- +DELETE FROM global_policy_history + WHERE global_policy_id IN ( + SELECT id + FROM global_policy + WHERE policy_of = 'PLUGIN' + AND version = 'V2' + ) +; + +--- +--- Drop the global policy related to plugin policy version 2. +--- +DELETE FROM global_policy + WHERE policy_of = 'PLUGIN' + AND version = 'V2'; + +--- +--- Drop the columns policy_type and version from the resource_qualifier_mapping_criteria table. +--- +ALTER TABLE "public"."resource_qualifier_mapping_criteria" + DROP COLUMN IF EXISTS policy_type, + DROP COLUMN IF EXISTS version; + +--- +--- Drop the searchable key for CI_PIPELINE_BRANCH_REGEX +--- +DELETE FROM devtron_resource_searchable_key + WHERE name IN ('CI_PIPELINE_BRANCH_REGEX') + AND is_removed = false; + +END; \ No newline at end of file diff --git a/scripts/sql/29902300_mandatory_plugin_v2.up.sql b/scripts/sql/29902300_mandatory_plugin_v2.up.sql new file mode 100644 index 00000000000..64fb34c6cb8 --- /dev/null +++ b/scripts/sql/29902300_mandatory_plugin_v2.up.sql @@ -0,0 +1,26 @@ +BEGIN; +--- +--- add policy_type and version columns to resource_qualifier_mapping_criteria table +--- +ALTER TABLE "public"."resource_qualifier_mapping_criteria" + ADD COLUMN IF NOT EXISTS policy_type varchar(50) NOT NULL DEFAULT 'lock-configuration', + ADD COLUMN IF NOT EXISTS version varchar(50) NOT NULL DEFAULT 'v1'; + +--- +--- drop default constraint for policy_type column, as it is not necessary +--- +ALTER TABLE "public"."resource_qualifier_mapping_criteria" + ALTER COLUMN policy_type DROP DEFAULT; + +--- +--- add searchable key for CI_PIPELINE_BRANCH_REGEX +--- +INSERT INTO devtron_resource_searchable_key(name, is_removed, created_on, created_by, updated_on, updated_by) +SELECT 'CI_PIPELINE_BRANCH_REGEX', false, now(), 1, now(), 1 + WHERE NOT EXISTS ( + SELECT 1 + FROM devtron_resource_searchable_key + WHERE name='CI_PIPELINE_BRANCH_REGEX' + AND is_removed = false) +; +END; \ No newline at end of file diff --git a/scripts/sql/30002300_appoval_email_template_subject_update.down.sql b/scripts/sql/30002300_appoval_email_template_subject_update.down.sql new file mode 100644 index 00000000000..c57d153d1d1 --- /dev/null +++ b/scripts/sql/30002300_appoval_email_template_subject_update.down.sql @@ -0,0 +1,15 @@ +---- update notification template for CD approval smtp/ses +UPDATE "public"."notification_templates" +SET template_payload = '{"from": "{{fromEmail}}", "to": "{{toEmail}}","subject": "🛎️ Image approval requested | Application > {{appName}} | Environment > {{envName}}","html": "
\"ci-triggered\"
Image approval request
{{eventTime}}
by{{triggeredBy}}
{{#imageApprovalLink}}View request{{/imageApprovalLink}}

Application
Environment
{{appName}}
{{envName}}
Image Details
Image tag
{{imageTag}}

Comment
{{comment}}

Tags
{{tags}}
BlogWebsite
© Devtron Labs 2024
"}' +WHERE event_type_id=4; + +---- update notification template for config approval smtp/ses +UPDATE "public"."notification_templates" +SET template_payload = '{"from": "{{fromEmail}}", "to": "{{toEmail}}","subject": "🛎️ Config Change approval requested | Application > {{appName}} | Change Impacts > {{envName}}","html": "
\"ci-triggered\"
Config Change approval request
{{eventTime}}
by{{triggeredBy}}
{{#approvalLink}}Approve{{/approvalLink}}
{{#protectConfigLink}}View request{{/protectConfigLink}}

Application
Change Impacts
{{appName}}
{{envName}}
File Details
File Type
File Name
{{protectConfigFileType}}
{{protectConfigFileName}}

Comment
{{protectConfigComment}}
BlogWebsite
© Devtron Labs 2024
"}' +WHERE event_type_id = 5; + +---- update notification template for config approval smtp/ses auto-deployment +UPDATE "public"."notification_templates" +SET template_payload = '{"from": "{{fromEmail}}", "to": "{{toEmail}}","subject": "🚫 Auto-deployment blocked:| Application: {{appName}} | Environment: {{envName}}","html":"{{#ciMaterials}} {{^webhookType}}{{/webhookType}} {{/ciMaterials}}
ci-triggered
🚫 Auto-deployment blocked
{{eventTime}}
by{{triggeredBy}}
{{#deploymentHistoryLink}}View Pipeline{{/deploymentHistoryLink}}
{{#appDetailsLink}}App Details{{/appDetailsLink}}

{{deploymentWindowComment}}
Application
Environment
{{appName}}
{{envName}}
Stage
{{stage}}
Source Code
Branch
Commit
{{appName}}/{{branch}}
{{commit}}
Image Details
Image tag
{{dockerImg}}

BlogWebsite
© Devtron Labs 2024
"}'; +WHERE event_type_id = 6; +and node_type = 'CD'; diff --git a/scripts/sql/30002300_appoval_email_template_subject_update.up.sql b/scripts/sql/30002300_appoval_email_template_subject_update.up.sql new file mode 100644 index 00000000000..e9124606e1b --- /dev/null +++ b/scripts/sql/30002300_appoval_email_template_subject_update.up.sql @@ -0,0 +1,18 @@ + +---- update notification template for CD approval ses/smtp +UPDATE notification_templates +SET template_payload = '{"from": "{{fromEmail}}", "to": "{{toEmail}}","subject": "🛎️ Image approval requested | Application: {{appName}} | Environment: {{envName}} at {{eventTime}}","html": "
\"ci-triggered\"
Image approval request
{{eventTime}}
by{{triggeredBy}}
{{#imageApprovalLink}}View request{{/imageApprovalLink}}

Application
Environment
{{appName}}
{{envName}}
Image Details
Image tag
{{imageTag}}

Comment
{{comment}}

Tags
{{tags}}
BlogWebsite
© Devtron Labs 2024
"}' +WHERE node_type = 'CD' +AND event_type_id = 4; + +---- update notification template for Config approval ses/smtp +UPDATE notification_templates +SET template_payload = '{"from": "{{fromEmail}}", "to": "{{toEmail}}","subject": "🛎️ Config Change approval requested | Application: {{appName}} | Change Impacts: {{envName}} at {{eventTime}}","html": "
\"ci-triggered\"
Config Change approval request
{{eventTime}}
by{{triggeredBy}}
{{#approvalLink}}Approve{{/approvalLink}}
{{#protectConfigLink}}View request{{/protectConfigLink}}

Application
Change Impacts
{{appName}}
{{envName}}
File Details
File Type
File Name
{{protectConfigFileType}}
{{protectConfigFileName}}

Comment
{{protectConfigComment}}
BlogWebsite
© Devtron Labs 2024
"}' +WHERE node_type = 'CD' +AND event_type_id = 5; + +---- update notification template for Config approval ses/smtp auto +UPDATE notification_templates +SET template_payload = '{"from": "{{fromEmail}}", "to": "{{toEmail}}","subject": "🚫 Auto-deployment blocked:| Application: {{appName}} | Environment: {{envName}} at {{eventTime}}","html":"{{#ciMaterials}} {{^webhookType}}{{/webhookType}} {{/ciMaterials}}
ci-triggered
🚫 Auto-deployment blocked
{{eventTime}}
by{{triggeredBy}}
{{#deploymentHistoryLink}}View Pipeline{{/deploymentHistoryLink}}
{{#appDetailsLink}}App Details{{/appDetailsLink}}

{{deploymentWindowComment}}
Application
Environment
{{appName}}
{{envName}}
Stage
{{stage}}
Source Code
Branch
Commit
{{appName}}/{{branch}}
{{commit}}
Image Details
Image tag
{{dockerImg}}

BlogWebsite
© Devtron Labs 2024
"}' +WHERE node_type = 'CD' +AND event_type_id = 6; diff --git a/scripts/sql/30102300_alter_cluster_table_.down.sql b/scripts/sql/30102300_alter_cluster_table_.down.sql new file mode 100644 index 00000000000..94d941dbc22 --- /dev/null +++ b/scripts/sql/30102300_alter_cluster_table_.down.sql @@ -0,0 +1,2 @@ +-- 29902101_add_is_prod_column_to_cluster_table.down.sql +ALTER TABLE cluster DROP COLUMN IF EXISTS is_prod; \ No newline at end of file diff --git a/scripts/sql/30102300_alter_cluster_table_.up.sql b/scripts/sql/30102300_alter_cluster_table_.up.sql new file mode 100644 index 00000000000..40d20a44133 --- /dev/null +++ b/scripts/sql/30102300_alter_cluster_table_.up.sql @@ -0,0 +1 @@ +ALTER TABLE cluster ADD COLUMN IF NOT EXISTS is_prod BOOLEAN DEFAULT FALSE; \ No newline at end of file diff --git a/scripts/sql/30202300_cluster_panel_.down.sql b/scripts/sql/30202300_cluster_panel_.down.sql new file mode 100644 index 00000000000..7f5bd98a7cf --- /dev/null +++ b/scripts/sql/30202300_cluster_panel_.down.sql @@ -0,0 +1,7 @@ +-- File: scripts/sql/30202300_cluster_panel_.down.sql + +-- Drop Table +DROP TABLE IF EXISTS "public"."panel"; + +-- Drop Sequence +DROP SEQUENCE IF EXISTS id_seq_panel; \ No newline at end of file diff --git a/scripts/sql/30202300_cluster_panel_.up.sql b/scripts/sql/30202300_cluster_panel_.up.sql new file mode 100644 index 00000000000..41d584734e0 --- /dev/null +++ b/scripts/sql/30202300_cluster_panel_.up.sql @@ -0,0 +1,18 @@ +-- File: scripts/sql/30202300_cluster_panel_.up.sql + +-- Sequence and defined type +CREATE SEQUENCE IF NOT EXISTS id_seq_panel; + +-- Table Definition +CREATE TABLE "public"."panel" ( + "id" int4 NOT NULL DEFAULT nextval('id_seq_panel'::regclass), + "name" varchar(250) NOT NULL, + "cluster_id" int4 NOT NULL, + "active" bool NOT NULL, + "embed_iframe" text, + "created_on" timestamptz, + "created_by" integer, + "updated_on" timestamptz, + "updated_by" integer, + PRIMARY KEY ("id") +); \ No newline at end of file diff --git a/vendor/github.com/golang-jwt/jwt/v4/parser.go b/vendor/github.com/golang-jwt/jwt/v4/parser.go index c0a6f692791..9dd36e5a5ac 100644 --- a/vendor/github.com/golang-jwt/jwt/v4/parser.go +++ b/vendor/github.com/golang-jwt/jwt/v4/parser.go @@ -36,19 +36,21 @@ func NewParser(options ...ParserOption) *Parser { return p } -// Parse parses, validates, verifies the signature and returns the parsed token. -// keyFunc will receive the parsed token and should return the key for validating. +// Parse parses, validates, verifies the signature and returns the parsed token. keyFunc will +// receive the parsed token and should return the key for validating. func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc) } -// ParseWithClaims parses, validates, and verifies like Parse, but supplies a default object implementing the Claims -// interface. This provides default values which can be overridden and allows a caller to use their own type, rather -// than the default MapClaims implementation of Claims. +// ParseWithClaims parses, validates, and verifies like Parse, but supplies a default object +// implementing the Claims interface. This provides default values which can be overridden and +// allows a caller to use their own type, rather than the default MapClaims implementation of +// Claims. // -// Note: If you provide a custom claim implementation that embeds one of the standard claims (such as RegisteredClaims), -// make sure that a) you either embed a non-pointer version of the claims or b) if you are using a pointer, allocate the -// proper memory for it before passing in the overall claims, otherwise you might run into a panic. +// Note: If you provide a custom claim implementation that embeds one of the standard claims (such +// as RegisteredClaims), make sure that a) you either embed a non-pointer version of the claims or +// b) if you are using a pointer, allocate the proper memory for it before passing in the overall +// claims, otherwise you might run into a panic. func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { token, parts, err := p.ParseUnverified(tokenString, claims) if err != nil { @@ -85,12 +87,17 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable} } + // Perform validation + token.Signature = parts[2] + if err := token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { + return token, &ValidationError{Inner: err, Errors: ValidationErrorSignatureInvalid} + } + vErr := &ValidationError{} // Validate Claims if !p.SkipClaimsValidation { if err := token.Claims.Valid(); err != nil { - // If the Claims Valid returned an error, check if it is a validation error, // If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set if e, ok := err.(*ValidationError); !ok { @@ -98,22 +105,14 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf } else { vErr = e } + return token, vErr } } - // Perform validation - token.Signature = parts[2] - if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { - vErr.Inner = err - vErr.Errors |= ValidationErrorSignatureInvalid - } - - if vErr.valid() { - token.Valid = true - return token, nil - } + // No errors so far, token is valid. + token.Valid = true - return token, vErr + return token, nil } // ParseUnverified parses the token but doesn't validate the signature. diff --git a/vendor/modules.txt b/vendor/modules.txt index ba2dc057ac1..f68c2455cb2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -344,7 +344,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136 +# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241114074942-28eb96763c64 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage @@ -556,7 +556,7 @@ github.com/gogo/protobuf/jsonpb github.com/gogo/protobuf/proto github.com/gogo/protobuf/sortkeys github.com/gogo/protobuf/types -# github.com/golang-jwt/jwt/v4 v4.5.0 +# github.com/golang-jwt/jwt/v4 v4.5.1 ## explicit; go 1.16 github.com/golang-jwt/jwt/v4 # github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da @@ -1949,7 +1949,7 @@ k8s.io/kubectl/pkg/util/storage k8s.io/kubectl/pkg/util/templates k8s.io/kubectl/pkg/util/term k8s.io/kubectl/pkg/validation -# k8s.io/kubernetes v1.29.6 +# k8s.io/kubernetes v1.29.10 ## explicit; go 1.21 k8s.io/kubernetes/pkg/api/legacyscheme k8s.io/kubernetes/pkg/api/v1/service @@ -2212,7 +2212,7 @@ xorm.io/xorm/log xorm.io/xorm/names xorm.io/xorm/schemas xorm.io/xorm/tags -# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136 +# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241114074942-28eb96763c64 # github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 # github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 # k8s.io/api => k8s.io/api v0.29.7 diff --git a/wire_gen.go b/wire_gen.go index 0602deef879..859c6e53dc4 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -42,7 +42,7 @@ import ( "github.com/devtron-labs/devtron/api/restHandler" "github.com/devtron-labs/devtron/api/restHandler/app/appInfo" "github.com/devtron-labs/devtron/api/restHandler/app/appList" - pipeline2 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline" + pipeline3 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline" "github.com/devtron-labs/devtron/api/restHandler/app/pipeline/configure" history2 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline/history" status3 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline/status" @@ -54,7 +54,7 @@ import ( app3 "github.com/devtron-labs/devtron/api/router/app" appInfo2 "github.com/devtron-labs/devtron/api/router/app/appInfo" appList2 "github.com/devtron-labs/devtron/api/router/app/appList" - pipeline3 "github.com/devtron-labs/devtron/api/router/app/pipeline" + pipeline4 "github.com/devtron-labs/devtron/api/router/app/pipeline" configure2 "github.com/devtron-labs/devtron/api/router/app/pipeline/configure" history3 "github.com/devtron-labs/devtron/api/router/app/pipeline/history" status4 "github.com/devtron-labs/devtron/api/router/app/pipeline/status" @@ -131,6 +131,7 @@ import ( "github.com/devtron-labs/devtron/pkg/auth/user" repository4 "github.com/devtron-labs/devtron/pkg/auth/user/repository" "github.com/devtron-labs/devtron/pkg/build/artifacts" + pipeline2 "github.com/devtron-labs/devtron/pkg/build/pipeline" "github.com/devtron-labs/devtron/pkg/bulkAction" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" @@ -148,10 +149,13 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/validation" "github.com/devtron-labs/devtron/pkg/deployment/manifest" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + read4 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" repository9 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics/repository" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" + read3 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/publish" "github.com/devtron-labs/devtron/pkg/deployment/providerConfig" "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps" @@ -542,10 +546,8 @@ func InitializeApp() (*App, error) { } globalPluginServiceImpl := plugin.NewGlobalPluginService(sugaredLogger, globalPluginRepositoryImpl, pipelineStageRepositoryImpl, userServiceImpl) pipelineStageServiceImpl := pipeline.NewPipelineStageService(sugaredLogger, pipelineStageRepositoryImpl, globalPluginRepositoryImpl, pipelineRepositoryImpl, scopedVariableManagerImpl, globalPluginServiceImpl) - ciBuildConfigRepositoryImpl := pipelineConfig.NewCiBuildConfigRepositoryImpl(db, sugaredLogger) - ciBuildConfigServiceImpl := pipeline.NewCiBuildConfigServiceImpl(sugaredLogger, ciBuildConfigRepositoryImpl) ciTemplateRepositoryImpl := pipelineConfig.NewCiTemplateRepositoryImpl(db, sugaredLogger) - ciTemplateServiceImpl := pipeline.NewCiTemplateServiceImpl(sugaredLogger, ciBuildConfigServiceImpl, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) + ciTemplateReadServiceImpl := pipeline2.NewCiTemplateReadServiceImpl(sugaredLogger, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) appLabelRepositoryImpl := pipelineConfig.NewAppLabelRepositoryImpl(db) materialRepositoryImpl := pipelineConfig.NewMaterialRepositoryImpl(db) installedAppDBServiceImpl := EAMode.NewInstalledAppDBServiceImpl(sugaredLogger, installedAppRepositoryImpl, appRepositoryImpl, userServiceImpl, environmentServiceImpl, installedAppVersionHistoryRepositoryImpl, deploymentConfigServiceImpl) @@ -567,19 +569,22 @@ func InitializeApp() (*App, error) { } prePostCdScriptHistoryRepositoryImpl := repository12.NewPrePostCdScriptHistoryRepositoryImpl(sugaredLogger, db) configMapHistoryRepositoryImpl := repository12.NewConfigMapHistoryRepositoryImpl(sugaredLogger, db, transactionUtilImpl) - configMapHistoryServiceImpl := history.NewConfigMapHistoryServiceImpl(sugaredLogger, configMapHistoryRepositoryImpl, pipelineRepositoryImpl, configMapRepositoryImpl, userServiceImpl, scopedVariableCMCSManagerImpl) + configMapHistoryServiceImpl := configMapAndSecret.NewConfigMapHistoryServiceImpl(sugaredLogger, configMapHistoryRepositoryImpl, pipelineRepositoryImpl, configMapRepositoryImpl, userServiceImpl, scopedVariableCMCSManagerImpl) prePostCdScriptHistoryServiceImpl := history.NewPrePostCdScriptHistoryServiceImpl(sugaredLogger, prePostCdScriptHistoryRepositoryImpl, configMapRepositoryImpl, configMapHistoryServiceImpl) gitMaterialHistoryRepositoryImpl := repository12.NewGitMaterialHistoryRepositoyImpl(db) gitMaterialHistoryServiceImpl := history.NewGitMaterialHistoryServiceImpl(gitMaterialHistoryRepositoryImpl, sugaredLogger) ciPipelineHistoryRepositoryImpl := repository12.NewCiPipelineHistoryRepositoryImpl(db, sugaredLogger) ciPipelineHistoryServiceImpl := history.NewCiPipelineHistoryServiceImpl(ciPipelineHistoryRepositoryImpl, sugaredLogger, ciPipelineRepositoryImpl) + ciBuildConfigRepositoryImpl := pipelineConfig.NewCiBuildConfigRepositoryImpl(db, sugaredLogger) + ciBuildConfigServiceImpl := pipeline.NewCiBuildConfigServiceImpl(sugaredLogger, ciBuildConfigRepositoryImpl) + ciTemplateServiceImpl := pipeline.NewCiTemplateServiceImpl(sugaredLogger, ciBuildConfigServiceImpl, ciTemplateRepositoryImpl, ciTemplateOverrideRepositoryImpl) pipelineConfigRepositoryImpl := chartConfig.NewPipelineConfigRepository(db) configMapServiceImpl := pipeline.NewConfigMapServiceImpl(chartRepositoryImpl, sugaredLogger, chartRepoRepositoryImpl, utilMergeUtil, pipelineConfigRepositoryImpl, configMapRepositoryImpl, envConfigOverrideRepositoryImpl, commonServiceImpl, appRepositoryImpl, configMapHistoryServiceImpl, environmentRepositoryImpl, scopedVariableCMCSManagerImpl) deploymentTemplateHistoryRepositoryImpl := repository12.NewDeploymentTemplateHistoryRepositoryImpl(sugaredLogger, db) - deploymentTemplateHistoryServiceImpl := history.NewDeploymentTemplateHistoryServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, pipelineRepositoryImpl, chartRepositoryImpl, userServiceImpl, cdWorkflowRepositoryImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl) + deploymentTemplateHistoryServiceImpl := deploymentTemplate.NewDeploymentTemplateHistoryServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, pipelineRepositoryImpl, chartRepositoryImpl, userServiceImpl, cdWorkflowRepositoryImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl) chartServiceImpl := chart.NewChartServiceImpl(chartRepositoryImpl, sugaredLogger, chartTemplateServiceImpl, chartRepoRepositoryImpl, appRepositoryImpl, utilMergeUtil, envConfigOverrideRepositoryImpl, pipelineConfigRepositoryImpl, environmentRepositoryImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, gitOpsConfigReadServiceImpl, deploymentConfigServiceImpl) - ciCdPipelineOrchestratorImpl := pipeline.NewCiCdPipelineOrchestrator(appRepositoryImpl, sugaredLogger, materialRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, cdWorkflowRepositoryImpl, clientImpl, ciCdConfig, appWorkflowRepositoryImpl, environmentRepositoryImpl, attributesServiceImpl, appCrudOperationServiceImpl, userAuthServiceImpl, prePostCdScriptHistoryServiceImpl, pipelineStageServiceImpl, gitMaterialHistoryServiceImpl, ciPipelineHistoryServiceImpl, ciTemplateServiceImpl, dockerArtifactStoreRepositoryImpl, ciArtifactRepositoryImpl, configMapServiceImpl, customTagServiceImpl, genericNoteServiceImpl, chartServiceImpl, transactionUtilImpl, gitOpsConfigReadServiceImpl, deploymentConfigServiceImpl) - ciServiceImpl := pipeline.NewCiServiceImpl(sugaredLogger, workflowServiceImpl, ciPipelineMaterialRepositoryImpl, ciWorkflowRepositoryImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineStageServiceImpl, userServiceImpl, ciTemplateServiceImpl, appCrudOperationServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, customTagServiceImpl, pluginInputVariableParserImpl, globalPluginServiceImpl, infraProviderImpl, ciCdPipelineOrchestratorImpl, attributesServiceImpl) + ciCdPipelineOrchestratorImpl := pipeline.NewCiCdPipelineOrchestrator(appRepositoryImpl, sugaredLogger, materialRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, cdWorkflowRepositoryImpl, clientImpl, ciCdConfig, appWorkflowRepositoryImpl, environmentRepositoryImpl, attributesServiceImpl, appCrudOperationServiceImpl, userAuthServiceImpl, prePostCdScriptHistoryServiceImpl, pipelineStageServiceImpl, gitMaterialHistoryServiceImpl, ciPipelineHistoryServiceImpl, ciTemplateReadServiceImpl, ciTemplateServiceImpl, dockerArtifactStoreRepositoryImpl, ciArtifactRepositoryImpl, configMapServiceImpl, customTagServiceImpl, genericNoteServiceImpl, chartServiceImpl, transactionUtilImpl, gitOpsConfigReadServiceImpl, deploymentConfigServiceImpl) + ciServiceImpl := pipeline.NewCiServiceImpl(sugaredLogger, workflowServiceImpl, ciPipelineMaterialRepositoryImpl, ciWorkflowRepositoryImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineStageServiceImpl, userServiceImpl, ciTemplateReadServiceImpl, appCrudOperationServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, customTagServiceImpl, pluginInputVariableParserImpl, globalPluginServiceImpl, infraProviderImpl, ciCdPipelineOrchestratorImpl, attributesServiceImpl) ciLogServiceImpl, err := pipeline.NewCiLogServiceImpl(sugaredLogger, ciServiceImpl, k8sServiceImpl) if err != nil { return nil, err @@ -601,8 +606,8 @@ func InitializeApp() (*App, error) { ciTemplateHistoryRepositoryImpl := repository12.NewCiTemplateHistoryRepositoryImpl(db, sugaredLogger) ciTemplateHistoryServiceImpl := history.NewCiTemplateHistoryServiceImpl(ciTemplateHistoryRepositoryImpl, sugaredLogger) buildPipelineSwitchServiceImpl := pipeline.NewBuildPipelineSwitchServiceImpl(sugaredLogger, ciPipelineRepositoryImpl, ciCdPipelineOrchestratorImpl, pipelineRepositoryImpl, ciWorkflowRepositoryImpl, appWorkflowRepositoryImpl, ciPipelineHistoryServiceImpl, ciTemplateOverrideRepositoryImpl, ciPipelineMaterialRepositoryImpl) - ciPipelineConfigServiceImpl := pipeline.NewCiPipelineConfigServiceImpl(sugaredLogger, ciCdPipelineOrchestratorImpl, dockerArtifactStoreRepositoryImpl, materialRepositoryImpl, appRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ecrConfig, appWorkflowRepositoryImpl, ciCdConfig, attributesServiceImpl, pipelineStageServiceImpl, ciPipelineMaterialRepositoryImpl, ciTemplateServiceImpl, ciTemplateOverrideRepositoryImpl, ciTemplateHistoryServiceImpl, enforcerUtilImpl, ciWorkflowRepositoryImpl, resourceGroupServiceImpl, customTagServiceImpl, cdWorkflowRepositoryImpl, buildPipelineSwitchServiceImpl, pipelineStageRepositoryImpl, globalPluginRepositoryImpl) - ciMaterialConfigServiceImpl := pipeline.NewCiMaterialConfigServiceImpl(sugaredLogger, materialRepositoryImpl, ciTemplateServiceImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, gitMaterialHistoryServiceImpl, pipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, transactionUtilImpl) + ciPipelineConfigServiceImpl := pipeline.NewCiPipelineConfigServiceImpl(sugaredLogger, ciCdPipelineOrchestratorImpl, dockerArtifactStoreRepositoryImpl, materialRepositoryImpl, appRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ecrConfig, appWorkflowRepositoryImpl, ciCdConfig, attributesServiceImpl, pipelineStageServiceImpl, ciPipelineMaterialRepositoryImpl, ciTemplateServiceImpl, ciTemplateReadServiceImpl, ciTemplateOverrideRepositoryImpl, ciTemplateHistoryServiceImpl, enforcerUtilImpl, ciWorkflowRepositoryImpl, resourceGroupServiceImpl, customTagServiceImpl, cdWorkflowRepositoryImpl, buildPipelineSwitchServiceImpl, pipelineStageRepositoryImpl, globalPluginRepositoryImpl) + ciMaterialConfigServiceImpl := pipeline.NewCiMaterialConfigServiceImpl(sugaredLogger, materialRepositoryImpl, ciTemplateReadServiceImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, gitMaterialHistoryServiceImpl, pipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, transactionUtilImpl) deploymentGroupRepositoryImpl := repository2.NewDeploymentGroupRepositoryImpl(sugaredLogger, db) pipelineStrategyHistoryRepositoryImpl := repository12.NewPipelineStrategyHistoryRepositoryImpl(sugaredLogger, db) pipelineStrategyHistoryServiceImpl := history.NewPipelineStrategyHistoryServiceImpl(sugaredLogger, pipelineStrategyHistoryRepositoryImpl, userServiceImpl) @@ -614,7 +619,7 @@ func InitializeApp() (*App, error) { pipelineConfigEventPublishServiceImpl := out.NewPipelineConfigEventPublishServiceImpl(sugaredLogger, pubSubClientServiceImpl) deploymentTypeOverrideServiceImpl := providerConfig.NewDeploymentTypeOverrideServiceImpl(sugaredLogger, environmentVariables, attributesServiceImpl) cdPipelineConfigServiceImpl := pipeline.NewCdPipelineConfigServiceImpl(sugaredLogger, pipelineRepositoryImpl, environmentRepositoryImpl, pipelineConfigRepositoryImpl, appWorkflowRepositoryImpl, pipelineStageServiceImpl, appRepositoryImpl, appServiceImpl, deploymentGroupRepositoryImpl, ciCdPipelineOrchestratorImpl, appStatusRepositoryImpl, ciPipelineRepositoryImpl, prePostCdScriptHistoryServiceImpl, clusterRepositoryImpl, helmAppServiceImpl, enforcerUtilImpl, pipelineStrategyHistoryServiceImpl, chartRepositoryImpl, resourceGroupServiceImpl, propertiesConfigServiceImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, environmentVariables, applicationServiceClientImpl, customTagServiceImpl, ciPipelineConfigServiceImpl, buildPipelineSwitchServiceImpl, argoClientWrapperServiceImpl, deployedAppMetricsServiceImpl, gitOpsConfigReadServiceImpl, gitOperationServiceImpl, chartServiceImpl, imageDigestPolicyServiceImpl, pipelineConfigEventPublishServiceImpl, deploymentTypeOverrideServiceImpl, deploymentConfigServiceImpl) - appArtifactManagerImpl := pipeline.NewAppArtifactManagerImpl(sugaredLogger, cdWorkflowRepositoryImpl, userServiceImpl, imageTaggingServiceImpl, ciArtifactRepositoryImpl, ciWorkflowRepositoryImpl, pipelineStageServiceImpl, cdPipelineConfigServiceImpl, dockerArtifactStoreRepositoryImpl, ciPipelineRepositoryImpl, ciTemplateServiceImpl) + appArtifactManagerImpl := pipeline.NewAppArtifactManagerImpl(sugaredLogger, cdWorkflowRepositoryImpl, userServiceImpl, imageTaggingServiceImpl, ciArtifactRepositoryImpl, ciWorkflowRepositoryImpl, pipelineStageServiceImpl, cdPipelineConfigServiceImpl, dockerArtifactStoreRepositoryImpl, ciPipelineRepositoryImpl, ciTemplateReadServiceImpl) devtronAppCMCSServiceImpl := pipeline.NewDevtronAppCMCSServiceImpl(sugaredLogger, appServiceImpl, attributesRepositoryImpl) globalStrategyMetadataChartRefMappingRepositoryImpl := chartRepoRepository.NewGlobalStrategyMetadataChartRefMappingRepositoryImpl(db, sugaredLogger) devtronAppStrategyServiceImpl := pipeline.NewDevtronAppStrategyServiceImpl(sugaredLogger, chartRepositoryImpl, globalStrategyMetadataChartRefMappingRepositoryImpl, ciCdPipelineOrchestratorImpl, cdPipelineConfigServiceImpl) @@ -640,9 +645,10 @@ func InitializeApp() (*App, error) { devtronAppGitOpConfigServiceImpl := gitOpsConfig.NewDevtronAppGitOpConfigServiceImpl(sugaredLogger, chartRepositoryImpl, chartServiceImpl, gitOpsConfigReadServiceImpl, gitOpsValidationServiceImpl, argoClientWrapperServiceImpl, deploymentConfigServiceImpl) cdHandlerImpl := pipeline.NewCdHandlerImpl(sugaredLogger, userServiceImpl, cdWorkflowRepositoryImpl, ciLogServiceImpl, ciArtifactRepositoryImpl, ciPipelineMaterialRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, ciWorkflowRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, imageTaggingServiceImpl, k8sServiceImpl, workflowServiceImpl, clusterServiceImplExtended, blobStorageConfigServiceImpl, customTagServiceImpl, deploymentConfigServiceImpl) appWorkflowServiceImpl := appWorkflow2.NewAppWorkflowServiceImpl(sugaredLogger, appWorkflowRepositoryImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, appRepositoryImpl, userAuthServiceImpl, chartServiceImpl, deploymentConfigServiceImpl) - appCloneServiceImpl := appClone.NewAppCloneServiceImpl(sugaredLogger, pipelineBuilderImpl, attributesServiceImpl, chartServiceImpl, configMapServiceImpl, appWorkflowServiceImpl, appListingServiceImpl, propertiesConfigServiceImpl, pipelineStageServiceImpl, ciTemplateServiceImpl, appRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, ciPipelineConfigServiceImpl, gitOpsConfigReadServiceImpl) + appCloneServiceImpl := appClone.NewAppCloneServiceImpl(sugaredLogger, pipelineBuilderImpl, attributesServiceImpl, chartServiceImpl, configMapServiceImpl, appWorkflowServiceImpl, appListingServiceImpl, propertiesConfigServiceImpl, pipelineStageServiceImpl, ciTemplateReadServiceImpl, appRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, ciPipelineConfigServiceImpl, gitOpsConfigReadServiceImpl) deploymentTemplateRepositoryImpl := repository2.NewDeploymentTemplateRepositoryImpl(db, sugaredLogger) - generateManifestDeploymentTemplateServiceImpl, err := generateManifest.NewDeploymentTemplateServiceImpl(sugaredLogger, chartServiceImpl, appListingServiceImpl, deploymentTemplateRepositoryImpl, helmAppServiceImpl, chartTemplateServiceImpl, helmAppClientImpl, k8sServiceImpl, propertiesConfigServiceImpl, deploymentTemplateHistoryServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, chartRefServiceImpl, pipelineOverrideRepositoryImpl, chartRepositoryImpl, pipelineRepositoryImpl, mergeUtil) + deploymentTemplateHistoryReadServiceImpl := read3.NewDeploymentTemplateHistoryReadServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, scopedVariableManagerImpl) + generateManifestDeploymentTemplateServiceImpl, err := generateManifest.NewDeploymentTemplateServiceImpl(sugaredLogger, chartServiceImpl, appListingServiceImpl, deploymentTemplateRepositoryImpl, helmAppServiceImpl, chartTemplateServiceImpl, helmAppClientImpl, k8sServiceImpl, propertiesConfigServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, chartRefServiceImpl, pipelineOverrideRepositoryImpl, chartRepositoryImpl, pipelineRepositoryImpl, mergeUtil, deploymentTemplateHistoryReadServiceImpl) if err != nil { return nil, err } @@ -657,13 +663,14 @@ func InitializeApp() (*App, error) { gitOpsManifestPushServiceImpl := publish.NewGitOpsManifestPushServiceImpl(sugaredLogger, pipelineStatusTimelineServiceImpl, pipelineOverrideRepositoryImpl, acdConfig, chartRefServiceImpl, gitOpsConfigReadServiceImpl, chartServiceImpl, gitOperationServiceImpl, argoClientWrapperServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, chartTemplateServiceImpl) argoK8sClientImpl := argocdServer.NewArgoK8sClientImpl(sugaredLogger, k8sServiceImpl) manifestCreationServiceImpl := manifest.NewManifestCreationServiceImpl(sugaredLogger, dockerRegistryIpsConfigServiceImpl, chartRefServiceImpl, scopedVariableCMCSManagerImpl, k8sCommonServiceImpl, deployedAppMetricsServiceImpl, imageDigestPolicyServiceImpl, mergeUtil, appCrudOperationServiceImpl, deploymentTemplateServiceImpl, applicationServiceClientImpl, configMapHistoryRepositoryImpl, configMapRepositoryImpl, chartRepositoryImpl, envConfigOverrideRepositoryImpl, environmentRepositoryImpl, pipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineOverrideRepositoryImpl, pipelineStrategyHistoryRepositoryImpl, pipelineConfigRepositoryImpl, deploymentTemplateHistoryRepositoryImpl, deploymentConfigServiceImpl) - deployedConfigurationHistoryServiceImpl := history.NewDeployedConfigurationHistoryServiceImpl(sugaredLogger, userServiceImpl, deploymentTemplateHistoryServiceImpl, pipelineStrategyHistoryServiceImpl, configMapHistoryServiceImpl, cdWorkflowRepositoryImpl, scopedVariableCMCSManagerImpl) + configMapHistoryReadServiceImpl := read4.NewConfigMapHistoryReadService(sugaredLogger, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl) + deployedConfigurationHistoryServiceImpl := history.NewDeployedConfigurationHistoryServiceImpl(sugaredLogger, userServiceImpl, deploymentTemplateHistoryServiceImpl, pipelineStrategyHistoryServiceImpl, configMapHistoryServiceImpl, cdWorkflowRepositoryImpl, scopedVariableCMCSManagerImpl, deploymentTemplateHistoryReadServiceImpl, configMapHistoryReadServiceImpl) userDeploymentRequestRepositoryImpl := repository15.NewUserDeploymentRequestRepositoryImpl(db, transactionUtilImpl) userDeploymentRequestServiceImpl := service2.NewUserDeploymentRequestServiceImpl(sugaredLogger, userDeploymentRequestRepositoryImpl) manifestPushConfigRepositoryImpl := repository10.NewManifestPushConfigRepository(sugaredLogger, db) scanToolExecutionHistoryMappingRepositoryImpl := security.NewScanToolExecutionHistoryMappingRepositoryImpl(db, sugaredLogger) imageScanServiceImpl := security2.NewImageScanServiceImpl(sugaredLogger, imageScanHistoryRepositoryImpl, imageScanResultRepositoryImpl, imageScanObjectMetaRepositoryImpl, cveStoreRepositoryImpl, imageScanDeployInfoRepositoryImpl, userServiceImpl, teamRepositoryImpl, appRepositoryImpl, environmentServiceImpl, ciArtifactRepositoryImpl, policyServiceImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, scanToolMetadataRepositoryImpl, scanToolExecutionHistoryMappingRepositoryImpl, cvePolicyRepositoryImpl) - triggerServiceImpl, err := devtronApps.NewTriggerServiceImpl(sugaredLogger, cdWorkflowCommonServiceImpl, gitOpsManifestPushServiceImpl, gitOpsConfigReadServiceImpl, argoK8sClientImpl, acdConfig, argoClientWrapperServiceImpl, pipelineStatusTimelineServiceImpl, chartTemplateServiceImpl, workflowEventPublishServiceImpl, manifestCreationServiceImpl, deployedConfigurationHistoryServiceImpl, argoUserServiceImpl, pipelineStageServiceImpl, globalPluginServiceImpl, customTagServiceImpl, pluginInputVariableParserImpl, prePostCdScriptHistoryServiceImpl, scopedVariableCMCSManagerImpl, workflowServiceImpl, imageDigestPolicyServiceImpl, userServiceImpl, clientImpl, helmAppServiceImpl, enforcerUtilImpl, userDeploymentRequestServiceImpl, helmAppClientImpl, eventSimpleFactoryImpl, eventRESTClientImpl, environmentVariables, appRepositoryImpl, ciPipelineMaterialRepositoryImpl, imageScanHistoryRepositoryImpl, imageScanDeployInfoRepositoryImpl, pipelineRepositoryImpl, pipelineOverrideRepositoryImpl, manifestPushConfigRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, cdWorkflowRepositoryImpl, ciWorkflowRepositoryImpl, ciArtifactRepositoryImpl, ciTemplateServiceImpl, materialRepositoryImpl, appLabelRepositoryImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, dockerArtifactStoreRepositoryImpl, imageScanServiceImpl, k8sServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, ciCdPipelineOrchestratorImpl, gitOperationServiceImpl, attributesServiceImpl) + triggerServiceImpl, err := devtronApps.NewTriggerServiceImpl(sugaredLogger, cdWorkflowCommonServiceImpl, gitOpsManifestPushServiceImpl, gitOpsConfigReadServiceImpl, argoK8sClientImpl, acdConfig, argoClientWrapperServiceImpl, pipelineStatusTimelineServiceImpl, chartTemplateServiceImpl, workflowEventPublishServiceImpl, manifestCreationServiceImpl, deployedConfigurationHistoryServiceImpl, argoUserServiceImpl, pipelineStageServiceImpl, globalPluginServiceImpl, customTagServiceImpl, pluginInputVariableParserImpl, prePostCdScriptHistoryServiceImpl, scopedVariableCMCSManagerImpl, workflowServiceImpl, imageDigestPolicyServiceImpl, userServiceImpl, clientImpl, helmAppServiceImpl, enforcerUtilImpl, userDeploymentRequestServiceImpl, helmAppClientImpl, eventSimpleFactoryImpl, eventRESTClientImpl, environmentVariables, appRepositoryImpl, ciPipelineMaterialRepositoryImpl, imageScanHistoryRepositoryImpl, imageScanDeployInfoRepositoryImpl, pipelineRepositoryImpl, pipelineOverrideRepositoryImpl, manifestPushConfigRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, cdWorkflowRepositoryImpl, ciWorkflowRepositoryImpl, ciArtifactRepositoryImpl, ciTemplateReadServiceImpl, materialRepositoryImpl, appLabelRepositoryImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, dockerArtifactStoreRepositoryImpl, imageScanServiceImpl, k8sServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, ciCdPipelineOrchestratorImpl, gitOperationServiceImpl, attributesServiceImpl) if err != nil { return nil, err } @@ -854,7 +861,7 @@ func InitializeApp() (*App, error) { appListingRouterImpl := appList2.NewAppListingRouterImpl(appListingRestHandlerImpl) appInfoRestHandlerImpl := appInfo.NewAppInfoRestHandlerImpl(sugaredLogger, appCrudOperationServiceImpl, userServiceImpl, validate, enforcerUtilImpl, enforcerImpl, helmAppServiceImpl, enforcerUtilHelmImpl, genericNoteServiceImpl) appInfoRouterImpl := appInfo2.NewAppInfoRouterImpl(sugaredLogger, appInfoRestHandlerImpl) - pipelineDeploymentConfigServiceImpl := pipeline.NewPipelineDeploymentConfigServiceImpl(sugaredLogger, envConfigOverrideRepositoryImpl, chartRepositoryImpl, pipelineRepositoryImpl, pipelineConfigRepositoryImpl, configMapRepositoryImpl, configMapHistoryServiceImpl, scopedVariableCMCSManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl) + pipelineDeploymentConfigServiceImpl := pipeline.NewPipelineDeploymentConfigServiceImpl(sugaredLogger, envConfigOverrideRepositoryImpl, chartRepositoryImpl, pipelineRepositoryImpl, pipelineConfigRepositoryImpl, configMapRepositoryImpl, scopedVariableCMCSManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, configMapHistoryReadServiceImpl) pipelineTriggerRestHandlerImpl := trigger.NewPipelineRestHandler(appServiceImpl, userServiceImpl, validate, enforcerImpl, teamServiceImpl, sugaredLogger, enforcerUtilImpl, deploymentGroupServiceImpl, argoUserServiceImpl, pipelineDeploymentConfigServiceImpl, deployedAppServiceImpl, triggerServiceImpl, workflowEventPublishServiceImpl) sseSSE := sse.NewSSE() pipelineTriggerRouterImpl := trigger2.NewPipelineTriggerRouter(pipelineTriggerRestHandlerImpl, sseSSE) @@ -868,8 +875,8 @@ func InitializeApp() (*App, error) { pipelineStatusRouterImpl := status4.NewPipelineStatusRouterImpl(pipelineStatusTimelineRestHandlerImpl) appWorkflowRestHandlerImpl := workflow.NewAppWorkflowRestHandlerImpl(sugaredLogger, userServiceImpl, appWorkflowServiceImpl, teamServiceImpl, enforcerImpl, pipelineBuilderImpl, appRepositoryImpl, enforcerUtilImpl, chartServiceImpl) appWorkflowRouterImpl := workflow2.NewAppWorkflowRouterImpl(appWorkflowRestHandlerImpl) - devtronAppAutoCompleteRestHandlerImpl := pipeline2.NewDevtronAppAutoCompleteRestHandlerImpl(sugaredLogger, userServiceImpl, teamServiceImpl, enforcerImpl, enforcerUtilImpl, devtronAppConfigServiceImpl, environmentServiceImpl, gitRegistryConfigImpl, dockerRegistryConfigImpl) - devtronAppAutoCompleteRouterImpl := pipeline3.NewDevtronAppAutoCompleteRouterImpl(devtronAppAutoCompleteRestHandlerImpl) + devtronAppAutoCompleteRestHandlerImpl := pipeline3.NewDevtronAppAutoCompleteRestHandlerImpl(sugaredLogger, userServiceImpl, teamServiceImpl, enforcerImpl, enforcerUtilImpl, devtronAppConfigServiceImpl, environmentServiceImpl, gitRegistryConfigImpl, dockerRegistryConfigImpl) + devtronAppAutoCompleteRouterImpl := pipeline4.NewDevtronAppAutoCompleteRouterImpl(devtronAppAutoCompleteRestHandlerImpl) appRouterImpl := app3.NewAppRouterImpl(appFilteringRouterImpl, appListingRouterImpl, appInfoRouterImpl, pipelineTriggerRouterImpl, pipelineConfigRouterImpl, pipelineHistoryRouterImpl, pipelineStatusRouterImpl, appWorkflowRouterImpl, devtronAppAutoCompleteRouterImpl, appWorkflowRestHandlerImpl, appListingRestHandlerImpl, appFilteringRestHandlerImpl) coreAppRestHandlerImpl := restHandler.NewCoreAppRestHandlerImpl(sugaredLogger, userServiceImpl, validate, enforcerUtilImpl, enforcerImpl, appCrudOperationServiceImpl, pipelineBuilderImpl, gitRegistryConfigImpl, chartServiceImpl, configMapServiceImpl, appListingServiceImpl, propertiesConfigServiceImpl, appWorkflowServiceImpl, materialRepositoryImpl, gitProviderRepositoryImpl, appWorkflowRepositoryImpl, environmentRepositoryImpl, configMapRepositoryImpl, chartRepositoryImpl, teamServiceImpl, argoUserServiceImpl, pipelineStageServiceImpl, ciPipelineRepositoryImpl) coreAppRouterImpl := router.NewCoreAppRouterImpl(coreAppRestHandlerImpl) @@ -896,7 +903,7 @@ func InitializeApp() (*App, error) { moduleRestHandlerImpl := module2.NewModuleRestHandlerImpl(sugaredLogger, moduleServiceImpl, userServiceImpl, enforcerImpl, validate) moduleRouterImpl := module2.NewModuleRouterImpl(moduleRestHandlerImpl) serverActionAuditLogRepositoryImpl := server.NewServerActionAuditLogRepositoryImpl(db) - serverServiceImpl := server.NewServerServiceImpl(sugaredLogger, serverActionAuditLogRepositoryImpl, serverDataStoreServerDataStore, serverEnvConfigServerEnvConfig, helmAppServiceImpl, moduleRepositoryImpl) + serverServiceImpl := server.NewServerServiceImpl(sugaredLogger, serverActionAuditLogRepositoryImpl, serverDataStoreServerDataStore, serverEnvConfigServerEnvConfig, helmAppServiceImpl, moduleRepositoryImpl, serverCacheServiceImpl) serverRestHandlerImpl := server2.NewServerRestHandlerImpl(sugaredLogger, serverServiceImpl, userServiceImpl, enforcerImpl, validate) serverRouterImpl := server2.NewServerRouterImpl(serverRestHandlerImpl) apiTokenSecretServiceImpl, err := apiToken.NewApiTokenSecretServiceImpl(sugaredLogger, attributesServiceImpl, apiTokenSecretStore) @@ -952,7 +959,7 @@ func InitializeApp() (*App, error) { if err != nil { return nil, err } - deploymentConfigurationServiceImpl, err := configDiff.NewDeploymentConfigurationServiceImpl(sugaredLogger, configMapServiceImpl, appRepositoryImpl, environmentRepositoryImpl, chartServiceImpl, generateManifestDeploymentTemplateServiceImpl, deploymentTemplateHistoryRepositoryImpl, pipelineStrategyHistoryRepositoryImpl, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl, configMapRepositoryImpl, pipelineDeploymentConfigServiceImpl, chartRefServiceImpl, pipelineRepositoryImpl, deploymentTemplateHistoryServiceImpl, configMapHistoryServiceImpl) + deploymentConfigurationServiceImpl, err := configDiff.NewDeploymentConfigurationServiceImpl(sugaredLogger, configMapServiceImpl, appRepositoryImpl, environmentRepositoryImpl, chartServiceImpl, generateManifestDeploymentTemplateServiceImpl, deploymentTemplateHistoryRepositoryImpl, pipelineStrategyHistoryRepositoryImpl, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl, configMapRepositoryImpl, pipelineDeploymentConfigServiceImpl, chartRefServiceImpl, pipelineRepositoryImpl, configMapHistoryServiceImpl, deploymentTemplateHistoryReadServiceImpl, configMapHistoryReadServiceImpl) if err != nil { return nil, err }