Skip to content

Commit

Permalink
fix(kubernetes): tolerate an empty manifest in KubernetesDeployManife…
Browse files Browse the repository at this point in the history
…stOperation (#6337)

in case the result of a bake stage is empty.  Without this there's:

java.lang.NullPointerException
	at com.netflix.spinnaker.clouddriver.kubernetes.op.manifest.KubernetesDeployManifestOperation.getManifestsFromDescription(KubernetesDeployManifestOperation.java:234)
	at com.netflix.spinnaker.clouddriver.kubernetes.op.manifest.KubernetesDeployManifestOperation.operate(KubernetesDeployManifestOperation.java:75)
	at com.netflix.spinnaker.clouddriver.kubernetes.op.manifest.KubernetesDeployManifestOperation.operate(KubernetesDeployManifestOperation.java:48)

because KubernetesDeployManifestDescription.getManifestsFromDescription assumes that description.getManifest() never returns null.
  • Loading branch information
dbyron-sf authored Jan 23, 2025
1 parent c4df136 commit 8c2c388
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,16 @@ private List<KubernetesManifest> getManifestsFromDescription() {
// check `manifest` for backwards compatibility until all existing stages have been updated.
@SuppressWarnings("deprecation")
KubernetesManifest manifest = description.getManifest();
log.warn(
"Relying on deprecated single manifest input (account: {}, kind: {}, name: {})",
accountName,
manifest.getKind(),
manifest.getName());
inputManifests = ImmutableList.of(manifest);

// manifest may be null as well, so check
if (manifest != null) {
log.warn(
"Relying on deprecated single manifest input (account: {}, kind: {}, name: {})",
accountName,
manifest.getKind(),
manifest.getName());
inputManifests = ImmutableList.of(manifest);
}
}
inputManifests = inputManifests.stream().filter(Objects::nonNull).collect(Collectors.toList());
return inputManifests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ void replaceStrategyWithLabelSelector() {
anyString());
}

@Test
void deployEmptyResource() {
KubernetesDeployManifestDescription deployManifestDescription =
baseDeployDescription("deploy/empty-resource.yml");
deploy(deployManifestDescription);
}

private static KubernetesDeployManifestDescription baseDeployDescription(String manifest) {
return baseDeployDescription(manifest, false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 8c2c388

Please sign in to comment.