Skip to content

Commit 464fc81

Browse files
Start installing chart from OCI registry in E2E
1 parent 4beb99a commit 464fc81

File tree

6 files changed

+139
-90
lines changed

6 files changed

+139
-90
lines changed

.evergreen.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,6 @@ tasks:
447447
- func: helm_registry_login
448448
- func: publish_helm_chart
449449

450-
- name: publish_helm_chart
451-
commands:
452-
- func: clone
453-
- func: setup_kubectl
454-
- func: setup_aws
455-
- func: prepare_aws
456-
- func: helm_registry_login
457-
- func: python_venv
458-
- func: publish_helm_chart
459-
460450
- name: prepare_aws
461451
priority: 59
462452
commands:

docker/mongodb-kubernetes-tests/kubetester/helm.py

Lines changed: 67 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
logger = test_logger.get_test_logger(__name__)
1212

13-
HELM_REGISTRY_AWS_REGION = "us-east-1"
14-
HELM_ECR_REGISTRY = "268558157000.dkr.ecr.us-east-1.amazonaws.com"
15-
1613
def helm_template(
1714
helm_args: Dict,
1815
helm_chart_path: Optional[str] = "helm_chart",
@@ -146,6 +143,53 @@ def process_run_and_check(args, **kwargs):
146143
logger.error(f"output: {exc.output}")
147144
raise
148145

146+
def oci_helm_registry_login(helm_registry: str, region: str):
147+
logger.info(f"Attempting to log into ECR registry: {helm_registry}, using helm registry login.")
148+
149+
aws_command = ["aws", "ecr", "get-login-password", "--region", region]
150+
151+
# as we can see the password is being provided by stdin, that would mean we will have to
152+
# pipe the aws_command (it figures out the password) into helm_command.
153+
helm_command = ["helm", "registry", "login", "--username", "AWS", "--password-stdin", helm_registry]
154+
155+
try:
156+
logger.info("Starting AWS ECR credential retrieval.")
157+
aws_proc = subprocess.Popen(
158+
aws_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True # Treat input/output as text strings
159+
)
160+
161+
logger.info("Starting Helm registry login.")
162+
helm_proc = subprocess.Popen(
163+
helm_command, stdin=aws_proc.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
164+
)
165+
166+
# Close the stdout stream of aws_proc in the parent process
167+
# to prevent resource leakage (only needed if you plan to do more processing)
168+
aws_proc.stdout.close()
169+
170+
# Wait for the Helm command (helm_proc) to finish and capture its output
171+
helm_stdout, helm_stderr = helm_proc.communicate()
172+
173+
# Wait for the AWS process to finish as well
174+
aws_proc.wait()
175+
176+
if aws_proc.returncode != 0:
177+
_, aws_stderr = aws_proc.communicate()
178+
raise Exception(f"aws command to get password failed. Error: {aws_stderr}")
179+
180+
if helm_proc.returncode == 0:
181+
logger.info("Login to helm registry was successful.")
182+
logger.info(helm_stdout.strip())
183+
else:
184+
raise Exception(
185+
f"Login to helm registry failed, Exit code: {helm_proc.returncode}, Error: {helm_stderr.strip()}"
186+
)
187+
188+
except FileNotFoundError as e:
189+
# This catches errors if 'aws' or 'helm' are not in the PATH
190+
raise Exception(f"Command not found. Please ensure '{e.filename}' is installed and in your system's PATH.")
191+
except Exception as e:
192+
raise Exception(f"An unexpected error occurred: {e}.")
149193

150194
def helm_upgrade(
151195
name: str,
@@ -168,10 +212,14 @@ def helm_upgrade(
168212
apply_crds_from_chart(chart_dir)
169213

170214
# login to helm registry because we are going to install published helm chart
171-
if not helm_registry_login():
172-
raise Exception(f"Failed logging in to the helm registry {HELM_ECR_REGISTRY}")
215+
try:
216+
registry, repository, region = oci_chart_info()
217+
218+
oci_helm_registry_login(registry, region)
219+
except Exception as e:
220+
raise Exception(f"Failed logging in to the helm registry {registry}. Error: {e}")
173221

174-
chart_dir = f"oci://{HELM_ECR_REGISTRY}/dev/helm-charts/mongodb-kubernetes"
222+
chart_uri = f"oci://{registry}/{repository}"
175223
command_args = _create_helm_args(helm_args, helm_options)
176224
args = [
177225
"helm",
@@ -181,89 +229,28 @@ def helm_upgrade(
181229
*command_args,
182230
name,
183231
]
184-
custom_operator_version = "0.0.0+68e3eec04df1df00072e1bb2"
232+
185233
if custom_operator_version:
186234
args.append(f"--version={custom_operator_version}")
235+
else:
236+
published_chart_version = os.environ.get("OPERATOR_VERSION")
237+
if not published_chart_version:
238+
logger.info("OPERATOR_VERSION env var is not set")
239+
args.append(f"--version=0.0.0+{published_chart_version}")
187240

188-
args.append(chart_dir)
241+
args.append(chart_uri)
189242

190243
command = " ".join(args)
191244
process_run_and_check(command, check=True, capture_output=True, shell=True)
192245

193-
def helm_registry_login():
194-
logger.info(f"Attempting to log into ECR registry: {HELM_ECR_REGISTRY}, using helm registry login.")
195-
196-
aws_command = [
197-
"aws",
198-
"ecr",
199-
"get-login-password",
200-
"--region",
201-
HELM_REGISTRY_AWS_REGION
202-
]
203-
204-
# as we can see the password is being provided by stdin, that would mean we will have to
205-
# pipe the aws_command (it figures out the password) into helm_command.
206-
helm_command = [
207-
"helm",
208-
"registry",
209-
"login",
210-
"--username",
211-
"AWS",
212-
"--password-stdin",
213-
HELM_ECR_REGISTRY
214-
]
246+
def oci_chart_info():
247+
registry = os.environ.get("OCI_HELM_REGISTRY")
248+
repository = os.environ.get("OCI_HELM_REPOSITORY")
249+
region = os.environ.get("OCI_HELM_REGION")
215250

216-
try:
217-
logger.info("Starting AWS ECR credential retrieval.")
218-
aws_proc = subprocess.Popen(
219-
aws_command,
220-
stdout=subprocess.PIPE,
221-
stderr=subprocess.PIPE,
222-
text=True # Treat input/output as text strings
223-
)
224-
225-
logger.info("Starting Helm registry login.")
226-
helm_proc = subprocess.Popen(
227-
helm_command,
228-
stdin=aws_proc.stdout,
229-
stdout=subprocess.PIPE,
230-
stderr=subprocess.PIPE,
231-
text=True
232-
)
233-
234-
# Close the stdout stream of aws_proc in the parent process
235-
# to prevent resource leakage (only needed if you plan to do more processing)
236-
aws_proc.stdout.close()
237-
238-
# Wait for the Helm command (helm_proc) to finish and capture its output
239-
helm_stdout, helm_stderr = helm_proc.communicate()
240-
241-
# Wait for the AWS process to finish as well
242-
aws_proc.wait()
243-
244-
if aws_proc.returncode != 0:
245-
logger.error(f"aws command to get password failed, (Exit Code {aws_proc.returncode}).")
246-
# We captured AWS stderr directly, so print it
247-
_, aws_stderr = aws_proc.communicate()
248-
logger.error(aws_stderr)
249-
return False
250-
251-
if helm_proc.returncode == 0:
252-
logger.info("Login to helm registry was successful.")
253-
logger.info(helm_stdout.strip())
254-
return True
255-
else:
256-
logger.error(f"Login to helm registry failed, (Exit Code {helm_proc.returncode}).")
257-
logger.error(helm_stderr.strip())
258-
return False
251+
print(f"oci chart details in test image is registry {registry}, repo {repository}, region {region}")
259252

260-
except FileNotFoundError as e:
261-
# This catches errors if 'aws' or 'helm' are not in the PATH
262-
logger.error(f"Command not found. Please ensure '{e.filename}' is installed and in your system's PATH.")
263-
return False
264-
except Exception as e:
265-
logger.error(f"An unexpected error occurred: {e}.")
266-
return False
253+
return registry, f"{repository}/mongodb-kubernetes", region
267254

268255
def apply_crds_from_chart(chart_dir: str):
269256
crd_files = glob.glob(os.path.join(chart_dir, "crds", "*.yaml"))

scripts/evergreen/deployments/test-app/templates/mongodb-enterprise-tests.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ spec:
174174
- name: OM_DEBUG_HTTP
175175
value: "{{ .Values.omDebugHttp }}"
176176
{{ end }}
177+
{{ if .Values.helm.oci.registry }}
178+
- name: OCI_HELM_REGISTRY
179+
value: "{{ .Values.helm.oci.registry }}"
180+
{{ end }}
181+
{{ if .Values.operator.version }}
182+
- name: OPERATOR_VERSION
183+
value: "{{ .Values.operator.version }}"
184+
{{ end }}
185+
{{ if .Values.helm.oci.repository }}
186+
- name: OCI_HELM_REPOSITORY
187+
value: "{{ .Values.helm.oci.repository }}"
188+
{{ end }}
189+
{{ if .Values.helm.oci.region }}
190+
- name: OCI_HELM_REGION
191+
value: "{{ .Values.helm.oci.region }}"
192+
{{ end }}
177193
- name: ops_manager_version
178194
value: "{{ .Values.opsManagerVersion }}"
179195
- name: cognito_user_pool_id

scripts/evergreen/deployments/test-app/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ mdbImageType: "ubi8"
4343

4444
# set to "true" to set OM_DEBUG_HTTP=true for the operator
4545
omDebugHttp:
46+
47+
# sets the configuration using which we can figure out the helm OCI repo of the MCK operator while deploying it
48+
# to run a test.
49+
helm:
50+
oci:
51+
registry: ""
52+
repository: ""
53+
region: ""
54+
55+
operator:
56+
version: ""

scripts/evergreen/e2e/single_e2e.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ deploy_test_app() {
4545
BUILD_ID="${BUILD_ID:-default_build_id}"
4646
BUILD_VARIANT="${BUILD_VARIANT:-default_build_variant}"
4747

48+
chart_info=$(scripts/dev/run_python.sh scripts/release/oci_chart_info.py)
49+
helm_oci_regisry=$(echo "$chart_info" | jq -r '.registry' )
50+
helm_oci_repository=$(echo "$chart_info" | jq -r '.repository' )
51+
helm_oci_registry_region=$(echo "$chart_info" | jq -r '.region' )
52+
4853
# note, that the 4 last parameters are used only for Mongodb resource testing - not for Ops Manager
4954
helm_params=(
5055
"--set" "taskId=${task_id:-'not-specified'}"
@@ -139,6 +144,22 @@ deploy_test_app() {
139144
helm_params+=("--set" "omDebugHttp=true")
140145
fi
141146

147+
if [[ -n "${helm_oci_regisry:-}" ]]; then
148+
helm_params+=("--set" "helm.oci.registry=${helm_oci_regisry}")
149+
fi
150+
151+
if [[ -n "${helm_oci_repository:-}" ]]; then
152+
helm_params+=("--set" "helm.oci.repository=${helm_oci_repository}")
153+
fi
154+
155+
if [[ -n "${helm_oci_registry_region:-}" ]]; then
156+
helm_params+=("--set" "helm.oci.region=${helm_oci_registry_region}")
157+
fi
158+
159+
if [[ -n "${OPERATOR_VERSION:-}" ]]; then
160+
helm_params+=("--set" "operator.version=${OPERATOR_VERSION}")
161+
fi
162+
142163
helm_params+=("--set" "opsManagerVersion=${ops_manager_version}")
143164

144165
helm template "scripts/evergreen/deployments/test-app" "${helm_params[@]}" > "${helm_template_file}" || exit 1

scripts/release/oci_chart_info.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import sys
3+
import json
4+
5+
from dataclasses import asdict
6+
from lib.base_logger import logger
7+
from scripts.release.build.build_info import load_build_info
8+
9+
def main():
10+
build_scenario = os.environ.get("BUILD_SCENARIO")
11+
build_info = load_build_info(build_scenario)
12+
chart_info = build_info.helm_charts["mongodb-kubernetes"]
13+
14+
j = json.dumps(asdict(chart_info))
15+
print(j)
16+
17+
18+
19+
if __name__ == "__main__":
20+
try:
21+
main()
22+
except Exception as e:
23+
logger.error(f"Failed while dumping the chart_info as json. Error: {e}")
24+
sys.exit(1)

0 commit comments

Comments
 (0)