Skip to content

Commit

Permalink
ApplyService#applyProjectRequest should be (truly) idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanKanojia committed Nov 29, 2019
1 parent 04423e8 commit 105bba5
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static io.jkube.kit.common.util.KubernetesHelper.getKind;
import static io.jkube.kit.common.util.KubernetesHelper.getName;
Expand Down Expand Up @@ -103,6 +105,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, KitLogger log) {
this.kubernetesClient = kubernetesClient;
Expand Down Expand Up @@ -1072,6 +1076,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 @@ -1086,6 +1094,8 @@ public boolean applyProjectRequest(ProjectRequest entity) {
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 105bba5

Please sign in to comment.