Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(k8s): allow specifying version for oci helm charts #5892

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions core/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,22 @@ const helmChartSpecSchema = () =>
"The path, relative to the action path, to the chart sources (i.e. where the Chart.yaml file is, if any)."
),
repo: helmChartRepoSchema(),
url: joi.string().uri().description("An absolute URL to a packaged URL."),
url: joi.string().uri().description("URL to OCI repository, or a URL to a packaged Helm chart archive."),
version: helmChartVersionSchema(),
})
.without("path", ["name", "repo", "version", "url"])
.without("url", ["name", "repo", "version", "path"])
.without("url", ["name", "repo", "path"])
.xor("name", "path", "url")
.description(
dedent`
Specify the Helm chart to use.

If the chart is defined in the same directory as the action, you can skip this, and the chart sources will be detected. If the chart is in the source tree but in a sub-directory, you should set \`chart.path\` to the directory path, relative to the action directory.

If the chart is remote, you can specify \`chart.name\` and \`chart.version\, and optionally \`chart.repo\` (if the chart is not in the default "stable" repo).

You may also specify an absolute URL to a packaged chart via \`chart.url\`.
For remote charts, there are multiple options:
- **[Helm Chart repository](https://helm.sh/docs/topics/chart_repository/)**: specify \`chart.name\` and \`chart.version\, and optionally \`chart.repo\` (if the chart is not in the default "stable" repo).
- **[OCI-Based Registry](https://helm.sh/docs/topics/registries/)**: specify \`chart.url\` with the \`oci://\` URL and optionally \`chart.version\`.
- **Absolute URL to a packaged chart**: specify \`chart.url\`.

One of \`chart.name\`, \`chart.path\` or \`chart.url\` must be specified.
`
Expand Down
17 changes: 17 additions & 0 deletions core/test/data/test-projects/helm/oci-url/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: Deploy
name: oci-url
description: Deploy a chart from OCI URL
type: helm
spec:
chart:
url: oci://registry-1.docker.io/bitnamicharts/memcached

---
kind: Deploy
name: oci-url-with-version
description: Deploy a chart from OCI URL, with version
type: helm
spec:
chart:
url: oci://registry-1.docker.io/bitnamicharts/memcached
version: 7.0.3
82 changes: 42 additions & 40 deletions core/test/integ/src/plugins/kubernetes/helm/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,46 +130,48 @@ describe("helmDeploy", () => {
} catch {}
})

it("should deploy a chart", async () => {
graph = await garden.getConfigGraph({ log: garden.log, emit: false })
const action = await garden.resolveAction<HelmDeployAction>({
action: graph.getDeploy("api"),
log: garden.log,
graph,
})
const actionLog = createActionLog({ log: garden.log, actionName: action.name, actionKind: action.kind })

// Here, we're not going through a router, so we listen for the `namespaceStatus` event directly.
let namespaceStatus: NamespaceStatus | null = null
ctx.events.once("namespaceStatus", (status) => (namespaceStatus = status))
await helmDeploy({
ctx,
log: actionLog,
action,
force: false,
})
expect(namespaceStatus).to.exist
expect(namespaceStatus!.namespaceName).to.eql("helm-test-default")

const releaseName = getReleaseName(action)
const releaseStatus = await getReleaseStatus({
ctx,
action,
releaseName,
log: garden.log,
})

expect(releaseStatus.state).to.equal("ready")
// getReleaseStatus fetches these details from a configmap in the action namespace.
// This means we are testing that the configmap is created correctly every time we
// test the gardenMetadata details from getReleaseStatus.
expect(releaseStatus.detail.gardenMetadata).to.eql({
actionName: "api",
projectName: garden.projectName,
version: action.versionString(),
mode: "default",
})
})
for (const deployName of ["api", "oci-url", "oci-url-with-version"]) {
it(`should deploy chart ${deployName} successfully`, async () => {
graph = await garden.getConfigGraph({ log: garden.log, emit: false })
const action = await garden.resolveAction<HelmDeployAction>({
action: graph.getDeploy(deployName),
log: garden.log,
graph,
})
const actionLog = createActionLog({ log: garden.log, actionName: action.name, actionKind: action.kind })

// Here, we're not going through a router, so we listen for the `namespaceStatus` event directly.
let namespaceStatus: NamespaceStatus | null = null
ctx.events.once("namespaceStatus", (status) => (namespaceStatus = status))
await helmDeploy({
ctx,
log: actionLog,
action,
force: false,
})
expect(namespaceStatus).to.exist
expect(namespaceStatus!.namespaceName).to.eql("helm-test-default")

const releaseName = getReleaseName(action)
const releaseStatus = await getReleaseStatus({
ctx,
action,
releaseName,
log: garden.log,
})

expect(releaseStatus.state).to.equal("ready")
// getReleaseStatus fetches these details from a configmap in the action namespace.
// This means we are testing that the configmap is created correctly every time we
// test the gardenMetadata details from getReleaseStatus.
expect(releaseStatus.detail.gardenMetadata).to.eql({
actionName: deployName,
projectName: garden.projectName,
version: action.versionString(),
mode: "default",
})
})
}

