-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes): support redblack and highlander strategies (#2844)
- Loading branch information
1 parent
5afddcc
commit 07384ab
Showing
9 changed files
with
334 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestHighlanderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.manifest; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ManifestHighlanderStrategy implements ManifestStrategy { | ||
private final ManifestStrategyHandler strategyHandler; | ||
|
||
@Autowired | ||
public ManifestHighlanderStrategy(ManifestStrategyHandler strategyHandler) { | ||
this.strategyHandler = strategyHandler; | ||
} | ||
|
||
public void composeFlow(DeployManifestContext parentContext, StageGraphBuilder graph) { | ||
strategyHandler.disableOldManifests(parentContext, graph); | ||
strategyHandler.deleteOldManifests(parentContext, graph); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...in/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestNoneStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.manifest; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ManifestNoneStrategy implements ManifestStrategy { | ||
public void composeFlow(DeployManifestContext parentContext, StageGraphBuilder graph) {} | ||
} |
36 changes: 36 additions & 0 deletions
36
...roovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestRedBlackStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.manifest; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ManifestRedBlackStrategy implements ManifestStrategy { | ||
private final ManifestStrategyHandler strategyHandler; | ||
|
||
@Autowired | ||
public ManifestRedBlackStrategy(ManifestStrategyHandler strategyHandler) { | ||
this.strategyHandler = strategyHandler; | ||
} | ||
|
||
public void composeFlow(DeployManifestContext parentContext, StageGraphBuilder graph) { | ||
strategyHandler.disableOldManifests(parentContext, graph); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...c/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.manifest; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder; | ||
|
||
public interface ManifestStrategy { | ||
void composeFlow(DeployManifestContext parentContext, StageGraphBuilder graph); | ||
} |
95 changes: 95 additions & 0 deletions
95
...groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestStrategyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.manifest; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.pipeline.manifest.DeleteManifestStage; | ||
import com.netflix.spinnaker.orca.clouddriver.pipeline.manifest.DisableManifestStage; | ||
import com.netflix.spinnaker.orca.clouddriver.utils.OortHelper; | ||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ManifestStrategyHandler { | ||
private final OortHelper oortHelper; | ||
|
||
void disableOldManifests(DeployManifestContext parentContext, StageGraphBuilder graph) { | ||
addStagesForOldManifests(parentContext, graph, DisableManifestStage.PIPELINE_CONFIG_TYPE); | ||
} | ||
|
||
void deleteOldManifests(DeployManifestContext parentContext, StageGraphBuilder graph) { | ||
addStagesForOldManifests(parentContext, graph, DeleteManifestStage.PIPELINE_CONFIG_TYPE); | ||
} | ||
|
||
private Map getNewManifest(DeployManifestContext parentContext) { | ||
List<Map<String, ?>> manifests = (List<Map<String, ?>>) parentContext.get("outputs.manifests"); | ||
return manifests.get(0); | ||
} | ||
|
||
private List<String> getOldManifestNames(String application, String account, String clusterName, String namespace, String newManifestName) { | ||
Map cluster = oortHelper.getCluster(application, account, clusterName, "kubernetes") | ||
.orElseThrow(() -> new IllegalArgumentException(String.format("Error fetching cluster %s in account %s and namespace %s", clusterName, account, namespace))); | ||
|
||
List<Map> serverGroups = Optional.ofNullable((List<Map>) cluster.get("serverGroups")) | ||
.orElse(null); | ||
|
||
if (serverGroups == null) { | ||
return new ArrayList<>(); | ||
} | ||
|
||
return serverGroups.stream() | ||
.filter(s -> s.get("region").equals(namespace)) | ||
.filter(s -> !s.get("name").equals(newManifestName)) | ||
.map(s -> (String) s.get("name")) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private void addStagesForOldManifests(DeployManifestContext parentContext, StageGraphBuilder graph, String stageType) { | ||
Map deployedManifest = getNewManifest(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); | ||
}); | ||
}); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...vy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestStrategyStagesAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.manifest; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ManifestStrategyStagesAdder { | ||
private final ManifestHighlanderStrategy highlanderStrategy; | ||
|
||
private final ManifestRedBlackStrategy redBlackStrategy; | ||
|
||
private final ManifestNoneStrategy noneStrategy; | ||
|
||
public void addAfterStages(ManifestStrategyType strategy, StageGraphBuilder graph, DeployManifestContext parentContext) { | ||
switch (strategy) { | ||
case RED_BLACK: | ||
redBlackStrategy.composeFlow(parentContext, graph); | ||
break; | ||
case HIGHLANDER: | ||
highlanderStrategy.composeFlow(parentContext, graph); | ||
break; | ||
default: | ||
noneStrategy.composeFlow(parentContext, graph); | ||
} | ||
} | ||
} |
Oops, something went wrong.