Skip to content

Commit 1553cbb

Browse files
authored
Gitops delete repo fix (#809)
* removed delete repo access error in gitops validation * changed gitops response for delete repo validation fix * review changes * wip * wip * review changes * fixed response name * review changes * review changes
1 parent 5b7b533 commit 1553cbb

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

api/restHandler/GitOpsConfigRestHandler.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,13 @@ func (impl GitOpsConfigRestHandlerImpl) CreateGitOpsConfig(w http.ResponseWriter
9797
writeJsonResp(w, err, nil, http.StatusBadRequest)
9898
return
9999
}
100-
gitOpsConfig, detailedErrorGitOpsConfigResponse, err := impl.gitOpsConfigService.ValidateAndCreateGitOpsConfig(&bean)
100+
detailedErrorGitOpsConfigResponse, err := impl.gitOpsConfigService.ValidateAndCreateGitOpsConfig(&bean)
101101
if err != nil {
102102
impl.logger.Errorw("service err, SaveGitRepoConfig", "err", err, "payload", bean)
103103
writeJsonResp(w, err, nil, http.StatusInternalServerError)
104104
}
105-
if gitOpsConfig != nil {
106-
writeJsonResp(w, nil, gitOpsConfig, http.StatusOK)
107-
} else {
108-
writeJsonResp(w, nil, detailedErrorGitOpsConfigResponse, http.StatusOK)
109-
}
105+
writeJsonResp(w, nil, detailedErrorGitOpsConfigResponse, http.StatusOK)
106+
110107
}
111108

112109
func (impl GitOpsConfigRestHandlerImpl) UpdateGitOpsConfig(w http.ResponseWriter, r *http.Request) {
@@ -138,16 +135,13 @@ func (impl GitOpsConfigRestHandlerImpl) UpdateGitOpsConfig(w http.ResponseWriter
138135
writeJsonResp(w, err, nil, http.StatusBadRequest)
139136
return
140137
}
141-
gitOpsConfig, detailedErrorGitOpsConfigResponse, err := impl.gitOpsConfigService.ValidateAndUpdateGitOpsConfig(&bean)
138+
detailedErrorGitOpsConfigResponse, err := impl.gitOpsConfigService.ValidateAndUpdateGitOpsConfig(&bean)
142139
if err != nil {
143140
impl.logger.Errorw("service err, UpdateGitOpsConfig", "err", err, "payload", bean)
144141
writeJsonResp(w, err, nil, http.StatusInternalServerError)
145142
}
146-
if gitOpsConfig != nil {
147-
writeJsonResp(w, nil, gitOpsConfig, http.StatusOK)
148-
} else {
149-
writeJsonResp(w, nil, detailedErrorGitOpsConfigResponse, http.StatusOK)
150-
}
143+
writeJsonResp(w, nil, detailedErrorGitOpsConfigResponse, http.StatusOK)
144+
151145
}
152146

