Auto DevOps deployment unable to find namespace when the environment exists with a different slug

Moved from gitlab-org/gitlab-services/design.gitlab.com#409 (moved), and the first comment thread below, #32341 (comment 219403617), outlines the investigation process that lead to this issue.

Problem

Kubernetes deployments with namespace-per-environment fail for all dynamically generated environments that were created prior to gitlab-foss!30551 (merged) due to the existing slug being different from the new slug.

This is especially common for review apps for generic branch names, such as patch-1 (with the corresponding environment name review/patch-1)

Details

The source of the mismatch seems to be that

  • in the build prerequisites, we use an already persisted environment.slug as the environment slug parameter
  • but when looking up the predefined cluster variables, we use a generated slug

Proposed solution

One solution might be to make KubernetesNamespaceFinder take environment_name instead of environment_slug, and join on the environments table in #find_namespace. Given that there's a unique index on environment (project_id, name), this should be safe and feasible

Examples

From design.gitlab.com:

  • Generic branch name: gitlab-org/gitlab-services/design.gitlab.com!1560 (closed)
  • Re-using a non-generic branch name: gitlab-org/gitlab-services/design.gitlab.com!1570 (closed)
  • Old MR: gitlab-org/gitlab-services/design.gitlab.com!850 (closed)
  • Old MR: gitlab-org/gitlab-services/design.gitlab.com!1439 (merged)
Edited Sep 19, 2019 by Hordur Freyr Yngvason
Assignee Loading
Time tracking Loading