Skip to content

Conversation

lsierant
Copy link
Contributor

@lsierant lsierant commented Aug 24, 2025

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 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?

@lsierant lsierant self-assigned this Aug 24, 2025
Copy link

github-actions bot commented Aug 24, 2025

⚠️ (this preview might not be accurate if the PR is not rebased on current master branch)

MCK 1.3.1 Release Notes

@lsierant lsierant force-pushed the lsierant/snippets-refactor branch 2 times, most recently from 3420ed1 to be64ad8 Compare August 26, 2025 07:09
@lsierant lsierant changed the title Refactor of existing snippets on master CLOUDP-341025: Refactor of existing snippets on master Aug 26, 2025
@lsierant lsierant force-pushed the lsierant/snippets-refactor branch from d5fd23e to b08575c Compare August 26, 2025 08:24
@lsierant lsierant marked this pull request as ready for review August 26, 2025 08:24
@lsierant lsierant requested a review from a team as a code owner August 26, 2025 08:24
@lsierant lsierant force-pushed the lsierant/snippets-refactor branch from b08575c to d6f389d Compare August 26, 2025 08:26
@lsierant lsierant requested a review from lucian-tosa August 26, 2025 08:26
@@ -1,16 +1,36 @@
#!/usr/bin/env bash
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, thanks, it's a debugging leftover!

Comment on lines 109 to 128
# Capture output first to check if it contains actual resources
local temp_output
temp_output=$(kubectl --context="${context}" -n "${namespace}" ${action} "${object}" 2>&1)

# Check if output contains actual resources (not just empty list)
# Skip if it's an empty YAML list (contains "items: []")
if printf '%s\n' "${temp_output}" | grep -Fq "items: []"; then
# Empty list, don't create file
return
fi

if [[ -n "${out_file}" ]]; then
{
header "${msg}"
echo "${temp_output}"
} > "${out_file}"
else
header "${msg}"
kubectl --context="${context}" -n "${namespace}" ${action} "${object}" 2>&1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This indentation looks off in github.

@lsierant lsierant force-pushed the lsierant/snippets-refactor branch from bc7095f to 9380a5a Compare August 26, 2025 11:46
@lsierant lsierant added the skip-changelog Use this label in Pull Request to not require new changelog entry file label Aug 26, 2025
@lsierant lsierant force-pushed the lsierant/snippets-refactor branch 2 times, most recently from 674c669 to 6d985d9 Compare August 28, 2025 20:23

run 9100_delete_backup_namespaces.sh &
run 9200_delete_om.sh &
run ra-06_9100_delete_backup_namespaces.sh &
Copy link
Contributor

@anandsyncs anandsyncs Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the significance of this ra prefix?
Edit: I released it probably stands for reference architecture(s) 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! :D

@@ -1,4 +1,4 @@
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OPERATOR_NAMESPACE}" rollout status deployment/mongodb-kubernetes-operator-multi-cluster
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OPERATOR_NAMESPACE}" rollout status --timeout=2m deployment/mongodb-kubernetes-operator-multi-cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it getting stuck?

Copy link
Contributor Author

@lsierant lsierant Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I don't have any proof anymore 🙈
I mean - not stuck, sometimes it took longer than default timeout on GKE clusters. Not sure why.

@lsierant lsierant force-pushed the lsierant/snippets-refactor branch 3 times, most recently from d63c5c1 to 56dbb8b Compare September 8, 2025 20:02
@lsierant
Copy link
Contributor Author

lsierant commented Sep 8, 2025

evergreen refresh

@lsierant lsierant force-pushed the lsierant/snippets-refactor branch from 56dbb8b to ed39d15 Compare September 8, 2025 20:04
@lsierant lsierant force-pushed the lsierant/snippets-refactor branch from 3588fa1 to d9d020a Compare September 10, 2025 19:42
@lsierant lsierant enabled auto-merge (squash) September 11, 2025 09:15
@lsierant lsierant merged commit 1ad24cf into master Sep 11, 2025
6 of 7 checks passed
@lsierant lsierant deleted the lsierant/snippets-refactor branch September 11, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use this label in Pull Request to not require new changelog entry file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants