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.
feat(scalability): adding first scalability checks
- Loading branch information
Joshua Kurz
committed
Feb 10, 2023
1 parent
04f533c
commit 2336ba1
Showing
5 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from ...resources import Resources | ||
from rich.console import Console | ||
from rich.panel import Panel | ||
from rich import print | ||
import kubernetes | ||
|
||
console = Console() | ||
|
||
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) | ||
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")) | ||
console.print() | ||
|
||
return good |
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
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
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 |
---|---|---|
@@ -0,0 +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") | ||
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 +" |