From ffadd5533ada218b764588412a57e17a9e4ca3c9 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Thu, 26 Mar 2015 12:47:49 -0700 Subject: [PATCH] Fix AWS region vs zone We were specifying a region, but naming it as a zone in util.sh The zone matters just as much as the region, e.g. for EBS volumes. We also change the config to require a Zone, not a Region. But we fallback to get the information from the metadata service. --- cmd/e2e/e2e.go | 2 +- pkg/cloudprovider/aws/aws.go | 19 +++++++------------ pkg/cloudprovider/aws/aws_test.go | 3 +++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index d06daa9165a..c8ed3169579 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -75,7 +75,7 @@ func main() { if *provider == "aws" { awsConfig := "[Global]\n" - awsConfig += fmt.Sprintf("Region=%s\n", *gceZone) + awsConfig += fmt.Sprintf("Zone=%s\n", *gceZone) var err error cloudConfig.Provider, err = cloudprovider.GetCloudProvider(*provider, strings.NewReader(awsConfig)) diff --git a/pkg/cloudprovider/aws/aws.go b/pkg/cloudprovider/aws/aws.go index 645b8dc61a5..dfe75d3d5ad 100644 --- a/pkg/cloudprovider/aws/aws.go +++ b/pkg/cloudprovider/aws/aws.go @@ -43,7 +43,6 @@ type EC2 interface { // Query EC2 for instances matching the filter Instances(instIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error) - // Attach a volume to an instance AttachVolume(volumeId string, instanceId string, mountDevice string) (resp *ec2.AttachVolumeResp, err error) // Detach a volume from whatever instance it is attached to @@ -241,22 +240,18 @@ func newAWSCloud(config io.Reader, authFunc AuthFunc, instanceId string, metadat ec2 := &goamzEC2{ec2: ec2.New(auth, region)} - if instanceId == "" { - instanceIdBytes, err := ec2.GetMetaData("instance-id") - if err != nil { - return nil, fmt.Errorf("error fetching instance-id from ec2 metadata service: %v", err) - } - instanceId = string(instanceIdBytes) - } - awsCloud := &AWSCloud{ - ec2: ec2, - cfg: cfg, + ec2: ec2, + cfg: cfg, region: region, availabilityZone: zone, } - awsCloud.selfAwsInstance = newAwsInstance(ec2, instanceId) + instanceIdBytes, err := metadata.GetMetaData("instance-id") + if err != nil { + return nil, fmt.Errorf("error fetching instance-id from ec2 metadata service: %v", err) + } + awsCloud.selfAwsInstance = newAwsInstance(ec2, string(instanceIdBytes)) return awsCloud, nil } diff --git a/pkg/cloudprovider/aws/aws_test.go b/pkg/cloudprovider/aws/aws_test.go index 8a30ceaad1a..ea93c882daf 100644 --- a/pkg/cloudprovider/aws/aws_test.go +++ b/pkg/cloudprovider/aws/aws_test.go @@ -178,11 +178,14 @@ func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter) type FakeMetadata struct { availabilityZone string + instanceId string } func (self *FakeMetadata) GetMetaData(key string) ([]byte, error) { if key == "placement/availability-zone" { return []byte(self.availabilityZone), nil + } else if key == "instance-id" { + return []byte(self.instanceId), nil } else { return nil, nil }