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

Add life-cycle labels to nodes #2615

Merged
merged 7 commits into from
Sep 7, 2020

Conversation

vaibhav-random
Copy link
Contributor

@vaibhav-random vaibhav-random commented Sep 3, 2020

closes #2614

Description

Added a default label to indicate if a node's life cycle is on demand or spot

Checklist

  • [+] Added tests that cover your change (if possible)
  • [+] Added/modified documentation as required (such as the README.md, or the userdocs directory)
  • [+] Manually tested
  • Added labels for change area (e.g. area/nodegroup), target version (e.g. version/0.12.0) and kind (e.g. kind/improvement)
  • Make sure the title of the PR is a good description that can go into the release notes

@vaibhav-random
Copy link
Contributor Author

kind/improvement

@@ -27,6 +27,13 @@ AWS_SERVICES_DOMAIN="$(get_metadata services/domain)"

source /etc/eksctl/kubelet.env # this can override MAX_PODS

INSTANCE_LIFECYCLE=$(aws ec2 describe-instances --instance-ids ${INSTANCE_ID} --query 'Reservations[0].Instances[0].InstanceLifecycle' --output text)
Copy link
Contributor

Choose a reason for hiding this comment

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

We are trying to avoid adding extra dependencies to the bootstrap scripts. Please use the get_metadata function with instance-life-cycle instead of the aws cli.

Copy link
Contributor

@martina-if martina-if left a comment

Choose a reason for hiding this comment

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

Hi @vaibhav-random , thank you for this PR, it's a good idea. The implementation needs a small change.

Also, could you add the same to the ubuntu script, please? We are trying to keep feature parity between them.

@vaibhav-random
Copy link
Contributor Author

@martina-if Thanks for the review, made the changes. Can you please check now

@@ -27,6 +27,14 @@ AWS_SERVICES_DOMAIN="$(get_metadata services/domain)"

source /etc/eksctl/kubelet.env # this can override MAX_PODS

INSTANCE_LIFECYCLE="$(get_metadata instance-life-cycle | grep 'spot')"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious, why the grep?

I think this would be simpler if we:

  • assigned "$(get_metadata instance-life-cycle)" to INSTANCE_LIFECYCLE
  • added its value directly to the NODE_LABELS if it is not empty

So I would remove the grep and only check that it's not empty before adding it to the labels. Although I doubt that it will produce an empty string 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the endpoint instance-life-cycle is available only on spot instances. For on demand instances the endpoint doesn't exist - will return a 404

Copy link
Contributor

Choose a reason for hiding this comment

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

The endpoint does exist for all instances :) And it returns on-demand:

$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \
> && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-life-cycle
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    56  100    56    0     0  56000      0 --:--:-- --:--:-- --:--:-- 56000
*   Trying 169.254.169.254...
* TCP_NODELAY set
* Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta-data/instance-life-cycle HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/7.61.1
> Accept: */*
> X-aws-ec2-metadata-token: AQAEAITQryp2rkEswx7rHzA4nAXSk3DsOaKVl2YNWfhAlNUejvsK0w==
> 
< HTTP/1.1 200 OK
< X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600
< Content-Type: text/plain
< Accept-Ranges: none
< Last-Modified: Mon, 07 Sep 2020 05:28:37 GMT
< Content-Length: 9
< Date: Mon, 07 Sep 2020 06:02:05 GMT
< Server: EC2ws
< Connection: close
< 
* Closing connection 0
on-demand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. This was added to on demand instances also beginning IMDSv2. Made the changes

@martina-if
Copy link
Contributor

Hi @vaibhav-random thanks for the changes, I added another comment. Can you also tell us if you manually tested the changes for both AL2 and Ubuntu?

@vaibhav-random
Copy link
Contributor Author

@martina-if Hey! yeah, I've manually tested the changes both the places

@vaibhav-random
Copy link
Contributor Author

@martina-if did the changes, please check now

@martina-if martina-if changed the title Add default labels based on instance life cycle Add life-cycle labels to nodes Sep 7, 2020
@weaveworksbot weaveworksbot merged commit 9c4d51c into eksctl-io:master Sep 7, 2020
@martina-if
Copy link
Contributor

@martina-if did the changes, please check now

@vaibhav-random I tried it but I didn't get the label set and I think this PR missed a step to get it working. Can you explain how you tested it? I can't seem to get it working...

@vaibhav-random
Copy link
Contributor Author

@martina-if oops! my bad, I tested it locally by overriding the bootstrap script, but did not check in a piece. I corrected it here - #2623 Can you please review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create additional label of instance life-cycle
3 participants