Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: deduplicate deploy status logs for ready statuses #3991

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions core/src/plugins/kubernetes/status/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ import { KubeApi } from "../api"
import { getAppNamespace } from "../namespace"
import Bluebird from "bluebird"
import { KubernetesResource, KubernetesServerResource, BaseResource, KubernetesWorkload } from "../types"
import { zip, isArray, isPlainObject, pickBy, mapValues, flatten, cloneDeep, omit, isEqual, keyBy } from "lodash"
import {
zip,
isArray,
isPlainObject,
pickBy,
mapValues,
flatten,
cloneDeep,
omit,
isEqual,
keyBy,
differenceWith,
} from "lodash"
import { KubernetesProvider, KubernetesPluginContext } from "../config"
import { isSubset } from "../../../util/is-subset"
import { Log } from "../../../logger/log-entry"
Expand Down Expand Up @@ -211,21 +223,29 @@ export async function waitForResources({

const api = await KubeApi.factory(log, ctx, provider)
let statuses: ResourceStatus[]
let printables: ResourceStatus[] = []
let readyAndPrinted: ResourceStatus[] = []

while (true) {
await sleep(2000 + 500 * loops)
loops += 1

// Make sure to print "ready" state only once
statuses = await checkResourceStatuses(api, namespace, resources, log)
printables = differenceWith(statuses, readyAndPrinted, isEqual)

for (const status of statuses) {
for (const status of printables) {
const resource = status.resource
const statusMessage = `${resource.kind} ${resource.metadata.name} is "${status.state}"`

const statusLogMsg = `Status of ${statusMessage}`
log.debug(statusLogMsg)
emitLog(statusLogMsg)

if (status.state === "ready") {
readyAndPrinted.push(status)
}

if (status.state === "unhealthy") {
let msg = `Error deploying ${actionName || "resources"}: ${status.lastMessage || statusMessage}`

Expand Down Expand Up @@ -473,7 +493,12 @@ export function isConfiguredForLocalMode(resource: SyncableResource): boolean {
}

function isWorkloadResource(resource: KubernetesResource): resource is KubernetesWorkload {
return resource.kind === "Deployment" || resource.kind === "DaemonSet" || resource.kind === "StatefulSet" || resource.kind === "ReplicaSet"
return (
resource.kind === "Deployment" ||
resource.kind === "DaemonSet" ||
resource.kind === "StatefulSet" ||
resource.kind === "ReplicaSet"
)
}

type KubernetesResourceMap = { [key: string]: KubernetesResource }
Expand All @@ -485,10 +510,10 @@ function detectChangedSpecSelector(manifestsMap: KubernetesResourceMap, deployed
const manifest = manifestsMap[k]
const deployedResource = deployedMap[k]
if (
deployedResource // If no corresponding resource to the local manifest has been deployed, this will be undefined.
&& isWorkloadResource(manifest)
&& isWorkloadResource(deployedResource)
&& !isEqual(manifest.spec.selector, deployedResource.spec.selector)
deployedResource && // If no corresponding resource to the local manifest has been deployed, this will be undefined.
isWorkloadResource(manifest) &&
isWorkloadResource(deployedResource) &&
!isEqual(manifest.spec.selector, deployedResource.spec.selector)
) {
changedKeys.push(getResourceKey(manifest))
}
Expand Down