Skip to content

Commit

Permalink
feat(kubernetes): permit multiple ReplicaSets to be deployed with a s…
Browse files Browse the repository at this point in the history
…ingle rollout strategy (#3264)
  • Loading branch information
maggieneterval authored and mergify[bot] committed Oct 29, 2019
1 parent e383297 commit e2d395a
Showing 1 changed file with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,44 @@ private void deleteOldManifests(Map parentContext, StageGraphBuilder graph) {

private void addStagesForOldManifests(
Map parentContext, StageGraphBuilder graph, String stageType) {
Map deployedManifest = getNewManifest(parentContext);
List<Map<String, ?>> deployedManifests = getNewManifests(parentContext);
String account = (String) parentContext.get("account");
Map manifestMoniker = (Map) parentContext.get("moniker");
String application = (String) manifestMoniker.get("app");

Map manifestMetadata = (Map) deployedManifest.get("metadata");
String manifestName = String.format("replicaSet %s", (String) manifestMetadata.get("name"));
String namespace = (String) manifestMetadata.get("namespace");
Map annotations = (Map) manifestMetadata.get("annotations");
String clusterName = (String) annotations.get("moniker.spinnaker.io/cluster");
String cloudProvider = "kubernetes";

List<String> previousManifestNames =
getOldManifestNames(application, account, clusterName, namespace, manifestName);
previousManifestNames.forEach(
name -> {
graph.append(
(stage) -> {
stage.setType(stageType);
Map<String, Object> context = stage.getContext();
context.put("account", account);
context.put("app", application);
context.put("cloudProvider", cloudProvider);
context.put("manifestName", name);
context.put("location", namespace);
deployedManifests.forEach(
manifest -> {
Map manifestMetadata = (Map) manifest.get("metadata");
String manifestName =
String.format("replicaSet %s", (String) manifestMetadata.get("name"));
String namespace = (String) manifestMetadata.get("namespace");
Map annotations = (Map) manifestMetadata.get("annotations");
String clusterName = (String) annotations.get("moniker.spinnaker.io/cluster");
String cloudProvider = "kubernetes";

List<String> previousManifestNames =
getOldManifestNames(application, account, clusterName, namespace, manifestName);
previousManifestNames.forEach(
name -> {
graph.append(
(stage) -> {
stage.setType(stageType);
Map<String, Object> context = stage.getContext();
context.put("account", account);
context.put("app", application);
context.put("cloudProvider", cloudProvider);
context.put("manifestName", name);
context.put("location", namespace);
});
});
});
}

private Map getNewManifest(Map parentContext) {
private List<Map<String, ?>> getNewManifests(Map parentContext) {
List<Map<String, ?>> manifests = (List<Map<String, ?>>) parentContext.get("outputs.manifests");
List<Map<String, ?>> replicaSetManifests =
manifests.stream()
.filter(manifest -> manifest.get("kind").equals("ReplicaSet"))
.collect(Collectors.toList());
if (replicaSetManifests.size() != 1) {
throw new IllegalArgumentException(
"Spinnaker can manage traffic for one ReplicaSet only. Please deploy one ReplicaSet manifest or disable rollout strategies.");
}
return replicaSetManifests.get(0);
return manifests.stream()
.filter(manifest -> manifest.get("kind").equals("ReplicaSet"))
.collect(Collectors.toList());
}

private List<String> getOldManifestNames(
Expand Down

0 comments on commit e2d395a

Please sign in to comment.