Skip to content

Commit d62b60c

Browse files
Install published helm chart instead of local one, during E2E
1 parent 95a4b32 commit d62b60c

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

.evergreen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ variables:
5454
variant: init_test_run
5555
- name: build_init_appdb_images_ubi
5656
variant: init_test_run
57+
- name: publish_helm_chart
58+
variant: init_test_run
5759

5860
- &community_dependency
5961
depends_on:

docker/mongodb-kubernetes-tests/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ RUN apt-get -qq update \
4545
libldap2-dev \
4646
libsasl2-dev \
4747
git \
48-
openssl
48+
openssl \
49+
unzip
4950

5051
RUN mkdir -p /tmp/mongodb-tools && \
5152
tar xfz /tmp/mongodb-tools.tgz -C /tmp/mongodb-tools && \
@@ -66,6 +67,11 @@ RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -
6667
&& chmod +x ./kubectl \
6768
&& mv ./kubectl /usr/local/bin/kubectl
6869

70+
# install aws, required to run helm registry login while running the tests
71+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
72+
&& unzip -q awscliv2.zip \
73+
&& ./aws/install
74+
6975
COPY --from=builder /venv /venv
7076

7177
ENV PATH="/venv/bin:${PATH}"

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
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"
1315

1416
def helm_template(
1517
helm_args: Dict,
@@ -162,8 +164,14 @@ def helm_upgrade(
162164
chart_dir = helm_chart_path if helm_override_path else _helm_chart_dir(helm_chart_path)
163165

164166
if apply_crds_first:
167+
# right now tests image has the entire helm_chart directory, maybe we should just copy the CRDs
165168
apply_crds_from_chart(chart_dir)
166169

170+
# 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}")
173+
174+
chart_dir = f"oci://{HELM_ECR_REGISTRY}/dev/helm-charts/mongodb-kubernetes"
167175
command_args = _create_helm_args(helm_args, helm_options)
168176
args = [
169177
"helm",
@@ -173,7 +181,7 @@ def helm_upgrade(
173181
*command_args,
174182
name,
175183
]
176-
184+
custom_operator_version = "0.0.0+68e3eec04df1df00072e1bb2"
177185
if custom_operator_version:
178186
args.append(f"--version={custom_operator_version}")
179187

@@ -182,6 +190,80 @@ def helm_upgrade(
182190
command = " ".join(args)
183191
process_run_and_check(command, check=True, capture_output=True, shell=True)
184192

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+
]
215+
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
259+
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
185267

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

0 commit comments

Comments
 (0)