Skip to content

Commit

Permalink
refactor: Remove pre-flight checks (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: Manu Chandrasekhar <manuchandrasekhar@gmail.com>
  • Loading branch information
mbeacom and quixoticmonk authored May 4, 2023
1 parent faf227d commit 9f0dd11
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 1,493 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/e2e-test-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ jobs:
run: |
echo "Test the cluster eksup-cluster-${{inputs.cluster_suffix}} with upgrade set to current version"
eksupgrade eksup-cluster-${{inputs.cluster_suffix}}-${{inputs.target_region}} ${{inputs.current_version}} ${{inputs.target_region}} --no-interactive
- name: Test pre-flight checks
id: preflight_checks
run: |
echo "Running pre-flight checks on the cluster eksup-cluster-${{inputs.cluster_suffix}} against version ${{inputs.target_version}} "
eksupgrade eksup-cluster-${{inputs.cluster_suffix}}-${{inputs.target_region}} ${{inputs.target_version}} ${{inputs.target_region}} --preflight --no-interactive
- name: Test standalone addon upgrade
id: addon_upgrade
run: |
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/PyCQA/bandit
rev: 1ed79063e3672a1c6d91ee27cb648e07a7465344 # frozen: 1.7.4
rev: ca4faf2f82a7c68a088100f8ba2b8e56f9bdcfe3 # frozen: 1.7.5
hooks:
- id: bandit
description: 'Bandit is a tool for finding common security issues in Python code'
additional_dependencies: [ "bandit[toml]" ]
args: ["-c", "pyproject.toml"]

- repo: https://github.com/psf/black
rev: b0d1fba7ac3be53c71fb0d3211d911e629f8aecb # frozen: 23.1.0
rev: bf7a16254ec96b084a6caf3d435ec18f0f245cc7 # frozen: 23.3.0
hooks:
- id: black
language_version: python3.10
Expand Down
2 changes: 1 addition & 1 deletion eksupgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"""

__version__: str = "0.8.3"
__version__: str = "0.9.0"
49 changes: 12 additions & 37 deletions eksupgrade/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Handle CLI specific logic and module definitions."""
from __future__ import annotations

import sys
from queue import Queue
from typing import Optional

Expand All @@ -10,12 +9,11 @@
from rich.table import Table

from eksupgrade import __version__
from eksupgrade.utils import confirm, echo_error, echo_info, echo_success, echo_warning, get_logger
from eksupgrade.utils import confirm, echo_error, echo_info, echo_warning, get_logger

from .exceptions import ClusterInactiveException
from .models.eks import Cluster
from .src.k8s_client import cluster_auto_enable_disable, is_cluster_auto_scaler_present
from .src.preflight_module import pre_flight_checks
from .starter import StatsWorker, actual_update

logger = get_logger(__name__)
Expand All @@ -37,13 +35,13 @@ def main(
region: str = typer.Argument(..., help="The AWS region where the target cluster resides"),
max_retry: int = typer.Option(default=2, help="The most number of times to retry an upgrade"),
force: bool = typer.Option(default=False, help="Force the upgrade (e.g. pod eviction with PDB)"),
preflight: bool = typer.Option(default=False, help="Run pre-flight check without upgrade"),
preflight: bool = typer.Option(default=False, help="Run pre-upgrade checks without upgrade"),
parallel: bool = typer.Option(default=False, help="Upgrade all nodegroups in parallel"),
latest_addons: bool = typer.Option(
default=False, help="Upgrade addons to the latest eligible version instead of default"
),
disable_checks: bool = typer.Option(
default=False, help="Disable the pre-flight and post-flight checks during upgrade scenarios"
default=False, help="Disable the pre-upgrade and post-upgrade checks during upgrade scenarios"
),
interactive: bool = typer.Option(default=True, help="If enabled, prompt the user for confirmations"),
version: Optional[bool] = typer.Option(
Expand All @@ -55,29 +53,16 @@ def main(
is_present: bool = False
replicas_value: int = 0

try:
# Preflight Logic
if not disable_checks:
if not pre_flight_checks(
preflight=True,
cluster_name=cluster_name,
region=region,
update_version=cluster_version,
force_upgrade=force,
):
echo_error(
f"Pre-flight check for cluster {cluster_name} targeting version: {cluster_version} failed!",
)
sys.exit()
else:
echo_success(
f"Pre-flight check for the cluster {cluster_name} succeeded!",
)
if preflight:
sys.exit()
else:
echo_warning("Checks disabled! Pre/post-flight checks not executing!")
if disable_checks:
echo_warning("--disable-checks is currently unused until the new validation workflows are implemented")

if preflight:
echo_warning(
"--preflight is unused and will be removed in an upcoming release. "
"Please use an EKS upgrade readiness assessment tool such as: github.com/clowdhaus/eksup"
)

try:
# Pull cluster details, populating the object for subsequent use throughout the upgrade.
target_cluster: Cluster = Cluster.get(
cluster_name=cluster_name, region=region, target_version=cluster_version, latest_addons=latest_addons
Expand Down Expand Up @@ -169,16 +154,6 @@ def main(
)
echo_info("Cluster Autoscaler is Enabled Again")
echo_info(f"EKS Cluster {cluster_name} UPDATED TO {cluster_version}")

if not disable_checks:
if not pre_flight_checks(preflight=False, cluster_name=cluster_name, region=region, force_upgrade=force):
echo_error(
f"Post flight check for cluster {cluster_name} failed after it upgraded",
)
else:
echo_success("After update check for cluster completed successfully")
else:
echo_warning("Post-flight check was disabled and didn't run.")
except typer.Abort:
echo_warning("Cluster upgrade aborted!")
except Exception as error:
Expand Down
8 changes: 4 additions & 4 deletions eksupgrade/src/boto_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ def get_old_lt(asg_name: str, region: str) -> List[str]:
asg_lt_name = ""
# finding the launch type
if "LaunchTemplate" in response["AutoScalingGroups"][0]:
lt_id = response["AutoScalingGroups"][0]["LaunchTemplate"]["LaunchTemplateId"]
response["AutoScalingGroups"][0]["LaunchTemplate"]["LaunchTemplateId"]
asg_lt_name = response["AutoScalingGroups"][0]["LaunchTemplate"]["LaunchTemplateName"]
elif "MixedInstancesPolicy" in response["AutoScalingGroups"][0]:
lt_id = response["AutoScalingGroups"][0]["MixedInstancesPolicy"]["LaunchTemplate"][
"LaunchTemplateSpecification"
]["LaunchTemplateId"]
response["AutoScalingGroups"][0]["MixedInstancesPolicy"]["LaunchTemplate"]["LaunchTemplateSpecification"][
"LaunchTemplateId"
]
asg_lt_name = response["AutoScalingGroups"][0]["MixedInstancesPolicy"]["LaunchTemplate"][
"LaunchTemplateSpecification"
]["LaunchTemplateName"]
Expand Down
Loading

0 comments on commit 9f0dd11

Please sign in to comment.