Skip to content

Commit

Permalink
Update list of deprecated api versions
Browse files Browse the repository at this point in the history
  • Loading branch information
seleznev committed Aug 29, 2019
1 parent df2667b commit 2678c0d
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 72 deletions.
108 changes: 76 additions & 32 deletions k8s_handle/k8s/deprecation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}

Expand All @@ -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

Expand Down
72 changes: 32 additions & 40 deletions k8s_handle/k8s/test_deprecation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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"))

0 comments on commit 2678c0d

Please sign in to comment.