Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVCON-6849] First part of new flow of adhoc mode #727

Merged
merged 20 commits into from
Mar 8, 2024
80 changes: 80 additions & 0 deletions cmd/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cmd

import (
"github.com/pkg/errors"
cfgParser "github.com/runatlantis/atlantis/server/config"
"github.com/runatlantis/atlantis/server/config/valid"
"github.com/runatlantis/atlantis/server/legacy"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/neptune/admin"
adminconfig "github.com/runatlantis/atlantis/server/neptune/admin/config"
neptune "github.com/runatlantis/atlantis/server/neptune/temporalworker/config"
)

type Admin struct{}

// NewServer returns the real Atlantis server object.
func (a *Admin) NewServer(userConfig legacy.UserConfig, config legacy.Config) (ServerStarter, error) {
ctxLogger, err := logging.NewLoggerFromLevel(userConfig.ToLogLevel())
if err != nil {
return nil, errors.Wrap(err, "failed to build context logger")
}

globalCfg := valid.NewGlobalCfg(userConfig.DataDir)
validator := &cfgParser.ParserValidator{}

// TODO: fill in values from globalCfg
smonero marked this conversation as resolved.
Show resolved Hide resolved
if userConfig.RepoConfig != "" {
globalCfg, err = validator.ParseGlobalCfg(userConfig.RepoConfig, globalCfg)
if err != nil {
return nil, errors.Wrapf(err, "parsing %s file", userConfig.RepoConfig)
}
}

parsedURL, err := legacy.ParseAtlantisURL(userConfig.AtlantisURL)
if err != nil {
return nil, errors.Wrapf(err,
"parsing atlantis url %q", userConfig.AtlantisURL)
}

appConfig, err := createGHAppConfig(userConfig)
if err != nil {
return nil, err
}

cfg := &adminconfig.Config{
AuthCfg: neptune.AuthConfig{
SslCertFile: userConfig.SSLCertFile,
SslKeyFile: userConfig.SSLKeyFile,
},
ServerCfg: neptune.ServerConfig{
URL: parsedURL,
Version: config.AtlantisVersion,
Port: userConfig.Port,
},
// we need the terraformcfg stuff, since we need terraformActivities
TerraformCfg: neptune.TerraformConfig{
DefaultVersion: userConfig.DefaultTFVersion,
DownloadURL: userConfig.TFDownloadURL,
LogFilters: globalCfg.TerraformLogFilter,
},
// Do not need deployment config
// do need datadir, we will save the archive there
DataDir: userConfig.DataDir,
// do need temporalconfig since we use temporal
TemporalCfg: globalCfg.Temporal,
// do need githubcfg, since we use github to get the archive
GithubCfg: globalCfg.Github,
// same as above
App: appConfig,
// we do need logging
CtxLogger: ctxLogger,
// we do need stats
StatsNamespace: userConfig.StatsNamespace,
// we do need metrics
Metrics: globalCfg.Metrics,
// no SnsTopicArn since we don't use the auditing
// no revision setter
}
return admin.NewServer(cfg)
}
smonero marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 8 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ var stringFlags = map[string]stringFlag{
"default: Runs atlantis with default event handler that processes events within same.\n" +
"gateway: Runs atlantis with gateway event handler that publishes events through sns.\n" +
"worker: Runs atlantis with a sqs handler that polls for events in the queue to process.\n" +
"hybrid: Runs atlantis with both a gateway event handler and sqs handler to perform both gateway and worker behaviors.",
"hybrid: Runs atlantis with both a gateway event handler and sqs handler to perform both gateway and worker behaviors.\n" +
"admin: Runs atlantis in an admin mode that allows for running terraform commands.",
defaultValue: "",
},
LyftWorkerQueueURLFlag: {
Expand Down Expand Up @@ -344,6 +345,7 @@ func NewServerCmd(v *viper.Viper, version string) *ServerCmd {
GatewayCreator: &GatewayCreator{},
WorkerCreator: &WorkerCreator{},
TemporalWorkerCreator: &TemporalWorker{},
AdminCreator: &Admin{},
},
Viper: v,
AtlantisVersion: version,
Expand Down Expand Up @@ -374,6 +376,7 @@ type ServerCreatorProxy struct {
GatewayCreator ServerCreator
WorkerCreator ServerCreator
TemporalWorkerCreator ServerCreator
AdminCreator ServerCreator
}

func (d *ServerCreatorProxy) NewServer(userConfig server.UserConfig, config server.Config) (ServerStarter, error) {
Expand All @@ -389,6 +392,10 @@ func (d *ServerCreatorProxy) NewServer(userConfig server.UserConfig, config serv
return d.TemporalWorkerCreator.NewServer(userConfig, config)
}

if userConfig.ToLyftMode() == server.Admin {
return d.AdminCreator.NewServer(userConfig, config)
}

return d.WorkerCreator.NewServer(userConfig, config)
}

Expand Down
12 changes: 6 additions & 6 deletions server/config/raw/global_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ type GlobalCfg struct {
Persistence Persistence `yaml:"persistence" json:"persistence"`
RevisionSetter RevisionSetter `yaml:"revision_setter" json:"revision_setter"`
Admin Admin `yaml:"admin" json:"admin"`
TerraformAdminMode TerraformAdminMode `yaml:"terraform_admin_mode" json:"terraform_admin_mode"`
AdminMode AdminMode `yaml:"admin_mode" json:"admin_mode"`
smonero marked this conversation as resolved.
Show resolved Hide resolved
}

type TerraformAdminMode struct {
type AdminMode struct {
Repo string `yaml:"repo" json:"repo"`
Root string `yaml:"root" json:"root"`
}

func (t TerraformAdminMode) ToValid() valid.TerraformAdminMode {
return valid.TerraformAdminMode{
func (t AdminMode) ToValid() valid.AdminMode {
return valid.AdminMode{
Repo: t.Repo,
Root: t.Root,
}
}

func (t TerraformAdminMode) Validate() error {
func (t AdminMode) Validate() error {
// We don't need to validate the inputs so we can just return nil
return nil
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func (g GlobalCfg) ToValid(defaultCfg valid.GlobalCfg) valid.GlobalCfg {
Github: g.Github.ToValid(),
Admin: g.Admin.ToValid(),
RevisionSetter: g.RevisionSetter.ToValid(),
TerraformAdminMode: g.TerraformAdminMode.ToValid(),
AdminMode: g.AdminMode.ToValid(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/config/valid/global_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ type GlobalCfg struct {
Github Github
RevisionSetter RevisionSetter
Admin Admin
TerraformAdminMode TerraformAdminMode
AdminMode AdminMode
}

type TerraformAdminMode struct {
type AdminMode struct {
Repo string
Root string
}
Expand Down
3 changes: 3 additions & 0 deletions server/legacy/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
Gateway
Worker
TemporalWorker
Admin
)

// UserConfig holds config values passed in by the user.
Expand Down Expand Up @@ -104,6 +105,8 @@ func (u UserConfig) ToLyftMode() Mode {
return Worker
case "temporalworker":
return TemporalWorker
case "admin":
return Admin
}
return Default
}
8 changes: 8 additions & 0 deletions server/legacy/user_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func TestUserConfig_ToLyftMode(t *testing.T) {
"",
server.Default,
},
{
"admin",
server.Admin,
},
{
"temporalworker",
server.TemporalWorker,
},
}

for _, c := range cases {
Expand Down
28 changes: 28 additions & 0 deletions server/neptune/admin/config/adminconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package adminconfig

import (
"github.com/palantir/go-githubapp/githubapp"
"github.com/runatlantis/atlantis/server/config/valid"
"github.com/runatlantis/atlantis/server/logging"
neptune "github.com/runatlantis/atlantis/server/neptune/temporalworker/config"
)

// Config is TerraformAdmin (admin mode) specific user config
type Config struct {
AuthCfg neptune.AuthConfig
ServerCfg neptune.ServerConfig
FeatureConfig neptune.FeatureConfig
TemporalCfg valid.Temporal
GithubCfg valid.Github
TerraformCfg neptune.TerraformConfig
DeploymentConfig valid.StoreConfig
JobConfig valid.StoreConfig
Metrics valid.Metrics

StatsNamespace string

DataDir string
CtxLogger logging.Logger
App githubapp.Config
LyftAuditJobsSnsTopicArn string
smonero marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading