Skip to content

Commit

Permalink
Merge pull request #42 from karellen/release_1.0.11
Browse files Browse the repository at this point in the history
Improve 400 error messaging (report as modification failure)
  • Loading branch information
arcivanov authored Dec 27, 2023
2 parents 8e067df + 3612312 commit 33a60fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use_plugin("filter_resources")

name = "kubernator"
version = "1.0.11.dev"
version = "1.0.11"

summary = "Kubernator is the a pluggable framework for K8S provisioning"
authors = [Author("Express Systems USA, Inc.", "")]
Expand Down Expand Up @@ -91,6 +91,7 @@ def set_properties(project):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
Expand Down
21 changes: 13 additions & 8 deletions src/main/python/kubernator/plugins/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,19 @@ def handle_400_strict_validation_error(e: ApiException):
if e.status == 400:
status = json.loads(e.body)

if status["status"] == "Failure" and FIELD_VALIDATION_STRICT_MARKER in status["message"]:
message = status["message"]
messages = message[message.find(FIELD_VALIDATION_STRICT_MARKER) +
len(FIELD_VALIDATION_STRICT_MARKER):].split(",")
for m in messages:
self._api_warnings(resource, m.strip())

raise e from None
if status["status"] == "Failure":
if FIELD_VALIDATION_STRICT_MARKER in status["message"]:
message = status["message"]
messages = message[message.find(FIELD_VALIDATION_STRICT_MARKER) +
len(FIELD_VALIDATION_STRICT_MARKER):].split(",")
for m in messages:
self._api_warnings(resource, m.strip())

raise e from None
else:
logger.error("FAILED MODIFYING resource %s from %s: %s",
resource, resource.source, status["message"])
raise e from None

def create(exists_ok=False):
logger.info("Creating resource %s%s%s", resource, status_msg,
Expand Down
6 changes: 4 additions & 2 deletions src/main/python/kubernator/plugins/k8s_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ def create(self, dry_run=True):
"field_manager": "kubernator",
}

if self._k8s_client_version[0] > 22:
# `and not self.rdef.custom` to be removed after solving https://github.com/kubernetes-client/gen/issues/259
if self._k8s_client_version[0] > 22 and not self.rdef.custom:
kwargs["field_validation"] = self._k8s_field_validation
if rdef.namespaced:
kwargs["namespace"] = self.namespace
Expand All @@ -430,7 +431,8 @@ def patch(self, json_patch, *, patch_type: K8SResourcePatchType, force=False, dr
"field_manager": "kubernator",
}

if self._k8s_client_version[0] > 22:
# `and not self.rdef.custom` to be removed after solving https://github.com/kubernetes-client/gen/issues/259
if self._k8s_client_version[0] > 22 and not self.rdef.custom:
kwargs["field_validation"] = self._k8s_field_validation
if patch_type == K8SResourcePatchType.SERVER_SIDE_PATCH:
kwargs["force"] = force
Expand Down

0 comments on commit 33a60fc

Please sign in to comment.