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

improvement(core): always require a namespace and simplify env config #1900

Merged
merged 2 commits into from
Jun 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/example-projects/using-garden-in-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ name: ci-demo-project
environments:
...
- name: preview
defaultNamespace: ${project.name}-${local.env.CIRCLE_BRANCH || local.username}
defaultNamespace: preview-${local.env.CIRCLE_BRANCH || local.username}
providers:
- name: kubernetes
environments: [preview]
Expand Down
58 changes: 11 additions & 47 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,13 @@ environments:
- # The name of the environment.
name:

# Control if and how this environment should support namespaces. If set to "optional" (the default), users can
# set a namespace for the environment. This is useful for any shared environments, e.g. testing and development
# environments, where namespaces separate different users or code versions within an environment. Users then
# specify an environment with `--env <namespace>.<environment>`, e.g. `--env alice.dev` or
# `--env my-branch.testing`.
# Set the default namespace to use. This can be templated to be user-specific, or to use an environment variable
# (e.g. in CI).
#
# If set to "required", this namespace separation is enforced, and an error is thrown if a namespace is not
# specified with the `--env` parameter.
#
# If set to "disabled", an error is thrown if a namespace is specified. This makes sense for e.g. production or
# staging environments, where you don't want to split the environment between users or code versions.
#
# When specified, namespaces must be a valid DNS-style label, much like other identifiers.
namespacing: optional

# Set a default namespace to use, when `namespacing` is `required` or `optional`. This can be templated to be
# user-specific, or to use an environment variable (e.g. in CI).
#
# If this is set, users can specify `--env <environment>` and skip the namespace part, even when `namespacing` is
# `required` for the environment.
defaultNamespace:
# You can also set this to `null`, in order to require an explicit namespace to be set on usage. This may be
# advisable for shared environments, but you may also be able to achieve the desired result by templating this
# field, as mentioned above.
defaultNamespace: default

# Flag the environment as a production environment.
#
Expand Down Expand Up @@ -232,39 +218,17 @@ environments:
- name: "dev"
```

### `environments[].namespacing`

[environments](#environments) > namespacing

Control if and how this environment should support namespaces. If set to "optional" (the default), users can
set a namespace for the environment. This is useful for any shared environments, e.g. testing and development
environments, where namespaces separate different users or code versions within an environment. Users then
specify an environment with `--env <namespace>.<environment>`, e.g. `--env alice.dev` or
`--env my-branch.testing`.

If set to "required", this namespace separation is enforced, and an error is thrown if a namespace is not
specified with the `--env` parameter.

If set to "disabled", an error is thrown if a namespace is specified. This makes sense for e.g. production or
staging environments, where you don't want to split the environment between users or code versions.

When specified, namespaces must be a valid DNS-style label, much like other identifiers.

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

### `environments[].defaultNamespace`

[environments](#environments) > defaultNamespace

Set a default namespace to use, when `namespacing` is `required` or `optional`. This can be templated to be user-specific, or to use an environment variable (e.g. in CI).
Set the default namespace to use. This can be templated to be user-specific, or to use an environment variable (e.g. in CI).

If this is set, users can specify `--env <environment>` and skip the namespace part, even when `namespacing` is `required` for the environment.
You can also set this to `null`, in order to require an explicit namespace to be set on usage. This may be advisable for shared environments, but you may also be able to achieve the desired result by templating this field, as mentioned above.

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

Example:

Expand Down
22 changes: 4 additions & 18 deletions docs/reference/providers/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ providers:
# A default hostname to use when no hostname is explicitly configured for a service.
defaultHostname:

# Set a default username (used for namespacing within a cluster).
defaultUsername:

# Defines the strategy for deploying the project services.
# Default is "rolling update" and there is experimental support for "blue/green" deployment.
# The feature only supports modules of type `container`: other types will just deploy using the default strategy.
Expand Down Expand Up @@ -314,10 +311,9 @@ providers:
# Path to kubeconfig file to use instead of the system default. Must be a POSIX-style path.
kubeconfig:

# Specify which namespace to deploy services to. Defaults to the environment namespace, if specified and enabled,
# otherwise the project name.
# Specify which namespace to deploy services to. Defaults to `<project name>-<environment namespace>`.
#
# Note that the framework generates other namespaces as well with this name as a prefix.
# Note that the framework may generate other namespaces as well with this name as a prefix.
namespace:

# Set this to `nginx` to install/enable the NGINX ingress controller.
Expand Down Expand Up @@ -431,16 +427,6 @@ providers:
- defaultHostname: "api.mydomain.com"
```

