Skip to content

Fix invalid K8s namespace name error due to project.slug casing and special character

An error was reported by a customer when using the template in the docs.

Under the If Namespace per environment was checked, use the following template: section in https://docs.gitlab.com/user/infrastructure/clusters/migrate_to_gitlab_agent/#migrate-from-gitlab-managed-clusters-to-kubernetes-resources:

objects:
  - apiVersion: v1
    kind: Namespace
    metadata:
      name: {{ .project.slug }}-{{ .project.id }}-{{ .environment.slug }}
  ...

Error:

"error\":\"dry run: apply: Namespace \\\"Upper-case-project-name\\\" is invalid: metadata.name: Invalid value: \\\"Upper-case-project-name\\\": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')\"}",

Edited by Taka Nishida