From 4ab6c43d6739d03b69df16b1ee63766dfa9ad093 Mon Sep 17 00:00:00 2001 From: Shawna Monero Date: Wed, 10 Apr 2024 13:41:16 -0700 Subject: [PATCH] merge --- cmd/adhoc.go | 22 +++----- server/neptune/adhoc/config/config.go | 8 ++- server/neptune/adhoc/server.go | 74 +++++++++++++++------------ 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/cmd/adhoc.go b/cmd/adhoc.go index cd22bb6e7..197f645e1 100644 --- a/cmd/adhoc.go +++ b/cmd/adhoc.go @@ -7,11 +7,8 @@ import ( "github.com/runatlantis/atlantis/server/legacy" "github.com/runatlantis/atlantis/server/logging" adhoc "github.com/runatlantis/atlantis/server/neptune/adhoc" - adhocHelpers "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocexecutionhelpers" adhocconfig "github.com/runatlantis/atlantis/server/neptune/adhoc/config" neptune "github.com/runatlantis/atlantis/server/neptune/temporalworker/config" - "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" - "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" ) type Adhoc struct{} @@ -58,18 +55,13 @@ func (a *Adhoc) NewServer(userConfig legacy.UserConfig, config legacy.Config) (S DownloadURL: userConfig.TFDownloadURL, LogFilters: globalCfg.TerraformLogFilter, }, - DataDir: userConfig.DataDir, - TemporalCfg: globalCfg.Temporal, - GithubCfg: globalCfg.Github, - App: appConfig, - CtxLogger: ctxLogger, - StatsNamespace: userConfig.StatsNamespace, - Metrics: globalCfg.Metrics, - AdhocExecutionParams: adhocHelpers.AdhocTerraformWorkflowExecutionParams{ - Revision: "", - TerraformRoots: []terraform.Root{}, - GithubRepo: github.Repo{}, - }, + DataDir: userConfig.DataDir, + TemporalCfg: globalCfg.Temporal, + GithubCfg: globalCfg.Github, + App: appConfig, + CtxLogger: ctxLogger, + StatsNamespace: userConfig.StatsNamespace, + Metrics: globalCfg.Metrics, GithubHostname: userConfig.GithubHostname, GithubAppID: userConfig.GithubAppID, GithubAppKeyFile: userConfig.GithubAppKeyFile, diff --git a/server/neptune/adhoc/config/config.go b/server/neptune/adhoc/config/config.go index c017e37ec..ac01acff5 100644 --- a/server/neptune/adhoc/config/config.go +++ b/server/neptune/adhoc/config/config.go @@ -4,7 +4,6 @@ import ( "github.com/palantir/go-githubapp/githubapp" "github.com/runatlantis/atlantis/server/config/valid" "github.com/runatlantis/atlantis/server/logging" - adhoc "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocexecutionhelpers" neptune "github.com/runatlantis/atlantis/server/neptune/temporalworker/config" ) @@ -20,10 +19,9 @@ type Config struct { StatsNamespace string - DataDir string - CtxLogger logging.Logger - App githubapp.Config - AdhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams + DataDir string + CtxLogger logging.Logger + App githubapp.Config GithubAppID int64 GithubAppKeyFile string diff --git a/server/neptune/adhoc/server.go b/server/neptune/adhoc/server.go index 4a71ff558..483bcff4b 100644 --- a/server/neptune/adhoc/server.go +++ b/server/neptune/adhoc/server.go @@ -48,20 +48,22 @@ import ( ) type Server struct { - Logger logging.Logger - CronScheduler *internalSync.CronScheduler - Crons []*internalSync.Cron - HTTPServerProxy *neptune_http.ServerProxy - Port int - StatsScope tally.Scope - StatsCloser io.Closer - TemporalClient *temporal.ClientWrapper - TerraformActivities *activities.Terraform - GithubActivities *activities.Github - AdhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams - TerraformTaskQueue string - RootConfigBuilder *root_config.Builder - GithubRetriever *adhocGithubHelpers.AdhocGithubRetriever + Logger logging.Logger + CronScheduler *internalSync.CronScheduler + Crons []*internalSync.Cron + HTTPServerProxy *neptune_http.ServerProxy + Port int + StatsScope tally.Scope + StatsCloser io.Closer + TemporalClient *temporal.ClientWrapper + TerraformActivities *activities.Terraform + GithubActivities *activities.Github + TerraformTaskQueue string + RootConfigBuilder *root_config.Builder + GithubRetriever *adhocGithubHelpers.AdhocGithubRetriever + Repo string + Root string + Revision string } func NewServer(config *adhocconfig.Config) (*Server, error) { @@ -222,17 +224,16 @@ func NewServer(config *adhocconfig.Config) (*Server, error) { Frequency: 1 * time.Minute, }, }, - HTTPServerProxy: httpServerProxy, - Port: config.ServerCfg.Port, - StatsScope: scope, - StatsCloser: statsCloser, - TemporalClient: temporalClient, - TerraformActivities: terraformActivities, - TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue, - GithubActivities: githubActivities, - AdhocExecutionParams: config.AdhocExecutionParams, - RootConfigBuilder: rootConfigBuilder, - GithubRetriever: githubRetriever, + HTTPServerProxy: httpServerProxy, + Port: config.ServerCfg.Port, + StatsScope: scope, + StatsCloser: statsCloser, + TemporalClient: temporalClient, + TerraformActivities: terraformActivities, + TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue, + GithubActivities: githubActivities, + RootConfigBuilder: rootConfigBuilder, + GithubRetriever: githubRetriever, } return &server, nil } @@ -241,18 +242,18 @@ func NewServer(config *adhocconfig.Config) (*Server, error) { // then executes the Terraform workflow. Note normally this workflow is executed // when a request is made to the server, but we are manually executing it here, // since we don't care about requests in adhoc mode. -func (s Server) manuallyExecuteTerraformWorkflow(adhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams) (interface{}, error) { +func (s Server) manuallyExecuteTerraformWorkflow(repo ghClient.Repo, revision string, root terraform.Root) (interface{}, error) { request := workflows.TerraformRequest{ - Revision: adhocExecutionParams.Revision, + Revision: revision, WorkflowMode: terraform.Adhoc, - Root: adhocExecutionParams.TerraformRoot, - Repo: adhocExecutionParams.GithubRepo, + Root: root, + Repo: repo, } options := client.StartWorkflowOptions{ TaskQueue: s.TerraformTaskQueue, SearchAttributes: map[string]interface{}{ - "atlantis_repository": adhocExecutionParams.AtlantisRepo, - "atlantis_root": adhocExecutionParams.AtlantisRoot, + "atlantis_repository": repo.GetFullName(), + "atlantis_root": root.Name, }, } @@ -290,9 +291,18 @@ func (s Server) Start() error { wg.Add(1) go func() { defer wg.Done() - _, err := s.manuallyExecuteTerraformWorkflow(s.AdhocExecutionParams) + + adhocExecutionParams, err := adhoc.ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx, s.Repo, s.Revision, s.GithubRetriever, s.RootConfigBuilder) if err != nil { s.Logger.Error(err.Error()) + return + } + + for _, root := range adhocExecutionParams.TerraformRoots { + _, err := s.manuallyExecuteTerraformWorkflow(adhocExecutionParams.GithubRepo, adhocExecutionParams.Revision, root) + if err != nil { + s.Logger.Error(err.Error()) + } } }()