Skip to content

Commit b2e3306

Browse files
lsierantlucian-tosa
authored andcommitted
Reference Architectures & automated code snippets (#3910)
# Summary This is the culmination of the code snippets automation & reference architecture epic. The main changes are: - `architectures` - this contains all the reference architectures with their respective code snippets - `scripts/code_snippets` - this contains all the scripts required for automating the code snippet tests (they were moved from public/scripts) - `scripts/dev/contexts` - 3 additional contexts which represent the 3 possible configurations for running the code snippet tests - evergreen configurations and scripts TD: REDACTED --------- Co-authored-by: Lucian Tosa <[email protected]> Co-authored-by: Lucian Tosa <[email protected]>
1 parent 5a86b10 commit b2e3306

File tree

138 files changed

+1525
-509
lines changed

Some content is hidden

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

138 files changed

+1525
-509
lines changed

.evergreen-functions.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ functions:
5050
shell: bash
5151
working_dir: src/github.com/10gen/ops-manager-kubernetes
5252
<<: *e2e_include_expansions_in_env
53+
add_to_path:
54+
- ${workdir}/bin
55+
- ${workdir}/google-cloud-sdk/bin
5356
script: |
5457
echo "Switching context"
5558
scripts/dev/switch_context.sh "${build_variant}"
@@ -77,6 +80,14 @@ functions:
7780
type: setup
7881
params:
7982
directory: src/github.com/10gen/ops-manager-kubernetes
83+
- command: subprocess.exec
84+
type: setup
85+
params:
86+
command: "git config --global user.name 'Evergreen'"
87+
- command: subprocess.exec
88+
type: setup
89+
params:
90+
command: "git config --global user.email '[email protected]'"
8091
- *setup_context
8192

8293
setup_kubectl: &setup_kubectl
@@ -111,6 +122,26 @@ functions:
111122
- ${workdir}/bin
112123
binary: scripts/evergreen/setup_aws.sh
113124

125+
setup_gcloud_cli:
126+
command: subprocess.exec
127+
type: setup
128+
params:
129+
working_dir: src/github.com/10gen/ops-manager-kubernetes
130+
include_expansions_in_env:
131+
- GCP_SERVICE_ACCOUNT_JSON_FOR_SNIPPETS_TESTS
132+
add_to_path:
133+
- ${workdir}/google-cloud-sdk/bin
134+
binary: scripts/evergreen/setup_gcloud_cli.sh
135+
136+
setup_mongosh:
137+
command: subprocess.exec
138+
type: setup
139+
params:
140+
working_dir: src/github.com/10gen/ops-manager-kubernetes
141+
add_to_path:
142+
- ${workdir}/google-cloud-sdk/bin
143+
binary: scripts/evergreen/setup_mongosh.sh
144+
114145
# configures Docker size, installs the Kind binary (if necessary)
115146
setup_kind: &setup_kind
116147
command: subprocess.exec
@@ -397,6 +428,19 @@ functions:
397428
params:
398429
file: "src/github.com/10gen/ops-manager-kubernetes/logs/myreport.xml"
399430

431+
upload_code_snippets_logs:
432+
- command: s3.put
433+
params:
434+
aws_key: ${enterprise_aws_access_key_id}
435+
aws_secret: ${enterprise_aws_secret_access_key}
436+
local_files_include_filter:
437+
- src/github.com/10gen/ops-manager-kubernetes/public/architectures/**/*.log
438+
- src/github.com/10gen/ops-manager-kubernetes/public/architectures/**/*.out
439+
remote_file: logs/${task_id}/${execution}/
440+
bucket: operator-e2e-artifacts
441+
permissions: public-read
442+
content_type: text/plain
443+
400444
preflight_image:
401445
- *switch_context
402446
- command: subprocess.exec
@@ -687,3 +731,28 @@ functions:
687731
files:
688732
- evergreen_tasks.json
689733
optional: true
734+
735+
#
736+
# Code snippet test automation
737+
#
738+
739+
gke_multi_cluster_snippets:
740+
- *switch_context
741+
- command: shell.exec
742+
params:
743+
shell: bash
744+
working_dir: src/github.com/10gen/ops-manager-kubernetes
745+
include_expansions_in_env:
746+
- version_id
747+
- code_snippets_teardown
748+
script: |
749+
./scripts/code_snippets/gke_multi_cluster_test.sh
750+
751+
code_snippets_commit_output:
752+
- *switch_context
753+
- command: shell.exec
754+
params:
755+
shell: bash
756+
working_dir: src/github.com/10gen/ops-manager-kubernetes
757+
script: |
758+
./scripts/code_snippets/sample_commit_output.sh

.evergreen-tasks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ tasks:
6565
vars:
6666
image_name: ops-manager
6767

68+
- name: gke_multi_cluster_snippets
69+
commands:
70+
- func: gke_multi_cluster_snippets
6871
## Below are only e2e runs for .evergreen.yml ##
6972

7073
- name: e2e_multiple_cluster_failures

.evergreen.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ variables:
6969
- func: setup_building_host
7070
- func: build_multi_cluster_binary
7171

72+
- &setup_and_teardown_group_gke_code_snippets
73+
setup_group:
74+
- func: clone
75+
- func: setup_gcloud_cli
76+
- func: setup_mongosh
77+
- func: download_kube_tools
78+
- func: build_multi_cluster_binary
79+
teardown_group:
80+
- func: code_snippets_commit_output
81+
- func: upload_code_snippets_logs
82+
7283
- &setup_and_teardown_task_cloudqa
7384
setup_task_can_fail_task: true
7485
setup_task:
@@ -149,6 +160,10 @@ parameters:
149160
value: ""
150161
description: "Patch id to reuse images from other Evergreen build"
151162

163+
- key: code_snippets_teardown
164+
value: "true"
165+
description: set this to false if you would like to keep the clusters created during code snippets tests
166+
152167
# Triggered manually or by PCT.
153168
patch_aliases:
154169
- alias: "periodic_builds"
@@ -532,6 +547,11 @@ task_groups:
532547
- unit_tests_python
533548
- sbom_tests
534549

550+
- name: gke_code_snippets
551+
<<: *setup_and_teardown_group_gke_code_snippets
552+
tasks:
553+
- gke_multi_cluster_snippets
554+
535555
# This is the task group that contains all the tests run in the e2e_mdb_kind_ubuntu_cloudqa build variant
536556
- name: e2e_mdb_kind_cloudqa_task_group
537557
max_hosts: -1
@@ -1672,6 +1692,38 @@ buildvariants:
16721692
tasks:
16731693
- name: release_all_agents_on_ecr
16741694

1695+
# These variants are used to test the code snippets and each one can be used in patches
1696+
# Prerelease is especially used when the repo is tagged
1697+
# More details in the TD: https://docs.google.com/document/d/1fuTxfRtP8QPtn7sKYxQM_AGcD6xycTZH8svngGxyKhc/edit?tab=t.0#bookmark=id.e8uva0393mbe
1698+
- name: public_gke_code_snippets
1699+
display_name: public_gke_code_snippets
1700+
allowed_requesters: ["patch"]
1701+
run_on:
1702+
- ubuntu2204-small
1703+
tasks:
1704+
- name: gke_code_snippets
1705+
1706+
- name: prerelease_gke_code_snippets
1707+
display_name: prerelease_gke_code_snippets
1708+
allowed_requesters: ["patch", "github_tag"]
1709+
depends_on:
1710+
- variant: release_images
1711+
name: '*'
1712+
patch_optional: true
1713+
run_on:
1714+
- ubuntu2204-small
1715+
tasks:
1716+
- name: gke_code_snippets
1717+
1718+
- name: private_gke_code_snippets
1719+
display_name: private_gke_code_snippets
1720+
allowed_requesters: ["patch"]
1721+
run_on:
1722+
- ubuntu2204-small
1723+
<<: *base_om8_dependency
1724+
tasks:
1725+
- name: gke_code_snippets
1726+
16751727
### Build variants for manual patch only
16761728

16771729
- name: publish_om60_images

.githooks/pre-commit

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,18 @@ function pre_commit() {
147147
run_shellcheck() {
148148
local file="$1"
149149
echo "Running shellcheck on $file"
150-
if ! shellcheck -x "$file" -e SC2154 -e SC1091 -e SC1090 -o require-variable-braces -P "scripts"; then
151-
echo "shellcheck failed on $file"
152-
exit 1
150+
if ! shellcheck -x "$file" -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P "scripts"; then
151+
echo "shellcheck failed on $file"
152+
exit 1
153153
fi
154154
}
155155

156156
start_shellcheck() {
157157
files_1=$(find scripts -type f -name "*.sh")
158158
files_2=$(find scripts/dev/contexts -type f)
159159
files_3=$(find scripts/funcs -type f)
160-
files=$(echo -e "$files_1\n$files_2\n$files_3")
160+
files_4=$(find public/architectures -type f -name "*.sh")
161+
files=$(echo -e "$files_1\n$files_2\n$files_3\n$files_4")
161162
# Process each file in parallel
162163
for file in $files; do
163164
run_shellcheck "$file" &

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ scripts/dev/contexts/private-context-*
3535

3636
public/support/*.gz
3737
public/support/logs*
38-
public/samples/**/log
39-
public/samples/**/*.run.log
40-
public/samples/**/.generated
41-
public/samples/**/certs/*
38+
public/architectures/**/log
39+
public/architectures/**/*.run.log
40+
public/architectures/**/.generated
41+
public/architectures/**/certs/*
4242

4343
docker/mongodb-enterprise-appdb/content/readinessprobe
4444
ops-manager-kubernetes
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
2+
apiVersion: cert-manager.io/v1
3+
kind: Certificate
4+
metadata:
5+
name: mdb-cert
6+
spec:
7+
dnsNames:
8+
- "*.${MDB_NAMESPACE}.svc.cluster.local"
9+
duration: 240h0m0s
10+
issuerRef:
11+
name: my-ca-issuer
12+
kind: ClusterIssuer
13+
renewBefore: 120h0m0s
14+
secretName: cert-prefix-mdb-cert
15+
usages:
16+
- server auth
17+
- client auth
18+
EOF
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
2+
apiVersion: mongodb.com/v1
3+
kind: MongoDBMultiCluster
4+
metadata:
5+
name: ${RESOURCE_NAME}
6+
spec:
7+
type: ReplicaSet
8+
version: 8.0.3
9+
opsManager:
10+
configMapRef:
11+
name: mdb-org-project-config
12+
credentials: mdb-org-owner-credentials
13+
duplicateServiceObjects: false
14+
persistent: true
15+
externalAccess: {}
16+
security:
17+
certsSecretPrefix: cert-prefix
18+
tls:
19+
ca: ca-issuer
20+
authentication:
21+
enabled: true
22+
modes: ["SCRAM"]
23+
clusterSpecList:
24+
- clusterName: ${K8S_CLUSTER_0_CONTEXT_NAME}
25+
members: 2
26+
- clusterName: ${K8S_CLUSTER_1_CONTEXT_NAME}
27+
members: 1
28+
- clusterName: ${K8S_CLUSTER_2_CONTEXT_NAME}
29+
members: 2
30+
EOF
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo; echo "Waiting for MongoDB to reach Running phase..."
2+
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" wait --for=jsonpath='{.status.phase}'=Running "mdbmc/${RESOURCE_NAME}" --timeout=900s
3+
echo; echo "Pods running in cluster ${K8S_CLUSTER_0_CONTEXT_NAME}"
4+
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
5+
echo; echo "Pods running in cluster ${K8S_CLUSTER_1_CONTEXT_NAME}"
6+
kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
7+
echo; echo "Pods running in cluster ${K8S_CLUSTER_2_CONTEXT_NAME}"
8+
kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: rs-user-password
6+
type: Opaque
7+
stringData:
8+
password: password
9+
---
10+
apiVersion: mongodb.com/v1
11+
kind: MongoDBUser
12+
metadata:
13+
name: rs-user
14+
spec:
15+
passwordSecretKeyRef:
16+
name: rs-user-password
17+
key: password
18+
username: "rs-user"
19+
db: "admin"
20+
mongodbResourceRef:
21+
name: ${RESOURCE_NAME}
22+
roles:
23+
- db: "admin"
24+
name: "root"
25+
EOF
26+
27+
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" wait --for=jsonpath='{.status.phase}'=Updated -n "${MDB_NAMESPACE}" mdbu/rs-user
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Load Balancers sometimes take longer to get an IP assigned, we need to retry
2+
while [ -z "$(kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" svc "${RESOURCE_NAME}-0-0-svc-external" -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")" ]
3+
do
4+
sleep 5
5+
done
6+
7+
external_ip="$(kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" svc "${RESOURCE_NAME}-0-0-svc-external" -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")"
8+
9+
mkdir -p certs
10+
kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" cm/ca-issuer -o=jsonpath='{.data.ca-pem}' > certs/ca.crt
11+
12+
mongosh --host "${external_ip}" --username rs-user --password password --tls --tlsCAFile certs/ca.crt --tlsAllowInvalidHostnames --eval "db.runCommand({connectionStatus : 1})"

0 commit comments

Comments
 (0)