From 26081d8df2974529b58d99dc7fdfec321053aecf Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 22 Sep 2023 17:20:02 +0530 Subject: [PATCH 1/4] feat: added env variable to skip gitops validation on create/update --- pkg/gitops/GitOpsConfigService.go | 6 ++++++ util/GlobalConfig.go | 3 ++- wire_gen.go | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/gitops/GitOpsConfigService.go b/pkg/gitops/GitOpsConfigService.go index 3146695aeb..24f00435f1 100644 --- a/pkg/gitops/GitOpsConfigService.go +++ b/pkg/gitops/GitOpsConfigService.go @@ -90,6 +90,7 @@ type DetailedErrorGitOpsConfigResponse struct { type GitOpsConfigServiceImpl struct { randSource rand.Source logger *zap.SugaredLogger + globalEnvVariables *util2.GlobalEnvVariables gitOpsRepository repository.GitOpsConfigRepository K8sUtil *util4.K8sUtil aCDAuthConfig *util3.ACDAuthConfig @@ -103,12 +104,14 @@ type GitOpsConfigServiceImpl struct { } func NewGitOpsConfigServiceImpl(Logger *zap.SugaredLogger, + globalEnvVariables *util2.GlobalEnvVariables, gitOpsRepository repository.GitOpsConfigRepository, K8sUtil *util4.K8sUtil, aCDAuthConfig *util3.ACDAuthConfig, clusterService cluster.ClusterService, envService cluster.EnvironmentService, versionService argocdServer.VersionService, gitFactory *util.GitFactory, chartTemplateService util.ChartTemplateService, argoUserService argo.ArgoUserService, clusterServiceCD cluster2.ServiceClient) *GitOpsConfigServiceImpl { return &GitOpsConfigServiceImpl{ randSource: rand.NewSource(time.Now().UnixNano()), logger: Logger, + globalEnvVariables: globalEnvVariables, gitOpsRepository: gitOpsRepository, K8sUtil: K8sUtil, aCDAuthConfig: aCDAuthConfig, @@ -684,6 +687,9 @@ func (impl *GitOpsConfigServiceImpl) GetGitOpsConfigActive() (*bean2.GitOpsConfi } func (impl *GitOpsConfigServiceImpl) GitOpsValidateDryRun(config *bean2.GitOpsConfigDto) DetailedErrorGitOpsConfigResponse { + if impl.globalEnvVariables.SkipGitOpsValidation { + return DetailedErrorGitOpsConfigResponse{} + } if config.Token == "" { model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) if err != nil { diff --git a/util/GlobalConfig.go b/util/GlobalConfig.go index 70f85a325c..54cb2f9d1f 100644 --- a/util/GlobalConfig.go +++ b/util/GlobalConfig.go @@ -7,7 +7,8 @@ import ( ) type GlobalEnvVariables struct { - GitOpsRepoPrefix string `env:"GITOPS_REPO_PREFIX" envDefault:""` + GitOpsRepoPrefix string `env:"GITOPS_REPO_PREFIX" envDefault:""` + SkipGitOpsValidation bool `env:"SKIP_GITOPS_VALIDATION" envDefault:"false"` } func GetGlobalEnvVariables() (*GlobalEnvVariables, error) { diff --git a/wire_gen.go b/wire_gen.go index e166a53e36..8dc5d7375a 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -651,7 +651,7 @@ func InitializeApp() (*App, error) { imageScanRouterImpl := router.NewImageScanRouterImpl(imageScanRestHandlerImpl) policyRestHandlerImpl := restHandler.NewPolicyRestHandlerImpl(sugaredLogger, policyServiceImpl, userServiceImpl, userAuthServiceImpl, enforcerImpl, enforcerUtilImpl, environmentServiceImpl) policyRouterImpl := router.NewPolicyRouterImpl(policyRestHandlerImpl) - gitOpsConfigServiceImpl := gitops.NewGitOpsConfigServiceImpl(sugaredLogger, gitOpsConfigRepositoryImpl, k8sUtil, acdAuthConfig, clusterServiceImplExtended, environmentServiceImpl, versionServiceImpl, gitFactory, chartTemplateServiceImpl, argoUserServiceImpl, serviceClientImpl) + gitOpsConfigServiceImpl := gitops.NewGitOpsConfigServiceImpl(sugaredLogger, globalEnvVariables, gitOpsConfigRepositoryImpl, k8sUtil, acdAuthConfig, clusterServiceImplExtended, environmentServiceImpl, versionServiceImpl, gitFactory, chartTemplateServiceImpl, argoUserServiceImpl, serviceClientImpl) gitOpsConfigRestHandlerImpl := restHandler.NewGitOpsConfigRestHandlerImpl(sugaredLogger, gitOpsConfigServiceImpl, userServiceImpl, validate, enforcerImpl, teamServiceImpl, gitOpsConfigRepositoryImpl) gitOpsConfigRouterImpl := router.NewGitOpsConfigRouterImpl(gitOpsConfigRestHandlerImpl) dashboardConfig, err := dashboard.GetConfig() From 00fb828df1b263df13cef840e1bd2e6e4c06da37 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 22 Sep 2023 18:35:35 +0530 Subject: [PATCH 2/4] feat: updated API response --- pkg/gitops/GitOpsConfigService.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/gitops/GitOpsConfigService.go b/pkg/gitops/GitOpsConfigService.go index 24f00435f1..f0685491de 100644 --- a/pkg/gitops/GitOpsConfigService.go +++ b/pkg/gitops/GitOpsConfigService.go @@ -81,10 +81,11 @@ const ( ) type DetailedErrorGitOpsConfigResponse struct { - SuccessfulStages []string `json:"successfulStages"` - StageErrorMap map[string]string `json:"stageErrorMap"` - ValidatedOn time.Time `json:"validatedOn"` - DeleteRepoFailed bool `json:"deleteRepoFailed"` + SuccessfulStages []string `json:"successfulStages"` + StageErrorMap map[string]string `json:"stageErrorMap"` + ValidatedOn time.Time `json:"validatedOn"` + DeleteRepoFailed bool `json:"deleteRepoFailed"` + IsValidationSkipped bool `json:"isValidationSkipped"` } type GitOpsConfigServiceImpl struct { @@ -688,7 +689,9 @@ func (impl *GitOpsConfigServiceImpl) GetGitOpsConfigActive() (*bean2.GitOpsConfi func (impl *GitOpsConfigServiceImpl) GitOpsValidateDryRun(config *bean2.GitOpsConfigDto) DetailedErrorGitOpsConfigResponse { if impl.globalEnvVariables.SkipGitOpsValidation { - return DetailedErrorGitOpsConfigResponse{} + return DetailedErrorGitOpsConfigResponse{ + IsValidationSkipped: true, + } } if config.Token == "" { model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) From 6e1463baa3288626a9764efc839e847834da333b Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 22 Sep 2023 18:53:55 +0530 Subject: [PATCH 3/4] feat: reverted API response changes --- pkg/gitops/GitOpsConfigService.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/gitops/GitOpsConfigService.go b/pkg/gitops/GitOpsConfigService.go index f0685491de..24f00435f1 100644 --- a/pkg/gitops/GitOpsConfigService.go +++ b/pkg/gitops/GitOpsConfigService.go @@ -81,11 +81,10 @@ const ( ) type DetailedErrorGitOpsConfigResponse struct { - SuccessfulStages []string `json:"successfulStages"` - StageErrorMap map[string]string `json:"stageErrorMap"` - ValidatedOn time.Time `json:"validatedOn"` - DeleteRepoFailed bool `json:"deleteRepoFailed"` - IsValidationSkipped bool `json:"isValidationSkipped"` + SuccessfulStages []string `json:"successfulStages"` + StageErrorMap map[string]string `json:"stageErrorMap"` + ValidatedOn time.Time `json:"validatedOn"` + DeleteRepoFailed bool `json:"deleteRepoFailed"` } type GitOpsConfigServiceImpl struct { @@ -689,9 +688,7 @@ func (impl *GitOpsConfigServiceImpl) GetGitOpsConfigActive() (*bean2.GitOpsConfi func (impl *GitOpsConfigServiceImpl) GitOpsValidateDryRun(config *bean2.GitOpsConfigDto) DetailedErrorGitOpsConfigResponse { if impl.globalEnvVariables.SkipGitOpsValidation { - return DetailedErrorGitOpsConfigResponse{ - IsValidationSkipped: true, - } + return DetailedErrorGitOpsConfigResponse{} } if config.Token == "" { model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) From 457242dff534bf4a4264dd916e57d0b7484f1866 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 25 Sep 2023 12:27:02 +0530 Subject: [PATCH 4/4] handled panic on CD pipeline save --- pkg/app/AppService.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/AppService.go b/pkg/app/AppService.go index 10b2481dc0..df657f44cf 100644 --- a/pkg/app/AppService.go +++ b/pkg/app/AppService.go @@ -1698,7 +1698,7 @@ func (impl *AppServiceImpl) CreateGitopsRepo(app *app.App, userId int32) (gitops gitOpsRepoName := impl.chartTemplateService.GetGitOpsRepoName(app.AppName) chartGitAttr, err = impl.chartTemplateService.CreateGitRepositoryForApp(gitOpsRepoName, chart.ReferenceTemplate, chart.ChartVersion, userId) if err != nil { - impl.logger.Errorw("error in pushing chart to git ", "path", chartGitAttr.ChartLocation, "err", err) + impl.logger.Errorw("error in pushing chart to git ", "gitOpsRepoName", gitOpsRepoName, "err", err) return "", nil, err } return gitOpsRepoName, chartGitAttr, nil