Skip to contentSkip to conversation

Add CI configuration for Kubernetes

PATCH In review Camilla Conte 3 participants 23 messages May 22, 2023 – May 30, 2023

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/5 Remove redundant CI variables

In reply to Camilla Conte

These are not needed when using gitlab.com shared runners.

---
 .gitlab-ci.d/opensbi.yml | 3 ---
 1 file changed, 3 deletions(-)
.gitlab-ci.d/opensbi.yml +0 -3
index 9a651465d8..13070575b6 100644
@@ -48,9 +48,6 @@ docker-opensbi:
   variables:
     GIT_DEPTH: 3
     IMAGE_TAG: $CI_REGISTRY_IMAGE:opensbi-cross-build
-    # We don't use TLS
-    DOCKER_HOST: tcp://docker:2375
-    DOCKER_TLS_CERTDIR: ""
   before_script:
     - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
   script:
Signature · 1 line
2.40.1
#3 lore raw

PATCH v2 2/5 Use docker "stable" tag

Use the same tag in all jobs.

---
 .gitlab-ci.d/container-template.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.gitlab-ci.d/container-template.yml +1 -1
index 519b8a9482..11569dd900 100644
@@ -3,7 +3,7 @@
   image: docker:stable
   stage: containers
   services:
-    - docker:dind
+    - docker:stable-dind
   before_script:
     - export TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest"
     - export COMMON_TAG="$CI_REGISTRY/qemu-project/qemu/qemu/$NAME:latest"
Signature · 1 line
2.40.1
#14 lore raw

PATCH v2 5/5 Add Kubernetes runner configuration

In reply to Camilla Conte

Custom values for the gitlab-runner Helm chart. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
 .../ci/gitlab-kubernetes-runners/values.yaml  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 scripts/ci/gitlab-kubernetes-runners/values.yaml
scripts/ci/gitlab-kubernetes-runners/values.yaml new file +30 -0
new file mode 100644
index 0000000000..204a96a842
@@ -0,0 +1,30 @@
+gitlabUrl: "https://gitlab.com/"
+runnerRegistrationToken: ""
+rbac:
+  create: true
+concurrent: 200
+runners:
+  privileged: true
+  config: |
+    [[runners]]
+      limit = 100
+      environment = [
+        "DOCKER_HOST=tcp://docker:2376",
+        "DOCKER_TLS_CERTDIR=/certs",
+        "DOCKER_TLS_VERIFY=1",
+        "DOCKER_CERT_PATH=/certs/client"
+      ]
+      [runners.kubernetes]
+        poll_timeout = 1200
+        image = "ubuntu:20.04"
+        cpu_request = "0.5"
+        service_cpu_request = "0.5"
+        helper_cpu_request = "0.25"
+        cpu_request_overwrite_max_allowed = "7"
+        memory_request_overwrite_max_allowed = "30Gi"
+      [[runners.kubernetes.volumes.empty_dir]]
+        name = "docker-certs"
+        mount_path = "/certs/client"
+        medium = "Memory"
+      [runners.kubernetes.node_selector]
+        agentpool = "jobs"
Signature · 1 line
2.40.1
#8 lore raw

PATCH v2 3/5 Add loop over docker info

In reply to Camilla Conte

Wait for docker info to return successfuly to ensure that the docker server (daemon) started.
This is needed for jobs running on Kubernetes. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
 .gitlab-ci.d/container-template.yml | 2 +-
 .gitlab-ci.d/opensbi.yml            | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
.gitlab-ci.d/container-template.yml +1 -1
index 11569dd900..9ac4a0ee25 100644
@@ -8,8 +8,8 @@
     - export TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest"
     - export COMMON_TAG="$CI_REGISTRY/qemu-project/qemu/qemu/$NAME:latest"
     - apk add python3
-    - docker info
     - docker login $CI_REGISTRY -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
