Skip to content

Commit

Permalink
Merge the standalone mode and dev mode
Browse files Browse the repository at this point in the history
This change replaces the legacy dev mode with the new standalone mode,
since they both provides the same feature: fast development mode.
The CRD will only be validated using OLM, as it is expected in production.

Change-Id: Ia8b416b3ed762f488e6368e3416b2e9e4f8e23a4
  • Loading branch information
TristanCacqueray authored and morucci committed Nov 15, 2023
1 parent 44f041c commit 118622e
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 128 deletions.
2 changes: 1 addition & 1 deletion cli/sfconfig/cmd/runTests.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Run test_only tag
playbookYAML = "playbooks/main.yaml"
if testOnly {
ansiblePlaybookOptions.Tags = "test_only"
ansiblePlaybookOptions.AddExtraVar("mode", "dev")
ansiblePlaybookOptions.AddExtraVar("mode", "standalone")
} else {
ansiblePlaybookOptions.AddExtraVar("mode", "olm")
}
Expand Down
3 changes: 3 additions & 0 deletions config/samples/sf_v1_softwarefactory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ spec:
username: zuul
hostname: gerrit-sshd
puburl: "https://gerrit.sfop.me"
executor:
logLevel: DEBUG
logserver:
loopDelay: 5
retentionDays: 30
storage:
size: 2Gi
# NOTE: use "crc-csi-hostpath-provisioner" in CRC deployment
Expand Down
24 changes: 13 additions & 11 deletions playbooks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
- setup-env
- sanity-check
- setup-namespaces
- start-gerrit
tasks:
- name: >-
Simulates the "dev" process (start with 'go run' the operator)
that we describe in the CONTRIBUTING doc
ansible.builtin.include_role:
name: run-operator-dev
when: mode == 'dev'
- name: CI process(standalone)
block:
- community.general.make:
target: "{{ item }}"
chdir: "{{ zuul.project.src_dir }}"
loop:
- install-cert-manager
- install-prometheus-operator
- ansible.builtin.include_role:
name: start-prometheus
when: mode == 'standalone'

- name: CI process(OLM install)
ansible.builtin.include_role:
name: "{{ item }}"
loop:
- microshift-workarounds
- start-gerrit
- build-operator-assets
- clean-installations
- install-operator
# we start prometheus after installing the operator, to ensure the prometheus-operator dependency was installed properly.
- start-prometheus
- apply-custom-resources
when: mode == 'olm'

- name: Apply custom resources
ansible.builtin.include_role:
name: apply-custom-resources

- name: Run tests
ansible.builtin.include_role:
name: run-tests
Expand Down
17 changes: 0 additions & 17 deletions playbooks/standalone.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions roles/clean-installations/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
- skip_ansible_lint
- sf_delete_instance

- name: Remove Standalone Software Factory operand(s) in the sf namespace
ansible.builtin.command: kubectl -n sf delete cm sf-standalone-owner
ignore_errors: true
tags:
- skip_ansible_lint
- sf_delete_instance

- name: Release PVCs created by the Software Factory operator in the sf namespace
ansible.builtin.command: kubectl -n sf delete pvc -l app=sf -l run!=gerrit
ignore_errors: true
Expand Down
81 changes: 47 additions & 34 deletions roles/health-check/check-sf-resource-ready/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
---
- name: Wait for the custom resources to be reconciledBy {{ reconciledBy }}
ansible.builtin.command: kubectl get sf my-sf -o=jsonpath='{.status}'
register: sf_ready
until:
- sf_ready.stdout != ""
- '"reconciledBy" in (sf_ready.stdout | from_json)'
- (sf_ready.stdout | from_json).reconciledBy == reconciledBy
retries: "{{ retries }}"
delay: "{{ delay }}"
when:
- reconciledBy is defined
- reconciledBy != ""
- name: "Ensure CR Ready (olm)"
when: mode == 'olm'
block:
- name: Wait for the custom resources to be reconciledBy {{ reconciledBy }}
ansible.builtin.command: kubectl get sf my-sf -o=jsonpath='{.status}'
register: sf_ready
until:
- sf_ready.stdout != ""
- '"reconciledBy" in (sf_ready.stdout | from_json)'
- (sf_ready.stdout | from_json).reconciledBy == reconciledBy
retries: "{{ retries }}"
delay: "{{ delay }}"
when:
- reconciledBy is defined
- reconciledBy != ""

