Skip to content

Commit 1ad24cf

Browse files
authored
CLOUDP-341025: Refactor of existing snippets on master (#366)
# Summary This PR refactors how we generate and manage outputs from snippet tests. Before, every snippet module has its own output/ directory. But because snippet modules were reused across different tests we had no way of storing the outputs from different test runs (the files were overwritten). Changes were needed to accommodate upcoming Search snippets, but due to the large scale of this refactoring it was extracted onto master. **Only changes to public/architectures has been made performed in this PR. Existing search snippets are left intact and will be refactored on the search feature branch**. After this PR is approved, a followup PR in the docs repo will be created adjusting for the new include paths. This PR incorporated changes from #150 to fix diagnostic dumps from GKE clusters. # What this change will help * committing back snippet output will be easy as adding changes from one directory `scripts/code_snippets/tests/outputs/test_*` instead of traversing the tree and dealing with the conflicts pushed from different test runs. * more clarity what snippets and outputs we're using in docs * ability to share snippet modules and gather different outputs from the same snippet module for different testing scenarios. ## Glossary * `Snippet module` - directory containing `test.sh` and scripts in a `code_snippets` sub directory. It's a reusable set of scripts, e.g. `public/architectures/setup-multi-cluster/ra-01-setup-gke`. * Snippet test - automated test running in evg that runs multiple snippet modules. It's a top level entrypoint that runs all the snippet modules. Examples: `scripts/code_snippets/tests/test_gke_multi_cluster_no_mesh_snippets.sh`, `scripts/code_snippets/test_gke_multi_cluster_snippets.sh`. * Previously we named these files a "task" and they were directly in `scripts/code_snippets` dir (e.g. `scripts/code_snippets/task_gke_multi_cluster_no_mesh_snippets_test.sh`). * `Snippet outputs` - output files (.out) gathered from a `Snippet test`. ## Changes * Snippet modules don't store their outputs in the snippet directory now, but in `scripts/code_snippets/tests/outputs/<test name>` directory, which is gathering *all* outputs from a given snippet test. * Every file name in any of the code_snippets directories in the codebase must have a globally unique name. Existing file names has been refactored to match the new convention (in public/architecture). * Validation/linter has been added (`scripts/code_snippets/validate_snippets.py`) added to `pre-commit` that enforces this convention. * The naming convention is the following: * Snippet module directory must be prefixed by some arbitrary prefix. Snippet modules in reference architectures has been prefixed with "ra-NN`, e.g. `ra-02-setup-operator`. Every snippet file belonging to this module should be also prefixed (e.g. `ra-02_0046_create_image_pull_secrets.sh`) * This allows for storing all the snippets outputs in a flat directory, guaranteeing we won't overwrite outputs. * This also helps quickly verifying the paths that will be used in the docs to include snippets and outputs. Having those prefixes will help identifying if any included file is coming from a correct snippet test and module. * Improved diagnostic gathering from the test runs * GKE clusters are correctly handled now * Every file name is prefixed with the kube context name and the namespace from which the files were downloaded. *This will impact all the e2e test runs*, but it will improve diagnostic archive in cases where we dump more than one namespace or k8s cluster. * All evergreen yamls related to snippets have been moved into .evergreen-snippets.yml (included from the main .evergreen-snippets.yml) Here is the fragment of the current directory structure: ``` public/architectures ├── ra-06-ops-manager-multi-cluster │   ├── code_snippets │   │   ├── ra-06_0250_generate_certs.sh │   │   ├── ra-06_0300_ops_manager_create_admin_credentials.sh [...] │   │   ├── ra-06_9100_delete_backup_namespaces.sh │   │   └── ra-06_9200_delete_om.sh │   ├── env_variables.sh │   ├── teardown.sh │   └── test.sh ├── ra-07-mongodb-replicaset-multi-cluster │   ├── code_snippets │   │   ├── ra-07_1050_generate_certs.sh │   │   ├── ra-07_1100_mongodb_replicaset_multi_cluster.sh [...] │   │   └── ra-07_9000_delete_resources.sh │   ├── env_variables.sh │   ├── teardown.sh │   └── test.sh ``` ``` scripts/code_snippets ├── tests │   ├── outputs │   │   ├── test_gke_multi_cluster_no_mesh_snippets │   │   ├── test_gke_multi_cluster_snippets │   │   │   ├── ra-01_0030_verify_access_to_clusters.out │   │   │   ├── ra-02_0200_kubectl_mongodb_configure_multi_cluster.out │   │   │   ├── ra-02_0205_helm_configure_repo.out [...] │   │   │   ├── ra-06_0321_ops_manager_wait_for_pending_state.out │   │   │   ├── ra-06_0322_ops_manager_wait_for_running_state.out │   │   │   └── ra-06_0522_ops_manager_wait_for_running_state.out │   │   └── test_kind_search_community_snippets │   │   ├── 01_0090_helm_add_mogodb_repo.out │   │   ├── 01_0100_install_operator.out [...] │   │   ├── 03_0450_execute_search_query.out │   │   └── 03_0455_execute_vector_search_query.out │   ├── test_gke_multi_cluster_no_mesh_snippets.sh │   ├── test_gke_multi_cluster_snippets.sh │   └── test_kind_search_community_snippets.sh ``` ## Proof of Work [Green EVG run](https://spruce.mongodb.com/version/68ae250c41ef2800073ac896/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC) for all snippets. ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 0c9e388 commit 1ad24cf

File tree

220 files changed

+1783
-976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+1783
-976
lines changed

.evergreen-functions.yml

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -475,33 +475,6 @@ functions:
475475
params:
476476
files: [ "src/github.com/mongodb/mongodb-kubernetes/logs/*.suite" ]
477477

478-
upload_code_snippets_logs:
479-
- command: s3.put
480-
params:
481-
aws_key: ${enterprise_aws_access_key_id}
482-
aws_secret: ${enterprise_aws_secret_access_key}
483-
local_files_include_filter:
484-
- src/github.com/mongodb/mongodb-kubernetes/public/architectures/**/*.log
485-
- src/github.com/mongodb/mongodb-kubernetes/docs/**/*.log
486-
remote_file: logs/${task_id}/${execution}/
487-
bucket: operator-e2e-artifacts
488-
permissions: private
489-
visibility: signed
490-
content_type: text/plain
491-
- command: s3.put
492-
params:
493-
aws_key: ${enterprise_aws_access_key_id}
494-
aws_secret: ${enterprise_aws_secret_access_key}
495-
local_files_include_filter:
496-
- src/github.com/mongodb/mongodb-kubernetes/public/architectures/**/*.out
497-
- src/github.com/mongodb/mongodb-kubernetes/docs/**/*.out
498-
preserve_path: true
499-
remote_file: logs/${task_id}/${execution}/
500-
bucket: operator-e2e-artifacts
501-
permissions: private
502-
visibility: signed
503-
content_type: text/plain
504-
505478
preflight_image:
506479
- *switch_context
507480
- command: subprocess.exec
@@ -817,7 +790,7 @@ functions:
817790
working_dir: src/github.com/mongodb/mongodb-kubernetes
818791
binary: scripts/code_snippets/sample_commit_output.sh
819792

820-
# it executes a script by convention: ./scripts/code_snippets/${task_name}_test.sh
793+
# it executes a script by convention: ./scripts/code_snippets/tests/${task_name}
821794
test_code_snippets:
822795
- *switch_context
823796
- command: shell.exec
@@ -830,7 +803,7 @@ functions:
830803
- code_snippets_reset
831804
- task_name
832805
script: |
833-
./scripts/code_snippets/${task_name}_test.sh
806+
./scripts/code_snippets/tests/${task_name}
834807
835808
#
836809
# kubectl mongodb plugin release functions

.evergreen-release.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,6 @@ buildvariants:
151151
tasks:
152152
- name: run_conditionally_prepare_and_upload_openshift_bundles
153153

154-
- name: prerelease_gke_code_snippets
155-
display_name: prerelease_gke_code_snippets
156-
tags: [ "release" ]
157-
allowed_requesters: ["patch", "github_tag"]
158-
depends_on:
159-
- variant: release_images
160-
name: '*'
161-
patch_optional: true
162-
run_on:
163-
- ubuntu2404-small
164-
tasks:
165-
- name: gke_code_snippets_task_group
166-
167154
- name: init_smoke_tests
168155
display_name: init_smoke_tests
169156
tags: [ "e2e_smoke_release_test_suite" ]

.evergreen-snippets.yml

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
variables:
2+
- &setup_and_teardown_group_gke_code_snippets
3+
setup_task_can_fail_task: true
4+
setup_group:
5+
- func: clone
6+
- func: setup_gcloud_cli
7+
- func: setup_mongosh
8+
- func: download_kube_tools
9+
- func: build_multi_cluster_binary
10+
teardown_task:
11+
- func: upload_e2e_logs
12+
- func: upload_code_snippets_logs
13+
- func: upload_code_snippets_outputs
14+
15+
- &setup_and_teardown_group_kind_code_snippets
16+
setup_task_can_fail_task: true
17+
setup_group:
18+
- func: clone
19+
- func: cleanup_exec_environment
20+
- func: download_kube_tools
21+
- func: configure_docker_auth
22+
- func: setup_kubernetes_environment
23+
teardown_task:
24+
- func: upload_e2e_logs
25+
- func: upload_code_snippets_logs
26+
- func: upload_code_snippets_outputs
27+
28+
# This variable is copied over from .evergreen.yml because anchors don't work for included files
29+
- &base_om8_dependency
30+
depends_on:
31+
- name: build_om_images
32+
variant: build_om80_images
33+
- name: build_operator_ubi
34+
variant: init_test_run
35+
- name: build_init_database_image_ubi
36+
variant: init_test_run
37+
- name: build_database_image_ubi
38+
variant: init_test_run
39+
- name: build_test_image
40+
variant: init_test_run
41+
- name: build_init_appdb_images_ubi
42+
variant: init_test_run
43+
- name: build_init_om_images_ubi
44+
variant: init_test_run
45+
- name: build_agent_images_ubi
46+
variant: init_test_run
47+
48+
functions:
49+
upload_code_snippets_logs:
50+
- command: s3.put
51+
params:
52+
aws_key: ${enterprise_aws_access_key_id}
53+
aws_secret: ${enterprise_aws_secret_access_key}
54+
local_files_include_filter:
55+
- src/github.com/mongodb/mongodb-kubernetes/public/architectures/**/*.log
56+
- src/github.com/mongodb/mongodb-kubernetes/docs/**/*.log
57+
remote_file: logs/${task_id}/${execution}/
58+
bucket: operator-e2e-artifacts
59+
permissions: private
60+
visibility: signed
61+
content_type: text/plain
62+
- command: s3.put
63+
params:
64+
aws_key: ${enterprise_aws_access_key_id}
65+
aws_secret: ${enterprise_aws_secret_access_key}
66+
local_files_include_filter:
67+
- src/github.com/mongodb/mongodb-kubernetes/public/architectures/**/*.out
68+
- src/github.com/mongodb/mongodb-kubernetes/docs/**/*.out
69+
preserve_path: true
70+
remote_file: logs/${task_id}/${execution}/
71+
bucket: operator-e2e-artifacts
72+
permissions: private
73+
visibility: signed
74+
content_type: text/plain
75+
76+
upload_code_snippets_outputs:
77+
- command: s3.put
78+
params:
79+
aws_key: ${enterprise_aws_access_key_id}
80+
aws_secret: ${enterprise_aws_secret_access_key}
81+
local_files_include_filter:
82+
- snippets_outputs.tgz
83+
remote_file: logs/${task_id}/${execution}/
84+
bucket: operator-e2e-artifacts
85+
permissions: private
86+
visibility: signed
87+
content_type: ${content_type|application/x-gzip}
88+
display_name: "Snippets Outputs"
89+
90+
tasks:
91+
# Code snippets tasks
92+
# Each scripts/code_snippets/tests/test_*.sh should have its task defined here.
93+
# TODO: it should be autogenerated
94+
# Each task executes test_code_snippets functon executes scripts/code_snippets/tests/${task_name} by task name convention
95+
- name: test_gke_multi_cluster_snippets.sh
96+
tags: [ "code_snippets" ]
97+
commands:
98+
- func: test_code_snippets
99+
- func: sample_commit_output
100+
101+
- name: test_gke_multi_cluster_no_mesh_snippets.sh
102+
tags: [ "code_snippets" ]
103+
commands:
104+
- func: test_code_snippets
105+
- func: sample_commit_output
106+
107+
- name: test_kind_search_community_snippets.sh
108+
tags: [ "code_snippets", "patch-run" ]
109+
commands:
110+
- func: test_code_snippets
111+
- func: sample_commit_output
112+
113+
task_groups:
114+
- name: gke_code_snippets_task_group
115+
<<: *setup_and_teardown_group_gke_code_snippets
116+
max_hosts: -1
117+
tasks:
118+
- test_gke_multi_cluster_snippets.sh
119+
- test_gke_multi_cluster_no_mesh_snippets.sh
120+
121+
- name: kind_code_snippets_task_group
122+
<<: *setup_and_teardown_group_kind_code_snippets
123+
max_hosts: -1
124+
tasks:
125+
- test_kind_search_community_snippets.sh
126+
127+
buildvariants:
128+
# These variants are used to test the code snippets and each one can be used in patches
129+
# Prerelease is especially used when the repo is tagged
130+
# More details in the TD: https://docs.google.com/document/d/1fuTxfRtP8QPtn7sKYxQM_AGcD6xycTZH8svngGxyKhc/edit?tab=t.0#bookmark=id.e8uva0393mbe
131+
- name: public_gke_code_snippets
132+
display_name: public_gke_code_snippets
133+
allowed_requesters: [ "patch" ]
134+
run_on:
135+
- ubuntu2204-small
136+
tasks:
137+
- name: gke_code_snippets_task_group
138+
139+
- name: prerelease_gke_code_snippets
140+
display_name: prerelease_gke_code_snippets
141+
tags: [ "release" ]
142+
allowed_requesters: [ "patch", "github_tag" ]
143+
depends_on:
144+
- variant: release_images
145+
name: '*'
146+
patch_optional: true
147+
run_on:
148+
- ubuntu2204-small
149+
tasks:
150+
- name: gke_code_snippets_task_group
151+
152+
- name: private_gke_code_snippets
153+
display_name: private_gke_code_snippets
154+
allowed_requesters: [ "patch" ]
155+
run_on:
156+
- ubuntu2204-small
157+
<<: *base_om8_dependency
158+
tasks:
159+
- name: gke_code_snippets_task_group
160+
161+
- name: private_kind_code_snippets
162+
display_name: private_kind_code_snippets
163+
tags: [ "e2e_test_suite" ]
164+
allowed_requesters: [ "patch", "github_pr" ]
165+
run_on:
166+
- ubuntu2204-large
167+
<<: *base_om8_dependency
168+
tasks:
169+
- name: kind_code_snippets_task_group
170+
171+
- name: prerelease_kind_code_snippets
172+
display_name: prerelease_kind_code_snippets
173+
allowed_requesters: [ "patch" ]
174+
run_on:
175+
- ubuntu2204-large
176+
tasks:
177+
- name: kind_code_snippets_task_group
178+
179+
- name: public_kind_code_snippets
180+
display_name: public_kind_code_snippets
181+
allowed_requesters: [ "patch" ]
182+
run_on:
183+
- ubuntu2204-large
184+
tasks:
185+
- name: kind_code_snippets_task_group

.evergreen.yml

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include:
55
- filename: .evergreen-functions.yml
66
- filename: .evergreen-tasks.yml
77
- filename: .evergreen-mco.yml
8+
- filename: .evergreen-snippets.yml
89
- filename: .evergreen-release.yml
910

1011
variables:
@@ -87,29 +88,6 @@ variables:
8788
- func: setup_building_host
8889
- func: build_multi_cluster_binary
8990

90-
- &setup_and_teardown_group_gke_code_snippets
91-
setup_task_can_fail_task: true
92-
setup_group:
93-
- func: clone
94-
- func: setup_gcloud_cli
95-
- func: setup_mongosh
96-
- func: download_kube_tools
97-
- func: build_multi_cluster_binary
98-
teardown_group:
99-
- func: upload_code_snippets_logs
100-
101-
- &setup_and_teardown_group_kind_code_snippets
102-
setup_task_can_fail_task: true
103-
setup_group:
104-
- func: clone
105-
- func: cleanup_exec_environment
106-
- func: download_kube_tools
107-
- func: configure_docker_auth
108-
- func: setup_kubernetes_environment
109-
teardown_task:
110-
- func: upload_e2e_logs
111-
- func: upload_code_snippets_logs
112-
11391
- &setup_and_teardown_task_cloudqa
11492
setup_task_can_fail_task: true
11593
setup_task:
@@ -173,6 +151,7 @@ variables:
173151
- name: build_init_om_images_ubi
174152
variant: init_test_run
175153

154+
# Any change to base_om8_dependency should be reflected to its copy in .evergreen-snippets.yml
176155
- &base_om8_dependency
177156
depends_on:
178157
- name: build_om_images
@@ -580,19 +559,6 @@ task_groups:
580559
- unit_tests_helm
581560
- sbom_tests
582561

583-
- name: gke_code_snippets_task_group
584-
<<: *setup_and_teardown_group_gke_code_snippets
585-
max_hosts: -1
586-
tasks:
587-
- task_gke_multi_cluster_snippets
588-
- task_gke_multi_cluster_no_mesh_snippets
589-
590-
- name: kind_code_snippets_task_group
591-
<<: *setup_and_teardown_group_kind_code_snippets
592-
max_hosts: -1
593-
tasks:
594-
- task_kind_community_search_snippets
595-
596562
# Task group for deploying mongodbcommunity resources and testing the (former) MCO
597563
- name: e2e_mdb_community_task_group
598564
max_hosts: -1
@@ -1827,52 +1793,6 @@ buildvariants:
18271793
tasks:
18281794
- name: release_all_currently_used_agents_on_ecr
18291795

1830-
# These variants are used to test the code snippets and each one can be used in patches
1831-
# Prerelease is especially used when the repo is tagged
1832-
# More details in the TD: https://docs.google.com/document/d/1fuTxfRtP8QPtn7sKYxQM_AGcD6xycTZH8svngGxyKhc/edit?tab=t.0#bookmark=id.e8uva0393mbe
1833-
- name: public_gke_code_snippets
1834-
display_name: public_gke_code_snippets
1835-
allowed_requesters: [ "patch" ]
1836-
run_on:
1837-
- ubuntu2404-small
1838-
tasks:
1839-
- name: gke_code_snippets_task_group
1840-
1841-
- name: private_gke_code_snippets
1842-
display_name: private_gke_code_snippets
1843-
allowed_requesters: [ "patch" ]
1844-
run_on:
1845-
- ubuntu2404-small
1846-
<<: *base_om8_dependency
1847-
tasks:
1848-
- name: gke_code_snippets_task_group
1849-
1850-
- name: private_kind_code_snippets
1851-
display_name: private_kind_code_snippets
1852-
tags: [ "e2e_test_suite" ]
1853-
allowed_requesters: [ "patch", "github_pr" ]
1854-
run_on:
1855-
- ubuntu2404-large
1856-
<<: *base_om8_dependency
1857-
tasks:
1858-
- name: kind_code_snippets_task_group
1859-
1860-
- name: prerelease_kind_code_snippets
1861-
display_name: prerelease_kind_code_snippets
1862-
allowed_requesters: [ "patch" ]
1863-
run_on:
1864-
- ubuntu2404-large
1865-
tasks:
1866-
- name: kind_code_snippets_task_group
1867-
1868-
- name: public_kind_code_snippets
1869-
display_name: public_kind_code_snippets
1870-
allowed_requesters: [ "patch" ]
1871-
run_on:
1872-
- ubuntu2404-large
1873-
tasks:
1874-
- name: kind_code_snippets_task_group
1875-
18761796
### Build variants for manual patch only
18771797

18781798
- name: backup_csv_images

.githooks/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ lint_code() {
163163
scripts/evergreen/lint_code.sh
164164
}
165165

166+
function validate_snippets() {
167+
scripts/code_snippets/validate_snippets.py
168+
}
169+
166170
# bg_job_ vars are global; run_job_in_background function is appending to them on each call
167171
bg_job_pids=()
168172
bg_job_pids_with_names=()
@@ -217,6 +221,7 @@ pre_commit() {
217221
run_job_in_background "regenerate_public_rbac_multi_cluster"
218222
run_job_in_background "python_formatting"
219223
run_job_in_background "check_erroneous_kubebuilder_annotations"
224+
run_job_in_background "validate_snippets"
220225

221226
if wait_for_all_background_jobs; then
222227
echo -e "${GREEN}pre-commit: All checks passed!${NO_COLOR}"

0 commit comments

Comments
 (0)