From 118622ed1d83e968bba701da8571791c66247a18 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Mon, 6 Nov 2023 21:52:07 +0000 Subject: [PATCH] Merge the standalone mode and dev mode 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 --- cli/sfconfig/cmd/runTests.go | 2 +- config/samples/sf_v1_softwarefactory.yaml | 3 + playbooks/main.yaml | 24 +++--- playbooks/standalone.yaml | 17 ---- roles/clean-installations/tasks/main.yaml | 7 ++ .../check-sf-resource-ready/tasks/main.yaml | 81 +++++++++++-------- .../zuul-connections/tasks/main.yaml | 7 +- roles/run-operator-dev/tasks/main.yaml | 13 --- .../defaults/main.yaml | 2 + roles/run-operator-standalone/tasks/main.yaml | 25 +++++- roles/run-tests/tasks/main.yaml | 52 ++++++------ roles/update-custom-resource/tasks/main.yaml | 54 +++++++++---- zuul.d/jobs.yaml | 14 ++-- zuul.d/project.yaml | 2 - 14 files changed, 175 insertions(+), 128 deletions(-) delete mode 100644 playbooks/standalone.yaml delete mode 100644 roles/run-operator-dev/tasks/main.yaml create mode 100644 roles/run-operator-standalone/defaults/main.yaml diff --git a/cli/sfconfig/cmd/runTests.go b/cli/sfconfig/cmd/runTests.go index f7c65c4f..bf5289d3 100644 --- a/cli/sfconfig/cmd/runTests.go +++ b/cli/sfconfig/cmd/runTests.go @@ -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") } diff --git a/config/samples/sf_v1_softwarefactory.yaml b/config/samples/sf_v1_softwarefactory.yaml index da4e9abe..4953a304 100644 --- a/config/samples/sf_v1_softwarefactory.yaml +++ b/config/samples/sf_v1_softwarefactory.yaml @@ -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 diff --git a/playbooks/main.yaml b/playbooks/main.yaml index fff46931..04675cf1 100644 --- a/playbooks/main.yaml +++ b/playbooks/main.yaml @@ -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 diff --git a/playbooks/standalone.yaml b/playbooks/standalone.yaml deleted file mode 100644 index 0fbb5b77..00000000 --- a/playbooks/standalone.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- hosts: "{{ hostname | default('controller') }}" - roles: - - setup-variables - - setup-env - - sanity-check - - setup-namespaces - - start-gerrit - tasks: - - community.general.make: - target: "{{ item }}" - chdir: "{{ src_dir }}" - loop: - - install-cert-manager - - install-prometheus-operator - - ansible.builtin.include_role: - name: run-operator-standalone diff --git a/roles/clean-installations/tasks/main.yaml b/roles/clean-installations/tasks/main.yaml index 39377b8d..45b32d21 100644 --- a/roles/clean-installations/tasks/main.yaml +++ b/roles/clean-installations/tasks/main.yaml @@ -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 diff --git a/roles/health-check/check-sf-resource-ready/tasks/main.yaml b/roles/health-check/check-sf-resource-ready/tasks/main.yaml index dc9d5f31..46a5d0b1 100644 --- a/roles/health-check/check-sf-resource-ready/tasks/main.yaml +++ b/roles/health-check/check-sf-resource-ready/tasks/main.yaml @@ -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 diff --git a/roles/health-check/zuul-connections/tasks/main.yaml b/roles/health-check/zuul-connections/tasks/main.yaml index bdae884e..6dbbb597 100644 --- a/roles/health-check/zuul-connections/tasks/main.yaml +++ b/roles/health-check/zuul-connections/tasks/main.yaml @@ -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: diff --git a/roles/run-operator-dev/tasks/main.yaml b/roles/run-operator-dev/tasks/main.yaml deleted file mode 100644 index 29ceb32f..00000000 --- a/roles/run-operator-dev/tasks/main.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Run the sfconfig command to get started - ansible.builtin.command: go run ./cli/sfconfig - args: - chdir: "{{ zuul.project.src_dir }}" - -- name: Run the operator in devel mode (in background) - async: 3600 - poll: 0 - ansible.builtin.shell: | - go run ./main.go --namespace sf > ~/zuul-output/logs/sf-operator.log 2>&1 - args: - chdir: "{{ zuul.project.src_dir }}" diff --git a/roles/run-operator-standalone/defaults/main.yaml b/roles/run-operator-standalone/defaults/main.yaml new file mode 100644 index 00000000..34a392cf --- /dev/null +++ b/roles/run-operator-standalone/defaults/main.yaml @@ -0,0 +1,2 @@ +glue: true +cr_path: config/samples/sf_v1_softwarefactory.yaml diff --git a/roles/run-operator-standalone/tasks/main.yaml b/roles/run-operator-standalone/tasks/main.yaml index 66377f9d..eba9cb7d 100644 --- a/roles/run-operator-standalone/tasks/main.yaml +++ b/roles/run-operator-standalone/tasks/main.yaml @@ -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 diff --git a/roles/run-tests/tasks/main.yaml b/roles/run-tests/tasks/main.yaml index 5e8dfe8c..ef3e5163 100644 --- a/roles/run-tests/tasks/main.yaml +++ b/roles/run-tests/tasks/main.yaml @@ -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 - diff --git a/roles/update-custom-resource/tasks/main.yaml b/roles/update-custom-resource/tasks/main.yaml index 11db1113..1b7a654a 100644 --- a/roles/update-custom-resource/tasks/main.yaml +++ b/roles/update-custom-resource/tasks/main.yaml @@ -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 diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index b9486fb3..5befed67 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -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 @@ -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 diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index e6a0282b..e18b220f 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -3,14 +3,12 @@ jobs: - sf-operator-olm - sf-operator-upgrade - - sf-operator-dev-multinode - sf-operator-standalone - sf-operator-ansible-lint gate: jobs: - sf-operator-olm - sf-operator-upgrade - - sf-operator-dev-multinode - sf-operator-standalone - sf-operator-ansible-lint release: