AWS: Don't store the AZ on the cloud

Now we have Ubernetes-Lite, an AWSCloud can span multiple AZs.
This commit is contained in:
Justin Santa Barbara 2016-02-27 10:20:10 -05:00
parent ddb5072a54
commit 8c492c7536

View File

@ -199,7 +199,6 @@ type AWSCloud struct {
asg ASG asg ASG
metadata EC2Metadata metadata EC2Metadata
cfg *AWSCloudConfig cfg *AWSCloudConfig
availabilityZone string
region string region string
vpcID string vpcID string
@ -632,7 +631,6 @@ func newAWSCloud(config io.Reader, awsServices AWSServices) (*AWSCloud, error) {
metadata: metadata, metadata: metadata,
cfg: cfg, cfg: cfg,
region: regionName, region: regionName,
availabilityZone: zone,
} }
selfAWSInstance, err := awsCloud.buildSelfAWSInstance() selfAWSInstance, err := awsCloud.buildSelfAWSInstance()
@ -879,10 +877,11 @@ func (aws *AWSCloud) List(filter string) ([]string, error) {
} }
// GetZone implements Zones.GetZone // GetZone implements Zones.GetZone
func (self *AWSCloud) GetZone() (cloudprovider.Zone, error) { func (c *AWSCloud) GetZone() (cloudprovider.Zone, error) {
i := c.getSelfAWSInstance()
return cloudprovider.Zone{ return cloudprovider.Zone{
FailureDomain: self.availabilityZone, FailureDomain: i.availabilityZone,
Region: self.region, Region: c.region,
}, nil }, nil
} }
@ -1099,13 +1098,11 @@ type awsDisk struct {
name string name string
// id in AWS // id in AWS
awsID string awsID string
// az which holds the volume
az string
} }
func newAWSDisk(aws *AWSCloud, name string) (*awsDisk, error) { func newAWSDisk(aws *AWSCloud, name string) (*awsDisk, error) {
if !strings.HasPrefix(name, "aws://") { if !strings.HasPrefix(name, "aws://") {
name = "aws://" + aws.availabilityZone + "/" + name name = "aws://" + "" + "/" + name
} }
// name looks like aws://availability-zone/id // name looks like aws://availability-zone/id
url, err := url.Parse(name) url, err := url.Parse(name)
@ -1126,14 +1123,9 @@ func newAWSDisk(aws *AWSCloud, name string) (*awsDisk, error) {
if strings.Contains(awsID, "/") || !strings.HasPrefix(awsID, "vol-") { if strings.Contains(awsID, "/") || !strings.HasPrefix(awsID, "vol-") {
return nil, fmt.Errorf("Invalid format for AWS volume (%s)", name) return nil, fmt.Errorf("Invalid format for AWS volume (%s)", name)
} }
az := url.Host // az := url.Host
// TODO: Better validation? // TODO: Validate AZ?
// TODO: Default to our AZ? Look it up? disk := &awsDisk{ec2: aws.ec2, name: name, awsID: awsID}
// TODO: Should this be a region or an AZ?
if az == "" {
return nil, fmt.Errorf("Invalid format for AWS volume (%s)", name)
}
disk := &awsDisk{ec2: aws.ec2, name: name, awsID: awsID, az: az}
return disk, nil return disk, nil
} }
@ -1393,10 +1385,13 @@ func (aws *AWSCloud) DetachDisk(diskName string, instanceName string) (string, e
// Implements Volumes.CreateVolume // Implements Volumes.CreateVolume
func (s *AWSCloud) CreateDisk(volumeOptions *VolumeOptions) (string, error) { func (s *AWSCloud) CreateDisk(volumeOptions *VolumeOptions) (string, error) {
// TODO: Should we tag this with the cluster id (so it gets deleted when the cluster does?) // Default to creating in the current zone
// TODO: Spread across zones?
selfInstance := s.getSelfAWSInstance()
// TODO: Should we tag this with the cluster id (so it gets deleted when the cluster does?)
request := &ec2.CreateVolumeInput{} request := &ec2.CreateVolumeInput{}
request.AvailabilityZone = &s.availabilityZone request.AvailabilityZone = &selfInstance.availabilityZone
volSize := int64(volumeOptions.CapacityGB) volSize := int64(volumeOptions.CapacityGB)
request.Size = &volSize request.Size = &volSize
request.VolumeType = aws.String(DefaultVolumeType) request.VolumeType = aws.String(DefaultVolumeType)
@ -1426,8 +1421,8 @@ func (s *AWSCloud) CreateDisk(volumeOptions *VolumeOptions) (string, error) {
} }
// Implements Volumes.DeleteDisk // Implements Volumes.DeleteDisk
func (aws *AWSCloud) DeleteDisk(volumeName string) (bool, error) { func (c *AWSCloud) DeleteDisk(volumeName string) (bool, error) {
awsDisk, err := newAWSDisk(aws, volumeName) awsDisk, err := newAWSDisk(c, volumeName)
if err != nil { if err != nil {
return false, err return false, err
} }