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

[JENKINS-60482] Persist the alternate ec2 endpoint #537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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