it("should deploy a chart from a converted Helm module referencing a container module version in its image tag", async () => {
graph = await garden.getConfigGraph({ log: garden.log, emit: false })
Expand Down
30 changes: 24 additions & 6 deletions docs/k8s-plugins/actions/deploy/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,30 @@ _[kubernetes guide](./kubernetes.md) for more info._
## Referencing external charts

Using external charts, where the chart sources are not located in your own project, can be quite straightforward. At a
minimum, you just need to point to the chart, and perhaps provide some values as inputs. For example here is the `redis` deploy from
our example project:
minimum, you just need to point to the chart, and perhaps provide some values as inputs. There are two options to deploy external Charts, [Helm chart repositories](https://helm.sh/docs/topics/chart_repository/) (Accessible via `https`) or [OCI-based registries](https://helm.sh/docs/topics/registries/).


### Example: Redis from Bitnami OCI Repository

A specific chart repository can be referenced via the `repo` field. This may be useful if you run your own Helm Chart Repository for your organization, or are referencing an action that isn't contained in the default Helm Repository.

```yaml
kind: Deploy
type: helm
name: redis
spec:
chart:
# Chart name is part of the OCI URL
url: oci://registry-1.docker.io/bitnamicharts/redis
version: "19.0.1"
values:
auth:
enabled: false
```

### Example: Redis from Bitnami Helm Repository

A specific chart repository can be referenced via the `repo` field. This may be useful if you run your own Helm Chart Repository for your organization, or are referencing an action that isn't contained in the default Helm Repository.

```yaml
kind: Deploy
Expand All @@ -37,10 +59,6 @@ spec:
enabled: false
```

This may be all you need for a chart to be deployed with the rest of your stack. You can also list `deploy.redis` as a dependency of one of your other actions. That will ensure redis being up and running before the other actions are executed.

A specific chart repository can be referenced via the `repo` field. This may be useful if you run your own chart repository for your organization, or are referencing an action that isn't contained in the default Helm repo.

## Local charts

Instead of fetching the chart sources from another repository, you'll often want to include your chart sources in your Garden project. To do this, you can simply add a `garden.yml` in your chart directory (next to your `Chart.yaml`) and start by giving it a name:
Expand Down
9 changes: 5 additions & 4 deletions docs/reference/action-types/Deploy/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ Specify the Helm chart to use.

If the chart is defined in the same directory as the action, you can skip this, and the chart sources will be detected. If the chart is in the source tree but in a sub-directory, you should set `chart.path` to the directory path, relative to the action directory.

If the chart is remote, you can specify `chart.name` and `chart.version\, and optionally `chart.repo` (if the chart is not in the default "stable" repo).

You may also specify an absolute URL to a packaged chart via `chart.url`.
For remote charts, there are multiple options:
- **[Helm Chart repository](https://helm.sh/docs/topics/chart_repository/)**: specify `chart.name` and `chart.version\, and optionally `chart.repo` (if the chart is not in the default "stable" repo).
- **[OCI-Based Registry](https://helm.sh/docs/topics/registries/)**: specify `chart.url` with the `oci://` URL and optionally `chart.version`.
- **Absolute URL to a packaged chart**: specify `chart.url`.

One of `chart.name`, `chart.path` or `chart.url` must be specified.

Expand Down Expand Up @@ -431,7 +432,7 @@ The repository URL to fetch the chart from. Defaults to the "stable" helm repo (

[spec](#spec) > [chart](#specchart) > url

An absolute URL to a packaged URL.
URL to OCI repository, or a URL to a packaged Helm chart archive.

| Type | Required |
| -------- | -------- |
Expand Down
9 changes: 5 additions & 4 deletions docs/reference/action-types/Run/helm-pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ Specify the Helm chart to use.

If the chart is defined in the same directory as the action, you can skip this, and the chart sources will be detected. If the chart is in the source tree but in a sub-directory, you should set `chart.path` to the directory path, relative to the action directory.

If the chart is remote, you can specify `chart.name` and `chart.version\, and optionally `chart.repo` (if the chart is not in the default "stable" repo).

You may also specify an absolute URL to a packaged chart via `chart.url`.
For remote charts, there are multiple options:
- **[Helm Chart repository](https://helm.sh/docs/topics/chart_repository/)**: specify `chart.name` and `chart.version\, and optionally `chart.repo` (if the chart is not in the default "stable" repo).
- **[OCI-Based Registry](https://helm.sh/docs/topics/registries/)**: specify `chart.url` with the `oci://` URL and optionally `chart.version`.
- **Absolute URL to a packaged chart**: specify `chart.url`.

One of `chart.name`, `chart.path` or `chart.url` must be specified.

Expand Down Expand Up @@ -454,7 +455,7 @@ The repository URL to fetch the chart from. Defaults to the "stable" helm repo (

[spec](#spec) > [chart](#specchart) > url

An absolute URL to a packaged URL.
URL to OCI repository, or a URL to a packaged Helm chart archive.

| Type | Required |
| -------- | -------- |
Expand Down
9 changes: 5 additions & 4 deletions docs/reference/action-types/Test/helm-pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ Specify the Helm chart to use.

If the chart is defined in the same directory as the action, you can skip this, and the chart sources will be detected. If the chart is in the source tree but in a sub-directory, you should set `chart.path` to the directory path, relative to the action directory.

If the chart is remote, you can specify `chart.name` and `chart.version\, and optionally `chart.repo` (if the chart is not in the default "stable" repo).

You may also specify an absolute URL to a packaged chart via `chart.url`.
For remote charts, there are multiple options:
- **[Helm Chart repository](https://helm.sh/docs/topics/chart_repository/)**: specify `chart.name` and `chart.version\, and optionally `chart.repo` (if the chart is not in the default "stable" repo).
- **[OCI-Based Registry](https://helm.sh/docs/topics/registries/)**: specify `chart.url` with the `oci://` URL and optionally `chart.version`.
- **Absolute URL to a packaged chart**: specify `chart.url`.

One of `chart.name`, `chart.path` or `chart.url` must be specified.

Expand Down Expand Up @@ -454,7 +455,7 @@ The repository URL to fetch the chart from. Defaults to the "stable" helm repo (

[spec](#spec) > [chart](#specchart) > url

An absolute URL to a packaged URL.
URL to OCI repository, or a URL to a packaged Helm chart archive.

| Type | Required |
| -------- | -------- |
Expand Down