Skip to content

Commit

Permalink
DEVPROD-3956: add admin settings for persistent DNS names (#7448)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimchelly authored Jan 25, 2024
1 parent d2d0c3b commit 871b5ef
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type AWSConfig struct {
// in S3.
ParserProject ParserProjectS3Config `bson:"parser_project" json:"parser_project" yaml:"parser_project"`

// PersistentDNS is AWS configuration for maintaining persistent DNS names for hosts.
PersistentDNS PersistentDNSConfig `bson:"persistent_dns" json:"persistent_dns" yaml:"persistent_dns"`

DefaultSecurityGroup string `bson:"default_security_group" json:"default_security_group" yaml:"default_security_group"`

AllowedRegions []string `bson:"allowed_regions" json:"allowed_regions" yaml:"allowed_regions"`
Expand Down Expand Up @@ -127,6 +130,16 @@ type ParserProjectS3Config struct {

func (c *ParserProjectS3Config) Validate() error { return nil }

// PersistentDNSConfig is the configuration options to support persistent DNS
// names for hosts.
type PersistentDNSConfig struct {
// HostedZoneID is the ID of the hosted zone in Route 53 where DNS names are
// managed.
HostedZoneID string `bson:"hosted_zone_id" json:"hosted_zone_id" yaml:"hosted_zone_id"`
// Domain is the domain name of persistent DNS names.
Domain string `bson:"domain" json:"domain" yaml:"domain"`
}

// AWSPodConfig represents configuration for using pods backed by AWS.
type AWSPodConfig struct {
// Role is the role to assume to make API calls that manage pods.
Expand Down
4 changes: 4 additions & 0 deletions rest/data/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func (s *AdminDataSuite) TestSetAndGetSettings() {
s.Equal(testSettings.Providers.AWS.ParserProject.Bucket, settingsFromConnector.Providers.AWS.ParserProject.Bucket)
s.Equal(testSettings.Providers.AWS.ParserProject.Prefix, settingsFromConnector.Providers.AWS.ParserProject.Prefix)
s.Equal(testSettings.Providers.AWS.ParserProject.GeneratedJSONPrefix, settingsFromConnector.Providers.AWS.ParserProject.GeneratedJSONPrefix)
s.Equal(testSettings.Providers.AWS.PersistentDNS.HostedZoneID, settingsFromConnector.Providers.AWS.PersistentDNS.HostedZoneID)
s.Equal(testSettings.Providers.AWS.PersistentDNS.Domain, settingsFromConnector.Providers.AWS.PersistentDNS.Domain)
s.EqualValues(testSettings.Providers.Docker.APIVersion, settingsFromConnector.Providers.Docker.APIVersion)
s.EqualValues(testSettings.RepoTracker.MaxConcurrentRequests, settingsFromConnector.RepoTracker.MaxConcurrentRequests)
s.EqualValues(testSettings.Scheduler.TaskFinder, settingsFromConnector.Scheduler.TaskFinder)
Expand Down Expand Up @@ -281,6 +283,8 @@ func (s *AdminDataSuite) TestSetAndGetSettings() {
s.Equal(testSettings.Providers.AWS.ParserProject.Bucket, settingsFromConnector.Providers.AWS.ParserProject.Bucket)
s.Equal(testSettings.Providers.AWS.ParserProject.Prefix, settingsFromConnector.Providers.AWS.ParserProject.Prefix)
s.Equal(testSettings.Providers.AWS.ParserProject.GeneratedJSONPrefix, settingsFromConnector.Providers.AWS.ParserProject.GeneratedJSONPrefix)
s.Equal(testSettings.Providers.AWS.PersistentDNS.HostedZoneID, settingsFromConnector.Providers.AWS.PersistentDNS.HostedZoneID)
s.Equal(testSettings.Providers.AWS.PersistentDNS.Domain, settingsFromConnector.Providers.AWS.PersistentDNS.Domain)
s.EqualValues(testSettings.Providers.Docker.APIVersion, settingsFromConnector.Providers.Docker.APIVersion)
s.EqualValues(testSettings.RepoTracker.MaxConcurrentRequests, settingsFromConnector.RepoTracker.MaxConcurrentRequests)
s.EqualValues(testSettings.Scheduler.TaskFinder, settingsFromConnector.Scheduler.TaskFinder)
Expand Down
48 changes: 48 additions & 0 deletions rest/model/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ type APIAWSConfig struct {
TaskSync *APIS3Credentials `json:"task_sync"`
TaskSyncRead *APIS3Credentials `json:"task_sync_read"`
ParserProject *APIParserProjectS3Config `json:"parser_project"`
PersistentDNS *APIPersistentDNSConfig `json:"persistent_dns"`
DefaultSecurityGroup *string `json:"default_security_group"`
AllowedInstanceTypes []*string `json:"allowed_instance_types"`
AllowedRegions []*string `json:"allowed_regions"`
Expand Down Expand Up @@ -1575,6 +1576,12 @@ func (a *APIAWSConfig) BuildFromService(h interface{}) error {
}
a.ParserProject = parserProject

persistentDNS := &APIPersistentDNSConfig{}
if err := persistentDNS.BuildFromService(v.PersistentDNS); err != nil {
return errors.Wrap(err, "converting persistent DNS config to API model")
}
a.PersistentDNS = persistentDNS

a.DefaultSecurityGroup = utility.ToStringPtr(v.DefaultSecurityGroup)
a.MaxVolumeSizePerUser = &v.MaxVolumeSizePerUser
a.AllowedInstanceTypes = utility.ToStringPtrSlice(v.AllowedInstanceTypes)
Expand Down Expand Up @@ -1654,6 +1661,19 @@ func (a *APIAWSConfig) ToService() (interface{}, error) {
}
config.ParserProject = parserProject

i, err = a.PersistentDNS.ToService()
if err != nil {
return nil, errors.Wrap(err, "converting persistent DNS config to service model")
}
var persistentDNS evergreen.PersistentDNSConfig
if i != nil {
persistentDNS, ok = i.(evergreen.PersistentDNSConfig)
if !ok {
return nil, errors.Errorf("programmatic error: expected parser project S3 config but got type %T", i)
}
}
config.PersistentDNS = persistentDNS

if a.MaxVolumeSizePerUser != nil {
config.MaxVolumeSizePerUser = *a.MaxVolumeSizePerUser
}
Expand Down Expand Up @@ -1760,6 +1780,34 @@ func (a *APIParserProjectS3Config) ToService() (interface{}, error) {
}, nil
}

// APIPersistentDNSConfig represents configuration options for supporting
// persistent DNS names for hosts.
type APIPersistentDNSConfig struct {
HostedZoneID *string `json:"hosted_zone_id"`
Domain *string `json:"domain"`
}

func (a *APIPersistentDNSConfig) BuildFromService(h interface{}) error {
switch v := h.(type) {
case evergreen.PersistentDNSConfig:
a.HostedZoneID = utility.ToStringPtr(v.HostedZoneID)
a.Domain = utility.ToStringPtr(v.Domain)
return nil
default:
return errors.Errorf("programmatic error: expected parser project S3 config but got type %T", h)
}
}

func (a *APIPersistentDNSConfig) ToService() (interface{}, error) {
if a == nil {
return nil, nil
}
return evergreen.PersistentDNSConfig{
HostedZoneID: utility.FromStringPtr(a.HostedZoneID),
Domain: utility.FromStringPtr(a.Domain),
}, nil
}

// APIAWSPodConfig represents configuration options for pods running in AWS.
type APIAWSPodConfig struct {
Role *string `json:"role"`
Expand Down
4 changes: 4 additions & 0 deletions rest/model/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func TestModelConversion(t *testing.T) {
assert.EqualValues(testSettings.Providers.AWS.ParserProject.Bucket, utility.FromStringPtr(apiSettings.Providers.AWS.ParserProject.Bucket))
assert.EqualValues(testSettings.Providers.AWS.ParserProject.Prefix, utility.FromStringPtr(apiSettings.Providers.AWS.ParserProject.Prefix))
assert.EqualValues(testSettings.Providers.AWS.ParserProject.GeneratedJSONPrefix, utility.FromStringPtr(apiSettings.Providers.AWS.ParserProject.GeneratedJSONPrefix))
assert.EqualValues(testSettings.Providers.AWS.PersistentDNS.HostedZoneID, utility.FromStringPtr(apiSettings.Providers.AWS.PersistentDNS.HostedZoneID))
assert.EqualValues(testSettings.Providers.AWS.PersistentDNS.Domain, utility.FromStringPtr(apiSettings.Providers.AWS.PersistentDNS.Domain))
assert.EqualValues(testSettings.Providers.AWS.Pod.Role, utility.FromStringPtr(apiSettings.Providers.AWS.Pod.Role))
assert.EqualValues(testSettings.Providers.AWS.Pod.Region, utility.FromStringPtr(apiSettings.Providers.AWS.Pod.Region))
assert.EqualValues(testSettings.Providers.AWS.Pod.ECS.MaxCPU, utility.FromIntPtr(apiSettings.Providers.AWS.Pod.ECS.MaxCPU))
Expand Down Expand Up @@ -310,6 +312,8 @@ func TestModelConversion(t *testing.T) {
assert.EqualValues(testSettings.Providers.AWS.ParserProject.Bucket, dbSettings.Providers.AWS.ParserProject.Bucket)
assert.EqualValues(testSettings.Providers.AWS.ParserProject.Prefix, dbSettings.Providers.AWS.ParserProject.Prefix)
assert.EqualValues(testSettings.Providers.AWS.ParserProject.GeneratedJSONPrefix, dbSettings.Providers.AWS.ParserProject.GeneratedJSONPrefix)
assert.EqualValues(testSettings.Providers.AWS.PersistentDNS.HostedZoneID, dbSettings.Providers.AWS.PersistentDNS.HostedZoneID)
assert.EqualValues(testSettings.Providers.AWS.PersistentDNS.Domain, dbSettings.Providers.AWS.PersistentDNS.Domain)
assert.EqualValues(testSettings.Providers.Docker.APIVersion, dbSettings.Providers.Docker.APIVersion)
assert.EqualValues(testSettings.RepoTracker.MaxConcurrentRequests, dbSettings.RepoTracker.MaxConcurrentRequests)
assert.EqualValues(testSettings.Scheduler.TaskFinder, dbSettings.Scheduler.TaskFinder)
Expand Down
2 changes: 2 additions & 0 deletions rest/route/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func (s *AdminRouteSuite) TestAdminRoute() {
s.Equal(len(testSettings.Providers.AWS.BinaryClient.Bucket), len(settings.Providers.AWS.BinaryClient.Bucket))
s.Equal(len(testSettings.Providers.AWS.BinaryClient.Key), len(settings.Providers.AWS.BinaryClient.Key))
s.Equal(len(testSettings.Providers.AWS.BinaryClient.Secret), len(settings.Providers.AWS.BinaryClient.Secret))
s.EqualValues(testSettings.Providers.AWS.PersistentDNS.HostedZoneID, settings.Providers.AWS.PersistentDNS.HostedZoneID)
s.EqualValues(testSettings.Providers.AWS.PersistentDNS.Domain, settings.Providers.AWS.PersistentDNS.Domain)
s.EqualValues(testSettings.Providers.Docker.APIVersion, settings.Providers.Docker.APIVersion)
s.EqualValues(testSettings.RepoTracker.MaxConcurrentRequests, settings.RepoTracker.MaxConcurrentRequests)
s.EqualValues(testSettings.Scheduler.TaskFinder, settings.Scheduler.TaskFinder)
Expand Down
8 changes: 8 additions & 0 deletions service/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,14 @@ <h2 class="modal-title">[[modalTitle]]</h2>
<label>Parser Project S3 Prefix</label>
<input type="text" ng-model="Settings.providers.aws.parser_project.prefix">
</md-input-container>
<md-input-container class="control" style="width:45%; margin-left:50px;">
<label>Persistent DNS Hosted Zone ID</label>
<input type="text" ng-model="Settings.providers.aws.persistent_dns.hosted_zone_id">
</md-input-container>
<md-input-container class="control" style="width:45%;">
<label>Persistent DNS Domain Name</label>
<input type="text" ng-model="Settings.providers.aws.persistent_dns.domain">
</md-input-container>
<md-input-container class="control" style="width:45%; margin-left:50px;">
<label>Default Security Group</label>
<input type="text" ng-model="Settings.providers.aws.default_security_group">
Expand Down
4 changes: 4 additions & 0 deletions testutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ func MockConfig() *evergreen.Settings {
},
Prefix: "parser_project_prefix",
},
PersistentDNS: evergreen.PersistentDNSConfig{
HostedZoneID: "hosted_zone_id",
Domain: "example.com",
},
TaskSync: evergreen.S3Credentials{
Key: "task_sync_key",
Secret: "task_sync_secret",
Expand Down

0 comments on commit 871b5ef

Please sign in to comment.