Skip to content

Commit

Permalink
improvement: slightly increase defensiveness
Browse files Browse the repository at this point in the history
Maybe the List is actually a CRD? Seems to be unlikely as other tools like Kustomize also treat kinds matching `*List` as lists.
But add a better error message here if items contains something unexpected just in case.

This logic is more or less equivalent to https://github.com/kubernetes-sigs/kustomize/blob/cf3e81b590ab1fd7fc8f50849535f44bfea0d355/api/resource/factory.go#L550
  • Loading branch information
stefreak committed May 31, 2023
1 parent 5374942 commit 0e46a7e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/plugins/kubernetes/kubernetes-type/common.ts
Expand Up @@ -52,7 +52,17 @@ export async function getManifests({
// remove *List objects
const manifests = rawManifests.flatMap((manifest) => {
if (manifest.kind.endsWith("List")) {
return manifest.items as KubernetesResource[]
if (!manifest.items || manifest.items.length === 0) {
// empty list
return []
} else if (manifest.items.length > 0 && manifest.items[0].kind) {
// at least the first manifest has a kind: seems to be a valid List
return manifest.items as KubernetesResource[]
} else {
throw new PluginError("Failed to read Kubernetes manifest: Encountered an invalid List manifest", {
manifest
})
}
}
return manifest
})
Expand Down

0 comments on commit 0e46a7e

Please sign in to comment.