Example #1
0
 def create_custom_object(self, name, group, version, plural, body):
     resp = self.k8s_custom_object_api.create_namespaced_custom_object(
         group=group,
         version=version,
         plural=plural,
         namespace=self.namespace,
         body=body,
     )
     logger.debug("Custom object `{}` was created".format(name))
     return resp
Example #2
0
 def delete_volume(self, name, reraise=False):
     try:
         self.k8s_api.delete_persistent_volume(
             name=name,
             body=client.V1DeleteOptions(
                 api_version=constants.K8S_API_VERSION_V1),
         )
         logger.debug("Volume `{}` Deleted".format(name))
     except ApiException as e:
         if reraise:
             raise PolyaxonK8SError(e)
         else:
             logger.debug("Volume `{}` was not found".format(name))
Example #3
0
 def delete_job(self, name, reraise=False):
     try:
         self.k8s_batch_api.delete_namespaced_job(
             name=name,
             namespace=self.namespace,
             body=client.V1DeleteOptions(
                 api_version=constants.K8S_API_VERSION_V1),
         )
         logger.debug("Pod `{}` deleted".format(name))
     except ApiException as e:
         if reraise:
             raise PolyaxonK8SError(e)
         else:
             logger.debug("Pod `{}` was not found".format(name))
Example #4
0
 def delete_service(self, name, reraise=False):
     found = False
     try:
         self.k8s_api.read_namespaced_service(name, self.namespace)
         found = True
         self.k8s_api.delete_namespaced_service(name, self.namespace)
         logger.debug('Service `{}` deleted'.format(name))
     except ApiException as e:
         if found:
             logger.error('Could not delete service `{}`'.format(name))
             if reraise:
                 raise PolyaxonK8SError(e)
         else:
             logger.debug('Service `{}` was not found'.format(name))
Example #5
0
 def delete_deployment(self, name, reraise=False):
     try:
         self.k8s_apps_api.delete_namespaced_deployment(
             name=name,
             namespace=self.namespace,
             body=client.V1DeleteOptions(
                 api_version=constants.K8S_API_VERSION_APPS_V1,
                 propagation_policy="Foreground",
             ),
         )
         logger.debug("Deployment `{}` deleted".format(name))
     except ApiException as e:
         if reraise:
             raise PolyaxonK8SError(e)
         else:
             logger.debug("Deployment `{}` was not found".format(name))
Example #6
0
 def delete_volume(self, name, reraise=False):
     found = False
     try:
         self.k8s_api.read_persistent_volume(name)
         found = True
         self.k8s_api.delete_persistent_volume(
             name,
             client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1))
         logger.debug('Volume `{}` Deleted'.format(name))
     except ApiException as e:
         if found:
             logger.error('Could not delete volume `{}`'.format(name))
             if reraise:
                 raise PolyaxonK8SError(e)
         else:
             logger.debug('Volume `{}` was not found'.format(name))
Example #7
0
 def delete_ingress(self, name, reraise=False):
     try:
         self.networking_v1_beta1_api.delete_namespaced_ingress(
             name=name,
             namespace=self.namespace,
             body=client.V1DeleteOptions(
                 api_version=constants.K8S_API_VERSION_NETWORKING_V1_BETA1,
                 propagation_policy="Foreground",
             ),
         )
         logger.debug("Ingress `{}` deleted".format(name))
     except ApiException as e:
         if reraise:
             raise PolyaxonK8SError(e)
         else:
             logger.debug("Ingress `{}` was not found".format(name))
Example #8
0
 def delete_config_map(self, name, reraise=False):
     found = False
     try:
         self.k8s_api.read_namespaced_config_map(name, self.namespace)
         found = True
         self.k8s_api.delete_namespaced_config_map(
             name,
             self.namespace,
             client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1))
         logger.debug('Config map `{}` Deleted'.format(name))
     except ApiException as e:
         if found:
             logger.error('Could not delete config map `{}`'.format(name))
             if reraise:
                 raise PolyaxonK8SError(e)
         else:
             logger.debug('Config map `{}` was not found'.format(name))
Example #9
0
 def delete_ingress(self, name, reraise=False):
     found = False
     try:
         self.k8s_beta_api.read_namespaced_ingress(name, self.namespace)
         found = True
         self.k8s_beta_api.delete_namespaced_ingress(
             name,
             self.namespace,
             client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1_BETA1,
                                    propagation_policy='Foreground'))
         logger.debug('Ingress `{}` deleted'.format(name))
     except ApiException as e:
         if found:
             logger.error('Could not delete Ingress `{}`'.format(name))
             if reraise:
                 raise PolyaxonK8SError(e)
         else:
             logger.debug('Ingress `{}` was not found'.format(name))
Example #10
0
 def delete_custom_object(self,
                          name,
                          group,
                          version,
                          plural,
                          reraise=False):
     try:
         self.k8s_custom_object_api.delete_namespaced_custom_object(
             name=name,
             group=group,
             version=version,
             plural=plural,
             namespace=self.namespace,
             body=client.V1DeleteOptions(),
         )
         logger.debug("Custom object `{}` deleted".format(name))
     except ApiException as e:
         if reraise:
             raise PolyaxonK8SError(e)
         else:
             logger.debug("Custom object `{}` was not found".format(name))