153147
func (impl GitOpsConfigRestHandlerImpl) GetGitOpsConfigById(w http.ResponseWriter, r *http.Request) {

internal/util/GitService.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type DetailedErrorGitOpsConfigActions struct {
7272
SuccessfulStages []string `json:"successfulStages"`
7373
StageErrorMap map[string]error `json:"stageErrorMap"`
7474
ValidatedOn time.Time `json:"validatedOn"`
75+
DeleteRepoFailed bool `json:"deleteRepoFailed"`
7576
}
7677

7778
func (factory *GitFactory) Reload() error {

pkg/gitops/GitOpsConfigService.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import (
4646
)
4747

4848
type GitOpsConfigService interface {
49-
ValidateAndCreateGitOpsConfig(config *bean2.GitOpsConfigDto) (*bean2.GitOpsConfigDto, DetailedErrorGitOpsConfigResponse, error)
50-
ValidateAndUpdateGitOpsConfig(config *bean2.GitOpsConfigDto) (*bean2.GitOpsConfigDto, DetailedErrorGitOpsConfigResponse, error)
49+
ValidateAndCreateGitOpsConfig(config *bean2.GitOpsConfigDto) (DetailedErrorGitOpsConfigResponse, error)
50+
ValidateAndUpdateGitOpsConfig(config *bean2.GitOpsConfigDto) (DetailedErrorGitOpsConfigResponse, error)
5151
GitOpsValidateDryRun(config *bean2.GitOpsConfigDto) DetailedErrorGitOpsConfigResponse
5252
CreateGitOpsConfig(config *bean2.GitOpsConfigDto) (*bean2.GitOpsConfigDto, error)
5353
UpdateGitOpsConfig(config *bean2.GitOpsConfigDto) error
@@ -80,7 +80,9 @@ type DetailedErrorGitOpsConfigResponse struct {
8080
SuccessfulStages []string `json:"successfulStages"`
8181
StageErrorMap map[string]string `json:"stageErrorMap"`
8282
ValidatedOn time.Time `json:"validatedOn"`
83+
DeleteRepoFailed bool `json:"deleteRepoFailed"`
8384
}
85+
8486
type GitOpsConfigServiceImpl struct {
8587
randSource rand.Source
8688
logger *zap.SugaredLogger
@@ -110,29 +112,27 @@ func NewGitOpsConfigServiceImpl(Logger *zap.SugaredLogger, ciHandler pipeline.Ci
110112
}
111113
}
112114

113-
func (impl *GitOpsConfigServiceImpl) ValidateAndCreateGitOpsConfig(config *bean2.GitOpsConfigDto) (*bean2.GitOpsConfigDto, DetailedErrorGitOpsConfigResponse, error) {
115+
func (impl *GitOpsConfigServiceImpl) ValidateAndCreateGitOpsConfig(config *bean2.GitOpsConfigDto) (DetailedErrorGitOpsConfigResponse, error) {
114116
detailedErrorGitOpsConfigResponse := impl.GitOpsValidateDryRun(config)
115117
if len(detailedErrorGitOpsConfigResponse.StageErrorMap) == 0 {
116-
gitOpsConfig, err := impl.CreateGitOpsConfig(config)
118+
_, err := impl.CreateGitOpsConfig(config)
117119
if err != nil {
118120
impl.logger.Errorw("service err, SaveGitRepoConfig", "err", err, "payload", config)
119-
return gitOpsConfig, detailedErrorGitOpsConfigResponse, err
121+
return detailedErrorGitOpsConfigResponse, err
120122
}
121-
return gitOpsConfig, detailedErrorGitOpsConfigResponse, nil
122123
}
123-
return nil, detailedErrorGitOpsConfigResponse, nil
124+
return detailedErrorGitOpsConfigResponse, nil
124125
}
125-
func (impl *GitOpsConfigServiceImpl) ValidateAndUpdateGitOpsConfig(config *bean2.GitOpsConfigDto) (*bean2.GitOpsConfigDto, DetailedErrorGitOpsConfigResponse, error) {
126+
func (impl *GitOpsConfigServiceImpl) ValidateAndUpdateGitOpsConfig(config *bean2.GitOpsConfigDto) (DetailedErrorGitOpsConfigResponse, error) {
126127
detailedErrorGitOpsConfigResponse := impl.GitOpsValidateDryRun(config)
127128
if len(detailedErrorGitOpsConfigResponse.StageErrorMap) == 0 {
128129
err := impl.UpdateGitOpsConfig(config)
129130
if err != nil {
130131
impl.logger.Errorw("service err, UpdateGitOpsConfig", "err", err, "payload", config)
131-
return config, detailedErrorGitOpsConfigResponse, err
132+
return detailedErrorGitOpsConfigResponse, err
132133
}
133-
return config, detailedErrorGitOpsConfigResponse, nil
134134
}
135-
return nil, detailedErrorGitOpsConfigResponse, nil
135+
return detailedErrorGitOpsConfigResponse, nil
136136
}
137137

138138
func (impl *GitOpsConfigServiceImpl) CreateGitOpsConfig(request *bean2.GitOpsConfigDto) (*bean2.GitOpsConfigDto, error) {
@@ -687,7 +687,9 @@ func (impl *GitOpsConfigServiceImpl) GitOpsValidateDryRun(config *bean2.GitOpsCo
687687
err = client.DeleteRepository(appName, config.Username, config.GitHubOrgId, config.AzureProjectName, repoOptions)
688688
if err != nil {
689689
impl.logger.Errorw("error in deleting repo", "err", err)
690-
detailedErrorGitOpsConfigActions.StageErrorMap[DeleteRepoStage] = impl.extractErrorMessageByProvider(err, config.Provider)
690+
//here below the assignment of delete is removed for making this stage optional, and it's failure not preventing it from saving/updating gitOps config
691+
//detailedErrorGitOpsConfigActions.StageErrorMap[DeleteRepoStage] = impl.extractErrorMessageByProvider(err, config.Provider)
692+
detailedErrorGitOpsConfigActions.DeleteRepoFailed = true
691693
} else {
692694
detailedErrorGitOpsConfigActions.SuccessfulStages = append(detailedErrorGitOpsConfigActions.SuccessfulStages, DeleteRepoStage)
693695
}
@@ -731,5 +733,6 @@ func (impl *GitOpsConfigServiceImpl) convertDetailedErrorToResponse(detailedErro
731733
for stage, err := range detailedErrorGitOpsConfigActions.StageErrorMap {
732734
detailedErrorResponse.StageErrorMap[stage] = err.Error()
733735
}
736+
detailedErrorResponse.DeleteRepoFailed = detailedErrorGitOpsConfigActions.DeleteRepoFailed
734737
return detailedErrorResponse
735738
}

0 commit comments

Comments
 (0)