Skip to content

Commit 4a517e4

Browse files
committed
Push with Environment Variables
Previously, when push or pushManifest were used, the contents of environmentVariables in the manifest was ignored. This change updates the code to ensure that environment variables are added or updated during push.
1 parent b5cfaa0 commit 4a517e4

File tree

2 files changed

+155
-67
lines changed

2 files changed

+155
-67
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
import java.util.Map;
119119
import java.util.NoSuchElementException;
120120
import java.util.Optional;
121-
import java.util.concurrent.ThreadLocalRandom;
122121
import java.util.function.BiFunction;
123122
import java.util.function.Predicate;
124123
import java.util.function.UnaryOperator;
@@ -708,9 +707,13 @@ private static Mono<String> getApplicationId(CloudFoundryClient cloudFoundryClie
708707
private static Mono<String> getApplicationId(CloudFoundryClient cloudFoundryClient, ApplicationManifest manifest, String spaceId, String stackId) {
709708
return requestApplications(cloudFoundryClient, manifest.getName(), spaceId)
710709
.singleOrEmpty()
711-
.map(ResourceUtils::getId)
712-
.then(applicationId -> requestUpdateApplication(cloudFoundryClient, applicationId, manifest, stackId)
713-
.map(ResourceUtils::getId))
710+
.then(application -> {
711+
Map<String, Object> environmentJsons = new HashMap<>(ResourceUtils.getEntity(application).getEnvironmentJsons());
712+
environmentJsons.putAll(manifest.getEnvironmentVariables());
713+
714+
return requestUpdateApplication(cloudFoundryClient, ResourceUtils.getId(application), environmentJsons, manifest, stackId)
715+
.map(ResourceUtils::getId);
716+
})
714717
.switchIfEmpty(requestCreateApplication(cloudFoundryClient, manifest, spaceId, stackId)
715718
.map(ResourceUtils::getId));
716719
}
@@ -1143,6 +1146,7 @@ private static Mono<CreateApplicationResponse> requestCreateApplication(CloudFou
11431146
.buildpack(manifest.getBuildpack())
11441147
.command(manifest.getCommand())
11451148
.diskQuota(manifest.getDisk())
1149+
.environmentJsons(manifest.getEnvironmentVariables())
11461150
.healthCheckTimeout(manifest.getTimeout())
11471151
.healthCheckType(Optional.ofNullable(manifest.getHealthCheckType()).map(ApplicationHealthCheck::getValue).orElse(null))
11481152
.instances(manifest.getInstances())
@@ -1385,27 +1389,29 @@ private static Mono<Void> requestTerminateApplicationInstance(CloudFoundryClient
13851389
.build());
13861390
}
13871391

1388-
private static Mono<AbstractApplicationResource> requestUpdateApplication(CloudFoundryClient cloudFoundryClient, String applicationId, ApplicationManifest manifest, String stackId) {
1389-
return requestUpdateApplication(cloudFoundryClient, applicationId,
1390-
builder -> {
1391-
builder
1392-
.buildpack(manifest.getBuildpack())
1393-
.command(manifest.getCommand())
1394-
.diskQuota(manifest.getDisk())
1395-
.healthCheckTimeout(manifest.getTimeout())
1396-
.healthCheckType(Optional.ofNullable(manifest.getHealthCheckType()).map(ApplicationHealthCheck::getValue).orElse(null))
1397-
.instances(manifest.getInstances())
1398-
.memory(manifest.getMemory())
1399-
.name(manifest.getName())
1400-
.stackId(stackId);
1401-
1402-
Optional.ofNullable(manifest.getDockerImage())
1403-
.ifPresent(dockerImage -> builder
1404-
.diego(true)
1405-
.dockerImage(dockerImage));
1406-
1407-
return builder;
1408-
});
1392+
private static Mono<AbstractApplicationResource> requestUpdateApplication(CloudFoundryClient cloudFoundryClient, String applicationId, Map<String, Object> environmentJsons,
1393+
ApplicationManifest manifest, String stackId) {
1394+
1395+
return requestUpdateApplication(cloudFoundryClient, applicationId, builder -> {
1396+
builder
1397+
.buildpack(manifest.getBuildpack())
1398+
.command(manifest.getCommand())
1399+
.diskQuota(manifest.getDisk())
1400+
.environmentJsons(environmentJsons)
1401+
.healthCheckTimeout(manifest.getTimeout())
1402+
.healthCheckType(Optional.ofNullable(manifest.getHealthCheckType()).map(ApplicationHealthCheck::getValue).orElse(null))
1403+
.instances(manifest.getInstances())
1404+
.memory(manifest.getMemory())
1405+
.name(manifest.getName())
1406+
.stackId(stackId);
1407+
1408+
Optional.ofNullable(manifest.getDockerImage())
1409+
.ifPresent(dockerImage -> builder
1410+
.diego(true)
1411+
.dockerImage(dockerImage));
1412+
1413+
return builder;
1414+
});
14091415
}
14101416

14111417
private static Mono<AbstractApplicationResource> requestUpdateApplication(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator<UpdateApplicationRequest.Builder> modifier) {

0 commit comments

Comments
 (0)