forked from aws-samples/hardeneks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b21cbc
commit 3bd0a0f
Showing
2 changed files
with
31 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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,33 +1,24 @@ | ||
from ...resources import Resources | ||
from rich.console import Console | ||
import re | ||
from rich.panel import Panel | ||
from rich import print | ||
import kubernetes | ||
|
||
console = Console() | ||
from hardeneks import console | ||
from ...resources import Resources | ||
|
||
def _get_version() -> str: | ||
client = kubernetes.client.VersionApi() | ||
version = client.get_code() | ||
return version | ||
|
||
def check_EKS_version(resources: Resources): | ||
version = _get_version() | ||
major = int(version.major) | ||
client = kubernetes.client.VersionApi() | ||
version = client.get_code() | ||
minor = version.minor | ||
last_char = version.minor[-1] | ||
if last_char == "+": | ||
minor = int(version.minor[:-1]) | ||
else: | ||
minor = int(minor) | ||
|
||
good = False | ||
|
||
if major >= 1 and minor >= 24: | ||
good = True | ||
|
||
if good == False: | ||
print(Panel("[red] Current Version == " + version.major + "." + version.minor + "", title="EKS Version Should be greater or equal too 1.24")) | ||
if int(re.sub("[^0-9]", "", minor)) < 24: | ||
console.print( | ||
Panel( | ||
f"[red]EKS Version Should be greater or equal too 1.24. Current Version == {version.major}.{version.minor}", | ||
subtitle="[link=https://aws.github.io/aws-eks-best-practices/scalability/docs/control-plane/#use-eks-124-or-above]Click to see the guide[/link]", | ||
) | ||
) | ||
console.print() | ||
|
||
return good | ||
return False | ||
|
||
return True |
This file contains 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,23 +1,23 @@ | ||
import pytest | ||
from hardeneks.resources import Resources | ||
from hardeneks.resources import Map | ||
from unittest.mock import patch | ||
|
||
from hardeneks.cluster_wide.scalability.control_plane import ( | ||
check_EKS_version | ||
) | ||
|
||
@patch("hardeneks.cluster_wide.scalability.control_plane._get_version") | ||
from hardeneks.cluster_wide.scalability.control_plane import check_EKS_version | ||
|
||
|
||
class Version: | ||
def __init__(self, minor): | ||
self.major = 1 | ||
self.minor = minor | ||
|
||
|
||
@patch("kubernetes.client.VersionApi.get_code") | ||
def test_check_EKS_version(mocked_client): | ||
namespaced_resources = Resources( | ||
"some_region", "some_context", "some_cluster", [] | ||
) | ||
mocked_client.return_value = Map({'major': '1', 'minor': "23+"}) | ||
good = check_EKS_version(namespaced_resources) | ||
assert good == False, "Value should be False" | ||
mocked_client.return_value = Map({'major': '1', 'minor': "24+"}) | ||
good = check_EKS_version(namespaced_resources) | ||
assert good == True, "Value should be True" | ||
mocked_client.return_value = Map({'major': '1', 'minor': "24"}) | ||
good = check_EKS_version(namespaced_resources) | ||
assert good == True, "Value should be True and Handle without +" | ||
mocked_client.return_value = Version("23+") | ||
assert not check_EKS_version(namespaced_resources) | ||
mocked_client.return_value = Version("24+") | ||
assert check_EKS_version(namespaced_resources) | ||
mocked_client.return_value = Version("24") | ||
assert check_EKS_version(namespaced_resources) |