From 5ef80e58588e97cafe3ec2c4e02cfd70ceb1092b Mon Sep 17 00:00:00 2001 From: fserucas Date: Thu, 9 Nov 2023 16:29:08 +0000 Subject: [PATCH] Remove Replicas definition from Zuul CRD This change removes Replicas from Zuul Merger and Zuul Executor CRD and annotations. Change-Id: I7f01bfbde0aba895fa805bd1c27791ca9aaeed37 --- api/v1/softwarefactory_types.go | 5 ---- ...efactory-project.io_softwarefactories.yaml | 9 ------- controllers/zuul.go | 6 ++--- doc/deployment/zuul.md | 13 ++++++++++ doc/reference/api/index.md | 2 -- .../scale-resources/defaults/main.yaml | 14 ++--------- .../scale-resources/tasks/main.yaml | 2 +- .../scale-resources/tasks/scale.yaml | 24 ++++++++----------- roles/run-tests/tasks/main.yaml | 9 +------ 9 files changed, 29 insertions(+), 55 deletions(-) diff --git a/api/v1/softwarefactory_types.go b/api/v1/softwarefactory_types.go index 45885c63..d6b493da 100644 --- a/api/v1/softwarefactory_types.go +++ b/api/v1/softwarefactory_types.go @@ -168,8 +168,6 @@ type ZuulOIDCAuthenticatorSpec struct { type ZuulExecutorSpec struct { // Storage-related settings Storage StorageSpec `json:"storage,omitempty"` - // How many executor pods to run - Replicas int32 `json:"replicas,omitempty"` // Specify the Log Level of the zuul-executor service. // Valid values are: // "INFO" (default), @@ -226,9 +224,6 @@ type ZuulMergerSpec struct { GitTimeout int32 `json:"gitTimeout,omitempty"` // Storage-related settings Storage StorageSpec `json:"storage,omitempty"` - // How many merger pods to run - // +kubebuilder:default:=1 - MinReplicas int32 `json:"minReplicas,omitempty"` // Specify the Log Level of the nodepool launcher service. // Valid values are: // "INFO" (default), diff --git a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml index 208d38c1..4c88d632 100644 --- a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml +++ b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml @@ -298,10 +298,6 @@ spec: - WARN - DEBUG type: string - replicas: - description: How many executor pods to run - format: int32 - type: integer storage: description: Storage-related settings properties: @@ -501,11 +497,6 @@ spec: - WARN - DEBUG type: string - minReplicas: - default: 1 - description: How many merger pods to run - format: int32 - type: integer storage: description: Storage-related settings properties: diff --git a/controllers/zuul.go b/controllers/zuul.go index ee1ad3b0..b2658aa5 100644 --- a/controllers/zuul.go +++ b/controllers/zuul.go @@ -359,13 +359,12 @@ func (r *SFController) EnsureZuulExecutor(cfg *ini.File) bool { "zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections), "zuul-component-config": utils.IniSectionsChecksum(cfg, sections), "zuul-image": base.ZuulImage("zuul-executor"), - "replicas": strconv.Itoa(int(r.cr.Spec.Zuul.Executor.Replicas)), "serial": "1", "zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-executor"))), "zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")), } - ze := r.mkHeadlessSatefulSet("zuul-executor", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Scheduler.Storage), int32(r.cr.Spec.Zuul.Executor.Replicas), apiv1.ReadWriteOnce) + ze := r.mkHeadlessSatefulSet("zuul-executor", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Scheduler.Storage), 1, apiv1.ReadWriteOnce) ze.Spec.Template.ObjectMeta.Annotations = annotations ze.Spec.Template.Spec.Containers = r.mkZuulContainer("zuul-executor") ze.Spec.Template.Spec.Volumes = mkZuulVolumes("zuul-executor", r) @@ -410,11 +409,10 @@ func (r *SFController) EnsureZuulMerger(cfg *ini.File) bool { "zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections), "zuul-component-config": utils.IniSectionsChecksum(cfg, sections), "zuul-image": base.ZuulImage(service), - "replicas": strconv.Itoa(int(r.cr.Spec.Zuul.Merger.MinReplicas)), "zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")), } - zm := r.mkHeadlessSatefulSet(service, "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Merger.Storage), int32(r.cr.Spec.Zuul.Merger.MinReplicas), apiv1.ReadWriteOnce) + zm := r.mkHeadlessSatefulSet(service, "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Merger.Storage), 1, apiv1.ReadWriteOnce) zm.Spec.Template.ObjectMeta.Annotations = annotations zm.Spec.Template.Spec.Containers = r.mkZuulContainer(service) zm.Spec.Template.Spec.Volumes = mkZuulVolumes(service, r) diff --git a/doc/deployment/zuul.md b/doc/deployment/zuul.md index d63e5b7c..b2f87111 100644 --- a/doc/deployment/zuul.md +++ b/doc/deployment/zuul.md @@ -12,6 +12,7 @@ but addresses specificities and idiosyncrasies induced by deploying Zuul with th 1. [Delegating temporary administrative powers on a tenant](#delegating-temporary-administrative-powers-on-a-tenant) 1. [Zuul-Client](#zuul-client) 1. [Zuul-Admin](#zuul-admin) +1. [Scaling Zuul](#scaling-zuul) ## Architecture @@ -72,3 +73,15 @@ kubectl exec --stdin --tty zuul-scheduler-0 -- /bin/sh Then from that shell, run the `zuul-admin` command. +## Scaling Zuul + +Zuul Executor and Zuul Merger services can be scaled whenever sf-operator deployment +no more fits the demand of the CI jobs. +The scale is done with Kubernetes scale cli command: +```bash +kubectl scale --replicas= + +# Example to scale Zuul Executor +kubectl scale sts zuul-executor --replicas=3 +``` +The scale will take no more that one minute. diff --git a/doc/reference/api/index.md b/doc/reference/api/index.md index bd1e28fe..ab1b3773 100644 --- a/doc/reference/api/index.md +++ b/doc/reference/api/index.md @@ -406,7 +406,6 @@ _Appears in:_ | Field | Description | Default Value | | --- | --- | --- | | `storage` _[StorageSpec](#storagespec)_ | Storage-related settings | -| -| `replicas` _integer_ | How many executor pods to run | -| | `logLevel` _[LogLevel](#loglevel)_ | Specify the Log Level of the zuul-executor service. Valid values are: "INFO" (default), "WARN", "DEBUG". Changing this value will restart the service. | INFO| @@ -427,7 +426,6 @@ _Appears in:_ | `gitHttpLowSpeedTime` _integer_ | the [git_http_low_speed_time](https://zuul-ci.org/docs/zuul/latest/configuration.html#attr-merger.git_http_low_speed_time) parameter | -| | `gitTimeout` _integer_ | the [git_timeout](https://zuul-ci.org/docs/zuul/latest/configuration.html#attr-merger.git_timeout) parameter | -| | `storage` _[StorageSpec](#storagespec)_ | Storage-related settings | -| -| `minReplicas` _integer_ | How many merger pods to run | {1}| | `logLevel` _[LogLevel](#loglevel)_ | Specify the Log Level of the nodepool launcher service. Valid values are: "INFO" (default), "WARN", "DEBUG". Changing this value will restart the service. | INFO| diff --git a/roles/health-check/scale-resources/defaults/main.yaml b/roles/health-check/scale-resources/defaults/main.yaml index 9d119422..7750af38 100644 --- a/roles/health-check/scale-resources/defaults/main.yaml +++ b/roles/health-check/scale-resources/defaults/main.yaml @@ -1,15 +1,5 @@ --- -# The scale_up_replicas values are hardcoded now, due it is using update-custom-resource -# role. More info: https://softwarefactory-project.io/r/c/software-factory/sf-operator/+/28387/comments/15f3bffd_f834d8f8 -scale_up_replicas: 4 -scale_down_replicas: 2 scaling_services: - name: zuul-executor - scale_up_resources: - zuul: - executor: - replicas: "{{ scale_up_replicas }}" - scale_down_resources: - zuul: - executor: - replicas: "{{ scale_down_replicas }}" + kind: sts + replicas: 2 diff --git a/roles/health-check/scale-resources/tasks/main.yaml b/roles/health-check/scale-resources/tasks/main.yaml index 664a1a7c..9db6c285 100644 --- a/roles/health-check/scale-resources/tasks/main.yaml +++ b/roles/health-check/scale-resources/tasks/main.yaml @@ -1,5 +1,5 @@ --- -- name: "Checking operation {{ operation }}" +- name: "Scaling resources" ansible.builtin.include_tasks: file: scale.yaml loop: diff --git a/roles/health-check/scale-resources/tasks/scale.yaml b/roles/health-check/scale-resources/tasks/scale.yaml index 7753340a..168c3fca 100644 --- a/roles/health-check/scale-resources/tasks/scale.yaml +++ b/roles/health-check/scale-resources/tasks/scale.yaml @@ -1,22 +1,18 @@ --- -- name: "Collect executor log before the scaleup" +- name: "Collect {{ service.kind }} log before executing the scale command" shell: | mkdir -p ~/zuul-output/logs/k8s-resources/sf/pod - kubectl logs zuul-executor-0 > ~/zuul-output/logs/k8s-resources/sf/pod/zuul-executor-0-zuul-executor-logs0.txt + kubectl logs {{ service.kind }}/{{ service.name }} > ~/zuul-output/logs/k8s-resources/sf/pod/{{ service.name }}-0-{{ service.name }}-logs0.txt -- name: "Scale {{ operation }} on statefulset {{ service.name }}" - ansible.builtin.include_role: - name: "update-custom-resource" - vars: - cr_spec: "{{ service['scale_' + operation + '_resources'] }}" +- name: "Scale on {{ service.kind }} {{ service.name }}" + ansible.builtin.command: + cmd: kubectl scale {{ service.kind }} {{ service.name }} --replicas {{ service.replicas }} -- name: "Get replica count for {{ service.name }} to operation {{ operation }}" +- name: "Get replica count for {{ service.name }}" ansible.builtin.command: > - kubectl get statefulsets {{ service.name }} + kubectl get {{ service.kind }} {{ service.name }} -o jsonpath='{.status.readyReplicas}' register: _scale_ready - -- name: Check if replica count is correct - fail: - msg: "The replica count for service {{ service.name }} is not {{ vars['scale_' + operation + '_replicas'] }}" - when: _scale_ready.stdout | int != vars['scale_' + operation + '_replicas'] + until: _scale_ready.stdout | int == service.replicas + retries: "{{ service.replicas }}" + delay: 10 diff --git a/roles/run-tests/tasks/main.yaml b/roles/run-tests/tasks/main.yaml index 7f1c120b..5e8dfe8c 100644 --- a/roles/run-tests/tasks/main.yaml +++ b/roles/run-tests/tasks/main.yaml @@ -18,6 +18,7 @@ loop: - check-service-uri - zuul-connections + - scale-resources - zuul-authenticators - config-update-zuul - config-update-nodepool-launcher @@ -34,11 +35,3 @@ loop_control: loop_var: role -- name: Check scaling - ansible.builtin.include_role: - name: health-check/scale-resources - loop: - - up - - down - loop_control: - loop_var: operation