Skip to content

Commit

Permalink
Attempt to create k8s venv without constraints if constraint build fa…
Browse files Browse the repository at this point in the history
…ils (#26407)

There is an issue with trying to install the k8s env where the
current requirements conflict with constraints. The k8s env
creation is failing in this case.

This PR will not fail hard when the constraint-build fails, instead
it will attempt to build the venv without constraints. This will work
in vast majority of cases.
  • Loading branch information
potiuk committed Sep 15, 2022
1 parent 951b708 commit 6f390fa
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions dev/breeze/src/airflow_breeze/utils/kubernetes_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@ def _requirements_changed() -> bool:
return False


def _install_packages_in_k8s_virtualenv(dry_run: bool, verbose: bool, with_constraints: bool):
install_command = [
str(PYTHON_BIN_PATH),
"-m",
"pip",
"install",
"-r",
str(K8S_REQUIREMENTS.resolve()),
]
if with_constraints:
install_command.extend(
[
"--constraint",
f"https://raw.githubusercontent.com/apache/airflow/{DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH}/"
f"constraints-{sys.version_info.major}.{sys.version_info.minor}.txt",
]
)
install_packages_result = run_command(
install_command,
verbose=verbose,
dry_run=dry_run,
check=False,
capture_output=True,
)
if install_packages_result.returncode != 0:
get_console().print(
f'[error]Error when updating pip to {PIP_VERSION}:[/]\n'
f'{install_packages_result.stdout}\n{install_packages_result.stderr}'
)
return install_packages_result


def create_virtualenv(force: bool, verbose: bool, dry_run: bool) -> RunCommandResult:
K8S_CLUSTERS_PATH.mkdir(parents=True, exist_ok=True)
if not force and not _requirements_changed():
Expand Down Expand Up @@ -354,29 +386,17 @@ def create_virtualenv(force: bool, verbose: bool, dry_run: bool) -> RunCommandRe
)
return pip_reinstall_result
get_console().print(f'[info]Installing necessary packages in {K8S_ENV_PATH}')
install_packages_result = run_command(
[
str(PYTHON_BIN_PATH),
"-m",
"pip",
"install",
"-r",
str(K8S_REQUIREMENTS.resolve()),
"--constraint",
f"https://raw.githubusercontent.com/apache/airflow/{DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH}/"
f"constraints-{sys.version_info.major}.{sys.version_info.minor}.txt",
],
verbose=verbose,
dry_run=dry_run,
check=False,
capture_output=True,

install_packages_result = _install_packages_in_k8s_virtualenv(
dry_run=dry_run, verbose=verbose, with_constraints=True
)
if install_packages_result.returncode != 0:
get_console().print(
f'[error]Error when updating pip to {PIP_VERSION}:[/]\n'
f'{install_packages_result.stdout}\n{install_packages_result.stderr}'
# if the first installation fails, attempt to install it without constraints
install_packages_result = _install_packages_in_k8s_virtualenv(
dry_run=dry_run, verbose=verbose, with_constraints=False
)
CACHED_K8S_REQUIREMENTS.write_text(K8S_REQUIREMENTS.read_text())
if install_packages_result.returncode == 0:
CACHED_K8S_REQUIREMENTS.write_text(K8S_REQUIREMENTS.read_text())
return install_packages_result


Expand Down

0 comments on commit 6f390fa

Please sign in to comment.