-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(manifest-replicas): Replicas value was not being set if it didn't…
… already have a value, however users expect that they can omit the value when leveraging the use-source-capacity strategy. Fix is setting the value despite there not already being one. Additionally, if a third party integration creates a manifest via JSON that serializes the replica count as an integer, a casting exception occurs, so this includes an update to play nicely with integers. (#5368) Co-authored-by: Ryan Morgan <ryan.morgan@armory.io>
- Loading branch information
Showing
4 changed files
with
112 additions
and
9 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
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
105 changes: 105 additions & 0 deletions
105
...spinnaker/clouddriver/kubernetes/description/manifest/KubernetesManifestReplicasTest.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,105 @@ | ||
/* | ||
* Copyright 2021 Netflix, 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.clouddriver.kubernetes.description.manifest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.platform.runner.JUnitPlatform; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(JUnitPlatform.class) | ||
public class KubernetesManifestReplicasTest { | ||
private static final JsonNodeFactory jsonFactory = JsonNodeFactory.instance; | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void replicasValueShouldBeNullWithoutSpecDefined() throws JsonProcessingException { | ||
String serialized = jsonFactory.objectNode().toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
assertThat(manifest.getReplicas()).isNull(); | ||
} | ||
|
||
@Test | ||
public void replicasValueShouldBeNullWithoutReplicasDefined() throws JsonProcessingException { | ||
String serialized = | ||
jsonFactory.objectNode().<ObjectNode>set("spec", jsonFactory.objectNode()).toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
assertThat(manifest.getReplicas()).isNull(); | ||
} | ||
|
||
@Test | ||
public void shouldGetReplicasDoubleValue() throws JsonProcessingException { | ||
String serialized = | ||
jsonFactory | ||
.objectNode() | ||
.<ObjectNode>set("spec", jsonFactory.objectNode().put("replicas", 2.0)) | ||
.toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
assertThat(manifest.getReplicas()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
public void shouldGetReplicasIntegerValue() throws JsonProcessingException { | ||
String serialized = | ||
jsonFactory | ||
.objectNode() | ||
.<ObjectNode>set("spec", jsonFactory.objectNode().put("replicas", 2)) | ||
.toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
assertThat(manifest.getReplicas()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
public void replicasValueShouldRemainUnsetWithoutSpecDefined() throws JsonProcessingException { | ||
String serialized = jsonFactory.objectNode().toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
|
||
manifest.setReplicas(2.0); | ||
|
||
assertThat(manifest.getReplicas()).isEqualTo(null); | ||
} | ||
|
||
@Test | ||
public void replicasValueShouldBeSetWithReplicasDefined() throws JsonProcessingException { | ||
String serialized = | ||
jsonFactory | ||
.objectNode() | ||
.<ObjectNode>set("spec", jsonFactory.objectNode().put("replicas", 1)) | ||
.toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
|
||
manifest.setReplicas(2.0); | ||
|
||
assertThat(manifest.getReplicas()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
public void replicasValueShouldBeSetWithReplicasUnDefined() throws JsonProcessingException { | ||
String serialized = | ||
jsonFactory.objectNode().<ObjectNode>set("spec", jsonFactory.objectNode()).toString(); | ||
KubernetesManifest manifest = objectMapper.readValue(serialized, KubernetesManifest.class); | ||
|
||
manifest.setReplicas(2.0); | ||
|
||
assertThat(manifest.getReplicas()).isEqualTo(2); | ||
} | ||
} |