-
Notifications
You must be signed in to change notification settings - Fork 23
[CLOUDP-352109] Run MCK E2E tests against OCI published helm chart #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
viveksinghggits
wants to merge
32
commits into
master
Choose a base branch
from
e2e-tests-on-published-chart
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
dfbc534
Publish helm chart to OCI registry for PR patches
viveksinghggits 982c77d
Consume build_scenario via build_info for registry repo and other info
viveksinghggits 0daaf61
Run precommit
viveksinghggits 4c753fc
Address review comments
viveksinghggits 8b511e5
Publish helm chart to OCI registry for PR patches
viveksinghggits 4f50441
Install published helm chart instead of local one, during E2E
viveksinghggits 087e06a
Don't copy entire helm_chart dir, just copy CRDs
viveksinghggits cb2a8d2
Delete not needed file
viveksinghggits b1162ec
Start installing chart from OCI registry in E2E
viveksinghggits 8a50020
Add newline
viveksinghggits c04e43a
Refactor
viveksinghggits 4132fc6
Add 0.0.0 while forming chart version
viveksinghggits 82bf02e
Fix `e2e_meko_mck_upgrade` by using OCI version only when version is …
viveksinghggits 6e641ce
Run precommit
viveksinghggits e96e180
Fix CRDs not found issue by installing CRD from correct path
viveksinghggits 93f3e12
Refactor a little, make consts etc
viveksinghggits eb65be5
Make sure local e2es use local helm chart
viveksinghggits 5cb41a0
Run precommit
viveksinghggits 8f50012
Merge branch 'master' into e2e-tests-on-published-chart
MaciejKaras 1068518
Review fixes
MaciejKaras 829393f
Fix tests
MaciejKaras 3aa3fce
Merge branch 'master' into e2e-tests-on-published-chart
MaciejKaras ca7881c
Fixes after merge with master
MaciejKaras 084b8f2
Add version_prefix to build_info.json + other fixes
MaciejKaras e1700ca
Fixes
MaciejKaras 2cc7bbd
Fix prefix concatenation
MaciejKaras f53071f
Merge branch 'master' into e2e-tests-on-published-chart
MaciejKaras c482251
Fix publish_helm_chart task
MaciejKaras 1ee164a
Fix multicluster tests
MaciejKaras ffceb0c
Merge branch 'master' into e2e-tests-on-published-chart
MaciejKaras cfee047
Use helm charts for release e2e smoke tests
MaciejKaras 1c8f00e
Merge branch 'master' into e2e-tests-on-published-chart
MaciejKaras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| OCI_HELM_VERSION = "OCI_HELM_VERSION" | ||
| OCI_HELM_REGISTRY_ENV_VAR_NAME = "OCI_HELM_REGISTRY" | ||
| OCI_HELM_REPOSITORY_ENV_VAR_NAME = "OCI_HELM_REPOSITORY" | ||
| OCI_HELM_REGION_ENV_VAR_NAME = "OCI_HELM_REGION" | ||
|
|
||
| LEGACY_OPERATOR_CHART = "mongodb/enterprise-operator" | ||
| MCK_HELM_CHART = "mongodb/mongodb-kubernetes" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,19 @@ | ||
| import glob | ||
| import logging | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import uuid | ||
| from typing import Dict, List, Optional, Tuple | ||
|
|
||
| from kubetester.consts import * | ||
| from tests import test_logger | ||
|
|
||
| logger = test_logger.get_test_logger(__name__) | ||
|
|
||
| # LOCAL_CRDs_DIR is the dir where local helm chart's CRDs are copied in tests image | ||
| LOCAL_CRDs_DIR = "helm_chart/crds" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Mixed casing |
||
| OCI_HELM_REGISTRY_ECR = "268558157000.dkr.ecr.us-east-1.amazonaws.com" | ||
|
|
||
|
|
||
| def helm_template( | ||
| helm_args: Dict, | ||
|
|
@@ -25,7 +29,7 @@ def helm_template( | |
| command_args.append("--show-only") | ||
| command_args.append(templates) | ||
|
|
||
| args = ("helm", "template", *(command_args), helm_chart_path) | ||
| args = ("helm", "template", *command_args, helm_chart_path) | ||
| logger.info(" ".join(args)) | ||
|
|
||
| yaml_file_name = "{}.yaml".format(str(uuid.uuid4())) | ||
|
|
@@ -145,6 +149,55 @@ def process_run_and_check(args, **kwargs): | |
| raise | ||
|
|
||
|
|
||
| def helm_registry_login_to_ecr(helm_registry: str, region: str): | ||
| logger.info(f"Attempting to log into ECR registry: {helm_registry}, using helm registry login.") | ||
|
|
||
| aws_command = ["aws", "ecr", "get-login-password", "--region", region] | ||
|
|
||
| # as we can see the password is being provided by stdin, that would mean we will have to | ||
| # pipe the aws_command (it figures out the password) into helm_command. | ||
| helm_command = ["helm", "registry", "login", "--username", "AWS", "--password-stdin", helm_registry] | ||
|
|
||
| try: | ||
| logger.info("Starting AWS ECR credential retrieval.") | ||
| aws_proc = subprocess.Popen( | ||
| aws_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True # Treat input/output as text strings | ||
| ) | ||
|
|
||
| logger.info("Starting Helm registry login.") | ||
| helm_proc = subprocess.Popen( | ||
| helm_command, stdin=aws_proc.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True | ||
MaciejKaras marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| # Close the stdout stream of aws_proc in the parent process | ||
| # to prevent resource leakage (only needed if you plan to do more processing) | ||
| aws_proc.stdout.close() | ||
|
|
||
| # Wait for the Helm command (helm_proc) to finish and capture its output | ||
| helm_stdout, helm_stderr = helm_proc.communicate() | ||
|
|
||
| # Wait for the AWS process to finish as well | ||
| aws_proc.wait() | ||
|
|
||
| if aws_proc.returncode != 0: | ||
| _, aws_stderr = aws_proc.communicate() | ||
| raise Exception(f"aws command to get password failed. Error: {aws_stderr}") | ||
|
|
||
| if helm_proc.returncode == 0: | ||
| logger.info("Login to helm registry was successful.") | ||
| logger.info(helm_stdout.strip()) | ||
| else: | ||
| raise Exception( | ||
| f"Login to helm registry failed, Exit code: {helm_proc.returncode}, Error: {helm_stderr.strip()}" | ||
| ) | ||
|
|
||
| except FileNotFoundError as e: | ||
| # This catches errors if 'aws' or 'helm' are not in the PATH | ||
| raise Exception(f"Command not found. Please ensure '{e.filename}' is installed and in your system's PATH.") | ||
| except Exception as e: | ||
| raise Exception(f"An unexpected error occurred: {e}.") | ||
|
|
||
|
|
||
| def helm_upgrade( | ||
| name: str, | ||
| namespace: str, | ||
|
|
@@ -162,7 +215,7 @@ def helm_upgrade( | |
| chart_dir = helm_chart_path | ||
|
|
||
| if apply_crds_first: | ||
| apply_crds_from_chart(chart_dir) | ||
| apply_crds_from_chart(LOCAL_CRDs_DIR) | ||
|
|
||
| command_args = _create_helm_args(helm_args, helm_options) | ||
| args = [ | ||
|
|
@@ -183,11 +236,24 @@ def helm_upgrade( | |
| process_run_and_check(command, check=True, capture_output=True, shell=True) | ||
|
|
||
|
|
||
| def apply_crds_from_chart(chart_dir: str): | ||
| crd_files = glob.glob(os.path.join(chart_dir, "crds", "*.yaml")) | ||
| # oci_chart_info returns the respective registry/repo and region information | ||
| # based on the build scenario (dev/staging) tests are being run in. These are | ||
| # read from build_info.json and then set to the tests image as env vars. | ||
| def oci_chart_info(): | ||
| registry = os.environ.get(OCI_HELM_REGISTRY_ENV_VAR_NAME) | ||
| repository = os.environ.get(OCI_HELM_REPOSITORY_ENV_VAR_NAME) | ||
| region = os.environ.get(OCI_HELM_REGION_ENV_VAR_NAME) | ||
|
|
||
| logger.info(f"oci chart details in test image is registry {registry}, repo {repository}, region {region}") | ||
|
|
||
| return registry, f"{repository}/mongodb-kubernetes", region | ||
|
|
||
|
|
||
| def apply_crds_from_chart(crds_dir: str): | ||
| crd_files = glob.glob(os.path.join(crds_dir, "*.yaml")) | ||
|
|
||
| if not crd_files: | ||
| raise Exception(f"No CRD files found in chart directory: {chart_dir}") | ||
| raise Exception(f"No CRD files found in chart directory: {crds_dir}") | ||
|
|
||
| logger.info(f"Found {len(crd_files)} CRD files to apply:") | ||
|
|
||
|
|
@@ -230,3 +296,35 @@ def _create_helm_args(helm_args: Dict[str, str], helm_options: Optional[List[str | |
| command_args.extend(helm_options) | ||
|
|
||
| return command_args | ||
|
|
||
|
|
||
| # helm_chart_path_and_version returns the chart path and version that we would like to install to run the E2E tests. | ||
| # for local tests it returns early with local helm chart dir and for other scenarios it figures out the chart and version | ||
| # based on the caller. In most of the cases we will install chart from OCI registry but for the tests where we would like | ||
| # to install MEKO's specific version or MCK's specific version, we would expect `helm_chart_path` to set already. | ||
| def helm_chart_path_and_version(helm_chart_path: str, operator_version: str) -> tuple[str, str]: | ||
| # these are imported here to resolve import cycle issue | ||
| from tests.conftest import LOCAL_HELM_CHART_DIR, local_operator | ||
|
|
||
| if local_operator(): | ||
| return LOCAL_HELM_CHART_DIR, "" | ||
|
|
||
| # helm_chart_path not being passed would mean we would like to install helm chart from OCI registry. | ||
| if not helm_chart_path: | ||
| # If operator_version is not passed, we want to install the current version. | ||
| if not operator_version: | ||
| operator_version = os.environ.get(OCI_HELM_VERSION) | ||
|
|
||
| registry, repository, region = oci_chart_info() | ||
| # If ECR we need to login first to the OCI container registry | ||
| if registry == OCI_HELM_REGISTRY_ECR: | ||
| try: | ||
| helm_registry_login_to_ecr(registry, region) | ||
| except Exception as e: | ||
| raise Exception(f"Failed to login to ECR helm registry {registry}. Error: {e}") | ||
|
|
||
| # figure out the registry URI, based on dev/staging scenario | ||
| chart_uri = f"oci://{registry}/{repository}" | ||
| helm_chart_path = chart_uri | ||
|
|
||
| return helm_chart_path, operator_version | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Prefer explicit import for code navigation.