+    - until docker info; do sleep 1; done
   script:
     - echo "TAG:$TAG"
     - echo "COMMON_TAG:$COMMON_TAG"
.gitlab-ci.d/opensbi.yml +1 -0
index 13070575b6..2e9d51764e 100644
@@ -50,6 +50,7 @@ docker-opensbi:
     IMAGE_TAG: $CI_REGISTRY_IMAGE:opensbi-cross-build
   before_script:
     - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
+    - until docker info; do sleep 1; done
   script:
     - docker pull $IMAGE_TAG || true
     - docker build --cache-from $IMAGE_TAG --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
Signature · 1 line
2.40.1
#12 lore raw

PATCH v2 4/5 Add CI variable RUNNER_TAG

In reply to Camilla Conte

This allows to set a job tag dinamically.
We need this to be able to select the Kubernetes runner. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
 .gitlab-ci.d/qemu-project.yml | 7 +++++++
 1 file changed, 7 insertions(+)
.gitlab-ci.d/qemu-project.yml +7 -0
index a7ed447fe4..4d914c4897 100644
@@ -1,6 +1,13 @@
 # This file contains the set of jobs run by the QEMU project:
 # https://gitlab.com/qemu-project/qemu/-/pipelines
 
+variables:
+  RUNNER_TAG: ""
+
+default:
+  tags:
+    - $RUNNER_TAG
+
 include:
   - local: '/.gitlab-ci.d/base.yml'
   - local: '/.gitlab-ci.d/stages.yml'
Signature · 1 line
2.40.1
#16 lore raw
In reply to Camilla Conte
Quoted 2 lines · Camilla Conte

Here's a second version (v2) of patches to support the Kubernetes runner for Gitlab CI.
You can find the v1 thread here: https://lore.kernel.org/qemu-devel/[email protected]/.

This does not work:

https://gitlab.com/qemu-project/qemu/-/pipelines/875254290

In particular, most jobs spent 30 minutes (until I cancelled them), e.g.

https://gitlab.com/qemu-project/qemu/-/jobs/4329346855#L7561

Client:
Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

r~

#17 lore raw
Quoted 11 lines · Richard Henderson
Quoted 2 lines · Camilla Conte

Here's a second version (v2) of patches to support the Kubernetes runner for Gitlab CI.
You can find the v1 thread here: https://lore.kernel.org/qemu-devel/[email protected]/.

This does not work:

https://gitlab.com/qemu-project/qemu/-/pipelines/875254290

In particular, most jobs spent 30 minutes (until I cancelled them), e.g.

Quoted 7 lines

https://gitlab.com/qemu-project/qemu/-/jobs/4329346855#L7561

Client:
Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Seems the problem is with the launcher for the k8s runner which throws a mass of warnings & errors earlier in the logs about pods not being ready

https://gitlab.com/qemu-project/qemu/-/jobs/4329346855#L12

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#18 lore raw
In reply to Richard Henderson
Quoted 3 lines · Richard Henderson

This does not work:

https://gitlab.com/qemu-project/qemu/-/pipelines/875254290

My bad, sorry. I didn't update the runner with the new values.yaml. The Docker environment variables were missing so it's looking for the Docker server at the wrong place.

Now I updated the runner. You have to add the "k8s" tag to the runner again in the settings:
https://gitlab.com/qemu-project/qemu/-/settings/ci_cd#Runners.
As soon as the "k8s" tag is there the pipeline should be able to run.

Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] Remove redundant CI variables

In reply to Camilla Conte
Quoted 6 lines · Camilla Conte

These are not needed when using gitlab.com shared runners.

---
 .gitlab-ci.d/opensbi.yml | 3 ---
 1 file changed, 3 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v2 2/5
#4 lore raw

Re: [PATCH v2 2/5] Use docker "stable" tag

In reply to Camilla Conte
Quoted 6 lines · Camilla Conte

Use the same tag in all jobs.

---
 .gitlab-ci.d/container-template.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v2 3/5
#9 lore raw

Re: [PATCH v2 3/5] Add loop over docker info

In reply to Camilla Conte
Quoted 10 lines · Camilla Conte

Wait for docker info to return successfuly to ensure that the docker server (daemon) started.
This is needed for jobs running on Kubernetes. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
 .gitlab-ci.d/container-template.yml | 2 +-
 .gitlab-ci.d/opensbi.yml            | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v2 4/5
#13 lore raw

Re: [PATCH v2 4/5] Add CI variable RUNNER_TAG

In reply to Camilla Conte
Quoted 1 line · Camilla Conte

This allows to set a job tag dinamically.

typo - s/dinamically/dynamically/

can be fixed when a maintainer queues this, no need to repost just for this typo.

Quoted 7 lines

We need this to be able to select the Kubernetes runner. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
 .gitlab-ci.d/qemu-project.yml | 7 +++++++
 1 file changed, 7 insertions(+)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v2 5/5
#15 lore raw

Re: [PATCH v2 5/5] Add Kubernetes runner configuration

In reply to Camilla Conte
Quoted 8 lines · Camilla Conte

Custom values for the gitlab-runner Helm chart. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
 .../ci/gitlab-kubernetes-runners/values.yaml  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 scripts/ci/gitlab-kubernetes-runners/values.yaml

Can't say I'm massively familiar with this, but there's nothing obviously terrible, so on the basis that you've tested it works

Quoted 16 lines
scripts/ci/gitlab-kubernetes-runners/values.yaml new file +9 -0
new file mode 100644
index 0000000000..204a96a842
@@ -0,0 +1,30 @@
+gitlabUrl: "https://gitlab.com/"
+runnerRegistrationToken: ""
+rbac:
+  create: true
+concurrent: 200
+runners:
+  privileged: true
+  config: |
+    [[runners]]

scripts/ci/gitlab-kubernetes-runners/values.yaml line 19

Quoted 10 lines
scripts/ci/gitlab-kubernetes-runners/values.yaml new file +10 -0
+      limit = 100
+      environment = [
+        "DOCKER_HOST=tcp://docker:2376",
+        "DOCKER_TLS_CERTDIR=/certs",
+        "DOCKER_TLS_VERIFY=1",
+        "DOCKER_CERT_PATH=/certs/client"
+      ]
+      [runners.kubernetes]
+        poll_timeout = 1200
+        image = "ubuntu:20.04"

Is it viable to update to 22.04 whic is the current newest LTS release stream ?

scripts/ci/gitlab-kubernetes-runners/values.yaml line 30

Quoted 11 lines
scripts/ci/gitlab-kubernetes-runners/values.yaml new file +11 -0
+        cpu_request = "0.5"
+        service_cpu_request = "0.5"
+        helper_cpu_request = "0.25"
+        cpu_request_overwrite_max_allowed = "7"
+        memory_request_overwrite_max_allowed = "30Gi"
+      [[runners.kubernetes.volumes.empty_dir]]
+        name = "docker-certs"
+        mount_path = "/certs/client"
+        medium = "Memory"
+      [runners.kubernetes.node_selector]
+        agentpool = "jobs"

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#21 lore raw

PATCH v3 5/5 Add Kubernetes runner configuration

In reply to Camilla Conte

Custom values for the gitlab-runner Helm chart. See https://wiki.qemu.org/Testing/CI/KubernetesRunners.

---
Changes since previous version (PATCH v2 5/5):
- Update ubuntu tag to 22.04. I tested it and it works.
- Remove concurrent jobs limits (use defaults).

 .../ci/gitlab-kubernetes-runners/values.yaml  | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 scripts/ci/gitlab-kubernetes-runners/values.yaml
