From 439559853dc5d9d997b1bcb44ced6be8c8d09010 Mon Sep 17 00:00:00 2001 From: Anna Mager <78752267+twelvemo@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:33:11 +0100 Subject: [PATCH] fix(container): container registry namespace is empty when not specified (#6638) * fix(container): container registry namespace is empty when not specified * chore: update reference docs * chore: use ternary --- core/src/plugins/container/config.ts | 4 ++-- core/src/plugins/container/helpers.ts | 4 ++-- core/src/plugins/container/moduleConfig.ts | 1 - core/test/unit/src/plugins/container/helpers.ts | 4 ++-- docs/reference/providers/kubernetes.md | 16 ++++++++-------- docs/reference/providers/local-kubernetes.md | 8 ++++---- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/core/src/plugins/container/config.ts b/core/src/plugins/container/config.ts index d3c2004a3e..dc45b10c58 100644 --- a/core/src/plugins/container/config.ts +++ b/core/src/plugins/container/config.ts @@ -825,7 +825,7 @@ export const containerDeploySchema = createSchema({ export interface ContainerRegistryConfig { hostname: string port?: number - namespace: string + namespace?: string insecure: boolean } @@ -840,7 +840,7 @@ export const containerRegistryConfigSchema = createSchema({ port: joi.number().integer().description("The port where the registry listens on, if not the default."), namespace: joi .string() - .default("_") + .optional() .description( "The registry namespace. Will be placed between hostname and image name, like so: //" ) diff --git a/core/src/plugins/container/helpers.ts b/core/src/plugins/container/helpers.ts index a18e8e7d2f..cddf46c12e 100644 --- a/core/src/plugins/container/helpers.ts +++ b/core/src/plugins/container/helpers.ts @@ -16,7 +16,7 @@ import { ConfigurationError, GardenError, RuntimeError } from "../../exceptions. import type { SpawnOutput } from "../../util/util.js" import { spawn } from "../../util/util.js" import type { ContainerBuildOutputs, ContainerModuleConfig, ContainerRegistryConfig } from "./moduleConfig.js" -import { defaultImageNamespace, defaultTag as _defaultTag } from "./moduleConfig.js" +import { defaultTag as _defaultTag } from "./moduleConfig.js" import type { Writable } from "stream" import { flatten, fromPairs, reduce, uniq } from "lodash-es" import type { ActionLog, Log } from "../../logger/log-entry.js" @@ -267,7 +267,7 @@ const helpers = { const name = parsed.tag ? `${parsed.repository}:${parsed.tag}` : parsed.repository if (parsed.host) { - return `${parsed.host}/${parsed.namespace || defaultImageNamespace}/${name}` + return `${parsed.host}/${parsed.namespace ? parsed.namespace + "/" : ""}${name}` } else if (parsed.namespace) { return `${parsed.namespace}/${name}` } else { diff --git a/core/src/plugins/container/moduleConfig.ts b/core/src/plugins/container/moduleConfig.ts index 6945a7b7e3..0274975c57 100644 --- a/core/src/plugins/container/moduleConfig.ts +++ b/core/src/plugins/container/moduleConfig.ts @@ -87,7 +87,6 @@ export interface ContainerModuleSpec extends ModuleSpec { export type ContainerModuleConfig = ModuleConfig -export const defaultImageNamespace = "_" export const defaultTag = "latest" const containerBuildSpecSchema = () => diff --git a/core/test/unit/src/plugins/container/helpers.ts b/core/test/unit/src/plugins/container/helpers.ts index a3b2000b60..e4f01d58cd 100644 --- a/core/test/unit/src/plugins/container/helpers.ts +++ b/core/test/unit/src/plugins/container/helpers.ts @@ -271,14 +271,14 @@ describe("containerHelpers", () => { ).to.equal("my-host.com/namespace/image:tag") }) - it("should set a default namespace when host but no namespace is specified", () => { + it("should ignore the namespace when host but no namespace is specified", () => { expect( helpers.unparseImageId({ host: "my-host.com", repository: "image", tag: "tag", }) - ).to.equal("my-host.com/_/image:tag") + ).to.equal("my-host.com/image:tag") }) it("should correctly compose an id with a host and multi-level namespace", () => { diff --git a/docs/reference/providers/kubernetes.md b/docs/reference/providers/kubernetes.md index bb348c0124..9b5b26dec9 100644 --- a/docs/reference/providers/kubernetes.md +++ b/docs/reference/providers/kubernetes.md @@ -139,7 +139,7 @@ providers: # The registry namespace. Will be placed between hostname and image name, like so: # // - namespace: _ + namespace: # Set to true to allow insecure connections to the registry (without SSL). insecure: false @@ -486,7 +486,7 @@ providers: # The registry namespace. Will be placed between hostname and image name, like so: // - namespace: _ + namespace: # Set to true to allow insecure connections to the registry (without SSL). insecure: false @@ -757,9 +757,9 @@ The port where the registry listens on, if not the default. The registry namespace. Will be placed between hostname and image name, like so: // -| Type | Default | Required | -| -------- | ------- | -------- | -| `string` | `"_"` | No | +| Type | Required | +| -------- | -------- | +| `string` | No | Example: @@ -2224,9 +2224,9 @@ The port where the registry listens on, if not the default. The registry namespace. Will be placed between hostname and image name, like so: // -| Type | Default | Required | -| -------- | ------- | -------- | -| `string` | `"_"` | No | +| Type | Required | +| -------- | -------- | +| `string` | No | Example: diff --git a/docs/reference/providers/local-kubernetes.md b/docs/reference/providers/local-kubernetes.md index 3e940dbd14..67d7ffb530 100644 --- a/docs/reference/providers/local-kubernetes.md +++ b/docs/reference/providers/local-kubernetes.md @@ -132,7 +132,7 @@ providers: # The registry namespace. Will be placed between hostname and image name, like so: # // - namespace: _ + namespace: # Set to true to allow insecure connections to the registry (without SSL). insecure: false @@ -702,9 +702,9 @@ The port where the registry listens on, if not the default. The registry namespace. Will be placed between hostname and image name, like so: // -| Type | Default | Required | -| -------- | ------- | -------- | -| `string` | `"_"` | No | +| Type | Required | +| -------- | -------- | +| `string` | No | Example: