Skip to content

Commit

Permalink
Add check for highest supported k8s version (#1336)
Browse files Browse the repository at this point in the history
* Add highest supported k8s version

* Add test for commons.py
  • Loading branch information
aktech authored Jun 21, 2022
1 parent f1ecde5 commit 7ca7f2f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions qhub/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
TERRAFORM_VERSION = "1.0.5"

HIGHEST_SUPPORTED_K8S_VERSION = "1.23.5"
5 changes: 3 additions & 2 deletions qhub/provider/cloud/amazon_web_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import boto3

from qhub.provider.cloud.commons import filter_by_highest_supported_k8s_version


@functools.lru_cache()
def regions():
Expand Down Expand Up @@ -40,8 +42,7 @@ def kubernetes_versions(region="us-west-2"):
)

supported_kubernetes_versions = sorted(list(set(supported_kubernetes_versions)))

return supported_kubernetes_versions
return filter_by_highest_supported_k8s_version(supported_kubernetes_versions)


@functools.lru_cache()
Expand Down
5 changes: 3 additions & 2 deletions qhub/provider/cloud/azure_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from azure.identity import EnvironmentCredential
from azure.mgmt.containerservice import ContainerServiceClient

from qhub.provider.cloud.commons import filter_by_highest_supported_k8s_version

logger = logging.getLogger("azure")
logger.setLevel(logging.ERROR)

Expand Down Expand Up @@ -41,5 +43,4 @@ def kubernetes_versions(region="Central US"):
supported_kubernetes_versions.append(key["orchestrator_version"])

supported_kubernetes_versions = sorted(supported_kubernetes_versions)

return supported_kubernetes_versions
return filter_by_highest_supported_k8s_version(supported_kubernetes_versions)
9 changes: 9 additions & 0 deletions qhub/provider/cloud/commons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from qhub.constants import HIGHEST_SUPPORTED_K8S_VERSION


def filter_by_highest_supported_k8s_version(k8s_versions_list):
filtered_k8s_versions_list = []
for k8s_version in k8s_versions_list:
if k8s_version <= HIGHEST_SUPPORTED_K8S_VERSION:
filtered_k8s_versions_list.append(k8s_version)
return filtered_k8s_versions_list
5 changes: 3 additions & 2 deletions qhub/provider/cloud/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import requests

from qhub.provider.cloud.commons import filter_by_highest_supported_k8s_version


def digital_ocean_request(url, method="GET", json=None):
BASE_DIGITALOCEAN_URL = "https://api.digitalocean.com/v2/"
Expand Down Expand Up @@ -46,5 +48,4 @@ def kubernetes_versions(region=None):
supported_kubernetes_versions = sorted(
[_["slug"] for _ in _kubernetes_options()["options"]["versions"]]
)

return supported_kubernetes_versions
return filter_by_highest_supported_k8s_version(supported_kubernetes_versions)
7 changes: 4 additions & 3 deletions qhub/provider/cloud/google_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import subprocess

from qhub.provider.cloud.commons import filter_by_highest_supported_k8s_version


@functools.lru_cache()
def projects():
Expand Down Expand Up @@ -43,9 +45,8 @@ def kubernetes_versions(region):
]
)
data = json.loads(output.decode("utf-8"))
supported_kubernetes_version = sorted([_ for _ in data["validMasterVersions"]])

return supported_kubernetes_version
supported_kubernetes_versions = sorted([_ for _ in data["validMasterVersions"]])
return filter_by_highest_supported_k8s_version(supported_kubernetes_versions)


@functools.lru_cache()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_commons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from qhub.provider.cloud.commons import filter_by_highest_supported_k8s_version


def test_filter_by_highest_supported_k8s_version():
k8s_versions = [
"1.21.7",
"1.21.9",
"1.22.4",
"1.22.6",
"1.23.3",
"1.23.5",
"1.24.0",
]
actual = filter_by_highest_supported_k8s_version(k8s_versions)
expected = sorted(list(set(k8s_versions) - {"1.24.0"}))
assert actual == expected

0 comments on commit 7ca7f2f

Please sign in to comment.