Skip to content

Commit

Permalink
fix(k8s): retrieving logs would sometimes fail after deployment rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Feb 14, 2020
1 parent ef2ab15 commit 0409e68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 6 additions & 4 deletions garden-service/src/plugins/kubernetes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function getWorkloadPods(api: KubeApi, namespace: string, resource:
if (resource.kind === "Deployment") {
// Make sure we only return the pods from the current ReplicaSet
const selectorString = labelSelectorToString(selector)
const replicaSets = await api.apps.listNamespacedReplicaSet(
const replicaSetRes = await api.apps.listNamespacedReplicaSet(
resource.metadata.namespace || namespace,
undefined, // pretty
undefined, // allowWatchBookmarks
Expand All @@ -139,12 +139,14 @@ export async function getWorkloadPods(api: KubeApi, namespace: string, resource:
selectorString // labelSelector
)

if (replicaSets.items.length === 0) {
const replicaSets = replicaSetRes.items.filter((r) => r.spec.replicas > 0)

if (replicaSets.length === 0) {
return []
}

const sorted = sortBy(replicaSets.items, (r) => r.metadata.creationTimestamp!)
const currentReplicaSet = sorted[replicaSets.items.length - 1]
const sorted = sortBy(replicaSets, (r) => r.metadata.creationTimestamp!)
const currentReplicaSet = sorted[replicaSets.length - 1]

return pods.filter((pod) => pod.metadata.name.startsWith(currentReplicaSet.metadata.name))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ describe("kubernetes", () => {
tail: -1,
})

console.log(entries)

expect(entries[0].msg).to.include("Server running...")
})
})
Expand Down

0 comments on commit 0409e68

Please sign in to comment.