mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
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.
This commit is contained in:
@@ -75,7 +75,7 @@ func main() {
|
|||||||
|
|
||||||
if *provider == "aws" {
|
if *provider == "aws" {
|
||||||
awsConfig := "[Global]\n"
|
awsConfig := "[Global]\n"
|
||||||
awsConfig += fmt.Sprintf("Region=%s\n", *gceZone)
|
awsConfig += fmt.Sprintf("Zone=%s\n", *gceZone)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
cloudConfig.Provider, err = cloudprovider.GetCloudProvider(*provider, strings.NewReader(awsConfig))
|
cloudConfig.Provider, err = cloudprovider.GetCloudProvider(*provider, strings.NewReader(awsConfig))
|
||||||
|
@@ -43,7 +43,6 @@ type EC2 interface {
|
|||||||
// Query EC2 for instances matching the filter
|
// Query EC2 for instances matching the filter
|
||||||
Instances(instIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error)
|
Instances(instIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error)
|
||||||
|
|
||||||
|
|
||||||
// Attach a volume to an instance
|
// Attach a volume to an instance
|
||||||
AttachVolume(volumeId string, instanceId string, mountDevice string) (resp *ec2.AttachVolumeResp, err error)
|
AttachVolume(volumeId string, instanceId string, mountDevice string) (resp *ec2.AttachVolumeResp, err error)
|
||||||
// Detach a volume from whatever instance it is attached to
|
// 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)}
|
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{
|
awsCloud := &AWSCloud{
|
||||||
ec2: ec2,
|
ec2: ec2,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
region: region,
|
region: region,
|
||||||
availabilityZone: zone,
|
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
|
return awsCloud, nil
|
||||||
}
|
}
|
||||||
|
@@ -178,11 +178,14 @@ func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter)
|
|||||||
|
|
||||||
type FakeMetadata struct {
|
type FakeMetadata struct {
|
||||||
availabilityZone string
|
availabilityZone string
|
||||||
|
instanceId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FakeMetadata) GetMetaData(key string) ([]byte, error) {
|
func (self *FakeMetadata) GetMetaData(key string) ([]byte, error) {
|
||||||
if key == "placement/availability-zone" {
|
if key == "placement/availability-zone" {
|
||||||
return []byte(self.availabilityZone), nil
|
return []byte(self.availabilityZone), nil
|
||||||
|
} else if key == "instance-id" {
|
||||||
|
return []byte(self.instanceId), nil
|
||||||
} else {
|
} else {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user