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

Fix #1715: ApplyService#applyProjectRequest should be (truly) idempotent #1717

Merged
merged 1 commit into from
Oct 4, 2019
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
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