Skip to content

Commit 457316e

Browse files
nammnfealebenpae
authored andcommitted
Development tooling improvements (#3115)
This commit changes the way we run tests in evergreen and locally via context switches. More can be read here: REDACTED and here: REDACTED
1 parent 5120da7 commit 457316e

File tree

101 files changed

+1541
-2040
lines changed

Some content is hidden

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

101 files changed

+1541
-2040
lines changed

.evergreen-periodic-builds.yaml

Lines changed: 374 additions & 367 deletions
Large diffs are not rendered by default.

.evergreen.yml

Lines changed: 101 additions & 461 deletions
Large diffs are not rendered by default.

.githooks/pre-commit

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
set -Eeou pipefail
44
set -x
55

6+
source scripts/dev/set_env_context.sh
7+
68
if [[ -z "${EVERGREEN_MODE:-}" ]]; then
79
git_last_changed=$(git diff --cached --name-only --diff-filter=ACM)
810
else
@@ -34,13 +36,13 @@ function generate_standalone_yaml() {
3436

3537
function black_formatting() {
3638
# installing Black
37-
if ! command -v "black" >/dev/null; then
38-
pip3 install -r docker/mongodb-enterprise-tests/requirements-dev.txt
39+
if [ -f "${workdir}"/venv/bin/black ]; then
40+
"${workdir}"/venv/bin/pip install -r docker/mongodb-enterprise-tests/requirements-dev.txt
3941
fi
4042

4143
# Black formatting of every python file that was changed
4244
for file in $(echo "$git_last_changed" | grep '\.py$'); do
43-
black -q "$file"
45+
"${workdir}"/venv/bin/black -q "$file"
4446
git add "$file"
4547
done
4648
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ helm_out
2525
.redo-last-namespace
2626
exports.do
2727
__debug_bin
28+
.generated/
29+
scripts/dev/contexts/private-context
2830

2931
# These files get generated by emacs and sometimes they are still present when committing
3032
**/flycheck_*

.rsyncignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public/
2+
.git

.rsyncinclude

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/scripts/dev/contexts/private-context

Makefile

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ usage:
1313
@ echo
1414
@ echo "Usage:"
1515
@ echo " prerequisites: installs the command line applications necessary for working with this tool and adds git pre-commit hook."
16-
@ echo " init: prepares operator environment."
1716
@ echo " switch: switch current dev context, e.g 'make switch context=kops'. Note, that it switches"
1817
@ echo " kubectl context as well and sets the current namespace to the one configured as the default"
1918
@ echo " one"
20-
@ echo " contexts: list all available contexts"
2119
@ echo " operator: build and push Operator image, deploy it to the Kubernetes cluster"
2220
@ echo " Use the 'debug' flag to build and deploy the Operator in debug mode - you need"
2321
@ echo " to ensure the 30042 port on the K8s node is open"
@@ -39,7 +37,7 @@ usage:
3937
@ echo " Use a 'local=true' to run the test locally using 'pytest'."
4038
@ echo " Use a 'skip=true' to skip cleaning resources (this may help developing long-running tests like for Ops Manager)"
4139
@ echo " Sometimes you may need to pass some custom configuration, this can be done this way:"
42-
@ echo " make e2e test=e2e_om_ops_manager_upgrade custom_om_version=4.2.8"
40+
@ echo " make e2e test=e2e_om_ops_manager_upgrade CUSTOM_OM_VERSION=4.2.8"
4341
@ echo " recreate-e2e-kops: deletes and creates a specified e2e cluster 'cluster' using kops (note, that you don't need to switch to the correct"
4442
@ echo " kubectl context - the script will handle everything). Pass the flag 'imsure=yes' to make it work."
4543
@ echo " Pass 'cluster' parameter for a cluster name if it's different from default ('e2e.mongokubernetes.com')"
@@ -58,42 +56,26 @@ usage:
5856
prerequisites:
5957
@ scripts/dev/install.sh
6058

61-
# prepare default configuration context files
62-
init:
63-
@ mkdir -p ~/.operator-dev/contexts
64-
@ cp -n scripts/dev/samples/* ~/.operator-dev/contexts || true
65-
@ echo "Initialized dev environment (~/.operator-dev)"
66-
@ make switch context=dev
67-
6859
switch:
6960
@ scripts/dev/switch_context.sh $(context)
7061

71-
# prints all current contexts
72-
contexts:
73-
@ scripts/dev/print_contexts
74-
7562
# builds the Operator binary file and docker image and pushes it to the remote registry if using a remote registry. Deploys it to
7663
# k8s cluster
7764
operator: configure-operator build-and-push-operator-image
7865
@ $(MAKE) deploy-operator
7966

8067
# build-push, (todo) restart database
8168
database: aws_login
82-
@ ./pipeline.py --include database
69+
@ scripts/evergreen/run_pipelinepy.sh --include database
8370

8471
# ensures cluster is up, cleans Kubernetes + OM, build-push-deploy operator,
8572
# push-deploy database, create secrets, config map, resources etc
86-
full: ensure-k8s-and-reset build-and-push-images
73+
full: build-and-push-images
8774
@ $(MAKE) deploy-and-configure-operator
88-
@ scripts/dev/apply_resources
8975

9076
# build-push appdb image
9177
appdb: aws_login
92-
@ ./pipeline.py --include appdb
93-
94-
log:
95-
@ . scripts/dev/read_context.sh
96-
@ kubectl logs -f deployment/mongodb-enterprise-operator --tail=1000
78+
@ scripts/evergreen/run_pipelinepy.sh --include appdb
9779

9880
# runs the e2e test: make e2e test=e2e_sharded_cluster_pv. The Operator is redeployed before the test, the namespace is cleaned.
9981
# The e2e test image is built and pushed together with all main ones (operator, database, init containers)
@@ -114,11 +96,6 @@ e2e-telepresence: build-and-push-test-image
11496
recreate-e2e-kops:
11597
@ scripts/dev/recreate_e2e_kops.sh $(imsure) $(cluster)
11698

117-
# TODO: Automate this process
118-
# deletes and creates a openshift e2e cluster
119-
recreate-e2e-openshift:
120-
@ echo "Please follow instructions in docs/openshift4.md to install the Openshift4 cluster."
121-
12299
# clean all kubernetes cluster resources and OM state. "light=true" to clean only Mongodb resources
123100
reset:
124101
@ scripts/dev/reset.sh $(light)
@@ -142,21 +119,21 @@ ac:
142119
# in parallel and both call 'aws_login') then Docker login may return an error "Error saving credentials:..The
143120
# specified item already exists in the keychain". Seems this allows to ignore the error
144121
aws_login:
145-
@ . scripts/dev/set_env_context.sh; scripts/dev/configure_docker_auth.sh
122+
@ scripts/dev/configure_docker_auth.sh
146123

147124
# cleans up aws resources, including s3 buckets which are older than 5 hours
148125
aws_cleanup:
149126
@ scripts/evergreen/prepare_aws.sh
150127

151128
build-and-push-operator-image: aws_login
152-
@ ./pipeline.py --include operator-quick
129+
@ scripts/evergreen/run_pipelinepy.sh --include operator-quick
153130

154131
build-and-push-database-image: aws_login
155132
@ scripts/dev/build_push_database_image
156133

157134
build-and-push-test-image: aws_login build-multi-cluster-binary
158135
@ if [[ -z "$(local)" ]]; then \
159-
./pipeline.py --include test; \
136+
scripts/evergreen/run_pipelinepy.sh --include test; \
160137
fi
161138

162139
build-multi-cluster-binary:
@@ -168,13 +145,13 @@ build-and-push-images: build-and-push-operator-image appdb-init-image om-init-im
168145
@ $(MAKE) database-init-image
169146

170147
database-init-image:
171-
@ ./pipeline.py --include init-database
148+
@ scripts/evergreen/run_pipelinepy.sh --include init-database
172149

173150
appdb-init-image:
174-
@ ./pipeline.py --include init-appdb
151+
@ scripts/evergreen/run_pipelinepy.sh --include init-appdb
175152

176153
om-init-image:
177-
@ ./pipeline.py --include init-ops-manager
154+
@ scripts/evergreen/run_pipelinepy.sh --include init-ops-manager
178155

179156
deploy-operator:
180157
@ scripts/dev/deploy_operator.sh $(debug)
@@ -184,19 +161,13 @@ configure-operator:
184161

185162
deploy-and-configure-operator: deploy-operator configure-operator
186163

187-
ensure-k8s:
188-
@ scripts/dev/ensure_k8s.sh
189-
190164
cert:
191165
@ openssl req -nodes -new -x509 -keyout ca-tls.key -out ca-tls.crt -extensions v3_ca -days 3650
192166
@ mv ca-tls.key ca-tls.crt docker/mongodb-enterprise-tests/tests/opsmanager/fixtures/
193167
@ cat docker/mongodb-enterprise-tests/tests/opsmanager/fixtures/ca-tls.crt \
194168
docker/mongodb-enterprise-tests/tests/opsmanager/fixtures/mongodb-download.crt \
195169
> docker/mongodb-enterprise-tests/tests/opsmanager/fixtures/ca-tls-full-chain.crt
196170

197-
ensure-k8s-and-reset: ensure-k8s
198-
@ $(MAKE) reset
199-
200171
.PHONY: recreate-e2e-multicluster-kind
201172
recreate-e2e-multicluster-kind:
202173
scripts/dev/recreate_kind_clusters.sh
@@ -288,7 +259,7 @@ undeploy:
288259

289260
# Generate manifests e.g. CRD, RBAC etc.
290261
manifests: controller-gen
291-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths=./... output:crd:artifacts:config=config/crd/bases
262+
export PATH=$(PATH); export GOROOT=$(GOROOT); $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths=./... output:crd:artifacts:config=config/crd/bases
292263
# copy the CRDs to the public folder
293264
cp config/crd/bases/* helm_chart/crds/
294265
cat "helm_chart/crds/"* > public/crds.yaml

docker/mongodb-enterprise-tests/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def evergreen_task_id() -> str:
167167

168168

169169
def get_evergreen_task_id():
170-
return os.environ.get("TASK_ID", "")
170+
return os.environ.get("task_id", "")
171171

172172

173173
@fixture(scope="module")

pipeline.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,6 @@ def make_list_of_str(value: Union[None, str, List[str]]) -> List[str]:
7575
return value
7676

7777

78-
def build_configuration_from_context_file(filename: str) -> Dict[str, str]:
79-
config = {}
80-
with open(filename) as fd:
81-
for line in fd.readlines():
82-
if line.startswith("#") or line.strip() == "":
83-
continue
84-
85-
key, value = line.split("=")
86-
key = key.replace("export ", "").lower()
87-
value = value.strip().replace('"', "")
88-
config[key] = value
89-
90-
# calculates skip_tags from image_type in local mode
91-
config["skip_tags"] = list(skippable_tags - {config["image_type"]})
92-
93-
# explicitly skipping release tags locally
94-
config["skip_tags"].append("release")
95-
96-
return config
97-
98-
9978
def build_configuration_from_env() -> Dict[str, str]:
10079
"""Builds a running configuration by reading values from environment.
10180
This is to be used in Evergreen environment.
@@ -105,7 +84,7 @@ def build_configuration_from_env() -> Dict[str, str]:
10584
# would replace the `username` we use locally.
10685
return {
10786
"image_type": os.environ.get("distro"),
108-
"base_repo_url": os.environ["registry"] + "/dev",
87+
"base_repo_url": os.environ["BASE_REPO_URL"],
10988
"include_tags": os.environ.get("include_tags"),
11089
"skip_tags": os.environ.get("skip_tags"),
11190
}
@@ -114,16 +93,7 @@ def build_configuration_from_env() -> Dict[str, str]:
11493
def operator_build_configuration(
11594
builder: str, parallel: bool, debug: bool
11695
) -> BuildConfiguration:
117-
# TODO: This will be fixed/changed once we update the local dev tooling
118-
default_config_location = os.path.expanduser("~/.operator-dev/context.env")
119-
context_file = os.environ.get(
120-
"OPERATOR_BUILD_CONFIGURATION", default_config_location
121-
)
122-
123-
if os.path.exists(context_file):
124-
context = build_configuration_from_context_file(context_file)
125-
else:
126-
context = build_configuration_from_env()
96+
context = build_configuration_from_env()
12797

12898
print(f"Context: {context}")
12999

public/support/mdb_operator_diagnostic_data.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ mkdir -p "${log_dir}" &>/dev/null
195195

196196
if [ -n "${CENTRAL_CLUSTER}" ]; then
197197
if [ -z "${MEMBER_CLUSTERS}" ]; then
198-
echo "central_cluster is set but no member_clusters"
198+
echo "CENTRAL_CLUSTER is set but no MEMBER_CLUSTERS"
199199
exit 1
200200
else
201-
echo "starting with the central_cluster!"
201+
echo "starting with the CENTRAL_CLUSTER!"
202202
kubectl config use-context "${CENTRAL_CLUSTER}"
203203
fi
204204
fi
205205

206206
if [ -n "${MEMBER_CLUSTERS}" ]; then
207207
if [ -z "${CENTRAL_CLUSTER}" ]; then
208-
echo "member_clusters is set but no central_cluster"
208+
echo "MEMBER_CLUSTERS is set but no CENTRAL_CLUSTER"
209209
exit 1
210210
fi
211211
fi

scripts/dev/apply_resources

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/dev/configure_docker_auth.sh

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

33
set -Eeou pipefail
44

5+
source scripts/dev/set_env_context.sh
56
source scripts/funcs/checks
67
source scripts/funcs/printing
78
source scripts/funcs/kubernetes

scripts/dev/configure_operator.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ kubectl delete secret ${om_admin_secret} -n "${NAMESPACE}" 2>/dev/null || true
4242
kubectl create secret generic ${om_admin_secret} --from-literal=Username="[email protected]" --from-literal=Password="Passw0rd." --from-literal=FirstName="Jane" --from-literal=LastName="Doe" -n "${NAMESPACE}"
4343

4444
title "All necessary ConfigMaps and Secrets for the Operator are configured"
45+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
script_name=$(readlink -f "${BASH_SOURCE[0]}")
6+
script_dir=$(dirname "${script_name}")
7+
8+
# shellcheck disable=SC1091
9+
source "$script_dir/root-context"
10+
# shellcheck disable=SC1091
11+
source "$script_dir/variables/om50_image"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
script_name=$(readlink -f "${BASH_SOURCE[0]}")
6+
script_dir=$(dirname "${script_name}")
7+
8+
# shellcheck disable=SC1091
9+
source "$script_dir/root-context"
10+
# shellcheck disable=SC1091
11+
source "$script_dir/variables/om60_image"

scripts/dev/contexts/e2e_kind_olm_ubi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
script_name=$(readlink -f "${BASH_SOURCE[0]}")
6+
script_dir=$(dirname "${script_name}")
7+
8+
# shellcheck disable=SC1091
9+
source "$script_dir/root-context"
10+
# shellcheck disable=SC1091
11+
source "$script_dir/variables/om50"
12+
13+
export KUBE_ENVIRONMENT_NAME=kind
14+
export CUSTOM_MDB_VERSION=5.0.5
15+
export CUSTOM_MDB_PREV_VERSION=4.4.20
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
script_name=$(readlink -f "${BASH_SOURCE[0]}")
6+
script_dir=$(dirname "${script_name}")
7+
8+
# shellcheck disable=SC1091
9+
source "$script_dir/root-context"
10+
11+
export ops_manager_version="cloud_qa"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
script_name=$(readlink -f "${BASH_SOURCE[0]}")
6+
script_dir=$(dirname "${script_name}")
7+
8+
# shellcheck disable=SC1091
9+
source "$script_dir/root-context"
10+
11+
export KUBE_ENVIRONMENT_NAME=openshift_4
12+
export CLUSTER_TYPE="openshift"
13+
export ecr_registry_needs_auth=ecr-registry
14+
export MANAGED_SECURITY_CONTEXT="true"
15+
export ALWAYS_REMOVE_TESTING_NAMESPACE="true"
16+
export ops_manager_version="cloud_qa"
17+
18+
export CUSTOM_MDB_VERSION=4.4.20
19+
20+
21+
# shellcheck disable=SC2154
22+
export OPENSHIFT_URL="$openshift_url"
23+
# shellcheck disable=SC2154
24+
export OPENSHIFT_TOKEN="$openshift_token"

0 commit comments

Comments
 (0)