Skip to content

Commit ffbcda3

Browse files
nammnfealebenpae
authored andcommitted
make private-context lean (#3723)
# Summary - move a lot of things out of private-context to root-context, add new context which is sourced in the beginning for ease of start of development - **that is done by pointing, by default, all registries to shared registries** - without the new context file that is sourced first, we had the problem that we could not defined sane defaults for everyone in the root-context. If a root-context contained something we did not want, we required to create an override-context, which is cumbersome - **that is solved by using a context, that is only for local dev and sourced first at all times, when you want something different, you can just make that change in your release.json** -  I now expect folks to more likely make changes to the new `local-defaults-context` and if not agreed, one can just override them for their special case in the private-context new sourcing order: ```local-defaults-context (local sane/opinionated defaults) -> private (local secrets and overrides) -> root (defaults shared with evg)```
1 parent 6f01f63 commit ffbcda3

File tree

4 files changed

+85
-58
lines changed

4 files changed

+85
-58
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
set -Eeou pipefail
4+
5+
# This context is the defacto local development default context, where we set sane defaults for everyone to be able to get started.
6+
# This is the first context we source, therefore we can easily overwrite this. in the private-context or overrides.
7+
# In case you don't agree with those defaults you can override them im your private-context without affecting
8+
# others.
9+
10+
script_name=$(readlink -f "${BASH_SOURCE[0]}")
11+
script_dir=$(dirname "${script_name}")
12+
# The workdir is used in many places and needs to point into the project root.
13+
# Don't change it unless you know what you're doing.
14+
export workdir="$script_dir/../../../"
15+
16+
17+
# Here are all the required registries used by the Operator. We are defaulting to images ecr for most, some to quay
18+
# The main registry to use for local test runs
19+
# - global: <registry>/dev is the shared registry
20+
# - dedicated: <registry>/<my-registry>
21+
# Note: in our root-context we default the image tag to latest, if VERSION_ID is not preset on your machine
22+
# Note2: For quick local development defaults we only use shared images
23+
export QUAY_REGISTRY=quay.io/mongodb
24+
export BASE_REPO_URL_SHARED="268558157000.dkr.ecr.us-east-1.amazonaws.com/dev"
25+
export REGISTRY="$BASE_REPO_URL_SHARED"
26+
export OPERATOR_REGISTRY="${BASE_REPO_URL_SHARED}"
27+
28+
export INIT_IMAGES_REGISTRY=${INIT_IMAGES_REGISTRY:-"${REGISTRY}"}
29+
30+
export INIT_APPDB_REGISTRY="${BASE_REPO_URL_SHARED}"
31+
export INIT_OPS_MANAGER_REGISTRY=${BASE_REPO_URL_SHARED:-"${QUAY_REGISTRY}"}
32+
export INIT_DATABASE_REGISTRY=${BASE_REPO_URL_SHARED:-"${QUAY_REGISTRY}"}
33+
export INIT_DATABASE_IMAGE_REPOSITORY="${BASE_REPO_URL_SHARED}/mongodb-enterprise-init-database"
34+
export DATABASE_REGISTRY="${QUAY_REGISTRY}"
35+
export OPS_MANAGER_REGISTRY="${QUAY_REGISTRY}"
36+
export MONGODB_REPO_URL="${QUAY_REGISTRY}"
37+
export APPDB_REGISTRY="${QUAY_REGISTRY}"
38+
export MONGODB_ENTERPRISE_DATABASE_IMAGE="${INIT_IMAGES_REGISTRY}/mongodb-enterprise-database-ubi"
39+
export MDB_AGENT_IMAGE_OPERATOR_VERSION=latest
40+
export MDB_AGENT_IMAGE_REPOSITORY="${BASE_REPO_URL_SHARED}/mongodb-agent-ubi"
41+
export AGENT_BASE_REGISTRY=${BASE_REPO_URL_SHARED}
42+
export AGENT_IMAGE="268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-agent-ubi:12.0.30.7791-1"
43+
44+
# these are needed to deploy OM
45+
export INIT_APPDB_IMAGE_REPOSITORY="${INIT_IMAGES_REGISTRY}/mongodb-enterprise-init-appdb"
46+
export OPS_MANAGER_IMAGE_REPOSITORY="${QUAY_REGISTRY}/mongodb-enterprise-ops-manager-ubi"
47+
export INIT_OPS_MANAGER_IMAGE_REPOSITORY="${INIT_IMAGES_REGISTRY}/mongodb-enterprise-init-ops-manager"
48+
49+
50+
# Environment variable needed for local development
51+
# Used in controllers/operator/mongodbopsmanager_controller.go
52+
# The file is created by scripts/dev/prepare_local_e2e_run.sh
53+
export MDB_OM_VERSION_MAPPING_PATH="$workdir/release.json"
54+
export ENV_FILE="$workdir/.ops-manager-env"
55+
export NAMESPACE_FILE="$workdir/.namespace"
56+
57+
# TO ensure we don't release by accident via pipeline.py
58+
export skip_tags="release"
59+
60+
# This setting is set if you want to remove your namespaces after running the tests
61+
export ALWAYS_REMOVE_TESTING_NAMESPACE="true"

scripts/dev/contexts/private-context-template

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
set -Eeou pipefail
44

5-
script_name=$(readlink -f "${BASH_SOURCE[0]}")
6-
script_dir=$(dirname "${script_name}")
7-
85
## This file contains properties that need to overridden by a user.
96
## Rename it to "private-context" and fill in with your data.
107

11-
# The workdir is used in many places and needs to point into the project root.
12-
# Don't change it unless you know what you're doing.
13-
export workdir="$script_dir/../../../"
14-
158
# Kubernetes namespace for deploying a test
169
# Allowed values:
1710
# - a valid Kubernetes namespace
@@ -83,8 +76,7 @@ export AWS_DEFAULT_REGION="eu-central-1"
8376
export OM_USER=""
8477
export OM_API_KEY=""
8578
export OM_ORGID=""
86-
export OM_HOST=https://cloud-qa.mongodb.com
87-
export OM_BASE_URL=https://cloud-qa.mongodb.com
79+
8880

8981
# The settings below are used by teardown.sh and setup_cloud_qa.py.
9082
# Typically, in a local environment they are empty but with provided default settings
@@ -98,46 +90,6 @@ export OM_BASE_URL=https://cloud-qa.mongodb.com
9890
export e2e_cloud_qa_orgid_owner="$OM_ORGID"
9991
export e2e_cloud_qa_apikey_owner="$OM_API_KEY"
10092
export e2e_cloud_qa_user_owner="$OM_USER"
101-
export e2e_cloud_qa_baseurl="$OM_HOST"
10293
export e2e_cloud_qa_orgid_owner_static_2="$OM_ORGID"
10394
export e2e_cloud_qa_apikey_owner_static_2="$OM_API_KEY"
10495
export e2e_cloud_qa_user_owner_static_2="$OM_USER"
105-
export e2e_cloud_qa_baseurl_static_2="$OM_HOST"
106-
export ENV_FILE="$workdir/.ops-manager-env"
107-
export NAMESPACE_FILE="$workdir/.namespace"
108-
109-
# Environment variable needed for local development
110-
# Used in controllers/operator/mongodbopsmanager_controller.go
111-
# The file is created by scripts/dev/prepare_local_e2e_run.sh
112-
export MDB_OM_VERSION_MAPPING_PATH="$workdir/release.json"
113-
114-
# TO ensure we don't release by accident via pipeline.py
115-
export skip_tags="release"
116-
117-
# This setting is set if you want to remove your namespaces after running the tests
118-
export ALWAYS_REMOVE_TESTING_NAMESPACE="true"
119-
120-
# Here are all the required registries used by the Operator. We are defaulting to images ecr
121-
# The main registry to use for local test runs
122-
# - global: <registry>/dev is the shared registry
123-
# - dedicated: <registry>/<my-registry>
124-
# Note: in our root-context we default the image tag to latest, if VERSION_ID is not preset on your machine
125-
export QUAY_REGISTRY=quay.io/mongodb
126-
export REGISTRY="$BASE_REPO_URL"
127-
export OPERATOR_REGISTRY=${REGISTRY}
128-
129-
export INIT_IMAGES_REGISTRY=${INIT_IMAGES_REGISTRY:-${REGISTRY}}
130-
131-
export INIT_APPDB_REGISTRY=${INIT_IMAGES_REGISTRY}
132-
export INIT_OPS_MANAGER_REGISTRY=${INIT_IMAGES_REGISTRY-"${QUAY_REGISTRY}"}
133-
export INIT_DATABASE_REGISTRY=${INIT_IMAGES_REGISTRY:-"${QUAY_REGISTRY}"}
134-
export DATABASE_REGISTRY=${INIT_IMAGES_REGISTRY:-"${QUAY_REGISTRY}"}
135-
export OPS_MANAGER_REGISTRY=${QUAY_REGISTRY}
136-
export APPDB_REGISTRY=${QUAY_REGISTRY}
137-
export MONGODB_ENTERPRISE_DATABASE_IMAGE="${INIT_IMAGES_REGISTRY}/mongodb-enterprise-database"
138-
export INIT_DATABASE_IMAGE_REPOSITORY="${INIT_IMAGES_REGISTRY}/mongodb-enterprise-init-database"
139-
export MDB_AGENT_IMAGE_REPOSITORY="${INIT_IMAGES_REGISTRY}/mongodb-agent-ubi"
140-
# these are needed to deploy OM
141-
export INIT_APPDB_IMAGE_REPOSITORY="${INIT_IMAGES_REGISTRY}/mongodb-enterprise-init-appdb"
142-
export OPS_MANAGER_IMAGE_REPOSITORY="${QUAY_REGISTRY}/mongodb-enterprise-ops-manager-ubi"
143-
export INIT_OPS_MANAGER_IMAGE_REPOSITORY=${INIT_IMAGES_REGISTRY}/mongodb-enterprise-init-ops-manager

scripts/dev/contexts/root-context

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -Eeou pipefail
44

55
script_name=$(readlink -f "${BASH_SOURCE[0]}")
66
script_dir=$(dirname "${script_name}")
7-
87
source "$script_dir/private-context"
98

109
export PROJECT_DIR="$PWD"
@@ -43,6 +42,7 @@ export OPS_MANAGER_NAMESPACE="operator-testing-50-current"
4342

4443
# Moved from the old set_env_context.sh
4544
export LOCAL_RUN=true
45+
4646
# version_id is similar to version_id from Evergreen. Used to differentiate different builds. Can be constant
4747
# for local run
4848
version_id=${version_id:-"latest"}
@@ -80,3 +80,10 @@ export SIGNING_PUBLIC_KEY_URL="https://cosign.mongodb.com/mongodb-enterprise-kub
8080
export CLUSTER_DOMAIN="cluster.local"
8181

8282
export MDB_MAX_CONCURRENT_RECONCILES=10
83+
84+
# leaving them empty for now
85+
export OM_HOST=https://cloud-qa.mongodb.com
86+
export OM_BASE_URL=https://cloud-qa.mongodb.com
87+
88+
export e2e_cloud_qa_baseurl="$OM_HOST"
89+
export e2e_cloud_qa_baseurl_static_2="$OM_HOST"

scripts/dev/switch_context.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ context="$1"
1515
additional_override="${2:-}"
1616

1717
context_file="scripts/dev/contexts/${context}"
18+
local_development_default_file="scripts/dev/contexts/local-defaults-context"
1819
override_context_file="scripts/dev/contexts/private-context-override"
1920
additional_override_file="scripts/dev/contexts/private-context-${additional_override}"
2021

@@ -26,26 +27,31 @@ fi
2627

2728
echo "Switching context to: ${context}"
2829

29-
# shellcheck disable=SC1090
30-
source "${context_file}"
3130

3231
# This means we are running on evergreen, in this case we need the environment variables from evg expansions.
3332
# If running locally, we don't need them since they are defined in the private-context already, so we don't need
3433
# any kind of current env var expansions
3534
if [ -n "${EVR_TASK_ID-}" ]; then
36-
# shellcheck disable=SC2207
37-
current_envs=$(env)
35+
# shellcheck disable=SC1090
36+
source "${context_file}"
37+
# shellcheck disable=SC2207
38+
current_envs=$(env)
3839
else
40+
# shellcheck disable=SC1090
41+
source "$local_development_default_file"
42+
# shellcheck disable=SC1090
43+
source "${context_file}"
44+
3945
# env -i makes sure to start the shell with an empty shell, such that we only save into context.env the env vars we have
4046
# defined.
4147
if [ -n "$additional_override" ]; then
4248
echo "Using additional override file: $additional_override_file."
43-
current_envs=$(env -i bash -c "source ${context_file} && source ${additional_override_file} && env")
49+
current_envs=$(env -i bash -c "source ${local_development_default_file} && source ${context_file} && source ${additional_override_file} && env")
4450
elif [ -f "$override_context_file" ]; then
4551
echo "Using override file: $override_context_file. If you do not want to use one, remove the file or content."
46-
current_envs=$(env -i bash -c "source ${context_file} && source ${override_context_file} && env")
52+
current_envs=$(env -i bash -c "source ${local_development_default_file} && source ${context_file} && source ${override_context_file} && env")
4753
else
48-
current_envs=$(env -i bash -c "source ${context_file} && env")
54+
current_envs=$(env -i bash -c "source ${local_development_default_file} && source ${context_file} && env")
4955
fi
5056
fi
5157

@@ -67,7 +73,8 @@ scripts/dev/print_operator_env.sh | sort | uniq >"${destination_envs_file}.opera
6773
awk '{print "export " $0}' < "${destination_envs_file}".operator.env > "${destination_envs_file}".operator.export.env
6874

6975
echo "Generated env files in $(readlink -f "$destination_envs_dir"):"
70-
ls -l1 "$destination_envs_dir"
76+
# shellcheck disable=SC2010
77+
ls -l1 "$destination_envs_dir" | grep "context"
7178

7279
if which kubectl > /dev/null; then
7380
if [ "${CLUSTER_NAME-}" ]; then

0 commit comments

Comments
 (0)