### `providers[].defaultUsername`

[providers](#providers) > defaultUsername

Set a default username (used for namespacing within a cluster).

| Type | Required |
| -------- | -------- |
| `string` | No |

### `providers[].deploymentStrategy`

[providers](#providers) > deploymentStrategy
Expand Down Expand Up @@ -1467,9 +1453,9 @@ Path to kubeconfig file to use instead of the system default. Must be a POSIX-st

[providers](#providers) > namespace

Specify which namespace to deploy services to. Defaults to the environment namespace, if specified and enabled, otherwise the project name.
Specify which namespace to deploy services to. Defaults to `<project name>-<environment namespace>`.

Note that the framework generates other namespaces as well with this name as a prefix.
Note that the framework may generate other namespaces as well with this name as a prefix.

| Type | Required |
| -------- | -------- |
Expand Down
13 changes: 0 additions & 13 deletions docs/reference/providers/local-kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ providers:
# A default hostname to use when no hostname is explicitly configured for a service.
defaultHostname:

# Set a default username (used for namespacing within a cluster).
defaultUsername:

# Defines the strategy for deploying the project services.
# Default is "rolling update" and there is experimental support for "blue/green" deployment.
# The feature only supports modules of type `container`: other types will just deploy using the default strategy.
Expand Down Expand Up @@ -397,16 +394,6 @@ providers:
- defaultHostname: "api.mydomain.com"
```

### `providers[].defaultUsername`

[providers](#providers) > defaultUsername

Set a default username (used for namespacing within a cluster).

| Type | Required |
| -------- | -------- |
| `string` | No |

### `providers[].deploymentStrategy`

[providers](#providers) > deploymentStrategy
Expand Down
2 changes: 1 addition & 1 deletion examples/build-dependencies/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: build-dependencies
environments:
- name: local
- name: remote
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/deployment-strategies/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environments:
- name: local-default
- name: local-blue-green
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
# Default deployment strategy
- name: local-kubernetes
Expand Down
2 changes: 1 addition & 1 deletion examples/disabled-configs/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ environments:
providers:
- name: local-kubernetes
environments: [local]
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
- name: kubernetes
environments: [remote]
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
# Replace these values as appropriate
context: gke_garden-dev-200012_europe-west1-b_garden-dev-1
defaultHostname: ${local.username}-disabled-configs.dev-1.sys.garden
Expand Down
2 changes: 1 addition & 1 deletion examples/hadolint/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: demo-project
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: hadolint
- name: local-kubernetes
Expand Down
2 changes: 1 addition & 1 deletion examples/hot-reload-post-sync-command/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: hot-reload-post-sync-command
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/hot-reload/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: hot-reload
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/kaniko/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: kaniko
environments:
- name: local
- name: remote
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/kubernetes-secrets/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: kubernetes-secrets
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/openfaas/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: openfaas
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/project-variables/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environments:
# We only want one replica of each service when developing locally
service-replicas: 1
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/remote-sources/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sources:
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/tasks/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: tasks
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/vote-helm/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: vote-helm
environments:
- name: local
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
2 changes: 1 addition & 1 deletion examples/vote/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ environments:
- name: local
- name: remote
- name: testing
defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
providers:
- name: local-kubernetes
environments: [local]
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
checkForUpdates,
checkForStaticDir,
} from "./helpers"
import { defaultEnvironments, ProjectConfig } from "../config/project"
import { defaultEnvironments, ProjectConfig, defaultNamespace } from "../config/project"
import { ERROR_LOG_FILENAME, DEFAULT_API_VERSION, DEFAULT_GARDEN_DIR_NAME, LOGS_DIR_NAME } from "../constants"
import stringify = require("json-stringify-safe")
import { generateBasicDebugInfoReport } from "../commands/get/get-debug-info"
Expand All @@ -70,7 +70,7 @@ const GLOBAL_OPTIONS_GROUP_NAME = "Global options"

export async function makeDummyGarden(root: string, gardenOpts: GardenOpts = {}) {
const environments = gardenOpts.environmentName
? [{ name: gardenOpts.environmentName, variables: {} }]
? [{ name: gardenOpts.environmentName, defaultNamespace, variables: {} }]
: defaultEnvironments

const config: ProjectConfig = {
Expand Down
Loading