Skip to content

Commit

Permalink
fix(k8s): do not throw if paused resource is missing (#6799)
Browse files Browse the repository at this point in the history
Before this fix, we'd check for paused Helm resources by listing all
rendered resources and not handling the error if the resource isn't
deployed in the first place.

Furthermore, we were missing an `await` statement so the 404 error from
a missing resource would pop up at a random time, usually after the
status handler returns.

So essentially a `helm` Deploy could fail if using AEC and a potentially
paused resource was missing.

Now we correctly ignore rendered resources that haven't been deployed
and await for the API call.
  • Loading branch information
eysi09 authored Jan 24, 2025
1 parent e86f5ad commit 62b77ed
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions core/src/plugins/kubernetes/helm/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { KubernetesResource, KubernetesServerResource } from "../types.js"
import { getActionNamespace } from "../namespace.js"
import { getTargetResource, isWorkload } from "../util.js"
import { getDeployedResource, isConfiguredForLocalMode } from "../status/status.js"
import { KubeApi } from "../api.js"
import { KubeApi, KubernetesError } from "../api.js"
import { getK8sIngresses } from "../status/ingress.js"
import type { DeployActionHandler } from "../../../plugin/action-types.js"
import type { HelmDeployAction } from "./config.js"
Expand Down Expand Up @@ -262,13 +262,28 @@ export async function getPausedResources({
const api = await KubeApi.factory(log, ctx, ctx.provider)
const renderedResources = await getRenderedResources({ ctx, action, releaseName, log })
const workloads = renderedResources.filter(isWorkload)
const deployedResources = await Promise.all(
workloads.map((workload) => api.readBySpec({ log, namespace, manifest: workload }))
)

const deployedResources = (
await Promise.all(
workloads.map(async (workload) => {
try {
const resource = await api.readBySpec({ log, namespace, manifest: workload })
return resource
} catch (err) {
// If readBySpec fails with 404 then the resource isn't deployed
if (err instanceof KubernetesError && err.responseStatusCode === 404) {
return null
}
throw err
}
})
)
).filter(isTruthy)

const pausedWorkloads = deployedResources.filter((resource) => {
return resource?.metadata?.annotations?.[gardenCloudAECPauseAnnotation] === "paused"
})

return pausedWorkloads
}

Expand Down

0 comments on commit 62b77ed

Please sign in to comment.