vmware-tanzu-labs / educates-training-platform

A platform for hosting interactive workshop environments in Kubernetes, or on top of a local container runtime.
https://docs.educates.dev
Apache License 2.0
63 stars 15 forks source link

Reason for request.objects failure not logged as message against workshop allocation resource. #394

Closed GrahamDumpleton closed 1 month ago

GrahamDumpleton commented 1 month ago

Describe the bug

Where an error occurs in creating request.objects, if it was a client side validation error, rather than server side Kubernetes error, then the exception would not be caught and a message as to why failure occurred not recorded in the status of the WorkshopAllocation resource. The status would also not be updated to failed. Rather than catch only Kubernetes exceptions, all exceptions should be caught.

        try:
            object_name = object_body["metadata"]["name"]
            object_namespace = object_body["metadata"]["namespace"]
            object_type = object_body["kind"]

            logger.debug(
                "Creating workshop request object %s of type %s in namespace %s for session %s.",
                object_name,
                object_type,
                object_namespace,
                session_name,
            )

            create_from_dict(object_body)

        except Exception as exc:
            logger.exception(
                "Unable to create workshop request objects for session, failed on creating workshop request object %s of type %s in namespace %s for session %s.",
                object_name,
                object_type,
                object_namespace,
                session_name,
            )

            patch["status"] = {
                OPERATOR_STATUS_KEY: {
                    "phase": "Failed",
                    "message": f"Unable to create workshop request objects for session, failed on creating workshop request object {object_name} of type {object_type} in namespace {object_namespace} for session {session_name}.",
                }
            }

            raise kopf.PermanentError(
                f"Unable to create workshop request objects for session, failed on creating workshop request object {object_name} of type {object_type} in namespace {object_namespace} for session {session_name}."
            ) from exc

Additional information

No response