Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 56d96f5

Browse files
committed
Fix #1715: ApplyService#applyProjectRequest should be (truly) idempotent
1 parent c1278ab commit 56d96f5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
2424
* Fix #1704: fabric8-build failing on openshift
2525
* Fix #1714: resource-goal converts types of kubernetes YAML annotations in fragment
2626
* Feature #1706: Prometheus Enricher; Configuration support for Prometheus path
27+
* Fix #1715: ApplyService#applyProjectRequest should be (truly) idempotent
2728
* Added generator support for Open Liberty
2829

2930
### 4.2.0 (01-08-2019)

core/src/main/java/io/fabric8/maven/core/service/ApplyService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@
7070
import java.net.HttpURLConnection;
7171
import java.nio.charset.Charset;
7272
import java.util.ArrayList;
73+
import java.util.HashSet;
7374
import java.util.List;
7475
import java.util.Map;
7576
import java.util.Objects;
77+
import java.util.Set;
7678

7779
import static io.fabric8.maven.core.util.kubernetes.KubernetesHelper.getKind;
7880
import static io.fabric8.maven.core.util.kubernetes.KubernetesHelper.getName;
@@ -102,6 +104,8 @@ public class ApplyService {
102104
private boolean rollingUpgradePreserveScale = true;
103105
private boolean recreateMode;
104106
private PatchService patchService;
107+
// This map is to track projects created.
108+
private static Set<String> projectsCreated = new HashSet<>();
105109

106110
public ApplyService(KubernetesClient kubernetesClient, Logger log) {
107111
this.kubernetesClient = kubernetesClient;
@@ -1090,6 +1094,10 @@ public boolean applyProject(Project project) {
10901094
* Returns true if the ProjectRequest is created
10911095
*/
10921096
public boolean applyProjectRequest(ProjectRequest entity) {
1097+
// Check whether project creation attempted before
1098+
if (projectsCreated.contains(getName(entity))) {
1099+
return false;
1100+
}
10931101
String namespace = getOrCreateMetadata(entity).getName();
10941102
log.info("Using project: " + namespace);
10951103
String name = getName(entity);
@@ -1100,10 +1108,11 @@ public boolean applyProjectRequest(ProjectRequest entity) {
11001108
return false;
11011109
}
11021110
boolean exists = checkNamespace(name);
1103-
// We may want to be more fine-grained on the phase of the project
11041111
if (!exists) {
11051112
try {
11061113
Object answer = openshiftClient.projectrequests().create(entity);
1114+
// Add project to created projects
1115+
projectsCreated.add(name);
11071116
logGeneratedEntity("Created ProjectRequest: ", namespace, entity, answer);
11081117
return true;
11091118
} catch (Exception e) {

0 commit comments

Comments
 (0)