def create(self, namespace: str, labels: Dict[str, str] = None, annotations: Dict[str, str] = None): # exclude labels with None values - labels won't be correctly added otherwise labels = {key: value for key, value in labels.items() if value} if labels else None exp_kubernetes = KubernetesObject( self, client.V1ObjectMeta(name=self.name, namespace=namespace, labels=labels), kind="Experiment", apiVersion=f"{self.api_group_name}/{self.crd_version}") schema = ExperimentKubernetesSchema() body, err = schema.dump(exp_kubernetes) if err: raise RuntimeError( Texts.K8S_DUMP_PREPARATION_ERROR_MSG.format(err=err)) self.body = body response = super().create(namespace=namespace) created_exp, err = schema.load(response) if err: raise RuntimeError( Texts.K8S_RESPONSE_LOAD_ERROR_MSG.format(err=err)) return created_exp
def create(self, namespace: str, labels: Dict[str, str] = None, annotations: Dict[str, str] = None): run_kubernetes = KubernetesObject( self, client.V1ObjectMeta(name=self.name, namespace=namespace, labels=labels, annotations=annotations), kind="Run", apiVersion=f"{self.api_group_name}/{self.crd_version}") schema = RunKubernetesSchema() body, err = schema.dump(run_kubernetes) if err: raise RuntimeError( f'preparing dump of RunKubernetes request object error - {err}' ) self.body = body response = super().create(namespace=namespace) created_run, err = schema.load(response) if err: raise RuntimeError( f'load of RunKubernetes request object error - {err}') return created_run
def update(self): exp_kubernetes = KubernetesObject(self, client.V1ObjectMeta(name=self.name, namespace=self.namespace), kind="Experiment", apiVersion=f"{self.api_group_name}/{self.crd_version}") schema = ExperimentKubernetesSchema() body, err = schema.dump(exp_kubernetes) if err: raise RuntimeError(Texts.K8S_DUMP_PREPARATION_ERROR_MSG.format(err=err)) self.body = body response = super().update() updated_exp, err = schema.load(response) if err: raise RuntimeError(Texts.K8S_RESPONSE_LOAD_ERROR_MSG.format(err=err)) return updated_exp
def update(self): run_kubernetes = KubernetesObject( self, client.V1ObjectMeta(name=self.name, namespace=self.namespace), kind="Run", apiVersion=f"{self.api_group_name}/{self.crd_version}") schema = RunKubernetesSchema() body, err = schema.dump(run_kubernetes) if err: raise RuntimeError( f'preparing dump of RunKubernetes request object error - {err}' ) self.body = body response = super().update() updated_run, err = schema.load(response) if err: raise RuntimeError( f'load of RunKubernetes request object error - {err}') return updated_run