scripts/ci/gitlab-kubernetes-runners/values.yaml new file +28 -0
new file mode 100644
index 0000000000..34c9befdce
@@ -0,0 +1,28 @@
+gitlabUrl: "https://gitlab.com/"
+runnerRegistrationToken: ""
+rbac:
+  create: true
+runners:
+  privileged: true
+  config: |
+    [[runners]]
+      environment = [
+        "DOCKER_HOST=tcp://docker:2376",
+        "DOCKER_TLS_CERTDIR=/certs",
+        "DOCKER_TLS_VERIFY=1",
+        "DOCKER_CERT_PATH=/certs/client"
+      ]
+      [runners.kubernetes]
+        poll_timeout = 1200
+        image = "ubuntu:22.04"
+        cpu_request = "0.5"
+        service_cpu_request = "0.5"
+        helper_cpu_request = "0.25"
+        cpu_request_overwrite_max_allowed = "7"
+        memory_request_overwrite_max_allowed = "30Gi"
+      [[runners.kubernetes.volumes.empty_dir]]
+        name = "docker-certs"
+        mount_path = "/certs/client"
+        medium = "Memory"
+      [runners.kubernetes.node_selector]
+        agentpool = "jobs"
Signature · 1 line
2.40.1
#10 lore raw

Re: [PATCH v2 3/5] Add loop over docker info

In reply to Camilla Conte
Quoted 1 line · Camilla Conte

+ - until docker info; do sleep 1; done

How long are you expecting this to have to wait?
Less than 5 seconds?

r~

#19 lore raw
In reply to Camilla Conte
Quoted 6 lines · Camilla Conte
Quoted 3 lines · Richard Henderson

This does not work:

https://gitlab.com/qemu-project/qemu/-/pipelines/875254290

Quoted 9 lines

My bad, sorry. I didn't update the runner with the new values.yaml. The Docker environment variables were missing so it's looking for the Docker server at the wrong place.

Now I updated the runner. You have to add the "k8s" tag to the runner again in the settings:
https://gitlab.com/qemu-project/qemu/-/settings/ci_cd#Runners.
As soon as the "k8s" tag is there the pipeline should be able to run.

The k8s tag has been there on the runner all along. Did you mean something else?

r~

#11 lore raw

Re: [PATCH v2 3/5] Add loop over docker info

In reply to Richard Henderson
Quoted 6 lines · Richard Henderson
Quoted 1 line · Camilla Conte

+ - until docker info; do sleep 1; done

How long are you expecting this to have to wait?
Less than 5 seconds?

I remember seeing jobs where it took longer than five seconds, but I can't find them at the moment.
I guess you wish the "until" loop to fail sooner, rather than having to wait for the whole job timing out.
What about setting a five seconds timeout for the loop and raise it later if we see
jobs failing?

Quoted 4 lines

r~

#20 lore raw
In reply to Richard Henderson
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Camilla Conte
Quoted 3 lines · Richard Henderson

This does not work:

https://gitlab.com/qemu-project/qemu/-/pipelines/875254290

My bad, sorry. I didn't update the runner with the new values.yaml. The Docker environment variables were missing so it's looking for the Docker server at the wrong place.

Quoted 7 lines
Quoted 5 lines

Now I updated the runner. You have to add the "k8s" tag to the runner again in the settings:
https://gitlab.com/qemu-project/qemu/-/settings/ci_cd#Runners.
As soon as the "k8s" tag is there the pipeline should be able to run.

The k8s tag has been there on the runner all along. Did you mean something else?

I had Paolo adding it a few hours ago.

Quoted 4 lines

r~

#5 lore raw

Re: [PATCH v2 2/5] Use docker "stable" tag

In reply to Camilla Conte
Quoted 12 lines · Camilla Conte

Use the same tag in all jobs.

---
 .gitlab-ci.d/container-template.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.gitlab-ci.d/container-template.yml +0 -0
index 519b8a9482..11569dd900 100644

.gitlab-ci.d/container-template.yml line 6

