Skip to content

Commit

Permalink
fix(k8s): harbor registry support (#2619)
Browse files Browse the repository at this point in the history
* fix: support newest Harbor registry error text

* test: add test for skopeo manifest unknown error
  • Loading branch information
mattpolzin authored Oct 25, 2021
1 parent 2ba8f6d commit edd5e3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/plugins/kubernetes/container/build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, {
Expand All @@ -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.
*/
Expand Down
34 changes: 34 additions & 0 deletions core/test/unit/src/plugins/kubernetes/container/build/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2018-2021 Garden Technologies, Inc. <[email protected]>
*
* 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
})
})
})

0 comments on commit edd5e3f

Please sign in to comment.