Skip to content

Commit

Permalink
fix(container): container registry namespace is empty when not specif…
Browse files Browse the repository at this point in the history
…ied (#6638)

* fix(container): container registry namespace is empty when not specified

* chore: update reference docs

* chore: use ternary
  • Loading branch information
twelvemo authored Nov 15, 2024
1 parent 0f7bf25 commit 4395598
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions core/src/plugins/container/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ export const containerDeploySchema = createSchema({
export interface ContainerRegistryConfig {
hostname: string
port?: number
namespace: string
namespace?: string
insecure: boolean
}

Expand All @@ -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: <hostname>/<namespace>/<image name>"
)
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/container/moduleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export interface ContainerModuleSpec extends ModuleSpec {

export type ContainerModuleConfig = ModuleConfig<ContainerModuleSpec>

export const defaultImageNamespace = "_"
export const defaultTag = "latest"

const containerBuildSpecSchema = () =>
Expand Down
4 changes: 2 additions & 2 deletions core/test/unit/src/plugins/container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
16 changes: 8 additions & 8 deletions docs/reference/providers/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ providers:

# The registry namespace. Will be placed between hostname and image name, like so:
# <hostname>/<namespace>/<image name>
namespace: _
namespace:

# Set to true to allow insecure connections to the registry (without SSL).
insecure: false
Expand Down Expand Up @@ -486,7 +486,7 @@ providers:

# The registry namespace. Will be placed between hostname and image name, like so: <hostname>/<namespace>/<image
# name>
namespace: _
namespace:

# Set to true to allow insecure connections to the registry (without SSL).
insecure: false
Expand Down Expand Up @@ -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: <hostname>/<namespace>/<image name>

| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | `"_"` | No |
| Type | Required |
| -------- | -------- |
| `string` | No |

Example:

Expand Down Expand Up @@ -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: <hostname>/<namespace>/<image name>

| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | `"_"` | No |
| Type | Required |
| -------- | -------- |
| `string` | No |

Example:

Expand Down
8 changes: 4 additions & 4 deletions docs/reference/providers/local-kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ providers:

# The registry namespace. Will be placed between hostname and image name, like so:
# <hostname>/<namespace>/<image name>
namespace: _
namespace:

# Set to true to allow insecure connections to the registry (without SSL).
insecure: false
Expand Down Expand Up @@ -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: <hostname>/<namespace>/<image name>

| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | `"_"` | No |
| Type | Required |
| -------- | -------- |
| `string` | No |

Example:

Expand Down

0 comments on commit 4395598

Please sign in to comment.