fix(provider/kubernetes): Replace artifact only if target found
Do not attempt artifact replacement if no target was found.
Reading a non-existing path can return an empty ArrayNode object,
in which case we should not attempt any replacement.
Add checks for bound artifacts in artifact replacement tests.
MODIFY
clouddriver-kubernetes/src/main/groovy/com/netflix/spinnaker/clouddriver/kubernetes/v2/artifact/ArtifactReplacer.java
clouddriver-kubernetes/src/main/groovy/com/netflix/spinnaker/clouddriver/kubernetes/v2/artifact/ArtifactReplacer.java
@@ -153,7 +153,7 @@ public class ArtifactReplacer {
String jsonPath = processPath(replacePath, artifact);
Object get = obj.read(jsonPath);
- if (get == null) {
+ if (get == null || (get instanceof ArrayNode && ((ArrayNode) get).size() == 0)) {
return false;
}

MODIFY
clouddriver-kubernetes/src/test/groovy/com/netflix/spinnaker/clouddriver/kubernetes/v2/op/deployer/KubernetesDeploymentHandlerSpec.groovy
clouddriver-kubernetes/src/test/groovy/com/netflix/spinnaker/clouddriver/kubernetes/v2/op/deployer/KubernetesDeploymentHandlerSpec.groovy
@@ -76,6 +76,8 @@ spec:
then:
result.manifest.spec.template.spec.containers[0].image == target
+ result.boundArtifacts.size() == 1
+ result.boundArtifacts.contains(artifact) == true
}
void "check that image isn't replaced by the artifact replacer"() {
@@ -91,6 +93,7 @@ spec:
then:
result.manifest.spec.template.spec.containers[0].image == IMAGE
+ result.boundArtifacts.isEmpty() == true
}
void "check that image is found"() {

fix(provider/kubernetes): Replace artifact only if target found (#2259)

Do not attempt artifact replacement if no target was found.
Reading a non-existing path can return an empty ArrayNode object,
in which case we should not attempt any replacement.
Add checks for bound artifacts in artifact replacement tests.