# This task is there by safety. From my understanding the generation field is updated
# by k8s right after any object change
# https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
- name: Ensure 1 sec delay to let time for k8s to update the metadata.generation field
command: sleep 1
# This task is there by safety. From my understanding the generation field is updated
# by k8s right after any object change
# https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
- name: Ensure 1 sec delay to let time for k8s to update the metadata.generation field
command: sleep 1

- name: Get current resource generation
ansible.builtin.command: kubectl get sf my-sf -o=jsonpath='{.metadata.generation}'
register: cr_generation
until: cr_generation.stdout != ""
retries: "{{ retries }}"
delay: "{{ delay }}"
- name: Get current resource generation
ansible.builtin.command: kubectl get sf my-sf -o=jsonpath='{.metadata.generation}'
register: cr_generation
until: cr_generation.stdout != ""
retries: "{{ retries }}"
delay: "{{ delay }}"

- name: Wait for the custom resources to be ready
ansible.builtin.command: kubectl get sf my-sf -o=jsonpath='{.status}'
register: sf_ready
until:
- sf_ready.stdout != ""
- '"ready" in (sf_ready.stdout | from_json)'
- '"observedGeneration" in (sf_ready.stdout | from_json)'
- (sf_ready.stdout | from_json).observedGeneration == (cr_generation.stdout | int)
- (sf_ready.stdout | from_json).ready == true
retries: "{{ retries }}"
delay: "{{ delay }}"
- name: Wait for the custom resources to be ready
ansible.builtin.command: kubectl get sf my-sf -o=jsonpath='{.status}'
register: sf_ready
until:
- sf_ready.stdout != ""
- '"ready" in (sf_ready.stdout | from_json)'
- '"observedGeneration" in (sf_ready.stdout | from_json)'
- (sf_ready.stdout | from_json).observedGeneration == (cr_generation.stdout | int)
- (sf_ready.stdout | from_json).ready == true
retries: "{{ retries }}"
delay: "{{ delay }}"

- name: "Ensure CR Ready (standalone)"
when: mode == 'standalone'
block:
- name: run the operator in standalone mode
ansible.builtin.include_role:
name: run-operator-standalone
vars:
cr_path: /tmp/current_cr.yaml
glue: false
7 changes: 6 additions & 1 deletion roles/health-check/zuul-connections/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
sshkey: "{{ '0000000000000000000000000000000000000000' | b64encode }}"

- name: Get current Zuul gerrit connections
command: kubectl get sf my-sf -o jsonpath='{.spec.zuul.gerritconns}'
command: |
{% if mode == 'olm' %}
kubectl get sf my-sf -o jsonpath='{.spec.zuul.gerritconns}'
{% else %}
echo '[{"name": "gerrit", "username": "zuul", "hostname": "gerrit-sshd", "puburl": "https://gerrit.sfop.me"}]'
{% endif %}
register: gerritconns

- set_fact:
Expand Down
13 changes: 0 additions & 13 deletions roles/run-operator-dev/tasks/main.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions roles/run-operator-standalone/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
glue: true
cr_path: config/samples/sf_v1_softwarefactory.yaml
25 changes: 24 additions & 1 deletion roles/run-operator-standalone/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
---
- name: Ensure ~/zuul-output/logs
ansible.builtin.file:
path: ~/zuul-output/logs
state: directory
when:
- glue

# Empty the sf-operator.log output before the run
- name: Ensure ~/zuul-output/logs
ansible.builtin.file:
path: ~/zuul-output/logs/sf-operator.log
state: absent
when:
- glue

- name: Run the operator in standalone mode
ansible.builtin.shell: |
go run ./main.go standalone --cr config/samples/sf_v1_softwarefactory.yaml --namespace sf
set -o pipefail
go run ./main.go standalone --cr {{ cr_path }} --namespace sf 2>&1 | tee -a ~/zuul-output/logs/sf-operator.log
args:
chdir: "{{ zuul.project.src_dir }}"

- name: Copy current spec
ansible.builtin.shell: "cp {{ cr_path }} /tmp/current_cr.yaml"
args:
chdir: "{{ zuul.project.src_dir }}"
when:
- glue
52 changes: 27 additions & 25 deletions roles/run-tests/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
---
- ansible.builtin.include_role:
name: setup-variables

