eladkal commented on code in PR #44568: URL: https://github.com/apache/airflow/pull/44568#discussion_r1867249959
########## providers/tests/deprecations_ignore.yml: ########## @@ -94,7 +94,6 @@ - providers/tests/google/cloud/operators/test_dataproc.py::test_scale_cluster_operator_extra_links - providers/tests/google/cloud/operators/test_dataproc.py::test_submit_spark_job_operator_extra_links - providers/tests/google/cloud/operators/test_gcs.py::TestGoogleCloudStorageListOperator::test_execute__delimiter -- providers/tests/google/cloud/operators/test_kubernetes_engine.py::TestGoogleCloudPlatformContainerOperator::test_create_execute_error_body Review Comment: How is this change related to the PR? ########## providers/src/airflow/providers/cncf/kubernetes/operators/kueue.py: ########## @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Manage a Kubernetes Kueue.""" + +from __future__ import annotations + +import json +import warnings +from collections.abc import Sequence +from functools import cached_property + +from kubernetes.utils import FailToCreateError + +from airflow.exceptions import AirflowException +from airflow.models import BaseOperator +from airflow.providers.cncf.kubernetes.hooks.kubernetes import KubernetesHook +from airflow.providers.cncf.kubernetes.operators.job import KubernetesJobOperator + + +class KubernetesInstallKueueOperator(BaseOperator): + """ + Installs a Kubernetes Kueue. + + :param kueue_version: The Kubernetes Kueue version to install. + :param kubernetes_conn_id: The :ref:`kubernetes connection id <howto/connection:kubernetes>` + for the Kubernetes cluster. + """ + + template_fields: Sequence[str] = ( + "kueue_version", + "kubernetes_conn_id", + ) + + def __init__(self, kueue_version: str, kubernetes_conn_id: str = "kubernetes_default", *args, **kwargs): + super().__init__(*args, **kwargs) + self.kubernetes_conn_id = kubernetes_conn_id + self.kueue_version = kueue_version + self._kueue_yaml_url = ( + f"https://github.com/kubernetes-sigs/kueue/releases/download/{self.kueue_version}/manifests.yaml" + ) + + @cached_property + def hook(self) -> KubernetesHook: + return KubernetesHook(conn_id=self.kubernetes_conn_id) + + def execute(self, context): + yaml_objects = self.hook.get_yaml_content_from_file(kueue_yaml_url=self._kueue_yaml_url) + try: + self.hook.apply_from_yaml_file(yaml_objects=yaml_objects) + except FailToCreateError as ex: + error_bodies = [json.loads(e.body) for e in ex.api_exceptions] + if next((e for e in error_bodies if e.get("reason") == "AlreadyExists"), None): + self.log.info("Kueue is already enabled for the cluster") + + if errors := [e for e in error_bodies if e.get("reason") != "AlreadyExists"]: + error_message = "\n".join(e.get("body") for e in errors) + raise AirflowException(error_message) + return + + self.hook.check_kueue_deployment_running(name="kueue-controller-manager", namespace="kueue-system") + self.log.info("Kueue installed successfully!") + + +class KubernetesStartKueueJobOperator(KubernetesJobOperator): + """ + Executes a Kubernetes Job in Kueue. + + :param queue_name: The name of the Queue in the cluster + """ + + template_fields = tuple({"queue_name"} | set(KubernetesJobOperator.template_fields)) + + def __init__(self, queue_name: str, *args, **kwargs) -> None: + super().__init__(*args, **kwargs) + self.queue_name = queue_name + + if self.suspend is False: + raise AirflowException( + "The `suspend` parameter can't be False. If you want to use Kueue for running Job" + " in a Kubernetes cluster, set the `suspend` parameter to True.", + ) + elif self.suspend is None: + warnings.warn( + f"You have not set parameter `suspend` in class {self.__class__.__name__}. " + "For running a Job in Kueue the `suspend` parameter should set to True.", + UserWarning, + stacklevel=2, + ) + self.suspend = True Review Comment: This operator is new code, so why do we need to warn users about wrong usage? We can simply "force" the right use from the start ########## providers/src/airflow/providers/cncf/kubernetes/operators/kueue.py: ########## @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Manage a Kubernetes Kueue.""" + +from __future__ import annotations + +import json +import warnings +from collections.abc import Sequence +from functools import cached_property + +from kubernetes.utils import FailToCreateError + +from airflow.exceptions import AirflowException +from airflow.models import BaseOperator +from airflow.providers.cncf.kubernetes.hooks.kubernetes import KubernetesHook +from airflow.providers.cncf.kubernetes.operators.job import KubernetesJobOperator + + +class KubernetesInstallKueueOperator(BaseOperator): Review Comment: Can you please add docs for all the new features in this PR? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org