From ba77d2bbf54f1996ed4d398bb20c80a83d21545d Mon Sep 17 00:00:00 2001 From: David Dooling Date: Tue, 25 Feb 2020 19:11:51 -0600 Subject: [PATCH] Consolidate k8s error message handling --- lib/api-helper/goal/sdmGoal.ts | 2 +- lib/api-helper/misc/project/filteredView.ts | 2 +- .../project/GitHubLazyProjectLoader.ts | 2 +- .../configuration/projectConfiguration.ts | 2 +- lib/core/pack/k8s/container.ts | 47 +++---------------- lib/core/pack/k8s/kubernetes/application.ts | 6 +-- lib/core/pack/k8s/kubernetes/apply.ts | 6 +-- lib/core/pack/k8s/kubernetes/delete.ts | 10 ++-- lib/core/pack/k8s/kubernetes/deployment.ts | 4 +- lib/core/pack/k8s/kubernetes/fetch.ts | 4 +- lib/core/pack/k8s/kubernetes/ingress.ts | 4 +- lib/core/pack/k8s/kubernetes/namespace.ts | 6 +-- lib/core/pack/k8s/kubernetes/role.ts | 6 +-- lib/core/pack/k8s/kubernetes/roleBinding.ts | 6 +-- lib/core/pack/k8s/kubernetes/secret.ts | 4 +- lib/core/pack/k8s/kubernetes/service.ts | 4 +- .../pack/k8s/kubernetes/serviceAccount.ts | 4 +- .../k8s/scheduler/KubernetesGoalScheduler.ts | 2 +- lib/core/pack/k8s/support/error.ts | 4 +- lib/core/pack/k8s/support/retry.ts | 4 +- lib/core/pack/k8s/sync/goals.ts | 4 +- lib/core/pack/k8s/sync/sync.ts | 6 +-- .../DefaultGoalImplementationMapper.test.ts | 2 +- .../api-helper/listener/executeCancel.test.ts | 2 +- test/api-helper/misc/child_process.test.ts | 2 +- test/api-helper/misc/job/createJob.test.ts | 2 +- .../project/GitHubLazyProjectLoader.test.ts | 2 +- .../pushtest/materialChangeTest.test.ts | 2 +- test/core/pack/k8s/support/error.test.ts | 31 ++++++------ 29 files changed, 75 insertions(+), 107 deletions(-) diff --git a/lib/api-helper/goal/sdmGoal.ts b/lib/api-helper/goal/sdmGoal.ts index 95d038282..3646d23d8 100644 --- a/lib/api-helper/goal/sdmGoal.ts +++ b/lib/api-helper/goal/sdmGoal.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2018 Atomist, Inc. + * Copyright © 2020 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/api-helper/misc/project/filteredView.ts b/lib/api-helper/misc/project/filteredView.ts index 45c7deb95..decd2a055 100644 --- a/lib/api-helper/misc/project/filteredView.ts +++ b/lib/api-helper/misc/project/filteredView.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Atomist, Inc. + * Copyright © 2020 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/api-helper/project/GitHubLazyProjectLoader.ts b/lib/api-helper/project/GitHubLazyProjectLoader.ts index 60f229ee0..b7acf50c1 100644 --- a/lib/api-helper/project/GitHubLazyProjectLoader.ts +++ b/lib/api-helper/project/GitHubLazyProjectLoader.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Atomist, Inc. + * Copyright © 2020 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/api-helper/project/configuration/projectConfiguration.ts b/lib/api-helper/project/configuration/projectConfiguration.ts index 7e8b658f5..866bcf349 100644 --- a/lib/api-helper/project/configuration/projectConfiguration.ts +++ b/lib/api-helper/project/configuration/projectConfiguration.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Atomist, Inc. + * Copyright © 2020 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/core/pack/k8s/container.ts b/lib/core/pack/k8s/container.ts index 377df49fd..181f764e4 100644 --- a/lib/core/pack/k8s/container.ts +++ b/lib/core/pack/k8s/container.ts @@ -31,6 +31,7 @@ import { Merge, } from "ts-essentials"; import { minimalClone } from "../../../api-helper/goal/minimalClone"; +import { goalData } from "../../../api-helper/goal/sdmGoal"; import { RepoContext } from "../../../api/context/SdmContext"; import { ExecuteGoalResult } from "../../../api/goal/ExecuteGoalResult"; import { @@ -81,6 +82,7 @@ import { KubernetesGoalScheduler, readNamespace, } from "./scheduler/KubernetesGoalScheduler"; +import { k8sErrMsg } from "./support/error"; // tslint:disable:max-file-line-count @@ -189,7 +191,7 @@ export function k8sFulfillmentCallback( } // Preserve the container registration in the goal data before it gets munged with internals - let data = parseGoalEventData(goalEvent); + let data = goalData(goalEvent); let newData: any = {}; delete spec.callback; _.set(newData, ContainerRegistrationGoalDataKey, spec); @@ -338,7 +340,7 @@ export function k8sFulfillmentCallback( }; // Store k8s service registration in goal data - data = JSON.parse(goalEvent.data || "{}"); + data = goalData(goalEvent); newData = {}; _.set(newData, `${ServiceRegistrationGoalDataKey}.${registration.name}`, serviceSpec); goalEvent.data = JSON.stringify(_.merge(data, newData)); @@ -355,7 +357,7 @@ export function k8sFulfillmentCallback( export const scheduleK8sJob: ExecuteGoal = async gi => { const { goalEvent } = gi; const { uniqueName } = goalEvent; - const data = parseGoalEventData(goalEvent); + const data = goalData(goalEvent); const containerReg: K8sContainerRegistration = data["@atomist/sdm/container"]; if (!containerReg) { throw new Error(`Goal ${uniqueName} event data has no container spec: ${goalEvent.data}`); @@ -416,7 +418,7 @@ export function executeK8sJob(): ExecuteGoal { const inputDir = process.env.ATOMIST_INPUT_DIR || ContainerInput; const outputDir = process.env.ATOMIST_OUTPUT_DIR || ContainerOutput; - const data = parseGoalEventData(goalEvent); + const data = goalData(goalEvent); if (!data[ContainerRegistrationGoalDataKey]) { throw new Error("Failed to read k8s ContainerRegistration from goal data"); } @@ -559,24 +561,6 @@ export function executeK8sJob(): ExecuteGoal { }; } -/** - * Read and parse container goal registration from goal event data. - */ -export function parseGoalEventData(goalEvent: SdmGoalEvent): any { - const goalName = goalEvent.uniqueName; - if (!goalEvent || !goalEvent.data) { - return {}; - } - let data: any; - try { - data = JSON.parse(goalEvent.data); - } catch (e) { - e.message = `Failed to parse goal event data for ${goalName} as JSON '${goalEvent.data}': ${e.message}`; - throw e; - } - return data; -} - /** * If running as isolated goal, use [[executeK8sJob]] to execute the * goal. Otherwise, schedule the goal execution as a Kubernetes job @@ -591,7 +575,7 @@ const containerFulfillerCacheRestore: GoalProjectListenerRegistration = { name: "cache restore", events: [GoalProjectListenerEvent.before], listener: async (project, gi) => { - const data = parseGoalEventData(gi.goalEvent); + const data = goalData(gi.goalEvent); if (!data[ContainerRegistrationGoalDataKey]) { throw new Error(`Goal ${gi.goal.uniqueName} has no Kubernetes container registration: ${gi.goalEvent.data}`); } @@ -788,20 +772,3 @@ function containerCleanup(c: ContainerDetritus): void { c.watcher.abort(); } } - -/** Try to find a Kubernetes API error message. */ -export function k8sErrMsg(e: any): string { - if (e.message && typeof e.message === "string") { - return e.message; - } else if (e.body && typeof e.body === "string") { - return e.body; - } else if (e.body?.message && typeof e.body.message === "string") { - return e.body.message; - } else if (e.response?.body && typeof e.response.body === "string") { - return e.response.body; - } else if (e.response?.body?.message && typeof e.response.body.message === "string") { - return e.response.body.message; - } else { - return "Kubernetes API request error"; - } -} diff --git a/lib/core/pack/k8s/kubernetes/application.ts b/lib/core/pack/k8s/kubernetes/application.ts index 5ee94c451..7f215339b 100644 --- a/lib/core/pack/k8s/kubernetes/application.ts +++ b/lib/core/pack/k8s/kubernetes/application.ts @@ -15,7 +15,7 @@ */ import * as k8s from "@kubernetes/client-node"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { KubernetesClients, makeApiClients, @@ -73,7 +73,7 @@ export async function upsertApplication(app: KubernetesApplication, sdmFulfiller k8sResources.push(await upsertIngress(req)); return k8sResources.filter(r => !!r); } catch (e) { - e.message = `Failed to upsert '${reqString(req)}': ${errMsg(e)}`; + e.message = `Failed to upsert '${reqString(req)}': ${k8sErrMsg(e)}`; throw e; } } @@ -170,7 +170,7 @@ export async function deleteApplication(del: KubernetesDelete): Promise client.create(spec), `create resource ${slug}`); } diff --git a/lib/core/pack/k8s/kubernetes/delete.ts b/lib/core/pack/k8s/kubernetes/delete.ts index 9f57084c8..555c58ca3 100644 --- a/lib/core/pack/k8s/kubernetes/delete.ts +++ b/lib/core/pack/k8s/kubernetes/delete.ts @@ -16,7 +16,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { K8sDeleteResponse, @@ -46,13 +46,13 @@ export async function deleteSpec(spec: k8s.KubernetesObject): Promise req.clients.apps.createNamespacedDeployment(spec.metadata.namespace, spec), `create deployment ${slug}`); diff --git a/lib/core/pack/k8s/kubernetes/fetch.ts b/lib/core/pack/k8s/kubernetes/fetch.ts index c1888c5e0..dd45d391b 100644 --- a/lib/core/pack/k8s/kubernetes/fetch.ts +++ b/lib/core/pack/k8s/kubernetes/fetch.ts @@ -16,7 +16,7 @@ import * as k8s from "@kubernetes/client-node"; import * as _ from "lodash"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { K8sObjectApi } from "./api"; import { KubernetesClients, @@ -172,7 +172,7 @@ export async function kubernetesFetch(options: KubernetesFetchOptions = defaultK client = kc.makeApiClient(K8sObjectApi); clients = makeApiClients(kc); } catch (e) { - e.message = `Failed to create Kubernetes client: ${errMsg(e)}`; + e.message = `Failed to create Kubernetes client: ${k8sErrMsg(e)}`; throw e; } diff --git a/lib/core/pack/k8s/kubernetes/ingress.ts b/lib/core/pack/k8s/kubernetes/ingress.ts index 849a27ba6..265493774 100644 --- a/lib/core/pack/k8s/kubernetes/ingress.ts +++ b/lib/core/pack/k8s/kubernetes/ingress.ts @@ -17,7 +17,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; import * as _ from "lodash"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels } from "./labels"; import { metadataTemplate } from "./metadata"; @@ -52,7 +52,7 @@ export async function upsertIngress(req: KubernetesResourceRequest): Promise req.clients.ext.createNamespacedIngress(spec.metadata.namespace, spec), `create ingress ${slug}`); return spec; diff --git a/lib/core/pack/k8s/kubernetes/namespace.ts b/lib/core/pack/k8s/kubernetes/namespace.ts index fa1f9d947..b0f5f9c2b 100644 --- a/lib/core/pack/k8s/kubernetes/namespace.ts +++ b/lib/core/pack/k8s/kubernetes/namespace.ts @@ -16,7 +16,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels } from "./labels"; import { metadataTemplate } from "./metadata"; @@ -41,7 +41,7 @@ export async function upsertNamespace(req: KubernetesResourceRequest): Promise req.clients.core.createNamespace(spec), `create namespace ${slug}`); return spec; @@ -51,7 +51,7 @@ export async function upsertNamespace(req: KubernetesResourceRequest): Promise req.clients.core.patchNamespace(spec.metadata.name, spec, undefined, undefined, undefined, undefined, patchHeaders()), `patch namespace ${slug}`); } catch (e) { - logger.warn(`Failed to patch existing namespace ${slug}, ignoring: ${errMsg(e)}`); + logger.warn(`Failed to patch existing namespace ${slug}, ignoring: ${k8sErrMsg(e)}`); } return spec; } diff --git a/lib/core/pack/k8s/kubernetes/role.ts b/lib/core/pack/k8s/kubernetes/role.ts index 1a9fa5c31..4f3ef72bf 100644 --- a/lib/core/pack/k8s/kubernetes/role.ts +++ b/lib/core/pack/k8s/kubernetes/role.ts @@ -17,7 +17,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; import * as _ from "lodash"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels } from "./labels"; import { metadataTemplate } from "./metadata"; @@ -43,7 +43,7 @@ export async function upsertRole(req: KubernetesResourceRequest): Promise req.clients.rbac.createClusterRole(spec), `create cluster role ${slug}`); return spec; @@ -57,7 +57,7 @@ export async function upsertRole(req: KubernetesResourceRequest): Promise req.clients.rbac.createNamespacedRole(spec.metadata.namespace, spec), `create role ${slug}`); return spec; diff --git a/lib/core/pack/k8s/kubernetes/roleBinding.ts b/lib/core/pack/k8s/kubernetes/roleBinding.ts index c870e8b17..ad0aff1d8 100644 --- a/lib/core/pack/k8s/kubernetes/roleBinding.ts +++ b/lib/core/pack/k8s/kubernetes/roleBinding.ts @@ -17,7 +17,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; import * as _ from "lodash"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels } from "./labels"; import { metadataTemplate } from "./metadata"; @@ -43,7 +43,7 @@ export async function upsertRoleBinding(req: KubernetesResourceRequest): Promise try { await req.clients.rbac.readClusterRoleBinding(spec.metadata.name); } catch (e) { - logger.debug(`Failed to read cluster role binding ${slug}, creating: ${errMsg(e)}`); + logger.debug(`Failed to read cluster role binding ${slug}, creating: ${k8sErrMsg(e)}`); logger.info(`Creating cluster role binding ${slug} using '${logObject(spec)}'`); await logRetry(() => req.clients.rbac.createClusterRoleBinding(spec), `create cluster role binding ${slug}`); @@ -58,7 +58,7 @@ export async function upsertRoleBinding(req: KubernetesResourceRequest): Promise try { await req.clients.rbac.readNamespacedRoleBinding(spec.metadata.name, spec.metadata.namespace); } catch (e) { - logger.debug(`Failed to read role binding ${slug}, creating: ${errMsg(e)}`); + logger.debug(`Failed to read role binding ${slug}, creating: ${k8sErrMsg(e)}`); logger.info(`Creating role binding ${slug} using '${logObject(spec)}'`); await logRetry(() => req.clients.rbac.createNamespacedRoleBinding(spec.metadata.namespace, spec), `create role binding ${slug}`); diff --git a/lib/core/pack/k8s/kubernetes/secret.ts b/lib/core/pack/k8s/kubernetes/secret.ts index 36e117148..e3189deb2 100644 --- a/lib/core/pack/k8s/kubernetes/secret.ts +++ b/lib/core/pack/k8s/kubernetes/secret.ts @@ -21,7 +21,7 @@ import { decrypt, encrypt, } from "../support/crypto"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels } from "./labels"; import { metadataTemplate } from "./metadata"; @@ -55,7 +55,7 @@ export async function upsertSecrets(req: KubernetesResourceRequest): Promise req.clients.core.createNamespacedSecret(spec.metadata.namespace, spec), `create secret ${secretName} for ${slug}`); diff --git a/lib/core/pack/k8s/kubernetes/service.ts b/lib/core/pack/k8s/kubernetes/service.ts index 1be3bb067..490218b1a 100644 --- a/lib/core/pack/k8s/kubernetes/service.ts +++ b/lib/core/pack/k8s/kubernetes/service.ts @@ -17,7 +17,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; import * as _ from "lodash"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels, @@ -51,7 +51,7 @@ export async function upsertService(req: KubernetesResourceRequest): Promise req.clients.core.createNamespacedService(spec.metadata.namespace, spec), `create service ${slug}`); return spec; diff --git a/lib/core/pack/k8s/kubernetes/serviceAccount.ts b/lib/core/pack/k8s/kubernetes/serviceAccount.ts index 05bbd7861..5e8a51da5 100644 --- a/lib/core/pack/k8s/kubernetes/serviceAccount.ts +++ b/lib/core/pack/k8s/kubernetes/serviceAccount.ts @@ -17,7 +17,7 @@ import { logger } from "@atomist/automation-client/lib/util/logger"; import * as k8s from "@kubernetes/client-node"; import * as _ from "lodash"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { logRetry } from "../support/retry"; import { applicationLabels } from "./labels"; import { metadataTemplate } from "./metadata"; @@ -42,7 +42,7 @@ export async function upsertServiceAccount(req: KubernetesResourceRequest): Prom try { await req.clients.core.readNamespacedServiceAccount(spec.metadata.name, spec.metadata.namespace); } catch (e) { - logger.debug(`Failed to read service account ${slug}, creating: ${errMsg(e)}`); + logger.debug(`Failed to read service account ${slug}, creating: ${k8sErrMsg(e)}`); logger.info(`Creating service account ${slug} using '${logObject(spec)}'`); await logRetry(() => req.clients.core.createNamespacedServiceAccount(spec.metadata.namespace, spec), `create service account ${slug}`); diff --git a/lib/core/pack/k8s/scheduler/KubernetesGoalScheduler.ts b/lib/core/pack/k8s/scheduler/KubernetesGoalScheduler.ts index 5dd438382..0fc8c114c 100644 --- a/lib/core/pack/k8s/scheduler/KubernetesGoalScheduler.ts +++ b/lib/core/pack/k8s/scheduler/KubernetesGoalScheduler.ts @@ -40,11 +40,11 @@ import { SdmGoalEvent } from "../../../../api/goal/SdmGoalEvent"; import { GoalScheduler } from "../../../../api/goal/support/GoalScheduler"; import { ServiceRegistrationGoalDataKey } from "../../../../api/registration/ServiceRegistration"; import { toArray } from "../../../util/misc/array"; -import { k8sErrMsg } from "../container"; import { loadKubeClusterConfig, loadKubeConfig, } from "../kubernetes/config"; +import { k8sErrMsg } from "../support/error"; import { K8sNamespaceFile } from "../support/namespace"; import { K8sServiceRegistrationType, diff --git a/lib/core/pack/k8s/support/error.ts b/lib/core/pack/k8s/support/error.ts index 5b6113348..6b4711c85 100644 --- a/lib/core/pack/k8s/support/error.ts +++ b/lib/core/pack/k8s/support/error.ts @@ -24,7 +24,7 @@ import * as request from "request"; * @param e Some sort of Error or similar * @return Error message */ -export function errMsg(e: any): string { +export function k8sErrMsg(e: any): string { if (!e) { return stringify(e); } else if (typeof e === "string") { @@ -36,7 +36,7 @@ export function errMsg(e: any): string { } else if (requestErrMsg(e)) { return requestErrMsg(e); } else { - return stringify(e, keyFilter); + return `Kubernetes API request error: ${stringify(e, keyFilter)}`; } } diff --git a/lib/core/pack/k8s/support/retry.ts b/lib/core/pack/k8s/support/retry.ts index e27d7e073..937031d22 100644 --- a/lib/core/pack/k8s/support/retry.ts +++ b/lib/core/pack/k8s/support/retry.ts @@ -18,7 +18,7 @@ import { doWithRetry, RetryOptions, } from "@atomist/automation-client/lib/util/retry"; -import { errMsg } from "./error"; +import { k8sErrMsg } from "./error"; /** * Extract Kubernetes errors for doWithRetry. @@ -30,7 +30,7 @@ export async function logRetry(f: () => Promise, desc: string, options?: R r = await f(); } catch (e) { if (!(e instanceof Error)) { - const err = new Error(errMsg(e)); + const err = new Error(k8sErrMsg(e)); Object.keys(e).forEach(k => (err as any)[k] = e[k]); throw err; } diff --git a/lib/core/pack/k8s/sync/goals.ts b/lib/core/pack/k8s/sync/goals.ts index 701a29364..056dd3323 100644 --- a/lib/core/pack/k8s/sync/goals.ts +++ b/lib/core/pack/k8s/sync/goals.ts @@ -37,7 +37,7 @@ import { KubernetesSyncOptions, SyncRepoRef, } from "../config"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { changeResource } from "./change"; import { diffPush } from "./diff"; import { isRemoteRepo } from "./repo"; @@ -124,7 +124,7 @@ export const K8sSync: ExecuteGoal = async gi => { try { await changeResource(p, change); } catch (e) { - e.message = `Failed to ${change.change} '${change.path}' resource for commit ${change.sha}: ${errMsg(e)}`; + e.message = `Failed to ${change.change} '${change.path}' resource for commit ${change.sha}: ${k8sErrMsg(e)}`; log.write(e.message); errs.push(e); } diff --git a/lib/core/pack/k8s/sync/sync.ts b/lib/core/pack/k8s/sync/sync.ts index 0572d3d68..ba2332350 100644 --- a/lib/core/pack/k8s/sync/sync.ts +++ b/lib/core/pack/k8s/sync/sync.ts @@ -31,7 +31,7 @@ import { parseKubernetesSpecs, specSlug, } from "../kubernetes/spec"; -import { errMsg } from "../support/error"; +import { k8sErrMsg } from "../support/error"; import { cleanName } from "../support/name"; import { defaultCloneOptions } from "./clone"; import { k8sSpecGlob } from "./diff"; @@ -140,13 +140,13 @@ function syncApply(opts: KubernetesSyncOptions): (p: GitProject) => Promise { +describe("core/pack/k8s/support/error", () => { - describe("errMsg", () => { + describe("k8sErrMsg", () => { it("should handle undefined", () => { - const m = errMsg(undefined); + const m = k8sErrMsg(undefined); assert(m === undefined); }); it("should handle null", () => { // tslint:disable-next-line:no-null-keyword - const m = errMsg(null); + const m = k8sErrMsg(null); assert(m === "null"); }); it("should handle an Error", () => { const r = new Error("Blitzen Trapper"); - const m = errMsg(r); + const m = k8sErrMsg(r); const e = "Blitzen Trapper"; assert(m === e); }); @@ -123,7 +123,7 @@ describe("pack/k8s/support/error", () => { retriesLeft: 5, }; /* tslint:enable:max-line-length no-null-keyword */ - const m = errMsg(r); + const m = k8sErrMsg(r); assert(m === r.body.message); }); @@ -169,7 +169,7 @@ describe("pack/k8s/support/error", () => { retriesLeft: 5, }; /* tslint:disable:no-null-keyword */ - const m = errMsg(r); + const m = k8sErrMsg(r); assert(m === "404 page not found\n"); }); @@ -177,21 +177,21 @@ describe("pack/k8s/support/error", () => { const r = { blitzenTrapper: "Furr", }; - const m = errMsg(r); - const e = JSON.stringify(r); + const m = k8sErrMsg(r); + const e = `Kubernetes API request error: {"blitzenTrapper":"Furr"}`; assert(m === e); }); it("should handle an array", () => { const r = ["Blitzen", "Trapper", "Furr"]; - const m = errMsg(r); + const m = k8sErrMsg(r); const e = JSON.stringify(r); assert(m === e); }); it("should handle a string", () => { const r = "Blitzen Trapper"; - const m = errMsg(r); + const m = k8sErrMsg(r); assert(m === r); }); @@ -208,8 +208,9 @@ describe("pack/k8s/support/error", () => { JWT: "Echo/Always On/Easy Con", }, }; - const m = errMsg(r); - const e = `{"blitzenTrapper":"Furr","token":"**************","Key":"******","song":{"JWT":"E*********************n"}}`; + const m = k8sErrMsg(r); + const e = "Kubernetes API request error: " + + `{"blitzenTrapper":"Furr","token":"**************","Key":"******","song":{"JWT":"E*********************n"}}`; assert(m === e); }); @@ -221,7 +222,7 @@ describe("pack/k8s/support/error", () => { }, }, }; - const m = errMsg(r); + const m = k8sErrMsg(r); assert(m === "Blitzen Trapper"); });