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

Commit

Permalink
Fix #1715: ApplyService#applyProjectRequest should be (truly) idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanKanojia committed Oct 3, 2019
1 parent 724bfae commit c861dca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Feature #1536: Java Image Builder Support
* Fix #1704: fabric8-build failing on openshift
* Feature #1706: Prometheus Enricher; Configuration support for Prometheus path
* Fix #1715: ApplyService#applyProjectRequest should be (truly) idempotent
* Added generator support for Open Liberty

### 4.2.0 (01-08-2019)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

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

public ApplyService(KubernetesClient kubernetesClient, Logger log) {
this.kubernetesClient = kubernetesClient;
Expand Down Expand Up @@ -1071,6 +1075,10 @@ public boolean applyProject(Project project) {
* Returns true if the ProjectRequest is created
*/
public boolean applyProjectRequest(ProjectRequest entity) {
// Check whether project creation attempted before
if (projectsCreated.contains(getName(entity))) {
return false;
}
String namespace = getOrCreateMetadata(entity).getName();
log.info("Using project: " + namespace);
String name = getName(entity);
Expand All @@ -1081,10 +1089,11 @@ public boolean applyProjectRequest(ProjectRequest entity) {
return false;
}
boolean exists = checkNamespace(name);
// We may want to be more fine-grained on the phase of the project
if (!exists) {
try {
Object answer = openshiftClient.projectrequests().create(entity);
// Add project to created projects
projectsCreated.add(name);
logGeneratedEntity("Created ProjectRequest: ", namespace, entity, answer);
return true;
} catch (Exception e) {
Expand Down

0 comments on commit c861dca

Please sign in to comment.