Skip to content

Configures agentk to know when to talk to KAS on staging canary

What does this MR do and why?

Configures agentk to know when to talk to canary

QA tests run against canary when the environment var
QA_COOKIES="gitlab_canary=true" is set. Up to now, agentk was always
talking to the non-canary infrastructure even if this cookie was set.

With this change we tell kas to add a canary cookie to its requests so
that its requests get redirected to the KAS canary server.

Related issue: gitlab-com/gl-infra/delivery#2557 (closed)

Screenshots or screen recordings

➜  qa git:(qa/jcunha/run-kas-tests-against-canary) QA_COOKIES="gitlab_canary=true" \
GITLAB_SANDBOX_NAME=[REDACTED] \
GITLAB_QA_USER_AGENT=[REDACTED] \
GITLAB_QA_ACCESS_TOKEN=[REDACTED] \
GITLAB_USERNAME=[REDACTED] \
GITLAB_PASSWORD=[REDACTED] \
bundle exec bin/qa Test::Instance::All https://staging.gitlab.com -- -- qa/specs/features/ee/api/7_configure/kubernetes/kubernetes_agent_spec.rb
warning: parser/current is loading parser/ruby27, which recognizes2.7.6-compliant syntax, but you are running 2.7.5.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
2022-11-23 15:57:11 / CONF	::
      ==> Base URL: https://staging.gitlab.com
      ==> Browser: #<Selenium::WebDriver::Chrome::Driver:0x0000000114957af8>
      ==> Libraries: Chemlab::Vendor
[Nov 23 2022 15:57:11 -03 (QA Tests)] INFO  -- Caching token for username: [REDACTED], last six chars of token:[REDACTED]
[Nov 23 2022 15:57:11 -03 (QA Tests)] INFO  -- Performing sanity check for environment!
Run options: exclude {:orchestrated=>true, :transient=>true, :sanity_feature_flags=>true, :geo=>true, :skip_live_env=>true}

Randomized with seed 3238

Configure
  Kubernetes Agent
[Nov 23 2022 15:57:12 -03 (QA Tests)] INFO  -- Starting test: Configure Kubernetes Agent deploys a K8s manifest file
checking for kubectl... yes
checking for gcloud... yes
[Nov 23 2022 15:57:13 -03 (QA Tests)] INFO  -- Executing: `gcloud container clusters create [REDACTED] --region europe-west2 --disk-size 10GB --num-nodes 1 && gcloud container clusters get-credentials --region europe-west2 [REDACTED] `
............
[Nov 23 2022 16:03:55 -03 (QA Tests)] INFO  -- Executing: `kubectl apply -f -`
..
[Nov 23 2022 16:04:02 -03 (QA Tests)] INFO  -- ==> Retrieved a QA::Resource::Sandbox with full_path '[REDACTED]' via api in 0.35 seconds
[Nov 23 2022 16:04:04 -03 (QA Tests)] INFO  -- ==> Built a QA::Resource::Group with full_path '[REDACTED]' via api in 1.54 seconds
[Nov 23 2022 16:04:05 -03 (QA Tests)] INFO  -- ==> Retrieved a QA::Resource::Project with full_path '[REDACTED]' via api in 3.37 seconds
[Nov 23 2022 16:04:06 -03 (QA Tests)] INFO  -- ==> Built a QA::Resource::Clusters::Agent with name '[REDACTED]' via api in 3.71 seconds
[Nov 23 2022 16:04:06 -03 (QA Tests)] INFO  -- ==> Built a QA::Resource::Clusters::AgentToken with id '[REDACTED]' via api in 4.19 seconds
[Nov 23 2022 16:04:06 -03 (QA Tests)] INFO  -- Executing: `kubectl create secret generic gitlab-agent-token --from-literal=token='[REDACTED]'`
.
[Nov 23 2022 16:04:07 -03 (QA Tests)] INFO  -- Executing: `kubectl apply -f -`
......
[Nov 23 2022 16:04:14 -03 (QA Tests)] INFO  -- ==> Built a QA::Resource::Repository::Commit via api in 1.62 seconds
[Nov 23 2022 16:04:15 -03 (QA Tests)] INFO  -- ==> Built a QA::Resource::Repository::Commit via api in 1.25 seconds
[Nov 23 2022 16:04:15 -03 (QA Tests)] INFO  -- Executing: `kubectl get namespace --no-headers --ignore-not-found galatic-empire`
[Nov 23 2022 16:04:22 -03 (QA Tests)] INFO  -- Executing: `kubectl get namespace --no-headers --ignore-not-found galatic-empire`
[Nov 23 2022 16:04:28 -03 (QA Tests)] INFO  -- Executing: `kubectl get namespace --no-headers --ignore-not-found galatic-empire`
[Nov 23 2022 16:04:33 -03 (QA Tests)] INFO  -- Executing: `kubectl get namespace --no-headers --ignore-not-found galatic-empire`
[Nov 23 2022 16:04:34 -03 (QA Tests)] INFO  -- Executing: `gcloud container clusters delete   --region europe-west2   [REDACTED]   --quiet --async `
[Nov 23 2022 16:04:36 -03 (QA Tests)] INFO  -- Removed a QA::Resource::Group with full_path '[REDACTED]'
    deploys a K8s manifest file

Top 1 slowest examples (443.77 seconds, 100.0% of total time):
  Configure Kubernetes Agent deploys a K8s manifest file
    443.77 seconds ./qa/specs/features/ee/api/7_configure/kubernetes/kubernetes_agent_spec.rb:30

Finished in 7 minutes 24 seconds (files took 3.54 seconds to load)
1 example, 0 failures

Randomized with seed 3238

How to set up and validate locally

  1. Have your local environment logged in to a GCP with a default GCP project setup.
  2. From your GitLab repo root folder, execute cd qa && bundle.
  3. Go to your staging.gitlab.com account and:
  • Create a group to use it as the GITLAB_SANDBOX_NAME.
  • Create a persons access token with the api scope to use as the GITLAB_QA_ACCESS_TOKEN.
  • Execute the command below replacing the environment variable values with your own:
QA_COOKIES="gitlab_canary=true" \
GITLAB_SANDBOX_NAME="{YOUR-OWN-STAGING-GROUP-ID}" \
GITLAB_QA_USER_AGENT="{TAKEN-FROM-1PASSWORD}" \
GITLAB_QA_ACCESS_TOKEN="{YOUR-OWN-STAGING-ACCESS-TOKEN}" \
GITLAB_USERNAME="{YOUR-OWN-STAGING-USERNAME}" \
GITLAB_PASSWORD="{YOUR-OWN-STAGING-PASSWORD}" \
bundle exec bin/qa Test::Instance::All https://staging.gitlab.com -- -- qa/specs/features/ee/api/7_configure/kubernetes/kubernetes_agent_spec.rb

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by João Alexandre Cunha

Merge request reports