Quoted 5 lines
.gitlab-ci.d/container-template.yml +1 -1
@@ -3,7 +3,7 @@
   image: docker:stable
   stage: containers
   services:
-    - docker:dind
+    - docker:stable-dind

For reasons I don't understand, this change is responsible for all our failed CI jobs involving Fedora being unable to resolve DNS

Fedora 37 - x86_64 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'fedora':
- Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-37&arch=x86_64&countme=1 [getaddrinfo() thread failed to start]
- Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-37&arch=x86_64 [getaddrinfo() thread failed to start]
Error: Failed to download metadata for repo 'fedora': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-37&arch=x86_64 [getaddrinfo() thread failed to start]

Switching back to ':dind' instead of ':stable-dind' makes it work again.

AFAICT, the ':stable-dind' and ':stable' tags are no longer even supported.

The last published content under these tags dates from 2020, and these tag names are not mentioned on

    https://hub.docker.com/_/docker

While reverting this change would fix our Fedora problems, it leaves usage of the 'stable-dind' tag in opensbi.yml, as well as 'stable' tag usage in other places.

Thus I'm going to test a patch to move everything to 'latest' / 'dind'

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw

Re: [PATCH v2 2/5] Use docker "stable" tag

Quoted 22 lines · Daniel P. Berrangé
Quoted 12 lines · Camilla Conte

Use the same tag in all jobs.

---
 .gitlab-ci.d/container-template.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.gitlab-ci.d/container-template.yml +0 -0
index 519b8a9482..11569dd900 100644

.gitlab-ci.d/container-template.yml line 6

Quoted 5 lines
.gitlab-ci.d/container-template.yml +1 -1
@@ -3,7 +3,7 @@
   image: docker:stable
   stage: containers
   services:
-    - docker:dind
+    - docker:stable-dind

For reasons I don't understand, this change is responsible for all our failed CI jobs involving Fedora being unable to resolve DNS

Quoted 1 line

AFAICT, the ':stable-dind' and ':stable' tags are no longer even supported.

And I found confirmation of this:

https://github.com/docker-library/docker/commit/606c63960a4845af7077721eb3900c706f5d0c5e

"This will remove the "test" and "stable" aliases for whatever
major release comes after 19.03 (so once the next release comes out, "stable" will become a stale alias).

I'm not 100% sure this is the right answer, but the "stable" alias has definitely been a huge source of confusion very recently (and it doesn't have much meaning anymore anyways given the death of the "edge" channel)."

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [PATCH v2 2/5] Use docker "stable" tag

Quoted 29 lines · Daniel P. Berrangé
Quoted 22 lines · Daniel P. Berrangé
Quoted 12 lines · Camilla Conte

Use the same tag in all jobs.

---
  .gitlab-ci.d/container-template.yml | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
.gitlab-ci.d/container-template.yml +0 -0
index 519b8a9482..11569dd900 100644

.gitlab-ci.d/container-template.yml line 6

Quoted 5 lines
.gitlab-ci.d/container-template.yml +1 -1
@@ -3,7 +3,7 @@
    image: docker:stable
    stage: containers
    services:
-    - docker:dind
+    - docker:stable-dind

For reasons I don't understand, this change is responsible for all our failed CI jobs involving Fedora being unable to resolve DNS

Quoted 1 line

AFAICT, the ':stable-dind' and ':stable' tags are no longer even supported.

And I found confirmation of this:

   https://github.com/docker-library/docker/commit/606c63960a4845af7077721eb3900c706f5d0c5e
Quoted 8 lines

"This will remove the "test" and "stable" aliases for whatever
major release comes after 19.03 (so once the next release comes out, "stable" will become a stale alias).

I'm not 100% sure this is the right answer, but the "stable" alias has definitely been a huge source of confusion very recently (and it doesn't have much meaning anymore anyways given the death of the "edge" channel)."

Excellent, thanks for the sleuthing.

r~