- name: Iterate on preparation roles
ansible.builtin.include_role:
name: "utils/{{ role }}"
name: "{{ role.name }}"
when: role.when | default(true)
loop:
- manage-hosts
- get-gerrit-admin-user-api-key
- config-repo-get-or-reset
- name: setup-variables
- name: run-operator-standalone
when: "{{ mode == 'standalone' }}"
- name: utils/manage-hosts
- name: utils/get-gerrit-admin-user-api-key
- name: utils/config-repo-get-or-reset
loop_control:
loop_var: role

- name: Iterate on tests
ansible.builtin.include_role:
name: "health-check/{{ role }}"
name: "health-check/{{ role.name }}"
when: role.when | default(true)
loop:
- check-service-uri
- zuul-connections
- scale-resources
- zuul-authenticators
- config-update-zuul
- config-update-nodepool-launcher
- config-update-nodepool-builder
- pod-spawning
- test-volumestats-sidecar
- expand-volume
- validate-purgelogs
- test-custom-route-certs
- test-cert-manager-letsencrypt
- zuul-client-api
- zuul-components
- test-monitoring
- name: check-service-uri
- name: scale-resources
- name: zuul-connections
- name: zuul-authenticators
- name: config-update-zuul
- name: config-update-nodepool-launcher
- name: config-update-nodepool-builder
- name: pod-spawning
- name: test-volumestats-sidecar
- name: expand-volume
- name: validate-purgelogs
- name: test-custom-route-certs
- name: test-cert-manager-letsencrypt
when: "{{ mode == 'olm' }}"
- name: zuul-client-api
- name: zuul-components
- name: test-monitoring
loop_control:
loop_var: role

54 changes: 40 additions & 14 deletions roles/update-custom-resource/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
---
- name: "Update SoftwareFactory resource {{ cr_name }}"
kubernetes.core.k8s:
kubeconfig: "{{ kubeconfig }}"
definition:
kind: "{{ cr_kind }}"
namespace: "{{ cr_namespace }}"
metadata:
name: "{{ cr_name }}"
namespace: sf
spec: "{{ cr_spec }}"

- ansible.builtin.include_role:
name: "health-check/check-sf-resource-ready"
when: check_sf_resource_ready | default(true)
- name: "Update CRD"
when: mode == 'olm'
block:
- name: "Update SoftwareFactory resource {{ cr_name }}"
kubernetes.core.k8s:
kubeconfig: "{{ kubeconfig }}"
definition:
kind: "{{ cr_kind }}"
namespace: "{{ cr_namespace }}"
metadata:
name: "{{ cr_name }}"
namespace: sf
spec: "{{ cr_spec }}"

- ansible.builtin.include_role:
name: "health-check/check-sf-resource-ready"
when: check_sf_resource_ready | default(true)

- name: "Update standalone"
when: mode == 'standalone'
block:
- name: read current crd
slurp:
src: "/tmp/current_cr.yaml"
register: base_cr

- name: merge the new cr
copy:
content: "{{ base_cr['content'] | b64decode | from_yaml | combine(new_cr, recursive=true) }}"
dest: "/tmp/current_cr.yaml"
vars:
new_cr:
spec: "{{ cr_spec }}"

- name: run the operator in standalone mode
ansible.builtin.include_role:
name: run-operator-standalone
vars:
cr_path: /tmp/current_cr.yaml
glue: false
14 changes: 5 additions & 9 deletions zuul.d/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@
timeout: 3600
parent: sf-operator
run: playbooks/upgrade.yaml
vars:
mode: "olm"

- job:
name: sf-operator-dev-multinode
description: Validates a sf-operator multinode deployment
name: sf-operator-standalone
description: Validates a sf-operator standalone deployment in multinode
timeout: 3600
parent: sf-operator-multinode
vars:
mode: "dev"
mode: "standalone"

- job:
name: sf-operator-ansible-lint
Expand All @@ -119,9 +121,3 @@
nodes:
- name: controller
label: cloud-centos-9-small

- job:
name: sf-operator-standalone
description: This test validates a sf-operator standalone deployment
parent: sf-operator
run: playbooks/standalone.yaml
Loading

0 comments on commit 118622e

Please sign in to comment.