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
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))
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))
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))
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))
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))
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))
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))
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))
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))
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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