def get_sagemaker_managed_namespace()

in src/hyperpod_cli/clients/kubernetes_client.py [0:0]


    def get_sagemaker_managed_namespace(self, namespace: Optional[str]):
        """
        Verify if a namespace is sagemaker managed. SageMaker created namespaces have custom label
        attached, indicating that the namespace is SageMaker managed.

        Args:
            namespace (Optional[str]): The input namespace that will be checked.

        Returns:
            Optional[V1Namespace]: V1Namespace response if namespace exists and it is verified being managed by SageMaker. Otherwise return None.
        """
        if namespace is None:
            return None
        try:
            response = client.CoreV1Api().read_namespace(name=namespace)
            labels = response.metadata.labels
            if labels and SAGEMAKER_MANAGED_QUEUE_LABEL in labels and labels[SAGEMAKER_MANAGED_QUEUE_LABEL] == "true":
                return response
        except ApiException as e:
            if e.status == RESOURCE_NOT_FOUND_CODE:
                return None
            else:
                raise e
        return None