From 44ce26030071c8395da0d8fefb8e4935377931e4 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 29 Aug 2024 19:25:55 +0200 Subject: [PATCH] Refresh properties before reconcile and profile init Refreshing the repositories ensures that when the requests get to the executor, the properties will have been fetched. Related: #4173 --- internal/reconcilers/repository.go | 9 +++++++++ internal/reconcilers/run_profile.go | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/reconcilers/repository.go b/internal/reconcilers/repository.go index dfe17a74de..5e6e763f58 100644 --- a/internal/reconcilers/repository.go +++ b/internal/reconcilers/repository.go @@ -33,6 +33,7 @@ import ( "github.com/stacklok/minder/internal/providers/github" "github.com/stacklok/minder/internal/reconcilers/messages" "github.com/stacklok/minder/internal/repositories" + ghreposvc "github.com/stacklok/minder/internal/repositories/github" "github.com/stacklok/minder/internal/verifier/verifyif" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" v1 "github.com/stacklok/minder/pkg/providers/v1" @@ -75,6 +76,14 @@ func (r *Reconciler) handleArtifactsReconcilerEvent(ctx context.Context, evt *me return fmt.Errorf("error instantiating provider: %w", err) } + _, err = r.repos.RefreshRepositoryByUpstreamID(ctx, repository.RepoID) + if errors.Is(err, v1.ErrEntityNotFound) || errors.Is(err, ghreposvc.ErrRepoNotFound) { + zerolog.Ctx(ctx).Debug().Err(err).Str("repository", repository.ID.String()).Msg("repository not found") + } else if err != nil { + zerolog.Ctx(ctx).Debug().Err(err).Str("repository", repository.ID.String()).Msg("error refreshing repository") + return fmt.Errorf("error refreshing repository: %w", err) + } + cli, err := v1.As[v1.GitHub](p) if err != nil { // Keeping this behaviour to match the existing logic diff --git a/internal/reconcilers/run_profile.go b/internal/reconcilers/run_profile.go index b0c86a2388..b77872d085 100644 --- a/internal/reconcilers/run_profile.go +++ b/internal/reconcilers/run_profile.go @@ -102,9 +102,15 @@ func (r *Reconciler) publishProfileInitEvents( } for _, dbrepo := range dbrepos { + _, err := r.repos.RefreshRepositoryByUpstreamID(ctx, dbrepo.RepoID) + if err != nil { + zerolog.Ctx(ctx).Debug().Err(err).Str("repository", dbrepo.ID.String()).Msg("error refreshing repository") + continue + } + // protobufs are our API, so we always execute on these instead of the DB directly. repo := repositories.PBRepositoryFromDB(dbrepo) - err := entities.NewEntityInfoWrapper(). + err = entities.NewEntityInfoWrapper(). WithProviderID(dbrepo.ProviderID). WithProjectID(projectID). WithRepository(repo).