From 6e2bba627e0904ce2b8863f103ea00d605ef67e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Sep=C3=BAlveda=20Blanco?= Date: Tue, 1 Mar 2022 12:22:28 +0100 Subject: [PATCH] Fix NPE while applying empty manifest --- .../KubernetesDeployManifestOperation.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/op/manifest/KubernetesDeployManifestOperation.java b/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/op/manifest/KubernetesDeployManifestOperation.java index 7a88c458882..aa5dcbdb607 100644 --- a/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/op/manifest/KubernetesDeployManifestOperation.java +++ b/clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/op/manifest/KubernetesDeployManifestOperation.java @@ -43,6 +43,7 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.CollectionUtils; public class KubernetesDeployManifestOperation implements AtomicOperation { private static final Logger log = @@ -167,11 +168,13 @@ public OperationResult operate(List _unused) { @NotNull private List getManifestsFromDescription() { List inputManifests = description.getManifests(); - if (inputManifests == null || inputManifests.isEmpty()) { - // The stage currently only supports using the `manifests` field but we need to continue to - // check `manifest` for backwards compatibility until all existing stages have been updated. - @SuppressWarnings("deprecation") - KubernetesManifest manifest = description.getManifest(); + + // The stage currently only supports using the `manifests` field but we need to continue to + // check `manifest` for backwards compatibility until all existing stages have been updated. + @SuppressWarnings("deprecation") + KubernetesManifest manifest = description.getManifest(); + + if (CollectionUtils.isEmpty(inputManifests) && manifest != null) { log.warn( "Relying on deprecated single manifest input (account: {}, kind: {}, name: {})", accountName, @@ -179,6 +182,7 @@ private List getManifestsFromDescription() { manifest.getName()); inputManifests = ImmutableList.of(manifest); } + inputManifests = inputManifests.stream().filter(Objects::nonNull).collect(Collectors.toList()); return inputManifests; }