Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 400 error messaging (report as modification failure) #42

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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