From edd5e3f4e2f9d87b278611ce15b2d676f9adcda0 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 24 Oct 2021 21:30:57 -0700 Subject: [PATCH] fix(k8s): harbor registry support (#2619) * fix: support newest Harbor registry error text * test: add test for skopeo manifest unknown error --- .../kubernetes/container/build/common.ts | 9 ++++- .../kubernetes/container/build/common.ts | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 core/test/unit/src/plugins/kubernetes/container/build/common.ts diff --git a/core/src/plugins/kubernetes/container/build/common.ts b/core/src/plugins/kubernetes/container/build/common.ts index bd6989e6d8..73f36497e1 100644 --- a/core/src/plugins/kubernetes/container/build/common.ts +++ b/core/src/plugins/kubernetes/container/build/common.ts @@ -256,7 +256,7 @@ export async function skopeoBuildStatus({ const res = err.detail?.result || {} // Non-zero exit code can both mean the manifest is not found, and any other unexpected error - if (res.exitCode !== 0 && !res.stderr?.includes("manifest unknown")) { + if (res.exitCode !== 0 && !skopeoManifestUnknown(res.stderr)) { const output = res.allLogs || err.message throw new RuntimeError(`Unable to query registry for image status: ${output}`, { @@ -268,6 +268,13 @@ export async function skopeoBuildStatus({ } } +export function skopeoManifestUnknown(errMsg: string | null | undefined): boolean { + if (!errMsg) { + return false + } + return errMsg.includes("manifest unknown") || /artifact [^ ]+ not found/.test(errMsg) +} + /** * Get a PodRunner for the util deployment in the garden-system namespace. */ diff --git a/core/test/unit/src/plugins/kubernetes/container/build/common.ts b/core/test/unit/src/plugins/kubernetes/container/build/common.ts new file mode 100644 index 0000000000..aa3180bbe0 --- /dev/null +++ b/core/test/unit/src/plugins/kubernetes/container/build/common.ts @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018-2021 Garden Technologies, Inc. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { skopeoManifestUnknown } from "../../../../../../../src/plugins/kubernetes/container/build/common" +import { expect } from "chai" + +describe("common build", () => { + describe("manifest error", () => { + it("should result in manifest unknown for common registry error", () => { + const errorMessage = "ERROR: manifest unknown: manifest unknown" + + expect(skopeoManifestUnknown(errorMessage)).to.be.true + }) + + it("should result in manifest unknown for Harbor registry error", () => { + const errorMessage = + 'Unable to query registry for image status: time="2021-10-13T17:50:25Z" level=fatal msg="Error parsing image name "docker://registry.domain/namespace/image-name:v-1f160eadbb": Error reading manifest v-1f160eadbb in registry.domain/namespace/image-name: unknown: artifact namespace/image-name:v-1f160eadbb not found"' + + expect(skopeoManifestUnknown(errorMessage)).to.be.true + }) + + it("should result in manifest not unknown for other errors", () => { + const errorMessage = + "unauthorized: unauthorized to access repository: namespace/image-name, action: push: unauthorized to access repository: namespace/image-name, action: push" + + expect(skopeoManifestUnknown(errorMessage)).to.be.false + }) + }) +})