From 7f7fa97a41368a97d3441620818b9552da72efb3 Mon Sep 17 00:00:00 2001 From: venkat k Date: Sat, 8 Jun 2024 17:49:53 +0530 Subject: [PATCH] error handling while synching crossplane project to keep crossplane project status in consistent state --- .../api/plugin_crossplane_project_apis.go | 18 +++++++++--------- .../capten-store/crossplane_project.go | 3 ++- .../common-pkg/capten-store/tekton_projects.go | 3 ++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/capten/agent/internal/api/plugin_crossplane_project_apis.go b/capten/agent/internal/api/plugin_crossplane_project_apis.go index 422df162..48f3a0f9 100644 --- a/capten/agent/internal/api/plugin_crossplane_project_apis.go +++ b/capten/agent/internal/api/plugin_crossplane_project_apis.go @@ -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 { @@ -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{ diff --git a/capten/common-pkg/capten-store/crossplane_project.go b/capten/common-pkg/capten-store/crossplane_project.go index 06484c29..7dfd7fb6 100644 --- a/capten/common-pkg/capten-store/crossplane_project.go +++ b/capten/common-pkg/capten-store/crossplane_project.go @@ -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) @@ -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 { diff --git a/capten/common-pkg/capten-store/tekton_projects.go b/capten/common-pkg/capten-store/tekton_projects.go index 2fcbfec3..2d7e4113 100644 --- a/capten/common-pkg/capten-store/tekton_projects.go +++ b/capten/common-pkg/capten-store/tekton_projects.go @@ -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) @@ -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 {