jenkinsci / jenkinsci/ec2-plugin
[JENKINS-63433] Instance cap calculation ignores instance profile
- Dominant language
- Java
- Stars
- 292
- Forks
- 709
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 4
Description
We have 2 agent templates that use the same AMI but with a different instance profile.
If I set instance cap = 1 on both agent templates, and there is already one agent active for one of them, then the other agent will fail to start.
The log would loop on
Jul 15, 2020 8:28:57 AM INFO hudson.plugins.ec2.EC2Cloud provision
SlaveTemplate{ami='ami-059e244da7c54c1fe', labels='docker docker-bakery'}. Attempting to provision slave needed by excess workload of 4 units
Jul 15, 2020 8:28:57 AM INFO hudson.plugins.ec2.EC2Cloud getNewOrExistingAvailableSlave
SlaveTemplate{ami='ami-059e244da7c54c1fe', labels='docker docker-bakery'}. Cannot provision - no capacity for instances: 0
Jul 15, 2020 8:28:57 AM WARNING hudson.plugins.ec2.EC2Cloud provision
Can't raise nodes for SlaveTemplate{ami='ami-059e244da7c54c1fe', labels='docker docker-bakery'}
I think the reason is that the query doesn't include instance profile.
Looking for existing instances with describe-instance: {Filters: [{Name: image-id,Values: [ami-059e244da7c54c1fe]}, {Name: instance-type,Values: [t3.micro]}, {Name: key-name,Values: [j4a-ec2-ssh-key]}, {Name: subnet-id,Values: [subnet-0eeb1506910488624]}, {Name: instance.group-id,Values: [sg-092080629f55910cb]}, {Name: tag:Name,Values: [ew1-j4a-jenkins-slave-ec2]}, {Name: tag:jenkins_server_url,Values: [https://example.com/]}, {Name: tag:DeploymentName,Values: [ew1-j4a]}, {Name: tag:Contact,Values: [example@example.com]}, {Name: tag:DeploymentType,Values: [dev]}, {Name: tag:DeploymentGroup,Values: [ew1-j4a]}, {Name: tag:CostCenter,Values: [31505007]}, {Name: tag:jenkins_slave_type,Values: [demand_ec2 (ami-059e244da7c54c1fe)]}],InstanceIds: [],}
I was able to work around the issue by adding a tag with the same value as instance profile.
---
Originally reported by jbochenski, imported from: Instance cap calculation ignores instance profile
Raw content of original issue
We have 2 agent templates that use the same AMI but with a different instance profile.
If I set instance cap = 1 on both agent templates, and there is already one agent active for one of them, then the other agent will fail to start.
The log would loop on
Jul 15, 2020 8:28:57 AM INFO hudson.plugins.ec2.EC2Cloud provision
SlaveTemplate{ami='ami-059e244da7c54c1fe', labels='docker docker-bakery'}. Attempting to provision slave needed by excess workload of 4 units
Jul 15, 2020 8:28:57 AM INFO hudson.plugins.ec2.EC2Cloud getNewOrExistingAvailableSlave
SlaveTemplate{ami='ami-059e244da7c54c1fe', labels='docker docker-bakery'}. Cannot provision - no capacity for instances: 0
Jul 15, 2020 8:28:57 AM WARNING hudson.plugins.ec2.EC2Cloud provision
Can't raise nodes for SlaveTemplate{ami='ami-059e244da7c54c1fe', labels='docker docker-bakery'}I think the reason is that the query doesn't include instance profile.
Looking for existing instances with describe-instance: {Filters: [{Name: image-id,Values: [ami-059e244da7c54c1fe]}, {Name: instance-type,Values: [t3.micro]}, {Name: key-name,Values: [j4a-ec2-ssh-key]}, {Name: subnet-id,Values: [subnet-0eeb1506910488624]}, {Name: instance.group-id,Values: [sg-092080629f55910cb]}, {Name: tag:Name,Values: [ew1-j4a-jenkins-slave-ec2]}, {Name: tag:jenkins_server_url,Values: [https://example.com/]}, {Name: tag:DeploymentName,Values: [ew1-j4a]}, {Name: tag:Contact,Values: [example@example.com]}, {Name: tag:DeploymentType,Values: [dev]}, {Name: tag:DeploymentGroup,Values: [ew1-j4a]}, {Name: tag:CostCenter,Values: [31505007]}, {Name: tag:jenkins_slave_type,Values: [demand_ec2 (ami-059e244da7c54c1fe)]}],InstanceIds: [],}I was able to work around the issue by adding a tag with the same value as instance profile.
environment
```
Jenkins 2.235.4
ec2-plugin 1.51
```
Contributor guide
Research direction
Start in EC2Cloud.provision and getNewOrExistingAvailableSlave, then trace the describe-instance filters shown in the report. Verify how instance profiles are represented for the two agent templates and how they affect instance-cap counting. Done means templates sharing an AMI but using different instance profiles no longer block each other when each cap is one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, java
- Domain
- cloud, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100