Skip to content

Commit

Permalink
Merge "Remove Replicas definition from Zuul CRD"
Browse files Browse the repository at this point in the history
  • Loading branch information
Microzuul CI authored and Gerrit Code Review committed Nov 15, 2023
2 parents a2dfdd9 + 5ef80e5 commit 435649c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 55 deletions.
5 changes: 0 additions & 5 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions doc/deployment/zuul.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <resource kind> <resource name> --replicas=<number of replicas>

# Example to scale Zuul Executor
kubectl scale sts zuul-executor --replicas=3
```
The scale will take no more that one minute.
2 changes: 0 additions & 2 deletions doc/reference/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|


Expand All @@ -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|


Expand Down
14 changes: 2 additions & 12 deletions roles/health-check/scale-resources/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion roles/health-check/scale-resources/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "Checking operation {{ operation }}"
- name: "Scaling resources"
ansible.builtin.include_tasks:
file: scale.yaml
loop:
Expand Down
24 changes: 10 additions & 14 deletions roles/health-check/scale-resources/tasks/scale.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 1 addition & 8 deletions roles/run-tests/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
loop:
- check-service-uri
- zuul-connections
- scale-resources
- zuul-authenticators
- config-update-zuul
- config-update-nodepool-launcher
Expand All @@ -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

0 comments on commit 435649c

Please sign in to comment.