Compare commits
No commits in common. "9c3ce54bb3eb696cc5a691d0c45e5654268c4928" and "3c270d9c121dff55ca505f4b63aa4dda6ad78eb9" have entirely different histories.
9c3ce54bb3
...
3c270d9c12
3 changed files with 13 additions and 68 deletions
|
@ -79,9 +79,7 @@ class Organization(ServalaModelMixin, models.Model):
|
||||||
support_message = _(
|
support_message = _(
|
||||||
"Need help? We're happy to help via the <a href='{support_url}'>support form</a>."
|
"Need help? We're happy to help via the <a href='{support_url}'>support form</a>."
|
||||||
).format(support_url=self.urls.support)
|
).format(support_url=self.urls.support)
|
||||||
return mark_safe(
|
return mark_safe(f"{message} {support_message}")
|
||||||
f'{message} <i class="bi bi-person-raised-hand"></i> {support_message}'
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
|
|
||||||
import kubernetes
|
import kubernetes
|
||||||
import rules
|
import rules
|
||||||
|
@ -605,32 +604,6 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
spec_data = prune_empty_data(spec_data)
|
spec_data = prune_empty_data(spec_data)
|
||||||
return spec_data
|
return spec_data
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _format_kubernetes_error(cls, error_message):
|
|
||||||
"""
|
|
||||||
Format Kubernetes API error messages for better user experience.
|
|
||||||
Converts validation error arrays into unordered lists.
|
|
||||||
"""
|
|
||||||
# Pattern to match validation errors in brackets
|
|
||||||
pattern = r"\[([^\]]+)\]"
|
|
||||||
match = re.search(pattern, error_message)
|
|
||||||
|
|
||||||
if not match:
|
|
||||||
return error_message
|
|
||||||
|
|
||||||
errors_text = match.group(1)
|
|
||||||
# Split by comma and clean up each error
|
|
||||||
errors = [error.strip() for error in errors_text.split(",")]
|
|
||||||
|
|
||||||
if len(errors) > 1:
|
|
||||||
# Format as HTML unordered list
|
|
||||||
error_list = "".join(f"<li>{error}</li>" for error in errors)
|
|
||||||
# Replace the bracketed section with the formatted list
|
|
||||||
formatted_message = re.sub(pattern, f"<ul>{error_list}</ul>", error_message)
|
|
||||||
return mark_safe(formatted_message)
|
|
||||||
|
|
||||||
return error_message
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_instance(cls, name, organization, context, created_by, spec_data):
|
def create_instance(cls, name, organization, context, created_by, spec_data):
|
||||||
# Ensure the namespace exists
|
# Ensure the namespace exists
|
||||||
|
@ -643,9 +616,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
context=context,
|
context=context,
|
||||||
)
|
)
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
message = _(
|
message = "An instance with this name already exists in this organization. Please choose a different name."
|
||||||
"An instance with this name already exists in this organization. Please choose a different name."
|
|
||||||
)
|
|
||||||
raise ValidationError(organization.add_support_message(message))
|
raise ValidationError(organization.add_support_message(message))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -684,21 +655,12 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
try:
|
try:
|
||||||
error_body = json.loads(e.body)
|
error_body = json.loads(e.body)
|
||||||
reason = error_body.get("message", str(e))
|
reason = error_body.get("message", str(e))
|
||||||
formatted_reason = cls._format_kubernetes_error(reason)
|
message = f"Kubernetes API error: {reason}."
|
||||||
message = _("Error reported by control plane: {reason}").format(
|
|
||||||
reason=formatted_reason
|
|
||||||
)
|
|
||||||
raise ValidationError(organization.add_support_message(message))
|
raise ValidationError(organization.add_support_message(message))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
formatted_error = cls._format_kubernetes_error(str(e))
|
message = f"Kubernetes API error: {str(e)}."
|
||||||
message = _("Error reported by control plane: {error}").format(
|
|
||||||
error=formatted_error
|
|
||||||
)
|
|
||||||
raise ValidationError(organization.add_support_message(message))
|
raise ValidationError(organization.add_support_message(message))
|
||||||
formatted_error = cls._format_kubernetes_error(str(e))
|
message = f"Error creating instance: {str(e)}."
|
||||||
message = _("Error creating instance: {error}").format(
|
|
||||||
error=formatted_error
|
|
||||||
)
|
|
||||||
raise ValidationError(organization.add_support_message(message))
|
raise ValidationError(organization.add_support_message(message))
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@ -720,29 +682,18 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
self.save() # Updates updated_at timestamp
|
self.save() # Updates updated_at timestamp
|
||||||
except ApiException as e:
|
except ApiException as e:
|
||||||
if e.status == 404:
|
if e.status == 404:
|
||||||
message = _(
|
message = "Service instance not found in Kubernetes. It may have been deleted externally."
|
||||||
"Service instance not found in control plane. It may have been deleted externally."
|
|
||||||
)
|
|
||||||
raise ValidationError(self.organization.add_support_message(message))
|
raise ValidationError(self.organization.add_support_message(message))
|
||||||
try:
|
try:
|
||||||
error_body = json.loads(e.body)
|
error_body = json.loads(e.body)
|
||||||
reason = error_body.get("message", str(e))
|
reason = error_body.get("message", str(e))
|
||||||
formatted_reason = self._format_kubernetes_error(reason)
|
message = f"Kubernetes API error updating instance: {reason}."
|
||||||
message = _(
|
|
||||||
"Error reported by control plane while updating instance: {reason}"
|
|
||||||
).format(reason=formatted_reason)
|
|
||||||
raise ValidationError(self.organization.add_support_message(message))
|
raise ValidationError(self.organization.add_support_message(message))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
formatted_error = self._format_kubernetes_error(str(e))
|
message = f"Kubernetes API error updating instance: {str(e)}."
|
||||||
message = _(
|
|
||||||
"Error reported by control plane while updating instance: {error}"
|
|
||||||
).format(error=formatted_error)
|
|
||||||
raise ValidationError(self.organization.add_support_message(message))
|
raise ValidationError(self.organization.add_support_message(message))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
formatted_error = self._format_kubernetes_error(str(e))
|
message = f"Error updating instance: {str(e)}."
|
||||||
message = _("Error updating instance: {error}").format(
|
|
||||||
error=formatted_error
|
|
||||||
)
|
|
||||||
raise ValidationError(self.organization.add_support_message(message))
|
raise ValidationError(self.organization.add_support_message(message))
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
|
|
|
@ -146,9 +146,7 @@ class ServiceOfferingDetailView(OrganizationViewMixin, HtmxViewMixin, DetailView
|
||||||
if not form: # Should not happen if context_object is valid, but as a safeguard
|
if not form: # Should not happen if context_object is valid, but as a safeguard
|
||||||
messages.error(
|
messages.error(
|
||||||
self.request,
|
self.request,
|
||||||
self.organization.add_support_message(
|
self.organization.add_support_message("Could not initialize service form."),
|
||||||
_("Could not initialize service form.")
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
|
@ -168,7 +166,7 @@ class ServiceOfferingDetailView(OrganizationViewMixin, HtmxViewMixin, DetailView
|
||||||
messages.error(
|
messages.error(
|
||||||
self.request,
|
self.request,
|
||||||
self.organization.add_support_message(
|
self.organization.add_support_message(
|
||||||
_(f"Error creating instance: {str(e)}.")
|
f"Error creating instance: {str(e)}."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -376,7 +374,7 @@ class ServiceInstanceUpdateView(
|
||||||
messages.error(
|
messages.error(
|
||||||
self.request,
|
self.request,
|
||||||
self.organization.add_support_message(
|
self.organization.add_support_message(
|
||||||
_(f"Error updating instance: {str(e)}.")
|
f"Error updating instance: {str(e)}."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
@ -447,9 +445,7 @@ class ServiceInstanceDeleteView(
|
||||||
messages.error(
|
messages.error(
|
||||||
self.request,
|
self.request,
|
||||||
self.organization.add_support_message(
|
self.organization.add_support_message(
|
||||||
_(
|
f"An error occurred while trying to delete instance '{self.object.name}': {str(e)}."
|
||||||
f"An error occurred while trying to delete instance '{self.object.name}': {str(e)}."
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue