Skip to content

Commit

Permalink
deprecate Spot config field in favour of string VMProvisioningType
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Jones committed Mar 27, 2019
1 parent 58f4e99 commit dcfe4d6
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 84 deletions.
2 changes: 1 addition & 1 deletion bosh/aws_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (client *AWSClient) Delete(stateFileBytes []byte) ([]byte, error) {
DBUsername: client.config.GetRDSUsername(),
S3AWSAccessKeyID: blobstoreUserAccessKeyID,
S3AWSSecretAccessKey: blobstoreSecretAccessKey,
Spot: client.config.GetSpot(),
Spot: client.config.IsSpot(),
}, client.config.GetDirectorPassword(), client.config.GetDirectorCert(), client.config.GetDirectorKey(), client.config.GetDirectorCACert(), nil)
return store["state.json"], err
}
4 changes: 2 additions & 2 deletions bosh/aws_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (client *AWSClient) createEnv(bosh boshcli.ICLI, state, creds []byte, custo
DBUsername: client.config.GetRDSUsername(),
S3AWSAccessKeyID: blobstoreUserAccessKeyID,
S3AWSSecretAccessKey: blobstoreSecretAccessKey,
Spot: client.config.GetSpot(),
Spot: client.config.IsSpot(),
WorkerType: client.config.GetWorkerType(),
CustomOperations: customOps,
}, client.config.GetDirectorPassword(), client.config.GetDirectorCert(), client.config.GetDirectorKey(), client.config.GetDirectorCACert(), tags)
Expand Down Expand Up @@ -246,7 +246,7 @@ func (client *AWSClient) updateCloudConfig(bosh boshcli.ICLI) error {
PrivateSubnetID: privateSubnetID,
ATCSecurityGroup: aTCSecurityGroupID,
VMSecurityGroup: vMsSecurityGroupID,
Spot: client.config.GetSpot(),
Spot: client.config.IsSpot(),
ExternalIP: directorPublicIP,
WorkerType: client.config.GetWorkerType(),
PublicCIDR: publicCIDR,
Expand Down
2 changes: 1 addition & 1 deletion bosh/gcp_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (client *GCPClient) Delete(stateFileBytes []byte) ([]byte, error) {
ProjectID: project,
PublicKey: client.config.GetPublicKey(),
PublicSubnetwork: publicSubnetwork,
Spot: client.config.GetSpot(),
Spot: client.config.IsSpot(),
Zone: client.provider.Zone(""),
}, client.config.GetDirectorPassword(), client.config.GetDirectorCert(), client.config.GetDirectorKey(), client.config.GetDirectorCACert(), nil)
return store["state.json"], err
Expand Down
4 changes: 2 additions & 2 deletions bosh/gcp_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (client *GCPClient) createEnv(bosh boshcli.ICLI, state, creds []byte, custo
ProjectID: project,
GcpCredentialsJSON: credentialsPath,
ExternalIP: directorPublicIP,
Spot: client.config.GetSpot(),
Spot: client.config.IsSpot(),
PublicKey: client.config.GetPublicKey(),
CustomOperations: customOps,
}, client.config.GetDirectorPassword(), client.config.GetDirectorCert(), client.config.GetDirectorKey(), client.config.GetDirectorCACert(), tags)
Expand Down Expand Up @@ -203,7 +203,7 @@ func (client *GCPClient) updateCloudConfig(bosh boshcli.ICLI) error {
PrivateCIDRGateway: privateCIDRGateway,
PrivateCIDRReserved: privateCIDRReserved,
PrivateCIDR: client.config.GetPrivateCIDR(),
Spot: client.config.GetSpot(),
Spot: client.config.IsSpot(),
PublicSubnetwork: publicSubnetwork,
PrivateSubnetwork: privateSubnetwork,
Zone: zone,
Expand Down
5 changes: 3 additions & 2 deletions concourse/client_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ sWbB3FCIsym1FXB+eRnVF3Y15RwBWWKA5RfwUNpEXFxtv24tQ8jrdA==
RDSPassword: "s3cret",
RDSUsername: "admin",
Region: "eu-west-1",
Spot: true,
TFStatePath: "example-path",
//These come from fixtures/director-creds.yml
CredhubUsername: "credhub-cli",
Expand Down Expand Up @@ -503,9 +504,9 @@ wEW5QkylaPEkbVDhJWeR1I8=
configAfterLoad.RDS2CIDR = "10.0.5.0/24"
configAfterLoad.RDSInstanceClass = "db.t2.4xlarge"
configAfterLoad.SourceAccessIP = "192.0.2.0"
configAfterLoad.Spot = false
configAfterLoad.Tags = args.Tags
configAfterLoad.WorkerType = args.WorkerType
configAfterLoad.VMProvisioningType = config.ON_DEMAND

terraformInputVars = &terraform.AWSInputVars{
AllowIPs: configAfterLoad.AllowIPs,
Expand Down Expand Up @@ -620,9 +621,9 @@ wEW5QkylaPEkbVDhJWeR1I8=
RDSUsername: "admingeneratedPassword7",
Region: "eu-west-1",
SourceAccessIP: "192.0.2.0",
Spot: true,
TFStatePath: "terraform.tfstate",
WorkerType: "m4",
VMProvisioningType: config.SPOT,
}

//Mutations we expect to have been done after load
Expand Down
6 changes: 3 additions & 3 deletions concourse/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func populateConfigWithDefaults(conf config.Config, provider iaas.Provider, pass
conf.PublicKey = strings.TrimSpace(string(publicKey))
conf.RDSPassword = passwordGenerator(defaultPasswordLength)
conf.RDSUsername = "admin" + passwordGenerator(7)
conf.Spot = true
conf.VMProvisioningType = config.SPOT
conf = populateConfigWithDefaultCIDRs(conf, provider)

return conf, nil
Expand Down Expand Up @@ -150,8 +150,8 @@ func populateConfigWithDefaultsOrProvidedArguments(conf config.Config, newConfig
if deployArgs.TagsIsSet {
conf.Tags = deployArgs.Tags
}
if newConfigCreated || deployArgs.SpotIsSet {
conf.Spot = deployArgs.Spot
if deployArgs.SpotIsSet {
conf.VMProvisioningType = config.ConvertSpotBoolToVMProvisioningType(deployArgs.Spot)
}
if newConfigCreated || deployArgs.WorkerTypeIsSet {
conf.WorkerType = deployArgs.WorkerType
Expand Down
11 changes: 11 additions & 0 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (client *Client) Load() (Config, error) {
return Config{}, err
}

conf = populateMandatoryFieldsAddedSinceLastSave(conf)

return conf, nil
}

Expand Down Expand Up @@ -186,3 +188,12 @@ func determineNamespace(namespace, region string) string {
}
return namespace
}

// Allow new mandatory fields to be populated based on old fields that are now deprecated
func populateMandatoryFieldsAddedSinceLastSave(oldConf Config) Config {
if oldConf.VMProvisioningType == "" {
oldConf.VMProvisioningType = ConvertSpotBoolToVMProvisioningType(oldConf.Spot)
}

return oldConf
}
31 changes: 18 additions & 13 deletions config/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,44 @@ var _ = Describe("Client", func() {
})
})

Describe("EnsureBucketExists", func(){
Describe("EnsureBucketExists", func() {
BeforeEach(func() {
provider = &iaasfakes.FakeProvider{}
provider.RegionReturns("eu-west-1")
client = New(provider, "test", "")
})

Context("when the bucket exists", func(){
JustBeforeEach(func(){
Context("when the bucket exists", func() {
JustBeforeEach(func() {
provider.BucketExistsReturns(false, nil)
})

It("no-ops and returns no error", func(){
It("no-ops and returns no error", func() {
err := client.EnsureBucketExists()
Expect(err).ToNot(HaveOccurred())
})
})

Context("when the bucket does not exist", func(){
JustBeforeEach(func(){
Context("when the bucket does not exist", func() {
JustBeforeEach(func() {
provider.BucketExistsReturns(false, nil)
provider.CreateBucketReturns(nil)
})

It("creates it", func(){
It("creates it", func() {
err := client.EnsureBucketExists()
Expect(err).ToNot(HaveOccurred())
// Will be 1 once we remove invocation from New()
Expect(provider.CreateBucketCallCount()).To(Equal(1))
})

Context("and it cannot be created", func(){
JustBeforeEach(func(){
Context("and it cannot be created", func() {
JustBeforeEach(func() {
provider.BucketExistsReturns(false, nil)
provider.CreateBucketReturns(fmt.Errorf("SOME IAAS ERROR"))
})

It("returns a useful error message", func(){
It("returns a useful error message", func() {
err := client.EnsureBucketExists()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("error creating config bucket [control-tower-test-eu-west-1-config]: [SOME IAAS ERROR]"))
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestClient_Load(t *testing.T) {
return defaultContents, true, nil
}
provider.LoadFileStub = func(bucket, path string) ([]byte, error) {
bytes, _ := json.Marshal(Config{})
bytes, _ := json.Marshal(Config{Spot: true})
return bytes, nil
}

Expand Down Expand Up @@ -265,7 +265,10 @@ func TestClient_Load(t *testing.T) {
BucketError: nil,
}
},
want: Config{},
want: Config{
Spot: true,
VMProvisioningType: SPOT,
},
wantErr: false,
},
}
Expand Down Expand Up @@ -330,7 +333,9 @@ func TestClient_HasConfig(t *testing.T) {
BucketError: nil,
}
},
want: Config{},
want: Config{
VMProvisioningType: ON_DEMAND,
},
wantErr: false,
},
}
Expand Down
133 changes: 73 additions & 60 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,62 +1,75 @@
package config

const SPOT = "spot"
const ON_DEMAND = "on-demand"

func ConvertSpotBoolToVMProvisioningType(spot bool) string {
if spot {
return SPOT
} else {
return ON_DEMAND
}
}

// Config represents a control-tower configuration file
type Config struct {
AllowIPs string `json:"allow_ips"`
AvailabilityZone string `json:"availability_zone"`
ConcourseCACert string `json:"concourse_ca_cert"`
ConcourseCert string `json:"concourse_cert"`
ConcourseKey string `json:"concourse_key"`
ConcoursePassword string `json:"concourse_password"`
ConcourseUsername string `json:"concourse_username"`
ConcourseWebSize string `json:"concourse_web_size"`
ConcourseWorkerCount int `json:"concourse_worker_count"`
ConcourseWorkerSize string `json:"concourse_worker_size"`
ConfigBucket string `json:"config_bucket"`
CredhubAdminClientSecret string `json:"credhub_admin_client_secret"`
CredhubCACert string `json:"credhub_ca_cert"`
CredhubPassword string `json:"credhub_password"`
CredhubURL string `json:"credhub_url"`
CredhubUsername string `json:"credhub_username"`
Deployment string `json:"deployment"`
DirectorCACert string `json:"director_ca_cert"`
DirectorCert string `json:"director_cert"`
DirectorHMUserPassword string `json:"director_hm_user_password"`
DirectorKey string `json:"director_key"`
DirectorMbusPassword string `json:"director_mbus_password"`
DirectorNATSPassword string `json:"director_nats_password"`
DirectorPassword string `json:"director_password"`
DirectorPublicIP string `json:"director_public_ip"`
DirectorRegistryPassword string `json:"director_registry_password"`
DirectorUsername string `json:"director_username"`
Domain string `json:"domain"`
EncryptionKey string `json:"encryption_key"`
GithubClientID string `json:"github_client_id"`
GithubClientSecret string `json:"github_client_secret"`
GrafanaPassword string `json:"grafana_password"`
HostedZoneID string `json:"hosted_zone_id"`
HostedZoneRecordPrefix string `json:"hosted_zone_record_prefix"`
IAAS string `json:"iaas"`
Namespace string `json:"namespace"`
NetworkCIDR string `json:"network_cidr"`
PrivateCIDR string `json:"private_cidr"`
PrivateKey string `json:"private_key"`
Project string `json:"project"`
PublicCIDR string `json:"public_cidr"`
PublicKey string `json:"public_key"`
RDS1CIDR string `json:"rds1_cidr"`
RDS2CIDR string `json:"rds2_cidr"`
RDSDefaultDatabaseName string `json:"rds_default_database_name"`
RDSInstanceClass string `json:"rds_instance_class"`
RDSPassword string `json:"rds_password"`
RDSUsername string `json:"rds_username"`
Region string `json:"region"`
SourceAccessIP string `json:"source_access_ip"`
Spot bool `json:"spot"`
Tags []string `json:"tags"`
TFStatePath string `json:"tf_state_path"`
Version string `json:"version"`
WorkerType string `json:"worker_type"`
AllowIPs string `json:"allow_ips"`
AvailabilityZone string `json:"availability_zone"`
ConcourseCACert string `json:"concourse_ca_cert"`
ConcourseCert string `json:"concourse_cert"`
ConcourseKey string `json:"concourse_key"`
ConcoursePassword string `json:"concourse_password"`
ConcourseUsername string `json:"concourse_username"`
ConcourseWebSize string `json:"concourse_web_size"`
ConcourseWorkerCount int `json:"concourse_worker_count"`
ConcourseWorkerSize string `json:"concourse_worker_size"`
ConfigBucket string `json:"config_bucket"`
CredhubAdminClientSecret string `json:"credhub_admin_client_secret"`
CredhubCACert string `json:"credhub_ca_cert"`
CredhubPassword string `json:"credhub_password"`
CredhubURL string `json:"credhub_url"`
CredhubUsername string `json:"credhub_username"`
Deployment string `json:"deployment"`
DirectorCACert string `json:"director_ca_cert"`
DirectorCert string `json:"director_cert"`
DirectorHMUserPassword string `json:"director_hm_user_password"`
DirectorKey string `json:"director_key"`
DirectorMbusPassword string `json:"director_mbus_password"`
DirectorNATSPassword string `json:"director_nats_password"`
DirectorPassword string `json:"director_password"`
DirectorPublicIP string `json:"director_public_ip"`
DirectorRegistryPassword string `json:"director_registry_password"`
DirectorUsername string `json:"director_username"`
Domain string `json:"domain"`
EncryptionKey string `json:"encryption_key"`
GithubClientID string `json:"github_client_id"`
GithubClientSecret string `json:"github_client_secret"`
GrafanaPassword string `json:"grafana_password"`
HostedZoneID string `json:"hosted_zone_id"`
HostedZoneRecordPrefix string `json:"hosted_zone_record_prefix"`
IAAS string `json:"iaas"`
Namespace string `json:"namespace"`
NetworkCIDR string `json:"network_cidr"`
PrivateCIDR string `json:"private_cidr"`
PrivateKey string `json:"private_key"`
Project string `json:"project"`
PublicCIDR string `json:"public_cidr"`
PublicKey string `json:"public_key"`
RDS1CIDR string `json:"rds1_cidr"`
RDS2CIDR string `json:"rds2_cidr"`
RDSDefaultDatabaseName string `json:"rds_default_database_name"`
RDSInstanceClass string `json:"rds_instance_class"`
RDSPassword string `json:"rds_password"`
RDSUsername string `json:"rds_username"`
Region string `json:"region"`
SourceAccessIP string `json:"source_access_ip"`
//Spot is deprecated, exists only as we need to migrate old configs to VMProvisioningType
Spot bool `json:"spot"`
Tags []string `json:"tags"`
TFStatePath string `json:"tf_state_path"`
Version string `json:"version"`
VMProvisioningType string `json:vm_provisioning_type`
WorkerType string `json:"worker_type"`
}

type ConfigView interface {
Expand Down Expand Up @@ -110,12 +123,12 @@ type ConfigView interface {
GetRDSUsername() string
GetRegion() string
GetSourceAccessIP() string
GetSpot() bool
GetTags() []string
GetTFStatePath() string
GetVersion() string
GetWorkerType() string
IsGithubAuthSet() bool
IsSpot() bool
}

func (c Config) GetAllowIPs() string {
Expand Down Expand Up @@ -318,10 +331,6 @@ func (c Config) GetSourceAccessIP() string {
return c.SourceAccessIP
}

func (c Config) GetSpot() bool {
return c.Spot
}

func (c Config) GetTags() []string {
return c.Tags
}
Expand All @@ -341,3 +350,7 @@ func (c Config) GetWorkerType() string {
func (c Config) IsGithubAuthSet() bool {
return c.GithubClientID != "" && c.GithubClientSecret != ""
}

func (c Config) IsSpot() bool {
return c.Spot
}

0 comments on commit dcfe4d6

Please sign in to comment.