Skip to content

Can not overwrite default template

Summary

When using managed Kubernetes resources, I can not redefine the default template

Steps to reproduce

  1. Create a project, register an agent, enable managed resources
  2. Create a new environment_templates/default.yaml under the agent config directory with the following content:
objects:
  - apiVersion: v1
    kind: Namespace
    metadata:
      name: 'nagyv-{{ .ci_pipeline.id }}-{{ .ci_job.id }}'

# Resource lifecycle configuration
apply_resources: on_start    # Resources are applied when environment is started/restarted
delete_resources: on_stop    # Resources are removed when environment is stopped
  1. Create a .gitlab-ci.yml with the following content, use your AGENT_CONTEXT value
test_managed_resource:
    image: portainer/kubectl-shell:2.26.1
    variables:
        AGENT_CONTEXT: gitlab-org/ci-cd/deploy-stage/demos/infra-platform:demo-dev
    before_script:
        - kubectl config get-contexts
        - kubectl config use-context $AGENT_CONTEXT
    script:
        - kubectl auth can-i --list
    environment:
        name: test-${CI_PIPELINE_IID}
        kubernetes:
            agent: $AGENT_CONTEXT
  1. Run the pipeline
  2. Check out the namespace name in the cluster

Example Project

What is the current bug behavior?

The created namespace follows the built-in default template pattern, not the custom one

What is the expected correct behavior?

The namespace name should follow the custom pattern

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Taka Nishida