Skip to content

Commit

Permalink
Merge pull request #537 from MRamonLeon/JENKINS-60482-just-keep-alt-e…
Browse files Browse the repository at this point in the history
…ndpoint
  • Loading branch information
MRamonLeon authored Nov 24, 2020
2 parents 7f8196c + aea5484 commit 0780e33
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class AmazonEC2Cloud extends EC2Cloud {
*/
private String region;

private String altEC2Endpoint;

public static final String CLOUD_ID_PREFIX = "ec2-";

private boolean noDelayProvisioning;
Expand Down Expand Up @@ -134,6 +136,15 @@ public void setNoDelayProvisioning(boolean noDelayProvisioning) {
this.noDelayProvisioning = noDelayProvisioning;
}

public String getAltEC2Endpoint() {
return altEC2Endpoint;
}

@DataBoundSetter
public void setAltEC2Endpoint(String altEC2Endpoint) {
this.altEC2Endpoint = altEC2Endpoint;
}

@Override
protected AWSCredentialsProvider createCredentialsProvider() {
return createCredentialsProvider(isUseInstanceProfileForCredentials(), getCredentialsId(), getRoleArn(), getRoleSessionName(), getRegion());
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/hudson/plugins/ec2/ConfigurationAsCodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ public void testConfigAsCodeExport() throws Exception {
assertEquals(expected, exported);
}

@Test
@ConfiguredWithCode("UnixData-withAltEndpoint.yml")
public void testConfigAsCodeWithAltEncpointExport() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode clouds = getJenkinsRoot(context).get("clouds");
String exported = toYamlString(clouds);
String expected = toStringFromYamlFile(this, "UnixDataExport-withAltEndpoint.yml");
assertEquals(expected, exported);
}

@Test
@ConfiguredWithCode("Ami.yml")
public void testAmi() throws Exception {
Expand Down
27 changes: 27 additions & 0 deletions src/test/resources/hudson/plugins/ec2/UnixData-withAltEndpoint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
jenkins:
clouds:
- amazonEC2:
altEC2Endpoint: "https.//ec2.us-east-1.amazonaws.com"
cloudName: "production"
region: "eu-central-1"
useInstanceProfileForCredentials: true
sshKeysCredentialsId: "random credentials id"
templates:
- description:
ami: "ami-12345"
labelString: "linux ubuntu"
type: "T2Micro"
remoteFS: "/home/ec2-user"
mode: "NORMAL"
spotConfig:
fallbackToOndemand: true
spotBlockReservationDuration: 3
spotMaxBidPrice: "0.15"
useBidPrice: true
amiType:
unixData:
rootCommandPrefix: "sudo"
slaveCommandPrefix: "sudo -u jenkins"
slaveCommandSuffix: "-fakeFlag"
sshPort: "22"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
- amazonEC2:
altEC2Endpoint: "https.//ec2.us-east-1.amazonaws.com"
cloudName: "production"
region: "eu-central-1"
sshKeysCredentialsId: "random credentials id"
templates:
- ami: "ami-12345"
amiType:
unixData:
rootCommandPrefix: "sudo"
slaveCommandPrefix: "sudo -u jenkins"
slaveCommandSuffix: "-fakeFlag"
sshPort: "22"
associatePublicIp: false
connectBySSHProcess: false
connectionStrategy: PRIVATE_IP
deleteRootOnTermination: false
ebsOptimized: false
hostKeyVerificationStrategy: CHECK_NEW_SOFT
labelString: "linux ubuntu"
maxTotalUses: -1
minimumNumberOfInstances: 0
minimumNumberOfSpareInstances: 0
mode: NORMAL
monitoring: false
numExecutors: 1
remoteFS: "/home/ec2-user"
spotConfig:
fallbackToOndemand: true
spotBlockReservationDuration: 3
spotMaxBidPrice: "0.15"
useBidPrice: true
stopOnTerminate: false
t2Unlimited: false
type: T2Micro
useDedicatedTenancy: false
useEphemeralDevices: false
useInstanceProfileForCredentials: true

0 comments on commit 0780e33

Please sign in to comment.