diff --git a/k8s_handle/k8s/deprecation_checker.py b/k8s_handle/k8s/deprecation_checker.py index d1e76cc..6d4db84 100644 --- a/k8s_handle/k8s/deprecation_checker.py +++ b/k8s_handle/k8s/deprecation_checker.py @@ -13,34 +13,78 @@ def __init__(self, server_version): self.server_version = server_version self.deprecated_versions = { "extensions/v1beta1": { - "since": "1.8.0", - "until": "1.16.0", - "resources": [ - "Deployment", - "DaemonSet", - "ReplicaSet", - "StatefulSet", - "PodSecurityPolicy", - "NetworkPolicy", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.16.0", + }, + "DaemonSet": { + "since": "1.8.0", + "until": "1.16.0", + }, + "ReplicaSet": { + "since": "1.8.0", + "until": "1.16.0", + }, + "NetworkPolicy": { + "since": "1.9.0", + "until": "1.16.0", + }, + "PodSecurityPolicy": { + "since": "1.10.0", + "until": "1.16.0", + }, + "Ingress": { + "since": "1.14.0", + "until": "1.19.0", + }, }, "apps/v1beta1": { - "since": "1.9.0", - "until": "1.16.0", - "resources": [ - "Deployment", - "DaemonSet", - "ReplicaSet", - ], + "Deployment": { + "since": "1.9.0", + "until": "1.16.0", + }, + "DaemonSet": { + "since": "1.9.0", + "until": "1.16.0", + }, + "ReplicaSet": { + "since": "1.9.0", + "until": "1.16.0", + }, + "StatefulSet": { + "since": "1.9.0", + "until": "1.16.0", + }, }, "apps/v1beta2": { - "since": "1.9.0", - "until": "1.16.0", - "resources": [ - "Deployment", - "DaemonSet", - "ReplicaSet", - ], + "Deployment": { + "since": "1.9.0", + "until": "1.16.0", + }, + "DaemonSet": { + "since": "1.9.0", + "until": "1.16.0", + }, + "ReplicaSet": { + "since": "1.9.0", + "until": "1.16.0", + }, + "StatefulSet": { + "since": "1.9.0", + "until": "1.16.0", + }, + }, + "scheduling.k8s.io/v1alpha1": { + "PriorityClass": { + "since": "1.14.0", + "until": "1.17.0", + }, + }, + "scheduling.k8s.io/v1beta1": { + "PriorityClass": { + "since": "1.14.0", + "until": "1.17.0", + }, }, } @@ -57,34 +101,34 @@ def _is_deprecated(self, api_version, kind): █████ █████ is {status} since {k8s_version} ██████████████ """ - if api_version not in self.deprecated_versions.keys(): + if api_version not in self.deprecated_versions: return False - if kind not in self.deprecated_versions[api_version].get("resources"): + if kind not in self.deprecated_versions[api_version]: return False - if self.deprecated_versions[api_version]["until"]: - if self._is_server_version_greater(self.deprecated_versions[api_version]["until"]): + if self.deprecated_versions[api_version][kind]["until"]: + if self._is_server_version_greater(self.deprecated_versions[api_version][kind]["until"]): log.warning(message.format( api_version=api_version, kind=kind, status="unsupported", - k8s_version=self.deprecated_versions[api_version]["until"], + k8s_version=self.deprecated_versions[api_version][kind]["until"], )) raise DeprecationError( "Version {} for resourse type '{}' is unsupported since kubernetes {}".format( api_version, kind, - self.deprecated_versions[api_version]["until"] + self.deprecated_versions[api_version][kind]["until"] ) ) - if self._is_server_version_greater(self.deprecated_versions[api_version]["since"]): + if self._is_server_version_greater(self.deprecated_versions[api_version][kind]["since"]): log.warning(message.format( api_version=api_version, kind=kind, status="deprecated", - k8s_version=self.deprecated_versions[api_version]["since"], + k8s_version=self.deprecated_versions[api_version][kind]["since"], )) return True diff --git a/k8s_handle/k8s/test_deprecation_checker.py b/k8s_handle/k8s/test_deprecation_checker.py index 0e8faf9..39c3579 100644 --- a/k8s_handle/k8s/test_deprecation_checker.py +++ b/k8s_handle/k8s/test_deprecation_checker.py @@ -10,11 +10,10 @@ def test_version_not_in_list(self): checker = ApiDeprecationChecker("1.9.7") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } self.assertFalse(checker._is_deprecated("test/v2", "Deployment")) @@ -23,11 +22,10 @@ def test_kind_not_in_list(self): checker = ApiDeprecationChecker("1.9.7") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } self.assertFalse(checker._is_deprecated("test/v1", "StatefulSet")) @@ -36,11 +34,10 @@ def test_version_not_deprecated_yet(self): checker = ApiDeprecationChecker("1.7.9") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } self.assertFalse(checker._is_deprecated("test/v1", "Deployment")) @@ -49,11 +46,10 @@ def test_version_is_deprecated_equal(self): checker = ApiDeprecationChecker("1.8.0") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } self.assertTrue(checker._is_deprecated("test/v1", "Deployment")) @@ -62,11 +58,10 @@ def test_version_is_deprecated(self): checker = ApiDeprecationChecker("1.9.9") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } self.assertTrue(checker._is_deprecated("test/v1", "Deployment")) @@ -75,11 +70,10 @@ def test_version_is_unsupported_equal(self): checker = ApiDeprecationChecker("1.10.0") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } with self.assertRaises(DeprecationError): @@ -89,11 +83,10 @@ def test_version_is_unsupported(self): checker = ApiDeprecationChecker("1.10.6") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "1.10.0", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "1.10.0", + }, } } with self.assertRaises(DeprecationError): @@ -103,11 +96,10 @@ def test_version_no_until(self): checker = ApiDeprecationChecker("1.10.6") checker.deprecated_versions = { "test/v1": { - "since": "1.8.0", - "until": "", - "resources": [ - "Deployment", - ], + "Deployment": { + "since": "1.8.0", + "until": "", + }, } } self.assertTrue(checker._is_deprecated("test/v1", "Deployment"))