Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak ec2 instance parsing to include more instance types #11724

Merged
merged 4 commits into from Jun 18, 2020

Conversation

wallyworld
Copy link
Member

Description of change

The way we got instance type metadata for ec2 was just wrong.
A symptom was that we failed to know about instance types in some regions, and falsely claimed instance types were available when they were not (for a given user). We also needed to hand craft and build into juju a large map each time a new instance type was available.

This PR uses the EC2 API to query available instance types for the credential in use, and also looks up the cost info as well. This is cached on the provider and reset when the cloud/cred info changes.

Also, bootstrap --build-agent now takes account of GOARCH so we can test custom agent binaries on different arches.

QA steps

The test case covers the issue in the bug (arm64 m6g instance in ap-northeast-1)

$ export GOARCH=arm64
$ juju bootstrap --constraints 'instance-type=m6g.4xlarge arch=arm64' aws/ap-northeast-1 foo --config vpc-id=vpc-44f2eb26 --build-agent
$ juju exec -m controller --machine 0 -- uname -a
Linux ip-172-31-6-199 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux

Bug reference

https://bugs.launchpad.net/juju/+bug/1872670

@@ -0,0 +1,328 @@
// Copyright 2016 Canonical Ltd.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file was renamed from instance_information.go and some methods from the old internal/ec2instancetypes package copied across.
supportedInstanceTypes() and instancetypeCosts() are new

provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
}
for _, info := range instTypeResults.InstanceTypes {
instType := instances.InstanceType{
Name: *info.InstanceType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil check needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InstanceType is never nil

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defensive programming would ignore the assumption and just continue the loop if the value is nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added check here and in other places eg zone names

provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
var token *string
for {
offeringResults, err := ec2Session.DescribeInstanceTypeOfferings(&ec2.DescribeInstanceTypeOfferingsInput{
LocationType: aws.String("availability-zone"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this works for "local-zones" but it should

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filters are OR'ed together so it's fine was my assumption.

provider/ec2/instancetypes.go Outdated Show resolved Hide resolved
}
var zoneNames []string
zoneFilter := &ec2.Filter{Name: aws.String("location")}
for _, z := range zoneResults.AvailabilityZones {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to support local zones like us-west-2-lax-1a or filter them out completely. Or if only local zones support an instance type, mark it as deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we care about the distinction. The only reason we get zone names is so that we can use them to know when to mark an instance as deprecated (terrible name but it precedes this work). If an instance type is not available across all zones (combination of az plus local), then deprecated = true.

Name: *info.InstanceType,
VirtType: virtType(info),
Deprecated: info.CurrentGeneration == nil || !*info.CurrentGeneration,
Cost: costs[*info.InstanceType],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the default cost of 0 treated correctly? We should default unknown costs as max uint64 so they are chosen as a last resort.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other providers default to 0 but then again they don't have costs for anything.
It's hard to know because in my testing, only 2 instance types didn't get a cost, one being t1.nano, and that's a low cost instance so we'd want to select that if possible.
Maybe using max int is ok

@wallyworld
Copy link
Member Author

$$merge$$

@jujubot jujubot merged commit 5620ba4 into juju:2.8 Jun 18, 2020
@SimonRichardson
Copy link
Member

@wallyworld a discourse post/email would be great about this new (great) change

@SimonRichardson
Copy link
Member

Also note #11725 (review)

jujubot added a commit that referenced this pull request Jun 18, 2020
#11725

Merges 2.8 into develop to bring forward:
- #11724 from wallyworld/aws-instancetypes-update
- #11719 from achilleasa/2.8-support-kvm-for-focal-hosts
- #11706 from manadart/2.8-controller-no-set-lld
- #11717 from manadart/2.8-no-clean-shutdown-svc
- #11715 from SimonRichardson/idle-condition
- #11720 from hpidcock/static-link-and-strip
- #11701 from hmlanigan/apply-profile-race
- #11683 from manadart/2.8-instance-poller-lld
- #11700 from SimonRichardson/integration-tests-lxd-profile
- #11711 from wallyworld/schemagen-flags
- #11707 from howbazaar/2.8-core-model-updates
- #11710 from wallyworld/tweak-cmr-tests
- #11705 from wallyworld/merge-2.7-20200612
- #11696 from wallyworld/k8s-dashboard-bootstrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants