Skip to content

Commit

Permalink
Merge pull request #513 from kube-tarian/fix-crossplane-register-error
Browse files Browse the repository at this point in the history
error handling while synching crossplane project to keep crossplane p…
  • Loading branch information
vramk23 authored Jun 8, 2024
2 parents 32df6aa + 7f7fa97 commit 01f66af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
18 changes: 9 additions & 9 deletions capten/agent/internal/api/plugin_crossplane_project_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ func (a *Agent) RegisterCrossplaneProject(ctx context.Context, request *captenpl
}, nil
}

crossplaneProject.Status = string(model.CrossplaneProjectConfigurationOngoing)
if err := a.as.UpsertCrossplaneProject(crossplaneProject); err != nil {
a.log.Errorf("failed to Set Cluster Gitopts Project, %v", err)
return &captenpluginspb.RegisterCrossplaneProjectResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "inserting data to Crossplane db got failed",
}, err
}

if ok, err := a.isProjectRegisteredWithArgoCD(ctx, crossplaneProject.GitProjectUrl); !ok && err == nil {
accessToken, userID, _, _, err := a.getGitProjectCredential(ctx, crossplaneProject.GitProjectId)
if err != nil {
Expand Down Expand Up @@ -83,6 +74,15 @@ func (a *Agent) RegisterCrossplaneProject(ctx context.Context, request *captenpl
}, nil
}

crossplaneProject.Status = string(model.CrossplaneProjectConfigurationOngoing)
if err := a.as.UpsertCrossplaneProject(crossplaneProject); err != nil {
a.log.Errorf("failed to Set Cluster Gitopts Project, %v", err)
return &captenpluginspb.RegisterCrossplaneProjectResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "inserting data to Crossplane db got failed",
}, err
}

a.configureCrossplaneGitRepo(crossplaneProject, providers)
a.log.Infof("Crossplane Git project %s registration triggerred", request.Id)
return &captenpluginspb.RegisterCrossplaneProjectResponse{
Expand Down
3 changes: 2 additions & 1 deletion capten/common-pkg/capten-store/crossplane_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (a *Store) updateCrossplaneProject() (*model.CrossplaneProject, error) {
ID: 1,
GitProjectID: gitProjectUUID,
GitProjectURL: crosplaneGitProject.ProjectUrl,
Status: string(model.CrossplaneProjectAvailable),
LastUpdateTime: time.Now(),
}
err = a.dbClient.Create(&project)
Expand All @@ -106,7 +107,7 @@ func (a *Store) updateCrossplaneProject() (*model.CrossplaneProject, error) {

project := CrossplaneProject{GitProjectID: gitProjectUUID,
GitProjectURL: crosplaneGitProject.ProjectUrl,
Status: crossplaneProject.Status,
Status: string(model.CrossplaneProjectAvailable),
LastUpdateTime: time.Now()}
err = a.dbClient.Update(&project, CrossplaneProject{ID: 1})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion capten/common-pkg/capten-store/tekton_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (a *Store) updateTektonProject() (*model.TektonProject, error) {
ID: 1,
GitProjectID: gitProjectUUID,
GitProjectURL: tektonGitProject.ProjectUrl,
Status: string(model.TektonProjectAvailable),
LastUpdateTime: time.Now(),
}
err = a.dbClient.Create(&project)
Expand All @@ -104,7 +105,7 @@ func (a *Store) updateTektonProject() (*model.TektonProject, error) {

project := TektonProject{GitProjectID: gitProjectUUID,
GitProjectURL: tektonGitProject.ProjectUrl,
Status: tektonProject.Status,
Status: string(model.TektonProjectAvailable),
LastUpdateTime: time.Now()}
err = a.dbClient.Update(&project, TektonProject{ID: 1})
if err != nil {
Expand Down

0 comments on commit 01f66af

Please sign in to comment.