Skip to content
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

Attempt to create k8s venv without constraints if constraint build fails #26407

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://github.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://github.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