Example #11
0
 def create_or_update_config_map(self, name, body, reraise=False):
     found = False
     try:
         self.k8s_api.read_namespaced_config_map(name, self.namespace)
         found = True
         logger.debug('A config map with name `{}` was found'.format(name))
         resp = self.k8s_api.patch_namespaced_config_map(name, self.namespace, body)
         logger.debug('Config map `{}` was patched'.format(name))
     except ApiException as e:
         if found:  # Config map was found but could not update, we need to raise
             logger.error("K8S error: {}".format(e))
             if reraise:
                 raise PolyaxonK8SError(e)
             resp = None
         else:
             resp = self.k8s_api.create_namespaced_config_map(self.namespace, body)
             logger.debug('Config map `{}` was created'.format(name))
     return resp, not found
Example #12
0
 def create_or_update_volume(self, name, data, reraise=False):
     found = False
     try:
         self.k8s_api.read_persistent_volume(name)
         found = True
         logger.debug('A Persistent volume with name `{}` was found'.format(name))
         resp = self.k8s_api.patch_persistent_volume(name, data)
         logger.debug('Persistent volume `{}` was patched'.format(name))
     except ApiException as e:
         if found:
             logger.error('Could not create volume `{}`'.format(name))
             if reraise:
                 raise PolyaxonK8SError(e)
             resp = None
         else:
             resp = self.k8s_api.create_persistent_volume(data)
             logger.debug('Persistent volume `{}` was created'.format(name))
     return resp, not found
Example #13
0
 def create_or_update_ingress(self, name, data, reraise=False):
     found = False
     try:
         self.k8s_beta_api.read_namespaced_ingress(name, self.namespace)
         found = True
         logger.debug('An ingress with name `{}` was found'.format(name))
         resp = self.k8s_beta_api.patch_namespaced_ingress(name, self.namespace, data)
         logger.debug('Ingress `{}` was patched'.format(name))
     except ApiException as e:
         if found:
             logger.error('Could not create ingress `{}`'.format(name))
             if reraise:
                 raise PolyaxonK8SError(e)
             resp = None
         else:
             resp = self.k8s_beta_api.create_namespaced_ingress(self.namespace, data)
             logger.debug('ingress `{}` was created'.format(name))
     return resp, not found
Example #14
0
 def update_job(self, name, body):
     resp = self.k8s_batch_api.patch_namespaced_job(
         name=name, namespace=self.namespace, body=body)
     logger.debug("Job `{}` was patched".format(name))
     return resp
Example #15
0
 def create_config_map(self, name, body):
     resp = self.k8s_api.create_namespaced_config_map(
         namespace=self.namespace, body=body)
     logger.debug("Config map `{}` was created".format(name))
     return resp
Example #16
0
 def update_config_map(self, name, body):
     resp = self.k8s_api.patch_namespaced_config_map(
         name=name, namespace=self.namespace, body=body)
     logger.debug("Config map `{}` was patched".format(name))
     return resp
Example #17
0
 def create_service(self, name, body):
     resp = self.k8s_api.create_namespaced_service(namespace=self.namespace,
                                                   body=body)
     logger.debug("Service `{}` was created".format(name))
     return resp
Example #18
0
 def update_service(self, name, body):
     resp = self.k8s_api.patch_namespaced_service(name=name,
                                                  namespace=self.namespace,
                                                  body=body)
     logger.debug("Service `{}` was patched".format(name))
     return resp
Example #19
0
 def update_ingress(self, name, body):
     resp = self.networking_v1_beta1_api.patch_namespaced_ingress(
         name=name, namespace=self.namespace, body=body)
     logger.debug("Ingress `{}` was patched".format(name))
     return resp
Example #20
0
 def create_ingress(self, name, body):
     resp = self.networking_v1_beta1_api.create_namespaced_ingress(
         namespace=self.namespace, body=body)
     logger.debug("ingress `{}` was created".format(name))
     return resp
Example #21
0
 def update_volume_claim(self, name, body):
     resp = self.k8s_api.patch_namespaced_persistent_volume_claim(
         name=name, namespace=self.namespace, body=body)
     logger.debug("Volume claim `{}` was patched".format(name))
     return resp
Example #22
0
 def update_volume(self, name, body):
     resp = self.k8s_api.patch_persistent_volume(name=name, body=body)
     logger.debug("Persistent volume `{}` was patched".format(name))
     return resp
Example #23
0
 def create_volume(self, name, body):
     resp = self.k8s_api.create_persistent_volume(body=body)
     logger.debug("Persistent volume `{}` was created".format(name))
     return resp
Example #24
0
 def update_deployment(self, name, body):
     resp = self.k8s_apps_api.patch_namespaced_deployment(
         name=name, namespace=self.namespace, body=body)
     logger.debug("Deployment `{}` was patched".format(name))
     return resp
Example #25
0
 def create_deployment(self, name, body):
     resp = self.k8s_apps_api.create_namespaced_deployment(
         namespace=self.namespace, body=body)
     logger.debug("Deployment `{}` was created".format(name))
     return resp
Example #26
0
 def create_pod(self, name, body):
     resp = self.k8s_api.create_namespaced_pod(namespace=self.namespace,
                                               body=body)
     logger.debug("Pod `{}` was created".format(name))
     return resp
Example #27
0
 def create_job(self, name, body):
     resp = self.k8s_batch_api.create_namespaced_job(
         namespace=self.namespace, body=body)
     logger.debug("Job `{}` was created".format(name))
     return resp
Example #28
0
 def update_pod(self, name, body):
     resp = self.k8s_api.patch_namespaced_pod(name=name,
                                              namespace=self.namespace,
                                              body=body)
     logger.debug("Pod `{}` was patched".format(name))
     return resp