Skip to content

Commit 9a76e72

Browse files
committed
Switch context by test
1 parent c242836 commit 9a76e72

15 files changed

+316
-49
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ precommit:
6262
switch:
6363
@ scripts/dev/switch_context.sh $(context) $(additional_override)
6464

65+
switcht:
66+
@ scripts/dev/switch_context_by_test.sh $(test)
67+
6568
# builds the Operator binary file and docker image and pushes it to the remote registry if using a remote registry. Deploys it to
6669
# k8s cluster
6770
operator: configure-operator build-and-push-operator-image

config/manifests/bases/mongodb-kubernetes.clusterserviceversion.yaml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ metadata:
88
certified: "true"
99
containerImage: quay.io/mongodb/mongodb-kubernetes:1.1.0
1010
createdAt: ""
11-
description: The MongoDB Controllers for Kubernetes enable easy deploys of
12-
MongoDB into Kubernetes clusters, using our management, monitoring and
13-
backup platforms, Ops Manager and Cloud Manager.
11+
description: The MongoDB Controllers for Kubernetes enable easy deploys of MongoDB
12+
into Kubernetes clusters, using our management, monitoring and backup platforms,
13+
Ops Manager and Cloud Manager.
1414
features.operators.openshift.io/disconnected: "true"
1515
features.operators.openshift.io/fips-compliant: "false"
1616
features.operators.openshift.io/proxy-aware: "false"
@@ -51,8 +51,7 @@ spec:
5151
x-descriptors:
5252
- urn:alm:descriptor:com.tectonic.ui:text
5353
- urn:alm:descriptor:com.tectonic.ui:fieldGroup:ClusterConfiguration
54-
- description: In a Replica Set deployment type, specifies the amount of
55-
members.
54+
- description: In a Replica Set deployment type, specifies the amount of members.
5655
displayName: Members of a Replica Set
5756
path: members
5857
x-descriptors:
@@ -66,8 +65,7 @@ spec:
6665
- description: Project configuration for this deployment
6766
displayName: Ops Manager project configuration
6867
path: opsManager
69-
- description: Name of the ConfigMap with the configuration for this
70-
project
68+
- description: Name of the ConfigMap with the configuration for this project
7169
displayName: Ops Manager Project Configuration
7270
path: opsManager.configMapRef.name
7371
x-descriptors:
@@ -166,8 +164,7 @@ spec:
166164
x-descriptors:
167165
- urn:alm:descriptor:com.tectonic.ui:text
168166
- urn:alm:descriptor:com.tectonic.ui:fieldGroup:ClusterConfiguration
169-
- description: In a Replica Set deployment type, specifies the amount of
170-
members.
167+
- description: In a Replica Set deployment type, specifies the amount of members.
171168
displayName: Members of a Replica Set
172169
path: members
173170
x-descriptors:
@@ -181,8 +178,7 @@ spec:
181178
- description: Project configuration for this deployment
182179
displayName: Ops Manager project configuration
183180
path: opsManager
184-
- description: Name of the ConfigMap with the configuration for this
185-
project
181+
- description: Name of the ConfigMap with the configuration for this project
186182
displayName: Ops Manager Project Configuration
187183
path: opsManager.configMapRef.name
188184
x-descriptors:
@@ -194,8 +190,8 @@ spec:
194190
x-descriptors:
195191
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
196192
- urn:alm:descriptor:com.tectonic.ui:fieldGroup:ClusterConfiguration
197-
- description: Optional. Specify whether to duplicate service objects
198-
among different Kubernetes clusters.
193+
- description: Optional. Specify whether to duplicate service objects among
194+
different Kubernetes clusters.
199195
displayName: Duplicate Service Objects
200196
path: duplicateServiceObjects
201197
x-descriptors:
@@ -256,8 +252,7 @@ spec:
256252
path: passwordSecretKeyRef.name
257253
x-descriptors:
258254
- urn:alm:descriptor:io.kubernetes:Secret
259-
- displayName: Name of the MongoDB resource to which this user is
260-
associated.
255+
- displayName: Name of the MongoDB resource to which this user is associated.
261256
path: mongodbResourceRef.name
262257
x-descriptors:
263258
- urn:alm:descriptor:io.kubernetes:mongodb
@@ -313,8 +308,8 @@ spec:
313308
x-descriptors:
314309
- urn:alm:descriptor:io.kubernetes:Secret
315310
- urn:alm:descriptor:com.tectonic.ui:fieldGroup:OpsManagerConfiguration
316-
- displayName: Secret to enable TLS for Ops Manager allowing it to serve
317-
traffic over HTTPS.
311+
- displayName: Secret to enable TLS for Ops Manager allowing it to serve traffic
312+
over HTTPS.
318313
path: security.tls.secretRef.name
319314
x-descriptors:
320315
- urn:alm:descriptor:io.kubernetes:Secret
@@ -324,8 +319,8 @@ spec:
324319
x-descriptors:
325320
- urn:alm:descriptor:com.tectonic.ui:number
326321
- urn:alm:descriptor:com.tectonic.ui:fieldGroup:ApplicationDatabase
327-
- displayName: Secret containing the TLS certificate signed by known or
328-
custom CA.
322+
- displayName: Secret containing the TLS certificate signed by known or custom
323+
CA.
329324
path: applicationDatabase.security.tls.secretRef.name
330325
x-descriptors:
331326
- urn:alm:descriptor:io.kubernetes:Secret

helm_chart/Chart.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
apiVersion: v2
22
name: mongodb-kubernetes
3-
description: MongoDB Controllers for Kubernetes translate the human knowledge of
4-
creating a MongoDB instance into a scalable, repeatable, and standardized
5-
method.
3+
description: MongoDB Controllers for Kubernetes translate the human knowledge of creating
4+
a MongoDB instance into a scalable, repeatable, and standardized method.
65
version: 1.1.0
76
kubeVersion: '>=1.16-0'
87
type: application

scripts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Makes 'scripts' a Python package.

scripts/dev/contexts/root-context

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,8 @@ export MDB_SEARCH_COMMUNITY_VERSION
116116

117117
export MDB_SEARCH_COMMUNITY_NAME="mongodb-search-community"
118118
export MDB_SEARCH_COMMUNITY_REPO_URL="quay.io/mongodb"
119+
120+
121+
if [[ ${MDB_BASH_DEBUG:-0} == 1 ]]; then
122+
export PS4='+(${BASH_SOURCE}:${LINENO})[^$?]: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
123+
fi

scripts/dev/launch_e2e.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -Eeou pipefail
44

5+
test "${MDB_BASH_DEBUG:-0}" -eq 1 && set -x
56

67
# The script launches e2e test. Note, that the Operator and necessary resources are deployed
78
# inside the test
@@ -49,5 +50,3 @@ else
4950
fi
5051

5152
title "E2e test ${test} is finished"
52-
53-

scripts/dev/set_env_context.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
22

33
set -Eeou pipefail
4+
test "${MDB_BASH_DEBUG:-0}" -eq 1 && set -x
45

56
# shellcheck disable=1091
67
source scripts/funcs/errors
78

89
script_name=$(readlink -f "${BASH_SOURCE[0]}")
910
script_dir=$(dirname "${script_name}")
10-
context_file="${script_dir}/../../.generated/context.export.env"
11+
context_file="$(realpath "${script_dir}/../../.generated/context.export.env")"
1112

1213
if [[ ! -f ${context_file} ]]; then
1314
fatal "File ${context_file} not found! Make sure to follow this guide to get started: https://wiki.corp.mongodb.com/display/MMS/Setting+up+local+development+and+E2E+testing#SettinguplocaldevelopmentandE2Etesting-GettingStartedGuide(VariantSwitching)"

scripts/dev/switch_context_by_test.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
test "${MDB_BASH_DEBUG:-0}" -eq 1 && set -x
5+
6+
usage() {
7+
echo "Switch context by passing the test (evergreen task name or full evergreen task URL)."
8+
echo "If there is more than one variant running given test, then fzf picker is used."
9+
echo "Usage: $0 <test>"
10+
echo " <test> is a task name from .evergreen.yml (e.g. 'e2e_search_community_basic') or a full Evergreen task URL."
11+
}
12+
13+
source scripts/funcs/errors
14+
15+
list_pytest_marks() {
16+
rg -g '*.py' -o --no-line-number --no-heading --replace '$1' -m 1 \
17+
'@(?:pytest\.)?mark\.(e2e_[a-zA-Z0-9_]+)' \
18+
docker/mongodb-kubernetes-tests
19+
}
20+
21+
pick_test_by_file_mark_or_task_url() {
22+
if ! test_list="$(list_pytest_marks | sort -u)"; then
23+
echo "Couldn't list pytest marks."
24+
echo "${test_list}"
25+
return 1
26+
fi
27+
28+
test=$(fzf --print-query --header-first --with-nth '{2}: {1}' -d ':' --accept-nth 2 \
29+
--header "Select file or task to find contexts where its used. You can paste full task's evergreen url here" <<< "${test_list}") || true
30+
if [[ -z ${test} ]]; then
31+
echo "Aborted selecting test"
32+
return 1
33+
fi
34+
35+
# test may contain one or two lines (file:mark or just mark/url)
36+
number_of_selected_lines=$(wc -l <<< "${test}")
37+
if [[ ${number_of_selected_lines} -eq 2 ]]; then
38+
test="$(tail -n 1 <<< "${test}")"
39+
elif [[ ${number_of_selected_lines} -gt 2 ]]; then
40+
echo "Too many lines selected: ${test}"
41+
return 1
42+
fi
43+
44+
echo "${test}"
45+
}
46+
47+
main() {
48+
test="${1:-}"
49+
50+
if [[ -z ${test} ]]; then
51+
test=$(pick_test_by_file_mark_or_task_url)
52+
echo "Selected test: ${test}"
53+
fi
54+
55+
if [[ "${test}" = *spruce.mongodb.com* ]]; then
56+
find_variant_arg="--task-url"
57+
else
58+
find_variant_arg="--task-name"
59+
fi
60+
61+
if ! contexts=$(scripts/evergreen/run_python.sh scripts/python/find_test_variants.py "${find_variant_arg}" "${test}"); then
62+
echo "Couldn't find any test contexts running test: ${test}"
63+
echo "${contexts}"
64+
exit 1
65+
fi
66+
67+
echo "Found contexts that are running test: ${test}"
68+
echo "${contexts}"
69+
70+
selected_context="${contexts}"
71+
if [[ $(wc -l <<< "${contexts}") -gt 1 ]]; then
72+
if ! selected_context=$(fzf --header "${test} runs in multiple variants/contexts. Select one to switch context into." --header-first --layout=reverse <<< "${contexts}"); then
73+
echo "Aborted selecting context"
74+
exit 1
75+
fi
76+
fi
77+
78+
scripts/dev/switch_context.sh "${selected_context}"
79+
}
80+
81+
main "$@"

scripts/evergreen/flakiness-report.py renamed to scripts/evergreen/flakiness_report.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import json
2-
import os
31
import sys
42

53
import requests
64

5+
from scripts.python.evergreen_api import get_evergreen_auth_headers
6+
77
EVERGREEN_API = "https://evergreen.mongodb.com/api"
88

99

@@ -18,16 +18,13 @@ def print_usage():
1818

1919

2020
def get_variants_with_retried_tasks() -> dict[str, list[dict]]:
21-
evg_user = os.environ.get("EVERGREEN_USER", "")
22-
api_key = os.environ.get("API_KEY", "")
23-
24-
if len(sys.argv) != 2 or evg_user == "" or api_key == "":
21+
if len(sys.argv) != 2:
2522
print_usage()
26-
exit(1)
23+
raise RuntimeError("Exactly one argument (patch version number) must be provided")
2724

2825
version = sys.argv[1]
26+
headers = get_evergreen_auth_headers()
2927

30-
headers = {"Api-User": evg_user, "Api-Key": api_key}
3128
print("Fetching build variants...", file=sys.stderr)
3229
build_ids = requests.get(url=f"{EVERGREEN_API}/rest/v2/versions/{version}", headers=headers).json()
3330
build_statuses = [build_status for build_status in build_ids["build_variants_status"]]

scripts/funcs/checks

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#!/usr/bin/env bash
22

3-
pushd "${PWD}" > /dev/null || return
4-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5-
cd "${DIR}" || return
6-
source errors
7-
popd > /dev/null || return
8-
93
check_env_var() {
104
local var_name="$1"
115
local msg="$2"

scripts/funcs/kubernetes

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
set -Eeou pipefail
44

5-
pushd "${PWD}" > /dev/null || return
6-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
7-
cd "${DIR}" || return
8-
# shellcheck source=scripts/funcs/checks
9-
source checks
10-
# shellcheck source=scripts/funcs/errors
11-
source errors
12-
# shellcheck source=scripts/funcs/printing
13-
source printing
14-
popd > /dev/null || return
5+
source scripts/funcs/checks
6+
source scripts/funcs/errors
7+
source scripts/funcs/printing
158

169
ensure_namespace() {
1710
local namespace="${1}"

scripts/python/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Makes 'scripts.python' a Python package.

scripts/python/evergreen_api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
3+
import requests
4+
5+
EVERGREEN_API = "https://evergreen.mongodb.com/api"
6+
7+
8+
def get_evergreen_auth_headers() -> dict:
9+
"""
10+
Returns Evergreen API authentication headers using EVERGREEN_USER and EVERGREEN_API_KEY environment variables.
11+
Raises RuntimeError if either variable is missing.
12+
"""
13+
evg_user = os.environ.get("EVERGREEN_USER", "")
14+
api_key = os.environ.get("EVERGREEN_API_KEY", "")
15+
if evg_user == "" or api_key == "":
16+
raise RuntimeError("EVERGREEN_USER and EVERGREEN_API_KEY must be set")
17+
return {"Api-User": evg_user, "Api-Key": api_key}
18+
19+
20+
def get_task_details(task_id: str) -> dict:
21+
"""
22+
Fetch task details from Evergreen API for a given task_id.
23+
Returns the JSON response as a dict.
24+
Raises requests.HTTPError if the request fails.
25+
"""
26+
url = f"{EVERGREEN_API}/rest/v2/tasks/{task_id}"
27+
headers = get_evergreen_auth_headers()
28+
response = requests.get(url, headers=headers)
29+
response.raise_for_status()
30+
return response.json()

0 commit comments

Comments
 (0)