From 31079dec6eabc259d8c4cf2cb9fd08ee90270064 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 5 Jan 2024 10:54:20 +0000 Subject: [PATCH 01/62] Pin kr8s to 0.9.0 (#852) --- .github/workflows/operator.yaml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index 5a8bb230f..3eec45023 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@v2 - name: Lint Helm Chart run: helm lint dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator - - name: Download Pluto + - name: Install Pluto uses: FairwindsOps/pluto/github-action@v5.11.1 - name: Check for deprecated APIs run: helm template --include-crds dask-operator dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator | pluto detect - diff --git a/requirements.txt b/requirements.txt index d7a850edf..665275ceb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ kubernetes-asyncio>=12.0.1 kopf>=1.35.3 pykube-ng>=22.9.0 rich>=12.5.1 -kr8s>=0.9.0 +kr8s==0.9.0 From ff71342802e9e76ebede93fe1311761775b7a95a Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 5 Jan 2024 11:36:25 +0000 Subject: [PATCH 02/62] Release 2024.1.0 From eeb3c409362f0ae7b59f105c7a068daf2d29b583 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 5 Jan 2024 08:45:22 -0500 Subject: [PATCH 03/62] Add quiet parameter to KubeCluster (#840) * Add quiet parameter to KubeCluster * Address feedback --------- Co-authored-by: Jacob Tomlinson --- dask_kubernetes/operator/kubecluster/kubecluster.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dask_kubernetes/operator/kubecluster/kubecluster.py b/dask_kubernetes/operator/kubecluster/kubecluster.py index 575fdef11..d5891ab4a 100644 --- a/dask_kubernetes/operator/kubecluster/kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/kubecluster.py @@ -115,6 +115,9 @@ class KubeCluster(Cluster): used to create the cluster instead of generating one from the other keyword arguments. scheduler_forward_port: int (optional) The port to use when forwarding the scheduler dashboard. Will utilize a random port by default + quiet: bool + If enabled, suppress all printed output. + Defaults to ``False``. **kwargs: dict Additional keyword arguments to pass to LocalCluster @@ -175,6 +178,7 @@ def __init__( jupyter: bool = False, loop: Optional[IOLoop] = None, asynchronous: bool = False, + quiet: bool = False, **kwargs, ): name = dask.config.get("kubernetes.name", override_with=name) @@ -258,7 +262,9 @@ def __init__( self._rich_spinner = Spinner("dots", speed=0.5) self._startup_component_status: dict = {} - super().__init__(name=name, loop=loop, asynchronous=asynchronous, **kwargs) + super().__init__( + name=name, loop=loop, asynchronous=asynchronous, quiet=quiet, **kwargs + ) # If https://github.com/dask/distributed/pull/7941 is merged we can # simplify the next 8 lines to ``if not self.called_from_running_loop:`` From 90c7d9b62f735a5b35e95b2e90452daaa29e6f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0ebek?= Date: Fri, 5 Jan 2024 15:01:51 +0100 Subject: [PATCH 04/62] Add priorityClassName value to operator deployment (#845) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Petr Šebek Co-authored-by: Jacob Tomlinson --- .../deployment/helm/dask-kubernetes-operator/README.md | 1 + .../helm/dask-kubernetes-operator/templates/deployment.yaml | 3 +++ .../deployment/helm/dask-kubernetes-operator/values.yaml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md index cd3552100..1b4530df2 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md @@ -35,6 +35,7 @@ The following table lists the configurable parameters of the Dask-kubernetes-ope | `nodeSelector` | Node selector | `{}` | | `tolerations` | Tolerations | `[]` | | `affinity` | Affinity | `{}` | +| `priorityClassName` | Priority class | `null` | | `kopfArgs` | Command line flags to pass to kopf on start up | `["--all-namespaces"]` | | `metrics.scheduler.enabled` | Enable scheduler metrics. Pip package [prometheus-client](https://pypi.org/project/prometheus-client/) should be present on scheduler. | `false` | | `metrics.scheduler.serviceMonitor.enabled` | Enable scheduler servicemonitor. | `false` | diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml index f4f22a9db..285259c0c 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml @@ -68,3 +68,6 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.priorityClassName }} + priorityClassName: {{ . | quote }} + {{- end }} diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml index d58264254..d4d863a55 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml @@ -52,6 +52,8 @@ tolerations: [] # Tolerations affinity: {} # Affinity +priorityClassName: null # Priority class + kopfArgs: # Command line flags to pass to kopf on start up - --all-namespaces From aae26886601e46b44264c93e130c57742113001f Mon Sep 17 00:00:00 2001 From: Dmitry Balabka Date: Fri, 5 Jan 2024 16:30:35 +0200 Subject: [PATCH 05/62] Fix fetching single running pod (#846) (#847) Co-authored-by: Jacob Tomlinson --- dask_kubernetes/common/networking.py | 1 + dask_kubernetes/operator/networking.py | 1 + 2 files changed, 2 insertions(+) diff --git a/dask_kubernetes/common/networking.py b/dask_kubernetes/common/networking.py index 30dc3ff9f..5c81f7409 100644 --- a/dask_kubernetes/common/networking.py +++ b/dask_kubernetes/common/networking.py @@ -204,6 +204,7 @@ async def wait_for_scheduler(cluster_name, namespace, timeout=None): try: pod = await Pod.get( label_selector=f"dask.org/component=scheduler,dask.org/cluster-name={cluster_name}", + field_selector="status.phase=Running", namespace=namespace, ) except kr8s.NotFoundError: diff --git a/dask_kubernetes/operator/networking.py b/dask_kubernetes/operator/networking.py index 640646991..b7bd300b0 100644 --- a/dask_kubernetes/operator/networking.py +++ b/dask_kubernetes/operator/networking.py @@ -203,6 +203,7 @@ async def wait_for_scheduler(cluster_name, namespace, timeout=None): try: pod = await Pod.get( label_selector=f"dask.org/component=scheduler,dask.org/cluster-name={cluster_name}", + field_selector="status.phase=Running", namespace=namespace, ) except kr8s.NotFoundError: From dfeca2b38fe504692091c153d297010004746aa7 Mon Sep 17 00:00:00 2001 From: Dmitry Balabka Date: Fri, 5 Jan 2024 16:58:22 +0200 Subject: [PATCH 06/62] Fix node port support (#848) (#849) Co-authored-by: Jacob Tomlinson --- dask_kubernetes/common/networking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dask_kubernetes/common/networking.py b/dask_kubernetes/common/networking.py index 5c81f7409..b789c2c06 100644 --- a/dask_kubernetes/common/networking.py +++ b/dask_kubernetes/common/networking.py @@ -83,7 +83,7 @@ async def get_external_address_for_scheduler_service( def _get_port(service, port_name, is_node_port=False): """NodePort is a special case when we have to use node_port instead of node""" [port] = [ - port.port if not is_node_port else port.node_port + port.port if not is_node_port else port.nodePort for port in service.spec.ports if port.name == service.metadata.name or port.name == port_name ] From 4c1336e6096c6c5d24be9802754bad70a263760a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:35:55 +0000 Subject: [PATCH 07/62] Update major go package version (#850) Co-authored-by: jacobtomlinson --- .../operator/go_client/hack/regenerate-code.sh | 2 +- .../go_client/pkg/apis/kubernetes.dask.org/v1/register.go | 2 +- .../go_client/pkg/client/clientset/versioned/clientset.go | 2 +- .../clientset/versioned/fake/clientset_generated.go | 6 +++--- .../pkg/client/clientset/versioned/fake/register.go | 2 +- .../pkg/client/clientset/versioned/scheme/register.go | 2 +- .../typed/kubernetes.dask.org/v1/daskautoscaler.go | 4 ++-- .../versioned/typed/kubernetes.dask.org/v1/daskcluster.go | 4 ++-- .../versioned/typed/kubernetes.dask.org/v1/daskjob.go | 4 ++-- .../typed/kubernetes.dask.org/v1/daskworkergroup.go | 4 ++-- .../kubernetes.dask.org/v1/fake/fake_daskautoscaler.go | 2 +- .../typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go | 2 +- .../typed/kubernetes.dask.org/v1/fake/fake_daskjob.go | 2 +- .../kubernetes.dask.org/v1/fake/fake_daskworkergroup.go | 2 +- .../v1/fake/fake_kubernetes.dask.org_client.go | 2 +- .../kubernetes.dask.org/v1/kubernetes.dask.org_client.go | 4 ++-- .../pkg/client/informers/externalversions/factory.go | 6 +++--- .../pkg/client/informers/externalversions/generic.go | 2 +- .../internalinterfaces/factory_interfaces.go | 2 +- .../externalversions/kubernetes.dask.org/interface.go | 4 ++-- .../kubernetes.dask.org/v1/daskautoscaler.go | 8 ++++---- .../kubernetes.dask.org/v1/daskcluster.go | 8 ++++---- .../externalversions/kubernetes.dask.org/v1/daskjob.go | 8 ++++---- .../kubernetes.dask.org/v1/daskworkergroup.go | 8 ++++---- .../externalversions/kubernetes.dask.org/v1/interface.go | 2 +- .../listers/kubernetes.dask.org/v1/daskautoscaler.go | 2 +- .../client/listers/kubernetes.dask.org/v1/daskcluster.go | 2 +- .../pkg/client/listers/kubernetes.dask.org/v1/daskjob.go | 2 +- .../listers/kubernetes.dask.org/v1/daskworkergroup.go | 2 +- go.mod | 2 +- 30 files changed, 52 insertions(+), 52 deletions(-) diff --git a/dask_kubernetes/operator/go_client/hack/regenerate-code.sh b/dask_kubernetes/operator/go_client/hack/regenerate-code.sh index 743d3254f..04cd31db2 100755 --- a/dask_kubernetes/operator/go_client/hack/regenerate-code.sh +++ b/dask_kubernetes/operator/go_client/hack/regenerate-code.sh @@ -2,7 +2,7 @@ CURRENT_DIR=$(dirname ${BASH_SOURCE}) REPO_DIR=$(realpath "$CURRENT_DIR/../../../..") -MAJOR_VERSION="v2023" +MAJOR_VERSION="v2024" PROJECT_MODULE="github.com/dask/dask-kubernetes/${MAJOR_VERSION}" IMAGE_NAME="kubernetes-codegen:latest" diff --git a/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go b/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go index 1510ebcdd..53861426e 100644 --- a/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go +++ b/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go @@ -1,7 +1,7 @@ package v1 import ( - daskoperator "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis" + daskoperator "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go index 91093aee1..7e4c4e586 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - kubernetesv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" + kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go index bc259815a..6fc50fc92 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -3,9 +3,9 @@ package fake import ( - clientset "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - kubernetesv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" - fakekubernetesv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake" + clientset "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" + fakekubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go index 6638546a8..691f89cf3 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go @@ -3,7 +3,7 @@ package fake import ( - kubernetesv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go index bbe3e7111..f6a9ffd69 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go @@ -3,7 +3,7 @@ package scheme import ( - kubernetesv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go index edb9f38e5..c3e734091 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go index 4f9dd9750..7c0aeb887 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go index f5ccdcd52..9987237cd 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go index c31ddd722..922ed414f 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go index e66a6c3cc..bd88c6535 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go index b9960a568..4296dc2f4 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go index 3f383e75f..9a41bb5b1 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go index 786bd6775..9580f0f26 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go index 25432e918..47e97dfb2 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go @@ -3,7 +3,7 @@ package fake import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go index 0cdcf9c1c..a252dd206 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go @@ -5,8 +5,8 @@ package v1 import ( "net/http" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" rest "k8s.io/client-go/rest" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go index 5c926e6f6..296e234dd 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go @@ -7,9 +7,9 @@ import ( sync "sync" time "time" - versioned "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - kubernetesdaskorg "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org" + versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + kubernetesdaskorg "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go index da8640b8e..7d1d14bc3 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go @@ -5,7 +5,7 @@ package externalversions import ( "fmt" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go index b49a70628..8ec55d7be 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -5,7 +5,7 @@ package internalinterfaces import ( time "time" - versioned "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go index 47c7b3bbf..426e84954 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go @@ -3,8 +3,8 @@ package kubernetes import ( - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1" ) // Interface provides access to each of this group's versions. diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go index e2e26e3d0..c0726c785 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go index 2ea06cb50..5b694db9e 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go index d5a1e796b..442da458e 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go index e369b1355..23dbd7700 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go index cc08a0904..bb3577be7 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go @@ -3,7 +3,7 @@ package v1 import ( - internalinterfaces "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" ) // Interface provides access to all the informers in this group version. diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go index c3d4d7f8f..4f48ad342 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go index 44621579c..7c383aff8 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go index 6a6b1e27e..c2035d1ba 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go index 64ae2c8cf..a7dd4da45 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/go.mod b/go.mod index 60ff66f32..0d523e1df 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/dask/dask-kubernetes/v2023 +module github.com/dask/dask-kubernetes/v2024 go 1.18 From 1ced2073bb0a817f763e1cfe8b7d8c27ef733c22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:36:16 +0000 Subject: [PATCH 08/62] Bump golang.org/x/net from 0.8.0 to 0.17.0 (#831) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.8.0 to 0.17.0. - [Commits](https://github.com/golang/net/compare/v0.8.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 0d523e1df..d65b3e48f 100644 --- a/go.mod +++ b/go.mod @@ -30,11 +30,11 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.8.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/term v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect diff --git a/go.sum b/go.sum index c08264dbd..5715c2565 100644 --- a/go.sum +++ b/go.sum @@ -347,8 +347,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -420,12 +420,12 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= -golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -435,8 +435,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From a9216b683943e80fd534c880d9ed1e6919abb5b6 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Mon, 19 Feb 2024 18:21:39 +0100 Subject: [PATCH 09/62] Fix versions in the go client (#861) --- .../kubernetes.dask.org/v1/daskclusterstatus.go | 2 +- .../kubernetes.dask.org/v1/daskjobstatus.go | 2 +- .../operator/go_client/pkg/client/applyconfiguration/utils.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go index 75dbe3b45..5c5f31d00 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go +++ b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" ) // DaskClusterStatusApplyConfiguration represents an declarative configuration of the DaskClusterStatus type for use diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go index 3ae40a5db..387d03976 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go +++ b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go @@ -3,7 +3,7 @@ package v1 import ( - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go index 009abda66..a9955d761 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go +++ b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go @@ -3,8 +3,8 @@ package applyconfiguration import ( - v1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2023/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1" schema "k8s.io/apimachinery/pkg/runtime/schema" ) From e0a771688b7a6422d57cfdb9d9b1c766c7caa9ef Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 20 Feb 2024 11:46:40 +0100 Subject: [PATCH 10/62] Bump Kubernetes in CI to 1.29 and minimum to 1.26 (#862) --- .github/workflows/helmcluster.yaml | 14 +++++++------- .github/workflows/kubecluster.yaml | 14 +++++++------- .github/workflows/operator.yaml | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/helmcluster.yaml b/.github/workflows/helmcluster.yaml index 6b7a90807..009a08631 100644 --- a/.github/workflows/helmcluster.yaml +++ b/.github/workflows/helmcluster.yaml @@ -29,14 +29,14 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10"] - kubernetes-version: ["1.27.0"] + kubernetes-version: ["1.29.2"] include: - - python-version: "3.10" - kubernetes-version: "1.24.13" - - python-version: "3.10" - kubernetes-version: "1.25.9" - - python-version: "3.10" - kubernetes-version: "1.26.4" + - python-version: '3.10' + kubernetes-version: 1.28.7 + - python-version: '3.10' + kubernetes-version: 1.27.11 + - python-version: '3.10' + kubernetes-version: 1.26.14 env: KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig diff --git a/.github/workflows/kubecluster.yaml b/.github/workflows/kubecluster.yaml index 9c4a6272c..108858cc3 100644 --- a/.github/workflows/kubecluster.yaml +++ b/.github/workflows/kubecluster.yaml @@ -29,14 +29,14 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10"] - kubernetes-version: ["1.27.0"] + kubernetes-version: ["1.29.2"] include: - - python-version: "3.10" - kubernetes-version: "1.24.13" - - python-version: "3.10" - kubernetes-version: "1.25.9" - - python-version: "3.10" - kubernetes-version: "1.26.4" + - python-version: '3.10' + kubernetes-version: 1.28.7 + - python-version: '3.10' + kubernetes-version: 1.27.11 + - python-version: '3.10' + kubernetes-version: 1.26.14 env: KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index 3eec45023..8d0968b2e 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -40,14 +40,14 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10"] - kubernetes-version: ["1.27.3"] + kubernetes-version: ["1.29.2"] include: - - python-version: "3.10" - kubernetes-version: "1.24.15" - - python-version: "3.10" - kubernetes-version: "1.25.11" - - python-version: "3.10" - kubernetes-version: "1.26.6" + - python-version: '3.10' + kubernetes-version: 1.28.7 + - python-version: '3.10' + kubernetes-version: 1.27.11 + - python-version: '3.10' + kubernetes-version: 1.26.14 env: KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig From 3a41910cdc6a49a2c1fc67249346a8d6bb1a5a74 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 20 Feb 2024 11:49:31 +0100 Subject: [PATCH 11/62] Bump Kubernetes badges to 1.26-1.29 (#863) --- README.rst | 2 +- doc/source/index.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 4ede504da..36acfdd61 100644 --- a/README.rst +++ b/README.rst @@ -25,7 +25,7 @@ Dask Kubernetes :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support -.. image:: https://img.shields.io/badge/Kubernetes%20support-1.24%7C1.25%7C1.26%7C1.27-blue +.. image:: https://img.shields.io/badge/Kubernetes%20support-1.26%7C1.27%7C1.28%7C1.29-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Kubernetes Support diff --git a/doc/source/index.rst b/doc/source/index.rst index 959b02bfa..be3a79fe8 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -13,7 +13,7 @@ Dask Kubernetes :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support -.. image:: https://img.shields.io/badge/Kubernetes%20support-1.24%7C1.25%7C1.26%7C1.27-blue +.. image:: https://img.shields.io/badge/Kubernetes%20support-1.26%7C1.27%7C1.28%7C1.29-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Kubernetes Support From 6070e82921869422198a91714bb2bd72414183ff Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 20 Feb 2024 12:02:23 +0100 Subject: [PATCH 12/62] Add sphinx theme workaround (#865) --- doc/requirements-docs.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/requirements-docs.txt b/doc/requirements-docs.txt index 654755a90..e55c5484e 100644 --- a/doc/requirements-docs.txt +++ b/doc/requirements-docs.txt @@ -4,3 +4,13 @@ sphinx-reredirects sphinxcontrib-mermaid dask-sphinx-theme>=3.0.0 frigate>=0.7.0 + +# FIXME: This workaround is required until we have sphinx>=5, as enabled by +# dask-sphinx-theme no longer pinning sphinx-book-theme==0.2.0. This is +# tracked in https://github.com/dask/dask-sphinx-theme/issues/68. +# +sphinxcontrib-applehelp<1.0.5 +sphinxcontrib-devhelp<1.0.6 +sphinxcontrib-htmlhelp<2.0.5 +sphinxcontrib-serializinghtml<1.1.10 +sphinxcontrib-qthelp<1.0.7 From 726f0f8f030e0edf527b7dc9d2bf0b78f3aa6a49 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 20 Feb 2024 12:07:49 +0100 Subject: [PATCH 13/62] Update CI badges (#866) * Update CI badges * Typo --- README.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 36acfdd61..e06275d3b 100644 --- a/README.rst +++ b/README.rst @@ -2,8 +2,17 @@ Dask Kubernetes =============== -.. image:: https://github.com/dask/dask-kubernetes/workflows/CI/badge.svg - :target: https://github.com/dask/dask-kubernetes/actions?query=workflow%3ACI +.. image:: https://github.com/dask/dask-kubernetes/actions/workflows/lint.yaml/badge.svg + :target: https://github.com/dask/dask-kubernetes/actions/workflows/lint.yaml + :alt: Linting GitHub Actions CI Status + +.. image:: https://github.com/dask/dask-kubernetes/actions/workflows/operator.yaml/badge.svg + :target: https://github.com/dask/dask-kubernetes/actions/workflows/operator.yaml + :alt: Operator Tests GitHub Actions CI Status + +.. image:: https://github.com/dask/dask-kubernetes/actions/workflows/release.yml/badge.svg + :target: https://github.com/dask/dask-kubernetes/actions/workflows/release.yml + :alt: Package build GitHub Actions CI Status .. image:: https://img.shields.io/readthedocs/dask-kubernetes?color=%232980B9&logo=read-the-docs&logoColor=white :target: https://kubernetes.dask.org/ From 84846b1f5e6e785c2f4ce2c8299bc5b8bff4b371 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 20 Feb 2024 15:43:11 +0100 Subject: [PATCH 14/62] Add Python 3.11 to the CI matrix (#864) * Bump min py * Upgrade versioneer for python 3.12 * Update badges * Exit tests after 3 failures and reduce reruns * Bumping Python in container to see if that fixes failures * Build container image for the right Python version * Drop 3.12 for now --- .github/workflows/helmcluster.yaml | 4 +- .github/workflows/kubecluster.yaml | 4 +- .github/workflows/operator.yaml | 4 +- README.rst | 2 +- ci/Dockerfile | 4 +- dask_kubernetes/__init__.py | 7 +- dask_kubernetes/_version.py | 320 +++++-- dask_kubernetes/conftest.py | 15 +- doc/source/index.rst | 2 +- pyproject.toml | 4 +- setup.cfg | 1 - versioneer.py | 1358 ++++++++++++++++++---------- 12 files changed, 1144 insertions(+), 581 deletions(-) diff --git a/.github/workflows/helmcluster.yaml b/.github/workflows/helmcluster.yaml index 009a08631..a56b787b9 100644 --- a/.github/workflows/helmcluster.yaml +++ b/.github/workflows/helmcluster.yaml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11"] kubernetes-version: ["1.29.2"] include: - python-version: '3.10' @@ -51,7 +51,7 @@ jobs: - name: Run tests env: KUBERNETES_VERSION: ${{ matrix.kubernetes-version }} - run: pytest dask_kubernetes/common/tests dask_kubernetes/helm/tests + run: pytest --reruns=5 dask_kubernetes/common/tests dask_kubernetes/helm/tests - name: Debug k8s resources if: success() || failure() run: kubectl get all -A diff --git a/.github/workflows/kubecluster.yaml b/.github/workflows/kubecluster.yaml index 108858cc3..89714ae54 100644 --- a/.github/workflows/kubecluster.yaml +++ b/.github/workflows/kubecluster.yaml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11"] kubernetes-version: ["1.29.2"] include: - python-version: '3.10' @@ -51,7 +51,7 @@ jobs: - name: Run tests env: KUBERNETES_VERSION: ${{ matrix.kubernetes-version }} - run: pytest dask_kubernetes/common/tests dask_kubernetes/classic/tests + run: pytest --reruns=5 dask_kubernetes/common/tests dask_kubernetes/classic/tests - name: Debug k8s resources if: success() || failure() run: kubectl get all -A diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index 8d0968b2e..35e21a192 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -39,7 +39,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11"] kubernetes-version: ["1.29.2"] include: - python-version: '3.10' @@ -64,7 +64,7 @@ jobs: KUBERNETES_VERSION: ${{ matrix.kubernetes-version }} TEST_ISTIO: "true" TEST_DASK_GATEWAY: "true" - run: pytest dask_kubernetes/common dask_kubernetes/operator + run: pytest --maxfail=3 --reruns=5 dask_kubernetes/common dask_kubernetes/operator - name: Debug kubernetes resources if: always() run: kubectl get all -A diff --git a/README.rst b/README.rst index e06275d3b..6e3fd7511 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10-blue +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support diff --git a/ci/Dockerfile b/ci/Dockerfile index 0f07821d1..5d6720cc7 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -1,4 +1,6 @@ -FROM ghcr.io/dask/dask:latest-py3.10 +ARG PYTHON=3.11 + +FROM ghcr.io/dask/dask:latest-py${PYTHON} # Install latest dev builds of Dask and Distributed RUN pip install git+https://github.com/dask/distributed@main diff --git a/dask_kubernetes/__init__.py b/dask_kubernetes/__init__.py index 941ff6629..11a1ea333 100644 --- a/dask_kubernetes/__init__.py +++ b/dask_kubernetes/__init__.py @@ -2,6 +2,7 @@ from warnings import warn from . import config +from . import _version from .common.auth import ( AutoRefreshConfiguration, AutoRefreshKubeConfigLoader, @@ -14,11 +15,7 @@ from .helm import HelmCluster __all__ = ["HelmCluster", "KubeCluster"] - -from ._version import get_versions - -__version__ = get_versions()["version"] -del get_versions +__version__ = _version.get_versions()["version"] def __getattr__(name): diff --git a/dask_kubernetes/_version.py b/dask_kubernetes/_version.py index 8b87e1f79..771a8a76d 100644 --- a/dask_kubernetes/_version.py +++ b/dask_kubernetes/_version.py @@ -4,19 +4,22 @@ # directories (produced by setup.py build) will contain a much shorter file # that just contains the computed version number. -# This file is released into the public domain. Generated by -# versioneer-0.18 (https://github.com/warner/python-versioneer) +# This file is released into the public domain. +# Generated by versioneer-0.29 +# https://github.com/python-versioneer/python-versioneer """Git implementation of _version.py.""" import errno +import functools import os import re import subprocess import sys +from typing import Any, Callable, Dict, List, Optional, Tuple -def get_keywords(): +def get_keywords() -> Dict[str, str]: """Get the keywords needed to look up the version information.""" # these strings will be replaced by git during git-archive. # setup.py/versioneer.py will grep for the variable names, so they must @@ -32,8 +35,15 @@ def get_keywords(): class VersioneerConfig: """Container for Versioneer configuration parameters.""" + VCS: str + style: str + tag_prefix: str + parentdir_prefix: str + versionfile_source: str + verbose: bool -def get_config(): + +def get_config() -> VersioneerConfig: """Create, populate and return the VersioneerConfig() object.""" # these strings are filled in when 'setup.py versioneer' creates # _version.py @@ -51,14 +61,14 @@ class NotThisMethod(Exception): """Exception raised if a method is not valid for the current scenario.""" -LONG_VERSION_PY = {} -HANDLERS = {} +LONG_VERSION_PY: Dict[str, str] = {} +HANDLERS: Dict[str, Dict[str, Callable]] = {} -def register_vcs_handler(vcs, method): # decorator - """Decorator to mark a method as the handler for a particular VCS.""" +def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator + """Create decorator to mark a method as the handler of a VCS.""" - def decorate(f): + def decorate(f: Callable) -> Callable: """Store f in HANDLERS[vcs][method].""" if vcs not in HANDLERS: HANDLERS[vcs] = {} @@ -68,24 +78,39 @@ def decorate(f): return decorate -def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None): +def run_command( + commands: List[str], + args: List[str], + cwd: Optional[str] = None, + verbose: bool = False, + hide_stderr: bool = False, + env: Optional[Dict[str, str]] = None, +) -> Tuple[Optional[str], Optional[int]]: """Call the given command(s).""" assert isinstance(commands, list) - p = None - for c in commands: + process = None + + popen_kwargs: Dict[str, Any] = {} + if sys.platform == "win32": + # This hides the console window if pythonw.exe is used + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + popen_kwargs["startupinfo"] = startupinfo + + for command in commands: try: - dispcmd = str([c] + args) + dispcmd = str([command] + args) # remember shell=False, so use git.cmd on windows, not just git - p = subprocess.Popen( - [c] + args, + process = subprocess.Popen( + [command] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None), + **popen_kwargs, ) break - except EnvironmentError: - e = sys.exc_info()[1] + except OSError as e: if e.errno == errno.ENOENT: continue if verbose: @@ -96,18 +121,20 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= if verbose: print("unable to find command, tried %s" % (commands,)) return None, None - stdout = p.communicate()[0].strip() - if sys.version_info[0] >= 3: - stdout = stdout.decode() - if p.returncode != 0: + stdout = process.communicate()[0].strip().decode() + if process.returncode != 0: if verbose: print("unable to run %s (error)" % dispcmd) print("stdout was %s" % stdout) - return None, p.returncode - return stdout, p.returncode + return None, process.returncode + return stdout, process.returncode -def versions_from_parentdir(parentdir_prefix, root, verbose): +def versions_from_parentdir( + parentdir_prefix: str, + root: str, + verbose: bool, +) -> Dict[str, Any]: """Try to determine the version from the parent directory name. Source tarballs conventionally unpack into a directory that includes both @@ -116,7 +143,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): """ rootdirs = [] - for i in range(3): + for _ in range(3): dirname = os.path.basename(root) if dirname.startswith(parentdir_prefix): return { @@ -126,9 +153,8 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): "error": None, "date": None, } - else: - rootdirs.append(root) - root = os.path.dirname(root) # up a level + rootdirs.append(root) + root = os.path.dirname(root) # up a level if verbose: print( @@ -139,41 +165,48 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): @register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs): +def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: """Extract version information from the given file.""" # the code embedded in _version.py can just fetch the value of these # keywords. When used from setup.py, we don't want to import _version.py, # so we do it with a regexp instead. This function is not used from # _version.py. - keywords = {} + keywords: Dict[str, str] = {} try: - f = open(versionfile_abs, "r") - for line in f.readlines(): - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - f.close() - except EnvironmentError: + with open(versionfile_abs, "r") as fobj: + for line in fobj: + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + except OSError: pass return keywords @register_vcs_handler("git", "keywords") -def git_versions_from_keywords(keywords, tag_prefix, verbose): +def git_versions_from_keywords( + keywords: Dict[str, str], + tag_prefix: str, + verbose: bool, +) -> Dict[str, Any]: """Get version information from git keywords.""" - if not keywords: - raise NotThisMethod("no keywords at all, weird") + if "refnames" not in keywords: + raise NotThisMethod("Short version file found") date = keywords.get("date") if date is not None: + # Use only the last line. Previous lines may contain GPG signature + # information. + date = date.splitlines()[-1] + # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 # -like" string, which we must then edit to make compliant), because @@ -186,11 +219,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = set([r.strip() for r in refnames.strip("()").split(",")]) + refs = {r.strip() for r in refnames.strip("()").split(",")} # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)]) + tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)} if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d @@ -198,8 +231,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # refs/heads/ and refs/tags/ prefixes that would let us distinguish # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "main". - tags = set([r for r in refs if re.search(r"\d", r)]) + # "stabilization", as well as "HEAD" and "master". + tags = {r for r in refs if re.search(r"\d", r)} if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: @@ -208,6 +241,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # sorting will prefer e.g. "2.0" over "2.0rc1" if ref.startswith(tag_prefix): r = ref[len(tag_prefix) :] + # Filter out refs that exactly match prefix or that don't start + # with a number once the prefix is stripped (mostly a concern + # when prefix is '') + if not re.match(r"\d", r): + continue if verbose: print("picking %s" % r) return { @@ -230,7 +268,9 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): @register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): +def git_pieces_from_vcs( + tag_prefix: str, root: str, verbose: bool, runner: Callable = run_command +) -> Dict[str, Any]: """Get version from 'git describe' in the root of the source tree. This only gets called if the git-archive 'subst' keywords were *not* @@ -241,7 +281,14 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if sys.platform == "win32": GITS = ["git.cmd", "git.exe"] - out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True) + # GIT_DIR can interfere with correct operation of Versioneer. + # It may be intended to be passed to the Versioneer-versioned project, + # but that should not change where we get our version from. + env = os.environ.copy() + env.pop("GIT_DIR", None) + runner = functools.partial(runner, env=env) + + _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=not verbose) if rc != 0: if verbose: print("Directory %s not under git control" % root) @@ -249,7 +296,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = run_command( + describe_out, rc = runner( GITS, [ "describe", @@ -258,7 +305,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): "--always", "--long", "--match", - "%s*" % tag_prefix, + f"{tag_prefix}[[:digit:]]*", ], cwd=root, ) @@ -266,16 +313,48 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if describe_out is None: raise NotThisMethod("'git describe' failed") describe_out = describe_out.strip() - full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) if full_out is None: raise NotThisMethod("'git rev-parse' failed") full_out = full_out.strip() - pieces = {} + pieces: Dict[str, Any] = {} pieces["long"] = full_out pieces["short"] = full_out[:7] # maybe improved later pieces["error"] = None + branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root) + # --abbrev-ref was added in git-1.6.3 + if rc != 0 or branch_name is None: + raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") + branch_name = branch_name.strip() + + if branch_name == "HEAD": + # If we aren't exactly on a branch, pick a branch which represents + # the current commit. If all else fails, we are on a branchless + # commit. + branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) + # --contains was added in git-1.5.4 + if rc != 0 or branches is None: + raise NotThisMethod("'git branch --contains' returned error") + branches = branches.split("\n") + + # Remove the first line if we're running detached + if "(" in branches[0]: + branches.pop(0) + + # Strip off the leading "* " from the list of branches. + branches = [branch[2:] for branch in branches] + if "master" in branches: + branch_name = "master" + elif not branches: + branch_name = None + else: + # Pick the first branch that is returned. Good or bad. + branch_name = branches[0] + + pieces["branch"] = branch_name + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] # TAG might have hyphens. git_describe = describe_out @@ -292,7 +371,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): # TAG-NUM-gHEX mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe) if not mo: - # unparseable. Maybe git-describe is misbehaving? + # unparsable. Maybe git-describe is misbehaving? pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out return pieces @@ -318,26 +397,27 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): else: # HEX: no tags pieces["closest-tag"] = None - count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root) - pieces["distance"] = int(count_out) # total number of commits + out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) + pieces["distance"] = len(out.split()) # total number of commits # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[ - 0 - ].strip() + date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip() + # Use only the last line. Previous lines may contain GPG signature + # information. + date = date.splitlines()[-1] pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) return pieces -def plus_or_dot(pieces): +def plus_or_dot(pieces: Dict[str, Any]) -> str: """Return a + if we don't already have one, else return a .""" if "+" in pieces.get("closest-tag", ""): return "." return "+" -def render_pep440(pieces): +def render_pep440(pieces: Dict[str, Any]) -> str: """Build up version string, with post-release "local version identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you @@ -361,23 +441,70 @@ def render_pep440(pieces): return rendered -def render_pep440_pre(pieces): - """TAG[.post.devDISTANCE] -- No -dirty. +def render_pep440_branch(pieces: Dict[str, Any]) -> str: + """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . + + The ".dev0" means not master branch. Note that .dev0 sorts backwards + (a feature branch will appear "older" than the master branch). Exceptions: - 1: no tags. 0.post.devDISTANCE + 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0" + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += "+untagged.%d.g%s" % (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: + """Split pep440 version string at the post-release segment. + + Returns the release segments before the post-release and the + post-release version number (or -1 if no post-release segment is present). + """ + vc = str.split(ver, ".post") + return vc[0], int(vc[1] or 0) if len(vc) == 2 else None + + +def render_pep440_pre(pieces: Dict[str, Any]) -> str: + """TAG[.postN.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post0.devDISTANCE + """ + if pieces["closest-tag"]: if pieces["distance"]: - rendered += ".post.dev%d" % pieces["distance"] + # update the post release segment + tag_version, post_version = pep440_split_post(pieces["closest-tag"]) + rendered = tag_version + if post_version is not None: + rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"]) + else: + rendered += ".post0.dev%d" % (pieces["distance"]) + else: + # no commits, use the tag as the version + rendered = pieces["closest-tag"] else: # exception #1 - rendered = "0.post.dev%d" % pieces["distance"] + rendered = "0.post0.dev%d" % pieces["distance"] return rendered -def render_pep440_post(pieces): +def render_pep440_post(pieces: Dict[str, Any]) -> str: """TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards @@ -404,12 +531,41 @@ def render_pep440_post(pieces): return rendered -def render_pep440_old(pieces): +def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: + """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . + + The ".dev0" means not master branch. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%s" % pieces["short"] + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += "+g%s" % pieces["short"] + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_old(pieces: Dict[str, Any]) -> str: """TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. - Eexceptions: + Exceptions: 1: no tags. 0.postDISTANCE[.dev0] """ if pieces["closest-tag"]: @@ -426,7 +582,7 @@ def render_pep440_old(pieces): return rendered -def render_git_describe(pieces): +def render_git_describe(pieces: Dict[str, Any]) -> str: """TAG[-DISTANCE-gHEX][-dirty]. Like 'git describe --tags --dirty --always'. @@ -446,7 +602,7 @@ def render_git_describe(pieces): return rendered -def render_git_describe_long(pieces): +def render_git_describe_long(pieces: Dict[str, Any]) -> str: """TAG-DISTANCE-gHEX[-dirty]. Like 'git describe --tags --dirty --always -long'. @@ -466,7 +622,7 @@ def render_git_describe_long(pieces): return rendered -def render(pieces, style): +def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: """Render the given version pieces into the requested style.""" if pieces["error"]: return { @@ -482,10 +638,14 @@ def render(pieces, style): if style == "pep440": rendered = render_pep440(pieces) + elif style == "pep440-branch": + rendered = render_pep440_branch(pieces) elif style == "pep440-pre": rendered = render_pep440_pre(pieces) elif style == "pep440-post": rendered = render_pep440_post(pieces) + elif style == "pep440-post-branch": + rendered = render_pep440_post_branch(pieces) elif style == "pep440-old": rendered = render_pep440_old(pieces) elif style == "git-describe": @@ -504,7 +664,7 @@ def render(pieces, style): } -def get_versions(): +def get_versions() -> Dict[str, Any]: """Get version information or return default if unable to do so.""" # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have # __file__, we can work backwards from there to the root. Some @@ -524,7 +684,7 @@ def get_versions(): # versionfile_source is the relative path from the top of the source # tree (where the .git directory might live) to this file. Invert # this to find the root from __file__. - for i in cfg.versionfile_source.split("/"): + for _ in cfg.versionfile_source.split("/"): root = os.path.dirname(root) except NameError: return { diff --git a/dask_kubernetes/conftest.py b/dask_kubernetes/conftest.py index 454802849..aadaa2aac 100644 --- a/dask_kubernetes/conftest.py +++ b/dask_kubernetes/conftest.py @@ -2,6 +2,7 @@ import os import pathlib import subprocess +import sys import tempfile import uuid @@ -36,7 +37,19 @@ def kopf_runner(k8s_cluster, ns): @pytest.fixture(scope="session") def docker_image(): image_name = "dask-kubernetes:dev" - subprocess.run(["docker", "build", "-t", image_name, "./ci/"], check=True) + python_version = f"{sys.version_info.major}.{sys.version_info.minor}" + subprocess.run( + [ + "docker", + "build", + "-t", + image_name, + "--build-arg", + f"PYTHON={python_version}", + "./ci/", + ], + check=True, + ) return image_name diff --git a/doc/source/index.rst b/doc/source/index.rst index be3a79fe8..3de09e815 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,7 +9,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10-blue +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support diff --git a/pyproject.toml b/pyproject.toml index 50583738a..6a5e3c394 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ exclude = [ per-file-ignores = {} ignore = [ - "E4", # Import formatting + "E4", # Import formatting "E721", # Comparing types instead of isinstance "E731", # Assigning lambda expression "E741", # Ambiguous variable names @@ -53,4 +53,4 @@ line-length = 120 dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Assume Python 3.8 -target-version = "py38" +target-version = "py39" diff --git a/setup.cfg b/setup.cfg index 8c72c205a..d07f1eb5b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,4 +39,3 @@ parentdir_prefix = dask-kubernetes- addopts = -v --keep-cluster --durations=10 timeout = 60 timeout_func_only = true -reruns = 10 diff --git a/versioneer.py b/versioneer.py index 722989c3c..1e3753e63 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1,4 +1,5 @@ -# Version: 0.18 + +# Version: 0.29 """The Versioneer - like a rocketeer, but for versions. @@ -6,18 +7,14 @@ ============== * like a rocketeer, but for versions! -* https://github.com/warner/python-versioneer +* https://github.com/python-versioneer/python-versioneer * Brian Warner -* License: Public Domain -* Compatible With: python2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, and pypy -* [![Latest Version] -(https://pypip.in/version/versioneer/badge.svg?style=flat) -](https://pypi.python.org/pypi/versioneer/) -* [![Build Status] -(https://travis-ci.org/warner/python-versioneer.png?branch=master) -](https://travis-ci.org/warner/python-versioneer) - -This is a tool for managing a recorded version number in distutils-based +* License: Public Domain (Unlicense) +* Compatible with: Python 3.7, 3.8, 3.9, 3.10, 3.11 and pypy3 +* [![Latest Version][pypi-image]][pypi-url] +* [![Build Status][travis-image]][travis-url] + +This is a tool for managing a recorded version number in setuptools-based python projects. The goal is to remove the tedious and error-prone "update the embedded version string" step from your release process. Making a new release should be as easy as recording a new tag in your version-control @@ -26,9 +23,38 @@ ## Quick Install -* `pip install versioneer` to somewhere to your $PATH -* add a `[versioneer]` section to your setup.cfg (see below) -* run `versioneer install` in your source tree, commit the results +Versioneer provides two installation modes. The "classic" vendored mode installs +a copy of versioneer into your repository. The experimental build-time dependency mode +is intended to allow you to skip this step and simplify the process of upgrading. + +### Vendored mode + +* `pip install versioneer` to somewhere in your $PATH + * A [conda-forge recipe](https://github.com/conda-forge/versioneer-feedstock) is + available, so you can also use `conda install -c conda-forge versioneer` +* add a `[tool.versioneer]` section to your `pyproject.toml` or a + `[versioneer]` section to your `setup.cfg` (see [Install](INSTALL.md)) + * Note that you will need to add `tomli; python_version < "3.11"` to your + build-time dependencies if you use `pyproject.toml` +* run `versioneer install --vendor` in your source tree, commit the results +* verify version information with `python setup.py version` + +### Build-time dependency mode + +* `pip install versioneer` to somewhere in your $PATH + * A [conda-forge recipe](https://github.com/conda-forge/versioneer-feedstock) is + available, so you can also use `conda install -c conda-forge versioneer` +* add a `[tool.versioneer]` section to your `pyproject.toml` or a + `[versioneer]` section to your `setup.cfg` (see [Install](INSTALL.md)) +* add `versioneer` (with `[toml]` extra, if configuring in `pyproject.toml`) + to the `requires` key of the `build-system` table in `pyproject.toml`: + ```toml + [build-system] + requires = ["setuptools", "versioneer[toml]"] + build-backend = "setuptools.build_meta" + ``` +* run `versioneer install --no-vendor` in your source tree, commit the results +* verify version information with `python setup.py version` ## Version Identifiers @@ -60,7 +86,7 @@ for example `git describe --tags --dirty --always` reports things like "0.7-1-g574ab98-dirty" to indicate that the checkout is one revision past the 0.7 tag, has a unique revision id of "574ab98", and is "dirty" (it has -uncommitted changes. +uncommitted changes). The version identifier is used for multiple purposes: @@ -165,7 +191,7 @@ Some situations are known to cause problems for Versioneer. This details the most significant ones. More can be found on Github -[issues page](https://github.com/warner/python-versioneer/issues). +[issues page](https://github.com/python-versioneer/python-versioneer/issues). ### Subprojects @@ -179,7 +205,7 @@ `setup.cfg`, and `tox.ini`. Projects like these produce multiple PyPI distributions (and upload multiple independently-installable tarballs). * Source trees whose main purpose is to contain a C library, but which also - provide bindings to Python (and perhaps other langauges) in subdirectories. + provide bindings to Python (and perhaps other languages) in subdirectories. Versioneer will look for `.git` in parent directories, and most operations should get the right version string. However `pip` and `setuptools` have bugs @@ -193,9 +219,9 @@ Pip-8.1.1 is known to have this problem, but hopefully it will get fixed in some later version. -[Bug #38](https://github.com/warner/python-versioneer/issues/38) is tracking +[Bug #38](https://github.com/python-versioneer/python-versioneer/issues/38) is tracking this issue. The discussion in -[PR #61](https://github.com/warner/python-versioneer/pull/61) describes the +[PR #61](https://github.com/python-versioneer/python-versioneer/pull/61) describes the issue from the Versioneer side in more detail. [pip PR#3176](https://github.com/pypa/pip/pull/3176) and [pip PR#3615](https://github.com/pypa/pip/pull/3615) contain work to improve @@ -223,31 +249,20 @@ cause egg_info to be rebuilt (including `sdist`, `wheel`, and installing into a different virtualenv), so this can be surprising. -[Bug #83](https://github.com/warner/python-versioneer/issues/83) describes +[Bug #83](https://github.com/python-versioneer/python-versioneer/issues/83) describes this one, but upgrading to a newer version of setuptools should probably resolve it. -### Unicode version strings - -While Versioneer works (and is continually tested) with both Python 2 and -Python 3, it is not entirely consistent with bytes-vs-unicode distinctions. -Newer releases probably generate unicode version strings on py2. It's not -clear that this is wrong, but it may be surprising for applications when then -write these strings to a network connection or include them in bytes-oriented -APIs like cryptographic checksums. - -[Bug #71](https://github.com/warner/python-versioneer/issues/71) investigates -this question. - ## Updating Versioneer To upgrade your project to a new release of Versioneer, do the following: * install the new Versioneer (`pip install -U versioneer` or equivalent) -* edit `setup.cfg`, if necessary, to include any new configuration settings - indicated by the release notes. See [UPGRADING](./UPGRADING.md) for details. -* re-run `versioneer install` in your source tree, to replace +* edit `setup.cfg` and `pyproject.toml`, if necessary, + to include any new configuration settings indicated by the release notes. + See [UPGRADING](./UPGRADING.md) for details. +* re-run `versioneer install --[no-]vendor` in your source tree, to replace `SRC/_version.py` * commit any changed files @@ -264,36 +279,70 @@ direction and include code from all supported VCS systems, reducing the number of intermediate scripts. +## Similar projects + +* [setuptools_scm](https://github.com/pypa/setuptools_scm/) - a non-vendored build-time + dependency +* [minver](https://github.com/jbweston/miniver) - a lightweight reimplementation of + versioneer +* [versioningit](https://github.com/jwodder/versioningit) - a PEP 518-based setuptools + plugin ## License To make Versioneer easier to embed, all its code is dedicated to the public domain. The `_version.py` that it creates is also in the public domain. -Specifically, both are released under the Creative Commons "Public Domain -Dedication" license (CC0-1.0), as described in -https://creativecommons.org/publicdomain/zero/1.0/ . +Specifically, both are released under the "Unlicense", as described in +https://unlicense.org/. -""" +[pypi-image]: https://img.shields.io/pypi/v/versioneer.svg +[pypi-url]: https://pypi.python.org/pypi/versioneer/ +[travis-image]: +https://img.shields.io/travis/com/python-versioneer/python-versioneer.svg +[travis-url]: https://travis-ci.com/github/python-versioneer/python-versioneer -from __future__ import print_function +""" +# pylint:disable=invalid-name,import-outside-toplevel,missing-function-docstring +# pylint:disable=missing-class-docstring,too-many-branches,too-many-statements +# pylint:disable=raise-missing-from,too-many-lines,too-many-locals,import-error +# pylint:disable=too-few-public-methods,redefined-outer-name,consider-using-with +# pylint:disable=attribute-defined-outside-init,too-many-arguments -try: - import configparser -except ImportError: - import ConfigParser as configparser +import configparser import errno import json import os import re import subprocess import sys +from pathlib import Path +from typing import Any, Callable, cast, Dict, List, Optional, Tuple, Union +from typing import NoReturn +import functools + +have_tomllib = True +if sys.version_info >= (3, 11): + import tomllib +else: + try: + import tomli as tomllib + except ImportError: + have_tomllib = False class VersioneerConfig: """Container for Versioneer configuration parameters.""" + VCS: str + style: str + tag_prefix: str + versionfile_source: str + versionfile_build: Optional[str] + parentdir_prefix: Optional[str] + verbose: Optional[bool] -def get_root(): + +def get_root() -> str: """Get the project root directory. We require that all commands are run from the project root, i.e. the @@ -301,20 +350,28 @@ def get_root(): """ root = os.path.realpath(os.path.abspath(os.getcwd())) setup_py = os.path.join(root, "setup.py") + pyproject_toml = os.path.join(root, "pyproject.toml") versioneer_py = os.path.join(root, "versioneer.py") - if not (os.path.exists(setup_py) or os.path.exists(versioneer_py)): + if not ( + os.path.exists(setup_py) + or os.path.exists(pyproject_toml) + or os.path.exists(versioneer_py) + ): # allow 'python path/to/setup.py COMMAND' root = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) setup_py = os.path.join(root, "setup.py") + pyproject_toml = os.path.join(root, "pyproject.toml") versioneer_py = os.path.join(root, "versioneer.py") - if not (os.path.exists(setup_py) or os.path.exists(versioneer_py)): - err = ( - "Versioneer was unable to run the project root directory. " - "Versioneer requires setup.py to be executed from " - "its immediate directory (like 'python setup.py COMMAND'), " - "or in a way that lets it use sys.argv[0] to find the root " - "(like 'python path/to/setup.py COMMAND')." - ) + if not ( + os.path.exists(setup_py) + or os.path.exists(pyproject_toml) + or os.path.exists(versioneer_py) + ): + err = ("Versioneer was unable to run the project root directory. " + "Versioneer requires setup.py to be executed from " + "its immediate directory (like 'python setup.py COMMAND'), " + "or in a way that lets it use sys.argv[0] to find the root " + "(like 'python path/to/setup.py COMMAND').") raise VersioneerBadRootError(err) try: # Certain runtime workflows (setup.py install/develop in a setuptools @@ -323,46 +380,62 @@ def get_root(): # module-import table will cache the first one. So we can't use # os.path.dirname(__file__), as that will find whichever # versioneer.py was first imported, even in later projects. - me = os.path.realpath(os.path.abspath(__file__)) - me_dir = os.path.normcase(os.path.splitext(me)[0]) + my_path = os.path.realpath(os.path.abspath(__file__)) + me_dir = os.path.normcase(os.path.splitext(my_path)[0]) vsr_dir = os.path.normcase(os.path.splitext(versioneer_py)[0]) - if me_dir != vsr_dir: - print( - "Warning: build in %s is using versioneer.py from %s" - % (os.path.dirname(me), versioneer_py) - ) + if me_dir != vsr_dir and "VERSIONEER_PEP518" not in globals(): + print("Warning: build in %s is using versioneer.py from %s" + % (os.path.dirname(my_path), versioneer_py)) except NameError: pass return root -def get_config_from_root(root): +def get_config_from_root(root: str) -> VersioneerConfig: """Read the project setup.cfg file to determine Versioneer config.""" - # This might raise EnvironmentError (if setup.cfg is missing), or + # This might raise OSError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . - setup_cfg = os.path.join(root, "setup.cfg") - parser = configparser.SafeConfigParser() - with open(setup_cfg, "r") as f: - parser.readfp(f) - VCS = parser.get("versioneer", "VCS") # mandatory - - def get(parser, name): - if parser.has_option("versioneer", name): - return parser.get("versioneer", name) - return None + root_pth = Path(root) + pyproject_toml = root_pth / "pyproject.toml" + setup_cfg = root_pth / "setup.cfg" + section: Union[Dict[str, Any], configparser.SectionProxy, None] = None + if pyproject_toml.exists() and have_tomllib: + try: + with open(pyproject_toml, 'rb') as fobj: + pp = tomllib.load(fobj) + section = pp['tool']['versioneer'] + except (tomllib.TOMLDecodeError, KeyError) as e: + print(f"Failed to load config from {pyproject_toml}: {e}") + print("Try to load it from setup.cfg") + if not section: + parser = configparser.ConfigParser() + with open(setup_cfg) as cfg_file: + parser.read_file(cfg_file) + parser.get("versioneer", "VCS") # raise error if missing + + section = parser["versioneer"] + + # `cast`` really shouldn't be used, but its simplest for the + # common VersioneerConfig users at the moment. We verify against + # `None` values elsewhere where it matters cfg = VersioneerConfig() - cfg.VCS = VCS - cfg.style = get(parser, "style") or "" - cfg.versionfile_source = get(parser, "versionfile_source") - cfg.versionfile_build = get(parser, "versionfile_build") - cfg.tag_prefix = get(parser, "tag_prefix") - if cfg.tag_prefix in ("''", '""'): + cfg.VCS = section['VCS'] + cfg.style = section.get("style", "") + cfg.versionfile_source = cast(str, section.get("versionfile_source")) + cfg.versionfile_build = section.get("versionfile_build") + cfg.tag_prefix = cast(str, section.get("tag_prefix")) + if cfg.tag_prefix in ("''", '""', None): cfg.tag_prefix = "" - cfg.parentdir_prefix = get(parser, "parentdir_prefix") - cfg.verbose = get(parser, "verbose") + cfg.parentdir_prefix = section.get("parentdir_prefix") + if isinstance(section, configparser.SectionProxy): + # Make sure configparser translates to bool + cfg.verbose = section.getboolean("verbose") + else: + cfg.verbose = section.get("verbose") + return cfg @@ -371,41 +444,48 @@ class NotThisMethod(Exception): # these dictionaries contain VCS-specific tools -LONG_VERSION_PY = {} -HANDLERS = {} +LONG_VERSION_PY: Dict[str, str] = {} +HANDLERS: Dict[str, Dict[str, Callable]] = {} -def register_vcs_handler(vcs, method): # decorator - """Decorator to mark a method as the handler for a particular VCS.""" - - def decorate(f): +def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator + """Create decorator to mark a method as the handler of a VCS.""" + def decorate(f: Callable) -> Callable: """Store f in HANDLERS[vcs][method].""" - if vcs not in HANDLERS: - HANDLERS[vcs] = {} - HANDLERS[vcs][method] = f + HANDLERS.setdefault(vcs, {})[method] = f return f - return decorate -def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None): +def run_command( + commands: List[str], + args: List[str], + cwd: Optional[str] = None, + verbose: bool = False, + hide_stderr: bool = False, + env: Optional[Dict[str, str]] = None, +) -> Tuple[Optional[str], Optional[int]]: """Call the given command(s).""" assert isinstance(commands, list) - p = None - for c in commands: + process = None + + popen_kwargs: Dict[str, Any] = {} + if sys.platform == "win32": + # This hides the console window if pythonw.exe is used + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + popen_kwargs["startupinfo"] = startupinfo + + for command in commands: try: - dispcmd = str([c] + args) + dispcmd = str([command] + args) # remember shell=False, so use git.cmd on windows, not just git - p = subprocess.Popen( - [c] + args, - cwd=cwd, - env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr else None), - ) + process = subprocess.Popen([command] + args, cwd=cwd, env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr + else None), **popen_kwargs) break - except EnvironmentError: - e = sys.exc_info()[1] + except OSError as e: if e.errno == errno.ENOENT: continue if verbose: @@ -416,28 +496,25 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= if verbose: print("unable to find command, tried %s" % (commands,)) return None, None - stdout = p.communicate()[0].strip() - if sys.version_info[0] >= 3: - stdout = stdout.decode() - if p.returncode != 0: + stdout = process.communicate()[0].strip().decode() + if process.returncode != 0: if verbose: print("unable to run %s (error)" % dispcmd) print("stdout was %s" % stdout) - return None, p.returncode - return stdout, p.returncode + return None, process.returncode + return stdout, process.returncode -LONG_VERSION_PY[ - "git" -] = ''' +LONG_VERSION_PY['git'] = r''' # This file helps to compute a version number in source trees obtained from # git-archive tarball (such as those provided by githubs download-from-tag # feature). Distribution tarballs (built by setup.py sdist) and build # directories (produced by setup.py build) will contain a much shorter file # that just contains the computed version number. -# This file is released into the public domain. Generated by -# versioneer-0.18 (https://github.com/warner/python-versioneer) +# This file is released into the public domain. +# Generated by versioneer-0.29 +# https://github.com/python-versioneer/python-versioneer """Git implementation of _version.py.""" @@ -446,9 +523,11 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= import re import subprocess import sys +from typing import Any, Callable, Dict, List, Optional, Tuple +import functools -def get_keywords(): +def get_keywords() -> Dict[str, str]: """Get the keywords needed to look up the version information.""" # these strings will be replaced by git during git-archive. # setup.py/versioneer.py will grep for the variable names, so they must @@ -464,8 +543,15 @@ def get_keywords(): class VersioneerConfig: """Container for Versioneer configuration parameters.""" + VCS: str + style: str + tag_prefix: str + parentdir_prefix: str + versionfile_source: str + verbose: bool + -def get_config(): +def get_config() -> VersioneerConfig: """Create, populate and return the VersioneerConfig() object.""" # these strings are filled in when 'setup.py versioneer' creates # _version.py @@ -483,13 +569,13 @@ class NotThisMethod(Exception): """Exception raised if a method is not valid for the current scenario.""" -LONG_VERSION_PY = {} -HANDLERS = {} +LONG_VERSION_PY: Dict[str, str] = {} +HANDLERS: Dict[str, Dict[str, Callable]] = {} -def register_vcs_handler(vcs, method): # decorator - """Decorator to mark a method as the handler for a particular VCS.""" - def decorate(f): +def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator + """Create decorator to mark a method as the handler of a VCS.""" + def decorate(f: Callable) -> Callable: """Store f in HANDLERS[vcs][method].""" if vcs not in HANDLERS: HANDLERS[vcs] = {} @@ -498,22 +584,35 @@ def decorate(f): return decorate -def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, - env=None): +def run_command( + commands: List[str], + args: List[str], + cwd: Optional[str] = None, + verbose: bool = False, + hide_stderr: bool = False, + env: Optional[Dict[str, str]] = None, +) -> Tuple[Optional[str], Optional[int]]: """Call the given command(s).""" assert isinstance(commands, list) - p = None - for c in commands: + process = None + + popen_kwargs: Dict[str, Any] = {} + if sys.platform == "win32": + # This hides the console window if pythonw.exe is used + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + popen_kwargs["startupinfo"] = startupinfo + + for command in commands: try: - dispcmd = str([c] + args) + dispcmd = str([command] + args) # remember shell=False, so use git.cmd on windows, not just git - p = subprocess.Popen([c] + args, cwd=cwd, env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr - else None)) + process = subprocess.Popen([command] + args, cwd=cwd, env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr + else None), **popen_kwargs) break - except EnvironmentError: - e = sys.exc_info()[1] + except OSError as e: if e.errno == errno.ENOENT: continue if verbose: @@ -524,18 +623,20 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, if verbose: print("unable to find command, tried %%s" %% (commands,)) return None, None - stdout = p.communicate()[0].strip() - if sys.version_info[0] >= 3: - stdout = stdout.decode() - if p.returncode != 0: + stdout = process.communicate()[0].strip().decode() + if process.returncode != 0: if verbose: print("unable to run %%s (error)" %% dispcmd) print("stdout was %%s" %% stdout) - return None, p.returncode - return stdout, p.returncode + return None, process.returncode + return stdout, process.returncode -def versions_from_parentdir(parentdir_prefix, root, verbose): +def versions_from_parentdir( + parentdir_prefix: str, + root: str, + verbose: bool, +) -> Dict[str, Any]: """Try to determine the version from the parent directory name. Source tarballs conventionally unpack into a directory that includes both @@ -544,15 +645,14 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): """ rootdirs = [] - for i in range(3): + for _ in range(3): dirname = os.path.basename(root) if dirname.startswith(parentdir_prefix): return {"version": dirname[len(parentdir_prefix):], "full-revisionid": None, "dirty": False, "error": None, "date": None} - else: - rootdirs.append(root) - root = os.path.dirname(root) # up a level + rootdirs.append(root) + root = os.path.dirname(root) # up a level if verbose: print("Tried directories %%s but none started with prefix %%s" %% @@ -561,41 +661,48 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): @register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs): +def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: """Extract version information from the given file.""" # the code embedded in _version.py can just fetch the value of these # keywords. When used from setup.py, we don't want to import _version.py, # so we do it with a regexp instead. This function is not used from # _version.py. - keywords = {} + keywords: Dict[str, str] = {} try: - f = open(versionfile_abs, "r") - for line in f.readlines(): - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - f.close() - except EnvironmentError: + with open(versionfile_abs, "r") as fobj: + for line in fobj: + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + except OSError: pass return keywords @register_vcs_handler("git", "keywords") -def git_versions_from_keywords(keywords, tag_prefix, verbose): +def git_versions_from_keywords( + keywords: Dict[str, str], + tag_prefix: str, + verbose: bool, +) -> Dict[str, Any]: """Get version information from git keywords.""" - if not keywords: - raise NotThisMethod("no keywords at all, weird") + if "refnames" not in keywords: + raise NotThisMethod("Short version file found") date = keywords.get("date") if date is not None: + # Use only the last line. Previous lines may contain GPG signature + # information. + date = date.splitlines()[-1] + # git-2.2.0 added "%%cI", which expands to an ISO-8601 -compliant # datestamp. However we prefer "%%ci" (which expands to an "ISO-8601 # -like" string, which we must then edit to make compliant), because @@ -608,11 +715,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = set([r.strip() for r in refnames.strip("()").split(",")]) + refs = {r.strip() for r in refnames.strip("()").split(",")} # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %%d @@ -620,8 +727,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # refs/heads/ and refs/tags/ prefixes that would let us distinguish # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "main". - tags = set([r for r in refs if re.search(r'\d', r)]) + # "stabilization", as well as "HEAD" and "master". + tags = {r for r in refs if re.search(r'\d', r)} if verbose: print("discarding '%%s', no digits" %% ",".join(refs - tags)) if verbose: @@ -630,6 +737,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # sorting will prefer e.g. "2.0" over "2.0rc1" if ref.startswith(tag_prefix): r = ref[len(tag_prefix):] + # Filter out refs that exactly match prefix or that don't start + # with a number once the prefix is stripped (mostly a concern + # when prefix is '') + if not re.match(r'\d', r): + continue if verbose: print("picking %%s" %% r) return {"version": r, @@ -645,7 +757,12 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): @register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): +def git_pieces_from_vcs( + tag_prefix: str, + root: str, + verbose: bool, + runner: Callable = run_command +) -> Dict[str, Any]: """Get version from 'git describe' in the root of the source tree. This only gets called if the git-archive 'subst' keywords were *not* @@ -656,8 +773,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if sys.platform == "win32": GITS = ["git.cmd", "git.exe"] - out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, - hide_stderr=True) + # GIT_DIR can interfere with correct operation of Versioneer. + # It may be intended to be passed to the Versioneer-versioned project, + # but that should not change where we get our version from. + env = os.environ.copy() + env.pop("GIT_DIR", None) + runner = functools.partial(runner, env=env) + + _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, + hide_stderr=not verbose) if rc != 0: if verbose: print("Directory %%s not under git control" %% root) @@ -665,24 +789,57 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", - "--always", "--long", - "--match", "%%s*" %% tag_prefix], - cwd=root) + describe_out, rc = runner(GITS, [ + "describe", "--tags", "--dirty", "--always", "--long", + "--match", f"{tag_prefix}[[:digit:]]*" + ], cwd=root) # --long was added in git-1.5.5 if describe_out is None: raise NotThisMethod("'git describe' failed") describe_out = describe_out.strip() - full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) if full_out is None: raise NotThisMethod("'git rev-parse' failed") full_out = full_out.strip() - pieces = {} + pieces: Dict[str, Any] = {} pieces["long"] = full_out pieces["short"] = full_out[:7] # maybe improved later pieces["error"] = None + branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], + cwd=root) + # --abbrev-ref was added in git-1.6.3 + if rc != 0 or branch_name is None: + raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") + branch_name = branch_name.strip() + + if branch_name == "HEAD": + # If we aren't exactly on a branch, pick a branch which represents + # the current commit. If all else fails, we are on a branchless + # commit. + branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) + # --contains was added in git-1.5.4 + if rc != 0 or branches is None: + raise NotThisMethod("'git branch --contains' returned error") + branches = branches.split("\n") + + # Remove the first line if we're running detached + if "(" in branches[0]: + branches.pop(0) + + # Strip off the leading "* " from the list of branches. + branches = [branch[2:] for branch in branches] + if "master" in branches: + branch_name = "master" + elif not branches: + branch_name = None + else: + # Pick the first branch that is returned. Good or bad. + branch_name = branches[0] + + pieces["branch"] = branch_name + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] # TAG might have hyphens. git_describe = describe_out @@ -699,7 +856,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): # TAG-NUM-gHEX mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) if not mo: - # unparseable. Maybe git-describe is misbehaving? + # unparsable. Maybe git-describe is misbehaving? pieces["error"] = ("unable to parse git-describe output: '%%s'" %% describe_out) return pieces @@ -724,26 +881,27 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): else: # HEX: no tags pieces["closest-tag"] = None - count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], - cwd=root) - pieces["distance"] = int(count_out) # total number of commits + out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) + pieces["distance"] = len(out.split()) # total number of commits # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = run_command(GITS, ["show", "-s", "--format=%%ci", "HEAD"], - cwd=root)[0].strip() + date = runner(GITS, ["show", "-s", "--format=%%ci", "HEAD"], cwd=root)[0].strip() + # Use only the last line. Previous lines may contain GPG signature + # information. + date = date.splitlines()[-1] pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) return pieces -def plus_or_dot(pieces): +def plus_or_dot(pieces: Dict[str, Any]) -> str: """Return a + if we don't already have one, else return a .""" if "+" in pieces.get("closest-tag", ""): return "." return "+" -def render_pep440(pieces): +def render_pep440(pieces: Dict[str, Any]) -> str: """Build up version string, with post-release "local version identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you @@ -768,23 +926,71 @@ def render_pep440(pieces): return rendered -def render_pep440_pre(pieces): - """TAG[.post.devDISTANCE] -- No -dirty. +def render_pep440_branch(pieces: Dict[str, Any]) -> str: + """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . + + The ".dev0" means not master branch. Note that .dev0 sorts backwards + (a feature branch will appear "older" than the master branch). Exceptions: - 1: no tags. 0.post.devDISTANCE + 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "%%d.g%%s" %% (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0" + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += "+untagged.%%d.g%%s" %% (pieces["distance"], + pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: + """Split pep440 version string at the post-release segment. + + Returns the release segments before the post-release and the + post-release version number (or -1 if no post-release segment is present). + """ + vc = str.split(ver, ".post") + return vc[0], int(vc[1] or 0) if len(vc) == 2 else None + + +def render_pep440_pre(pieces: Dict[str, Any]) -> str: + """TAG[.postN.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post0.devDISTANCE + """ + if pieces["closest-tag"]: if pieces["distance"]: - rendered += ".post.dev%%d" %% pieces["distance"] + # update the post release segment + tag_version, post_version = pep440_split_post(pieces["closest-tag"]) + rendered = tag_version + if post_version is not None: + rendered += ".post%%d.dev%%d" %% (post_version + 1, pieces["distance"]) + else: + rendered += ".post0.dev%%d" %% (pieces["distance"]) + else: + # no commits, use the tag as the version + rendered = pieces["closest-tag"] else: # exception #1 - rendered = "0.post.dev%%d" %% pieces["distance"] + rendered = "0.post0.dev%%d" %% pieces["distance"] return rendered -def render_pep440_post(pieces): +def render_pep440_post(pieces: Dict[str, Any]) -> str: """TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards @@ -811,12 +1017,41 @@ def render_pep440_post(pieces): return rendered -def render_pep440_old(pieces): +def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: + """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . + + The ".dev0" means not master branch. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%%d" %% pieces["distance"] + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%%s" %% pieces["short"] + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0.post%%d" %% pieces["distance"] + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += "+g%%s" %% pieces["short"] + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_old(pieces: Dict[str, Any]) -> str: """TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. - Eexceptions: + Exceptions: 1: no tags. 0.postDISTANCE[.dev0] """ if pieces["closest-tag"]: @@ -833,7 +1068,7 @@ def render_pep440_old(pieces): return rendered -def render_git_describe(pieces): +def render_git_describe(pieces: Dict[str, Any]) -> str: """TAG[-DISTANCE-gHEX][-dirty]. Like 'git describe --tags --dirty --always'. @@ -853,7 +1088,7 @@ def render_git_describe(pieces): return rendered -def render_git_describe_long(pieces): +def render_git_describe_long(pieces: Dict[str, Any]) -> str: """TAG-DISTANCE-gHEX[-dirty]. Like 'git describe --tags --dirty --always -long'. @@ -873,7 +1108,7 @@ def render_git_describe_long(pieces): return rendered -def render(pieces, style): +def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: """Render the given version pieces into the requested style.""" if pieces["error"]: return {"version": "unknown", @@ -887,10 +1122,14 @@ def render(pieces, style): if style == "pep440": rendered = render_pep440(pieces) + elif style == "pep440-branch": + rendered = render_pep440_branch(pieces) elif style == "pep440-pre": rendered = render_pep440_pre(pieces) elif style == "pep440-post": rendered = render_pep440_post(pieces) + elif style == "pep440-post-branch": + rendered = render_pep440_post_branch(pieces) elif style == "pep440-old": rendered = render_pep440_old(pieces) elif style == "git-describe": @@ -905,7 +1144,7 @@ def render(pieces, style): "date": pieces.get("date")} -def get_versions(): +def get_versions() -> Dict[str, Any]: """Get version information or return default if unable to do so.""" # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have # __file__, we can work backwards from there to the root. Some @@ -926,7 +1165,7 @@ def get_versions(): # versionfile_source is the relative path from the top of the source # tree (where the .git directory might live) to this file. Invert # this to find the root from __file__. - for i in cfg.versionfile_source.split('/'): + for _ in cfg.versionfile_source.split('/'): root = os.path.dirname(root) except NameError: return {"version": "0+unknown", "full-revisionid": None, @@ -953,41 +1192,48 @@ def get_versions(): @register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs): +def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: """Extract version information from the given file.""" # the code embedded in _version.py can just fetch the value of these # keywords. When used from setup.py, we don't want to import _version.py, # so we do it with a regexp instead. This function is not used from # _version.py. - keywords = {} + keywords: Dict[str, str] = {} try: - f = open(versionfile_abs, "r") - for line in f.readlines(): - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - f.close() - except EnvironmentError: + with open(versionfile_abs, "r") as fobj: + for line in fobj: + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + except OSError: pass return keywords @register_vcs_handler("git", "keywords") -def git_versions_from_keywords(keywords, tag_prefix, verbose): +def git_versions_from_keywords( + keywords: Dict[str, str], + tag_prefix: str, + verbose: bool, +) -> Dict[str, Any]: """Get version information from git keywords.""" - if not keywords: - raise NotThisMethod("no keywords at all, weird") + if "refnames" not in keywords: + raise NotThisMethod("Short version file found") date = keywords.get("date") if date is not None: + # Use only the last line. Previous lines may contain GPG signature + # information. + date = date.splitlines()[-1] + # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 # -like" string, which we must then edit to make compliant), because @@ -1000,11 +1246,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = set([r.strip() for r in refnames.strip("()").split(",")]) + refs = {r.strip() for r in refnames.strip("()").split(",")} # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)]) + tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d @@ -1012,8 +1258,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # refs/heads/ and refs/tags/ prefixes that would let us distinguish # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "main". - tags = set([r for r in refs if re.search(r"\d", r)]) + # "stabilization", as well as "HEAD" and "master". + tags = {r for r in refs if re.search(r'\d', r)} if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: @@ -1021,30 +1267,33 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): for ref in sorted(tags): # sorting will prefer e.g. "2.0" over "2.0rc1" if ref.startswith(tag_prefix): - r = ref[len(tag_prefix) :] + r = ref[len(tag_prefix):] + # Filter out refs that exactly match prefix or that don't start + # with a number once the prefix is stripped (mostly a concern + # when prefix is '') + if not re.match(r'\d', r): + continue if verbose: print("picking %s" % r) - return { - "version": r, - "full-revisionid": keywords["full"].strip(), - "dirty": False, - "error": None, - "date": date, - } + return {"version": r, + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": None, + "date": date} # no suitable tags, so version is "0+unknown", but full hex is still there if verbose: print("no suitable tags, using unknown + full revision id") - return { - "version": "0+unknown", - "full-revisionid": keywords["full"].strip(), - "dirty": False, - "error": "no suitable tags", - "date": None, - } + return {"version": "0+unknown", + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": "no suitable tags", "date": None} @register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): +def git_pieces_from_vcs( + tag_prefix: str, + root: str, + verbose: bool, + runner: Callable = run_command +) -> Dict[str, Any]: """Get version from 'git describe' in the root of the source tree. This only gets called if the git-archive 'subst' keywords were *not* @@ -1055,7 +1304,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if sys.platform == "win32": GITS = ["git.cmd", "git.exe"] - out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True) + # GIT_DIR can interfere with correct operation of Versioneer. + # It may be intended to be passed to the Versioneer-versioned project, + # but that should not change where we get our version from. + env = os.environ.copy() + env.pop("GIT_DIR", None) + runner = functools.partial(runner, env=env) + + _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, + hide_stderr=not verbose) if rc != 0: if verbose: print("Directory %s not under git control" % root) @@ -1063,33 +1320,57 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = run_command( - GITS, - [ - "describe", - "--tags", - "--dirty", - "--always", - "--long", - "--match", - "%s*" % tag_prefix, - ], - cwd=root, - ) + describe_out, rc = runner(GITS, [ + "describe", "--tags", "--dirty", "--always", "--long", + "--match", f"{tag_prefix}[[:digit:]]*" + ], cwd=root) # --long was added in git-1.5.5 if describe_out is None: raise NotThisMethod("'git describe' failed") describe_out = describe_out.strip() - full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) if full_out is None: raise NotThisMethod("'git rev-parse' failed") full_out = full_out.strip() - pieces = {} + pieces: Dict[str, Any] = {} pieces["long"] = full_out pieces["short"] = full_out[:7] # maybe improved later pieces["error"] = None + branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], + cwd=root) + # --abbrev-ref was added in git-1.6.3 + if rc != 0 or branch_name is None: + raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") + branch_name = branch_name.strip() + + if branch_name == "HEAD": + # If we aren't exactly on a branch, pick a branch which represents + # the current commit. If all else fails, we are on a branchless + # commit. + branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) + # --contains was added in git-1.5.4 + if rc != 0 or branches is None: + raise NotThisMethod("'git branch --contains' returned error") + branches = branches.split("\n") + + # Remove the first line if we're running detached + if "(" in branches[0]: + branches.pop(0) + + # Strip off the leading "* " from the list of branches. + branches = [branch[2:] for branch in branches] + if "master" in branches: + branch_name = "master" + elif not branches: + branch_name = None + else: + # Pick the first branch that is returned. Good or bad. + branch_name = branches[0] + + pieces["branch"] = branch_name + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] # TAG might have hyphens. git_describe = describe_out @@ -1098,16 +1379,17 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): dirty = git_describe.endswith("-dirty") pieces["dirty"] = dirty if dirty: - git_describe = git_describe[: git_describe.rindex("-dirty")] + git_describe = git_describe[:git_describe.rindex("-dirty")] # now we have TAG-NUM-gHEX or HEX if "-" in git_describe: # TAG-NUM-gHEX - mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe) + mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) if not mo: - # unparseable. Maybe git-describe is misbehaving? - pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out + # unparsable. Maybe git-describe is misbehaving? + pieces["error"] = ("unable to parse git-describe output: '%s'" + % describe_out) return pieces # tag @@ -1116,12 +1398,10 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if verbose: fmt = "tag '%s' doesn't start with prefix '%s'" print(fmt % (full_tag, tag_prefix)) - pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % ( - full_tag, - tag_prefix, - ) + pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" + % (full_tag, tag_prefix)) return pieces - pieces["closest-tag"] = full_tag[len(tag_prefix) :] + pieces["closest-tag"] = full_tag[len(tag_prefix):] # distance: number of commits since tag pieces["distance"] = int(mo.group(2)) @@ -1132,19 +1412,20 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): else: # HEX: no tags pieces["closest-tag"] = None - count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root) - pieces["distance"] = int(count_out) # total number of commits + out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) + pieces["distance"] = len(out.split()) # total number of commits # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[ - 0 - ].strip() + date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip() + # Use only the last line. Previous lines may contain GPG signature + # information. + date = date.splitlines()[-1] pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) return pieces -def do_vcs_install(manifest_in, versionfile_source, ipy): +def do_vcs_install(versionfile_source: str, ipy: Optional[str]) -> None: """Git-specific installation logic for Versioneer. For Git, this means creating/changing .gitattributes to mark _version.py @@ -1153,36 +1434,40 @@ def do_vcs_install(manifest_in, versionfile_source, ipy): GITS = ["git"] if sys.platform == "win32": GITS = ["git.cmd", "git.exe"] - files = [manifest_in, versionfile_source] + files = [versionfile_source] if ipy: files.append(ipy) - try: - me = __file__ - if me.endswith(".pyc") or me.endswith(".pyo"): - me = os.path.splitext(me)[0] + ".py" - versioneer_file = os.path.relpath(me) - except NameError: - versioneer_file = "versioneer.py" - files.append(versioneer_file) + if "VERSIONEER_PEP518" not in globals(): + try: + my_path = __file__ + if my_path.endswith((".pyc", ".pyo")): + my_path = os.path.splitext(my_path)[0] + ".py" + versioneer_file = os.path.relpath(my_path) + except NameError: + versioneer_file = "versioneer.py" + files.append(versioneer_file) present = False try: - f = open(".gitattributes", "r") - for line in f.readlines(): - if line.strip().startswith(versionfile_source): - if "export-subst" in line.strip().split()[1:]: - present = True - f.close() - except EnvironmentError: + with open(".gitattributes", "r") as fobj: + for line in fobj: + if line.strip().startswith(versionfile_source): + if "export-subst" in line.strip().split()[1:]: + present = True + break + except OSError: pass if not present: - f = open(".gitattributes", "a+") - f.write("%s export-subst\n" % versionfile_source) - f.close() + with open(".gitattributes", "a+") as fobj: + fobj.write(f"{versionfile_source} export-subst\n") files.append(".gitattributes") run_command(GITS, ["add", "--"] + files) -def versions_from_parentdir(parentdir_prefix, root, verbose): +def versions_from_parentdir( + parentdir_prefix: str, + root: str, + verbose: bool, +) -> Dict[str, Any]: """Try to determine the version from the parent directory name. Source tarballs conventionally unpack into a directory that includes both @@ -1191,30 +1476,23 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): """ rootdirs = [] - for i in range(3): + for _ in range(3): dirname = os.path.basename(root) if dirname.startswith(parentdir_prefix): - return { - "version": dirname[len(parentdir_prefix) :], - "full-revisionid": None, - "dirty": False, - "error": None, - "date": None, - } - else: - rootdirs.append(root) - root = os.path.dirname(root) # up a level + return {"version": dirname[len(parentdir_prefix):], + "full-revisionid": None, + "dirty": False, "error": None, "date": None} + rootdirs.append(root) + root = os.path.dirname(root) # up a level if verbose: - print( - "Tried directories %s but none started with prefix %s" - % (str(rootdirs), parentdir_prefix) - ) + print("Tried directories %s but none started with prefix %s" % + (str(rootdirs), parentdir_prefix)) raise NotThisMethod("rootdir doesn't start with parentdir_prefix") SHORT_VERSION_PY = """ -# This file was generated by 'versioneer.py' (0.18) from +# This file was generated by 'versioneer.py' (0.29) from # revision-control system data, or from the parent directory name of an # unpacked source archive. Distribution tarballs contain a pre-generated copy # of this file. @@ -1231,43 +1509,41 @@ def get_versions(): """ -def versions_from_file(filename): +def versions_from_file(filename: str) -> Dict[str, Any]: """Try to determine the version from _version.py if present.""" try: with open(filename) as f: contents = f.read() - except EnvironmentError: + except OSError: raise NotThisMethod("unable to read _version.py") - mo = re.search( - r"version_json = '''\n(.*)''' # END VERSION_JSON", contents, re.M | re.S - ) + mo = re.search(r"version_json = '''\n(.*)''' # END VERSION_JSON", + contents, re.M | re.S) if not mo: - mo = re.search( - r"version_json = '''\r\n(.*)''' # END VERSION_JSON", contents, re.M | re.S - ) + mo = re.search(r"version_json = '''\r\n(.*)''' # END VERSION_JSON", + contents, re.M | re.S) if not mo: raise NotThisMethod("no version_json in _version.py") return json.loads(mo.group(1)) -def write_to_version_file(filename, versions): +def write_to_version_file(filename: str, versions: Dict[str, Any]) -> None: """Write the given version number to the given _version.py file.""" - os.unlink(filename) - contents = json.dumps(versions, sort_keys=True, indent=1, separators=(",", ": ")) + contents = json.dumps(versions, sort_keys=True, + indent=1, separators=(",", ": ")) with open(filename, "w") as f: f.write(SHORT_VERSION_PY % contents) print("set %s to '%s'" % (filename, versions["version"])) -def plus_or_dot(pieces): +def plus_or_dot(pieces: Dict[str, Any]) -> str: """Return a + if we don't already have one, else return a .""" if "+" in pieces.get("closest-tag", ""): return "." return "+" -def render_pep440(pieces): +def render_pep440(pieces: Dict[str, Any]) -> str: """Build up version string, with post-release "local version identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you @@ -1285,29 +1561,78 @@ def render_pep440(pieces): rendered += ".dirty" else: # exception #1 - rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"]) + rendered = "0+untagged.%d.g%s" % (pieces["distance"], + pieces["short"]) if pieces["dirty"]: rendered += ".dirty" return rendered -def render_pep440_pre(pieces): - """TAG[.post.devDISTANCE] -- No -dirty. +def render_pep440_branch(pieces: Dict[str, Any]) -> str: + """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . + + The ".dev0" means not master branch. Note that .dev0 sorts backwards + (a feature branch will appear "older" than the master branch). Exceptions: - 1: no tags. 0.post.devDISTANCE + 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0" + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += "+untagged.%d.g%s" % (pieces["distance"], + pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: + """Split pep440 version string at the post-release segment. + + Returns the release segments before the post-release and the + post-release version number (or -1 if no post-release segment is present). + """ + vc = str.split(ver, ".post") + return vc[0], int(vc[1] or 0) if len(vc) == 2 else None + + +def render_pep440_pre(pieces: Dict[str, Any]) -> str: + """TAG[.postN.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post0.devDISTANCE + """ + if pieces["closest-tag"]: if pieces["distance"]: - rendered += ".post.dev%d" % pieces["distance"] + # update the post release segment + tag_version, post_version = pep440_split_post(pieces["closest-tag"]) + rendered = tag_version + if post_version is not None: + rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"]) + else: + rendered += ".post0.dev%d" % (pieces["distance"]) + else: + # no commits, use the tag as the version + rendered = pieces["closest-tag"] else: # exception #1 - rendered = "0.post.dev%d" % pieces["distance"] + rendered = "0.post0.dev%d" % pieces["distance"] return rendered -def render_pep440_post(pieces): +def render_pep440_post(pieces: Dict[str, Any]) -> str: """TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards @@ -1334,12 +1659,41 @@ def render_pep440_post(pieces): return rendered -def render_pep440_old(pieces): +def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: + """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . + + The ".dev0" means not master branch. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%s" % pieces["short"] + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["branch"] != "master": + rendered += ".dev0" + rendered += "+g%s" % pieces["short"] + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_old(pieces: Dict[str, Any]) -> str: """TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. - Eexceptions: + Exceptions: 1: no tags. 0.postDISTANCE[.dev0] """ if pieces["closest-tag"]: @@ -1356,7 +1710,7 @@ def render_pep440_old(pieces): return rendered -def render_git_describe(pieces): +def render_git_describe(pieces: Dict[str, Any]) -> str: """TAG[-DISTANCE-gHEX][-dirty]. Like 'git describe --tags --dirty --always'. @@ -1376,7 +1730,7 @@ def render_git_describe(pieces): return rendered -def render_git_describe_long(pieces): +def render_git_describe_long(pieces: Dict[str, Any]) -> str: """TAG-DISTANCE-gHEX[-dirty]. Like 'git describe --tags --dirty --always -long'. @@ -1396,26 +1750,28 @@ def render_git_describe_long(pieces): return rendered -def render(pieces, style): +def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: """Render the given version pieces into the requested style.""" if pieces["error"]: - return { - "version": "unknown", - "full-revisionid": pieces.get("long"), - "dirty": None, - "error": pieces["error"], - "date": None, - } + return {"version": "unknown", + "full-revisionid": pieces.get("long"), + "dirty": None, + "error": pieces["error"], + "date": None} if not style or style == "default": style = "pep440" # the default if style == "pep440": rendered = render_pep440(pieces) + elif style == "pep440-branch": + rendered = render_pep440_branch(pieces) elif style == "pep440-pre": rendered = render_pep440_pre(pieces) elif style == "pep440-post": rendered = render_pep440_post(pieces) + elif style == "pep440-post-branch": + rendered = render_pep440_post_branch(pieces) elif style == "pep440-old": rendered = render_pep440_old(pieces) elif style == "git-describe": @@ -1425,20 +1781,16 @@ def render(pieces, style): else: raise ValueError("unknown style '%s'" % style) - return { - "version": rendered, - "full-revisionid": pieces["long"], - "dirty": pieces["dirty"], - "error": None, - "date": pieces.get("date"), - } + return {"version": rendered, "full-revisionid": pieces["long"], + "dirty": pieces["dirty"], "error": None, + "date": pieces.get("date")} class VersioneerBadRootError(Exception): """The project root directory is unknown or missing key files.""" -def get_versions(verbose=False): +def get_versions(verbose: bool = False) -> Dict[str, Any]: """Get the project version from whatever source is available. Returns dict with two keys: 'version' and 'full'. @@ -1453,10 +1805,9 @@ def get_versions(verbose=False): assert cfg.VCS is not None, "please set [versioneer]VCS= in setup.cfg" handlers = HANDLERS.get(cfg.VCS) assert handlers, "unrecognized VCS '%s'" % cfg.VCS - verbose = verbose or cfg.verbose - assert ( - cfg.versionfile_source is not None - ), "please set versioneer.versionfile_source" + verbose = verbose or bool(cfg.verbose) # `bool()` used to avoid `None` + assert cfg.versionfile_source is not None, \ + "please set versioneer.versionfile_source" assert cfg.tag_prefix is not None, "please set versioneer.tag_prefix" versionfile_abs = os.path.join(root, cfg.versionfile_source) @@ -1510,22 +1861,22 @@ def get_versions(verbose=False): if verbose: print("unable to compute version") - return { - "version": "0+unknown", - "full-revisionid": None, - "dirty": None, - "error": "unable to compute version", - "date": None, - } + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, "error": "unable to compute version", + "date": None} -def get_version(): +def get_version() -> str: """Get the short version string for this project.""" return get_versions()["version"] -def get_cmdclass(): - """Get the custom setuptools/distutils subclasses used by Versioneer.""" +def get_cmdclass(cmdclass: Optional[Dict[str, Any]] = None): + """Get the custom setuptools subclasses used by Versioneer. + + If the package uses a different cmdclass (e.g. one from numpy), it + should be provide as an argument. + """ if "versioneer" in sys.modules: del sys.modules["versioneer"] # this fixes the "python setup.py develop" case (also 'install' and @@ -1539,25 +1890,25 @@ def get_cmdclass(): # parent is protected against the child's "import versioneer". By # removing ourselves from sys.modules here, before the child build # happens, we protect the child from the parent's versioneer too. - # Also see https://github.com/warner/python-versioneer/issues/52 + # Also see https://github.com/python-versioneer/python-versioneer/issues/52 - cmds = {} + cmds = {} if cmdclass is None else cmdclass.copy() - # we add "version" to both distutils and setuptools - from distutils.core import Command + # we add "version" to setuptools + from setuptools import Command class cmd_version(Command): description = "report generated version string" - user_options = [] - boolean_options = [] + user_options: List[Tuple[str, str, str]] = [] + boolean_options: List[str] = [] - def initialize_options(self): + def initialize_options(self) -> None: pass - def finalize_options(self): + def finalize_options(self) -> None: pass - def run(self): + def run(self) -> None: vers = get_versions(verbose=True) print("Version: %s" % vers["version"]) print(" full-revisionid: %s" % vers.get("full-revisionid")) @@ -1565,10 +1916,9 @@ def run(self): print(" date: %s" % vers.get("date")) if vers["error"]: print(" error: %s" % vers["error"]) - cmds["version"] = cmd_version - # we override "build_py" in both distutils and setuptools + # we override "build_py" in setuptools # # most invocation pathways end up running build_py: # distutils/build -> build_py @@ -1583,30 +1933,68 @@ def run(self): # then does setup.py bdist_wheel, or sometimes setup.py install # setup.py egg_info -> ? + # pip install -e . and setuptool/editable_wheel will invoke build_py + # but the build_py command is not expected to copy any files. + # we override different "build_py" commands for both environments - if "setuptools" in sys.modules: - from setuptools.command.build_py import build_py as _build_py + if 'build_py' in cmds: + _build_py: Any = cmds['build_py'] else: - from distutils.command.build_py import build_py as _build_py + from setuptools.command.build_py import build_py as _build_py class cmd_build_py(_build_py): - def run(self): + def run(self) -> None: root = get_root() cfg = get_config_from_root(root) versions = get_versions() _build_py.run(self) + if getattr(self, "editable_mode", False): + # During editable installs `.py` and data files are + # not copied to build_lib + return # now locate _version.py in the new build/ directory and replace # it with an updated value if cfg.versionfile_build: - target_versionfile = os.path.join(self.build_lib, cfg.versionfile_build) + target_versionfile = os.path.join(self.build_lib, + cfg.versionfile_build) print("UPDATING %s" % target_versionfile) write_to_version_file(target_versionfile, versions) - cmds["build_py"] = cmd_build_py - if "cx_Freeze" in sys.modules: # cx_freeze enabled? - from cx_Freeze.dist import build_exe as _build_exe + if 'build_ext' in cmds: + _build_ext: Any = cmds['build_ext'] + else: + from setuptools.command.build_ext import build_ext as _build_ext + + class cmd_build_ext(_build_ext): + def run(self) -> None: + root = get_root() + cfg = get_config_from_root(root) + versions = get_versions() + _build_ext.run(self) + if self.inplace: + # build_ext --inplace will only build extensions in + # build/lib<..> dir with no _version.py to write to. + # As in place builds will already have a _version.py + # in the module dir, we do not need to write one. + return + # now locate _version.py in the new build/ directory and replace + # it with an updated value + if not cfg.versionfile_build: + return + target_versionfile = os.path.join(self.build_lib, + cfg.versionfile_build) + if not os.path.exists(target_versionfile): + print(f"Warning: {target_versionfile} does not exist, skipping " + "version update. This can happen if you are running build_ext " + "without first running build_py.") + return + print("UPDATING %s" % target_versionfile) + write_to_version_file(target_versionfile, versions) + cmds["build_ext"] = cmd_build_ext + if "cx_Freeze" in sys.modules: # cx_freeze enabled? + from cx_Freeze.dist import build_exe as _build_exe # type: ignore # nczeczulin reports that py2exe won't like the pep440-style string # as FILEVERSION, but it can be used for PRODUCTVERSION, e.g. # setup(console=[{ @@ -1615,7 +2003,7 @@ def run(self): # ... class cmd_build_exe(_build_exe): - def run(self): + def run(self) -> None: root = get_root() cfg = get_config_from_root(root) versions = get_versions() @@ -1627,28 +2015,24 @@ def run(self): os.unlink(target_versionfile) with open(cfg.versionfile_source, "w") as f: LONG = LONG_VERSION_PY[cfg.VCS] - f.write( - LONG - % { - "DOLLAR": "$", - "STYLE": cfg.style, - "TAG_PREFIX": cfg.tag_prefix, - "PARENTDIR_PREFIX": cfg.parentdir_prefix, - "VERSIONFILE_SOURCE": cfg.versionfile_source, - } - ) - + f.write(LONG % + {"DOLLAR": "$", + "STYLE": cfg.style, + "TAG_PREFIX": cfg.tag_prefix, + "PARENTDIR_PREFIX": cfg.parentdir_prefix, + "VERSIONFILE_SOURCE": cfg.versionfile_source, + }) cmds["build_exe"] = cmd_build_exe del cmds["build_py"] - if "py2exe" in sys.modules: # py2exe enabled? + if 'py2exe' in sys.modules: # py2exe enabled? try: - from py2exe.distutils_buildexe import py2exe as _py2exe # py3 + from py2exe.setuptools_buildexe import py2exe as _py2exe # type: ignore except ImportError: - from py2exe.build_exe import py2exe as _py2exe # py2 + from py2exe.distutils_buildexe import py2exe as _py2exe # type: ignore class cmd_py2exe(_py2exe): - def run(self): + def run(self) -> None: root = get_root() cfg = get_config_from_root(root) versions = get_versions() @@ -1660,27 +2044,60 @@ def run(self): os.unlink(target_versionfile) with open(cfg.versionfile_source, "w") as f: LONG = LONG_VERSION_PY[cfg.VCS] - f.write( - LONG - % { - "DOLLAR": "$", - "STYLE": cfg.style, - "TAG_PREFIX": cfg.tag_prefix, - "PARENTDIR_PREFIX": cfg.parentdir_prefix, - "VERSIONFILE_SOURCE": cfg.versionfile_source, - } - ) - + f.write(LONG % + {"DOLLAR": "$", + "STYLE": cfg.style, + "TAG_PREFIX": cfg.tag_prefix, + "PARENTDIR_PREFIX": cfg.parentdir_prefix, + "VERSIONFILE_SOURCE": cfg.versionfile_source, + }) cmds["py2exe"] = cmd_py2exe + # sdist farms its file list building out to egg_info + if 'egg_info' in cmds: + _egg_info: Any = cmds['egg_info'] + else: + from setuptools.command.egg_info import egg_info as _egg_info + + class cmd_egg_info(_egg_info): + def find_sources(self) -> None: + # egg_info.find_sources builds the manifest list and writes it + # in one shot + super().find_sources() + + # Modify the filelist and normalize it + root = get_root() + cfg = get_config_from_root(root) + self.filelist.append('versioneer.py') + if cfg.versionfile_source: + # There are rare cases where versionfile_source might not be + # included by default, so we must be explicit + self.filelist.append(cfg.versionfile_source) + self.filelist.sort() + self.filelist.remove_duplicates() + + # The write method is hidden in the manifest_maker instance that + # generated the filelist and was thrown away + # We will instead replicate their final normalization (to unicode, + # and POSIX-style paths) + from setuptools import unicode_utils + normalized = [unicode_utils.filesys_decode(f).replace(os.sep, '/') + for f in self.filelist.files] + + manifest_filename = os.path.join(self.egg_info, 'SOURCES.txt') + with open(manifest_filename, 'w') as fobj: + fobj.write('\n'.join(normalized)) + + cmds['egg_info'] = cmd_egg_info + # we override different "sdist" commands for both environments - if "setuptools" in sys.modules: - from setuptools.command.sdist import sdist as _sdist + if 'sdist' in cmds: + _sdist: Any = cmds['sdist'] else: - from distutils.command.sdist import sdist as _sdist + from setuptools.command.sdist import sdist as _sdist class cmd_sdist(_sdist): - def run(self): + def run(self) -> None: versions = get_versions() self._versioneer_generated_versions = versions # unless we update this, the command will keep using the old @@ -1688,7 +2105,7 @@ def run(self): self.distribution.metadata.version = versions["version"] return _sdist.run(self) - def make_release_tree(self, base_dir, files): + def make_release_tree(self, base_dir: str, files: List[str]) -> None: root = get_root() cfg = get_config_from_root(root) _sdist.make_release_tree(self, base_dir, files) @@ -1697,10 +2114,8 @@ def make_release_tree(self, base_dir, files): # updated value target_versionfile = os.path.join(base_dir, cfg.versionfile_source) print("UPDATING %s" % target_versionfile) - write_to_version_file( - target_versionfile, self._versioneer_generated_versions - ) - + write_to_version_file(target_versionfile, + self._versioneer_generated_versions) cmds["sdist"] = cmd_sdist return cmds @@ -1743,25 +2158,28 @@ def make_release_tree(self, base_dir, files): """ -INIT_PY_SNIPPET = """ +OLD_SNIPPET = """ from ._version import get_versions __version__ = get_versions()['version'] del get_versions """ +INIT_PY_SNIPPET = """ +from . import {0} +__version__ = {0}.get_versions()['version'] +""" + -def do_setup(): - """Main VCS-independent setup function for installing Versioneer.""" +def do_setup() -> int: + """Do main VCS-independent setup function for installing Versioneer.""" root = get_root() try: cfg = get_config_from_root(root) - except ( - EnvironmentError, - configparser.NoSectionError, - configparser.NoOptionError, - ) as e: - if isinstance(e, (EnvironmentError, configparser.NoSectionError)): - print("Adding sample versioneer config to setup.cfg", file=sys.stderr) + except (OSError, configparser.NoSectionError, + configparser.NoOptionError) as e: + if isinstance(e, (OSError, configparser.NoSectionError)): + print("Adding sample versioneer config to setup.cfg", + file=sys.stderr) with open(os.path.join(root, "setup.cfg"), "a") as f: f.write(SAMPLE_CONFIG) print(CONFIG_ERROR, file=sys.stderr) @@ -1770,76 +2188,46 @@ def do_setup(): print(" creating %s" % cfg.versionfile_source) with open(cfg.versionfile_source, "w") as f: LONG = LONG_VERSION_PY[cfg.VCS] - f.write( - LONG - % { - "DOLLAR": "$", - "STYLE": cfg.style, - "TAG_PREFIX": cfg.tag_prefix, - "PARENTDIR_PREFIX": cfg.parentdir_prefix, - "VERSIONFILE_SOURCE": cfg.versionfile_source, - } - ) - - ipy = os.path.join(os.path.dirname(cfg.versionfile_source), "__init__.py") + f.write(LONG % {"DOLLAR": "$", + "STYLE": cfg.style, + "TAG_PREFIX": cfg.tag_prefix, + "PARENTDIR_PREFIX": cfg.parentdir_prefix, + "VERSIONFILE_SOURCE": cfg.versionfile_source, + }) + + ipy = os.path.join(os.path.dirname(cfg.versionfile_source), + "__init__.py") + maybe_ipy: Optional[str] = ipy if os.path.exists(ipy): try: with open(ipy, "r") as f: old = f.read() - except EnvironmentError: + except OSError: old = "" - if INIT_PY_SNIPPET not in old: + module = os.path.splitext(os.path.basename(cfg.versionfile_source))[0] + snippet = INIT_PY_SNIPPET.format(module) + if OLD_SNIPPET in old: + print(" replacing boilerplate in %s" % ipy) + with open(ipy, "w") as f: + f.write(old.replace(OLD_SNIPPET, snippet)) + elif snippet not in old: print(" appending to %s" % ipy) with open(ipy, "a") as f: - f.write(INIT_PY_SNIPPET) + f.write(snippet) else: print(" %s unmodified" % ipy) else: print(" %s doesn't exist, ok" % ipy) - ipy = None - - # Make sure both the top-level "versioneer.py" and versionfile_source - # (PKG/_version.py, used by runtime code) are in MANIFEST.in, so - # they'll be copied into source distributions. Pip won't be able to - # install the package without this. - manifest_in = os.path.join(root, "MANIFEST.in") - simple_includes = set() - try: - with open(manifest_in, "r") as f: - for line in f: - if line.startswith("include "): - for include in line.split()[1:]: - simple_includes.add(include) - except EnvironmentError: - pass - # That doesn't cover everything MANIFEST.in can do - # (http://docs.python.org/2/distutils/sourcedist.html#commands), so - # it might give some false negatives. Appending redundant 'include' - # lines is safe, though. - if "versioneer.py" not in simple_includes: - print(" appending 'versioneer.py' to MANIFEST.in") - with open(manifest_in, "a") as f: - f.write("include versioneer.py\n") - else: - print(" 'versioneer.py' already in MANIFEST.in") - if cfg.versionfile_source not in simple_includes: - print( - " appending versionfile_source ('%s') to MANIFEST.in" - % cfg.versionfile_source - ) - with open(manifest_in, "a") as f: - f.write("include %s\n" % cfg.versionfile_source) - else: - print(" versionfile_source already in MANIFEST.in") + maybe_ipy = None # Make VCS-specific changes. For git, this means creating/changing # .gitattributes to mark _version.py for export-subst keyword # substitution. - do_vcs_install(manifest_in, cfg.versionfile_source, ipy) + do_vcs_install(cfg.versionfile_source, maybe_ipy) return 0 -def scan_setup_py(): +def scan_setup_py() -> int: """Validate the contents of setup.py against Versioneer's expectations.""" found = set() setters = False @@ -1876,10 +2264,14 @@ def scan_setup_py(): return errors +def setup_command() -> NoReturn: + """Set up Versioneer and exit with appropriate error code.""" + errors = do_setup() + errors += scan_setup_py() + sys.exit(1 if errors else 0) + + if __name__ == "__main__": cmd = sys.argv[1] if cmd == "setup": - errors = do_setup() - errors += scan_setup_py() - if errors: - sys.exit(1) + setup_command() From 1e9d9d9767175dfc4a5644c103ec29f5ab0dfdd7 Mon Sep 17 00:00:00 2001 From: Dmitry Balabka Date: Tue, 20 Feb 2024 17:33:23 +0200 Subject: [PATCH 15/62] Fix python-box compatability (#848) (#858) Co-authored-by: Jacob Tomlinson --- dask_kubernetes/operator/networking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dask_kubernetes/operator/networking.py b/dask_kubernetes/operator/networking.py index b7bd300b0..1e9916406 100644 --- a/dask_kubernetes/operator/networking.py +++ b/dask_kubernetes/operator/networking.py @@ -79,7 +79,7 @@ async def get_external_address_for_scheduler_service( def _get_port(service, port_name, is_node_port=False): """NodePort is a special case when we have to use node_port instead of node""" [port] = [ - port.port if not is_node_port else port.node_port + port.port if not is_node_port else port.nodePort for port in service.spec.ports if port.name == service.metadata.name or port.name == port_name ] From 39038bece61ae9ce8fc44272b87ac1619836f462 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 20 Feb 2024 16:41:32 +0100 Subject: [PATCH 16/62] Remove 3.12 from badge (#868) --- README.rst | 2 +- doc/source/index.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 6e3fd7511..49d6f2249 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support diff --git a/doc/source/index.rst b/doc/source/index.rst index 3de09e815..ab427fe47 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,7 +9,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support From a7cbd740e74f501e148f51616872486c27902b92 Mon Sep 17 00:00:00 2001 From: jonded94 Date: Fri, 1 Mar 2024 16:50:11 +0100 Subject: [PATCH 17/62] Fix issue of duplicated environment variables (#869) * Fix issue of replicated environment variables * Test for non-replicated environment variables --------- Co-authored-by: Jonas Dedden --- .../operator/controller/controller.py | 55 ++++++++++--------- .../controller/tests/test_controller.py | 8 +++ 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 00c47aeed..f8a300085 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -1,4 +1,5 @@ import asyncio +import copy import time from collections import defaultdict from contextlib import suppress @@ -79,14 +80,15 @@ def build_scheduler_deployment_spec( "labels": labels, "annotations": annotations, } - spec = {} - spec["replicas"] = 1 - spec["selector"] = { - "matchLabels": labels, - } - spec["template"] = { - "metadata": metadata, - "spec": pod_spec, + spec = { + "replicas": 1, + "selector": { + "matchLabels": labels, + }, + "template": { + "metadata": metadata, + "spec": pod_spec, + }, } return { "apiVersion": "apps/v1", @@ -132,14 +134,15 @@ def build_worker_deployment_spec( "labels": labels, "annotations": annotations, } - spec = {} - spec["replicas"] = 1 # make_worker_spec returns dict with a replicas key? - spec["selector"] = { - "matchLabels": labels, - } - spec["template"] = { - "metadata": metadata, - "spec": pod_spec, + spec = { + "replicas": 1, + "selector": { + "matchLabels": labels, + }, + "template": { + "metadata": metadata, + "spec": copy.deepcopy(pod_spec), + }, } deployment_spec = { "apiVersion": "apps/v1", @@ -157,13 +160,11 @@ def build_worker_deployment_spec( "value": f"tcp://{cluster_name}-scheduler.{namespace}.svc.cluster.local:8786", }, ] - for i in range(len(deployment_spec["spec"]["template"]["spec"]["containers"])): - if "env" in deployment_spec["spec"]["template"]["spec"]["containers"][i]: - deployment_spec["spec"]["template"]["spec"]["containers"][i]["env"].extend( - env - ) + for container in deployment_spec["spec"]["template"]["spec"]["containers"]: + if "env" in container: + container["env"].extend(env) else: - deployment_spec["spec"]["template"]["spec"]["containers"][i]["env"] = env + container["env"] = env return deployment_spec @@ -187,7 +188,7 @@ def build_job_pod_spec(job_name, cluster_name, namespace, spec, annotations, lab "labels": labels, "annotations": annotations, }, - "spec": spec, + "spec": copy.deepcopy(spec), } env = [ { @@ -195,11 +196,11 @@ def build_job_pod_spec(job_name, cluster_name, namespace, spec, annotations, lab "value": f"tcp://{cluster_name}-scheduler.{namespace}.svc.cluster.local:8786", }, ] - for i in range(len(pod_spec["spec"]["containers"])): - if "env" in pod_spec["spec"]["containers"][i]: - pod_spec["spec"]["containers"][i]["env"].extend(env) + for container in pod_spec["spec"]["containers"]: + if "env" in container: + container["env"].extend(env) else: - pod_spec["spec"]["containers"][i]["env"] = env + container["env"] = env return pod_spec diff --git a/dask_kubernetes/operator/controller/tests/test_controller.py b/dask_kubernetes/operator/controller/tests/test_controller.py index 0bc3b0997..e4f3d5112 100644 --- a/dask_kubernetes/operator/controller/tests/test_controller.py +++ b/dask_kubernetes/operator/controller/tests/test_controller.py @@ -636,6 +636,14 @@ async def test_object_dask_cluster(k8s_cluster, kopf_runner, gen_cluster): wg = worker_groups[0] assert isinstance(wg, DaskWorkerGroup) + # Test for non-replicated environment variables; Fix for https://github.com/dask/dask-kubernetes/issues/841 + for deployment in await wg.deployments(): + env_vars = deployment.spec["template"]["spec"]["containers"]["env"] + env_var_names = [env_var["name"] for env_var in env_vars] + assert len(env_var_names) == len(set(env_var_names)) + assert "DASK_WORKER_NAME" in env_var_names + assert "DASK_SCHEDULER_ADDRESS" in env_var_names + scheduler_pod = await cluster.scheduler_pod() assert isinstance(scheduler_pod, Pod) From 1efdc519a7615edec9fc0b54110ab30d5514e3d6 Mon Sep 17 00:00:00 2001 From: Johanna Date: Fri, 1 Mar 2024 16:55:31 +0100 Subject: [PATCH 18/62] Validate Dask Cluster Names (#871) * fix(validation): Validate Dask Cluster Names This commit introduces cluster name validation in order to avoid the invalid state in which a `DaskCluster` resource with a too-long or RFC-1123-noncompliant name is created but cannot be deleted while the operator retries infinitely to create a scheduler service (see https://github.com/dask/dask-kubernetes/issues/826 for more details on this bug). Issues fixed: https://github.com/dask/dask-kubernetes/issues/870 https://github.com/dask/dask-kubernetes/issues/826 * Actually, stop removing the dask cluster automatically. It can be manually deleted. * Move the cluster name validation into a common module, add it to KubeCluster init, and add tests --------- Co-authored-by: Johanna Goergen --- dask_kubernetes/common/objects.py | 21 ++++++- dask_kubernetes/common/tests/test_objects.py | 26 +++++++- dask_kubernetes/constants.py | 10 +++ dask_kubernetes/exceptions.py | 7 +++ .../operator/controller/controller.py | 15 ++++- .../controller/tests/test_controller.py | 63 +++++++++++++++++-- .../operator/kubecluster/kubecluster.py | 2 + .../kubecluster/tests/test_kubecluster.py | 20 +++++- 8 files changed, 153 insertions(+), 11 deletions(-) diff --git a/dask_kubernetes/common/objects.py b/dask_kubernetes/common/objects.py index 44c90fd56..1eedeebd7 100644 --- a/dask_kubernetes/common/objects.py +++ b/dask_kubernetes/common/objects.py @@ -1,6 +1,7 @@ """ Convenience functions for creating pod templates. """ + import copy import json from collections import namedtuple @@ -8,7 +9,12 @@ from kubernetes import client from kubernetes.client.configuration import Configuration -from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME +from dask_kubernetes.constants import ( + KUBECLUSTER_CONTAINER_NAME, + MAX_CLUSTER_NAME_LEN, + VALID_CLUSTER_NAME, +) +from dask_kubernetes.exceptions import ValidationError _FakeResponse = namedtuple("_FakeResponse", ["data"]) @@ -365,3 +371,16 @@ def clean_pdb_template(pdb_template): pdb_template.spec.selector = client.V1LabelSelector() return pdb_template + + +def validate_cluster_name(cluster_name: str) -> None: + """Raise exception if cluster name is too long and/or has invalid characters""" + if not VALID_CLUSTER_NAME.match(cluster_name): + raise ValidationError( + message=( + f"The DaskCluster {cluster_name} is invalid: a lowercase RFC 1123 subdomain must " + "consist of lower case alphanumeric characters, '-' or '.', and must start " + "and end with an alphanumeric character. DaskCluster name must also be under " + f"{MAX_CLUSTER_NAME_LEN} characters." + ) + ) diff --git a/dask_kubernetes/common/tests/test_objects.py b/dask_kubernetes/common/tests/test_objects.py index 61ef99b3f..23e318961 100644 --- a/dask_kubernetes/common/tests/test_objects.py +++ b/dask_kubernetes/common/tests/test_objects.py @@ -1,5 +1,8 @@ -from dask_kubernetes.common.objects import make_pod_from_dict -from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME +import pytest + +from dask_kubernetes.common.objects import make_pod_from_dict, validate_cluster_name +from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME, MAX_CLUSTER_NAME_LEN +from dask_kubernetes.exceptions import ValidationError def test_make_pod_from_dict(): @@ -64,3 +67,22 @@ def test_make_pod_from_dict_default_container_name(): assert pod.spec.containers[0].name == "dask-0" assert pod.spec.containers[1].name == "sidecar" assert pod.spec.containers[2].name == "dask-2" + + +@pytest.mark.parametrize( + "cluster_name", + [ + (MAX_CLUSTER_NAME_LEN + 1) * "a", + "invalid.chars.in.name", + ], +) +def test_validate_cluster_name_raises_on_invalid_name( + cluster_name, +): + + with pytest.raises(ValidationError): + validate_cluster_name(cluster_name) + + +def test_validate_cluster_name_success_on_valid_name(): + assert validate_cluster_name("valid-cluster-name-123") is None diff --git a/dask_kubernetes/constants.py b/dask_kubernetes/constants.py index f22c804a5..5133e2de7 100644 --- a/dask_kubernetes/constants.py +++ b/dask_kubernetes/constants.py @@ -1 +1,11 @@ +import re + KUBECLUSTER_CONTAINER_NAME = "dask-container" +KUBERNETES_MAX_RESOURCE_NAME_LENGTH = 63 +SCHEDULER_NAME_TEMPLATE = "{cluster_name}-scheduler" +MAX_CLUSTER_NAME_LEN = KUBERNETES_MAX_RESOURCE_NAME_LENGTH - len( + SCHEDULER_NAME_TEMPLATE.format(cluster_name="") +) +VALID_CLUSTER_NAME = re.compile( + rf"^(?=.{{,{MAX_CLUSTER_NAME_LEN}}}$)[a-z0-9]([-a-z0-9]*[a-z0-9])?$" +) diff --git a/dask_kubernetes/exceptions.py b/dask_kubernetes/exceptions.py index d501aab48..dc107c8c3 100644 --- a/dask_kubernetes/exceptions.py +++ b/dask_kubernetes/exceptions.py @@ -4,3 +4,10 @@ class CrashLoopBackOffError(Exception): class SchedulerStartupError(Exception): """Scheduler failed to start.""" + + +class ValidationError(Exception): + """Manifest validation exception""" + + def __init__(self, message: str) -> None: + self.message = message diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index f8a300085..7bb70a09c 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -15,6 +15,9 @@ from importlib_metadata import entry_points from kr8s.asyncio.objects import Deployment, Pod, Service +from dask_kubernetes.common.objects import validate_cluster_name +from dask_kubernetes.constants import SCHEDULER_NAME_TEMPLATE +from dask_kubernetes.exceptions import ValidationError from dask_kubernetes.operator._objects import ( DaskAutoscaler, DaskCluster, @@ -76,7 +79,7 @@ def build_scheduler_deployment_spec( } ) metadata = { - "name": f"{cluster_name}-scheduler", + "name": SCHEDULER_NAME_TEMPLATE.format(cluster_name=cluster_name), "labels": labels, "annotations": annotations, } @@ -109,7 +112,7 @@ def build_scheduler_service_spec(cluster_name, spec, annotations, labels): "apiVersion": "v1", "kind": "Service", "metadata": { - "name": f"{cluster_name}-scheduler", + "name": SCHEDULER_NAME_TEMPLATE.format(cluster_name=cluster_name), "labels": labels, "annotations": annotations, }, @@ -274,6 +277,12 @@ async def daskcluster_create(name, namespace, logger, patch, **kwargs): This allows us to track that the operator is running. """ logger.info(f"DaskCluster {name} created in {namespace}.") + try: + validate_cluster_name(name) + except ValidationError as validation_exc: + patch.status["phase"] = "Error" + raise kopf.PermanentError(validation_exc.message) + patch.status["phase"] = "Created" @@ -600,7 +609,7 @@ async def daskworkergroup_replica_update( if workers_needed < 0: worker_ids = await retire_workers( n_workers=-workers_needed, - scheduler_service_name=f"{cluster_name}-scheduler", + scheduler_service_name=SCHEDULER_NAME_TEMPLATE.format(cluster_name), worker_group_name=name, namespace=namespace, logger=logger, diff --git a/dask_kubernetes/operator/controller/tests/test_controller.py b/dask_kubernetes/operator/controller/tests/test_controller.py index e4f3d5112..144865955 100644 --- a/dask_kubernetes/operator/controller/tests/test_controller.py +++ b/dask_kubernetes/operator/controller/tests/test_controller.py @@ -11,6 +11,7 @@ from dask.distributed import Client from kr8s.asyncio.objects import Deployment, Pod, Service +from dask_kubernetes.constants import MAX_CLUSTER_NAME_LEN from dask_kubernetes.operator._objects import DaskCluster, DaskJob, DaskWorkerGroup from dask_kubernetes.operator.controller import ( KUBERNETES_DATETIME_FORMAT, @@ -22,17 +23,32 @@ _EXPECTED_ANNOTATIONS = {"test-annotation": "annotation-value"} _EXPECTED_LABELS = {"test-label": "label-value"} +DEFAULT_CLUSTER_NAME = "simple" @pytest.fixture() -def gen_cluster(k8s_cluster, ns): +def gen_cluster_manifest(tmp_path): + def factory(cluster_name=DEFAULT_CLUSTER_NAME): + original_manifest_path = os.path.join(DIR, "resources", "simplecluster.yaml") + with open(original_manifest_path, "r") as original_manifest_file: + manifest = yaml.safe_load(original_manifest_file) + + manifest["metadata"]["name"] = cluster_name + new_manifest_path = tmp_path / "cluster.yaml" + new_manifest_path.write_text(yaml.safe_dump(manifest)) + return tmp_path + + return factory + + +@pytest.fixture() +def gen_cluster(k8s_cluster, ns, gen_cluster_manifest): """Yields an instantiated context manager for creating/deleting a simple cluster.""" @asynccontextmanager - async def cm(): - cluster_path = os.path.join(DIR, "resources", "simplecluster.yaml") - cluster_name = "simple" + async def cm(cluster_name=DEFAULT_CLUSTER_NAME): + cluster_path = gen_cluster_manifest(cluster_name) # Create cluster resource k8s_cluster.kubectl("apply", "-n", ns, "-f", cluster_path) while cluster_name not in k8s_cluster.kubectl( @@ -695,3 +711,42 @@ async def test_object_dask_job(k8s_cluster, kopf_runner, gen_job): cluster = await job.cluster() assert isinstance(cluster, DaskCluster) + + +async def _get_cluster_status(k8s_cluster, ns, cluster_name): + """ + Will loop infinitely in search of non-falsey cluster status. + Make sure there is a timeout on any test which calls this. + """ + while True: + cluster_status = k8s_cluster.kubectl( + "get", + "-n", + ns, + "daskcluster.kubernetes.dask.org", + cluster_name, + "-o", + "jsonpath='{.status.phase}'", + ).strip("'") + if cluster_status: + return cluster_status + await asyncio.sleep(0.1) + + +@pytest.mark.timeout(180) +@pytest.mark.anyio +@pytest.mark.parametrize( + "cluster_name,expected_status", + [ + ("valid-name", "Created"), + ((MAX_CLUSTER_NAME_LEN + 1) * "a", "Error"), + ("invalid.chars.in.name", "Error"), + ], +) +async def test_create_cluster_validates_name( + cluster_name, expected_status, k8s_cluster, kopf_runner, gen_cluster +): + with kopf_runner: + async with gen_cluster(cluster_name=cluster_name) as (_, ns): + actual_status = await _get_cluster_status(k8s_cluster, ns, cluster_name) + assert expected_status == actual_status diff --git a/dask_kubernetes/operator/kubecluster/kubecluster.py b/dask_kubernetes/operator/kubecluster/kubecluster.py index d5891ab4a..5b2b540d0 100644 --- a/dask_kubernetes/operator/kubecluster/kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/kubecluster.py @@ -29,6 +29,7 @@ from rich.table import Table from tornado.ioloop import IOLoop +from dask_kubernetes.common.objects import validate_cluster_name from dask_kubernetes.exceptions import CrashLoopBackOffError, SchedulerStartupError from dask_kubernetes.operator._objects import ( DaskAutoscaler, @@ -258,6 +259,7 @@ def __init__( name = name.format( user=getpass.getuser(), uuid=str(uuid.uuid4())[:10], **os.environ ) + validate_cluster_name(name) self._instances.add(self) self._rich_spinner = Spinner("dots", speed=0.5) self._startup_component_status: dict = {} diff --git a/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py b/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py index 931f24b90..662e711fa 100644 --- a/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py @@ -2,7 +2,8 @@ from dask.distributed import Client from distributed.utils import TimeoutError -from dask_kubernetes.exceptions import SchedulerStartupError +from dask_kubernetes.constants import MAX_CLUSTER_NAME_LEN +from dask_kubernetes.exceptions import SchedulerStartupError, ValidationError from dask_kubernetes.operator import KubeCluster, make_cluster_spec @@ -202,3 +203,20 @@ def test_typo_resource_limits(ns): }, namespace=ns, ) + + +@pytest.mark.parametrize( + "cluster_name", + [ + (MAX_CLUSTER_NAME_LEN + 1) * "a", + "invalid.chars.in.name", + ], +) +def test_invalid_cluster_name_fails(cluster_name, kopf_runner, docker_image, ns): + with kopf_runner: + with pytest.raises(ValidationError): + KubeCluster( + name=cluster_name, + namespace=ns, + image=docker_image, + ) From b668cc62944dc3eac225dc4c4ff01f2b3743c9da Mon Sep 17 00:00:00 2001 From: Johanna Date: Mon, 4 Mar 2024 18:32:27 +0100 Subject: [PATCH 19/62] Fix: KeyError on Building Scheduler Name in Replica Count Decrease (#872) --- dask_kubernetes/operator/controller/controller.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 7bb70a09c..efbd3887b 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -609,7 +609,9 @@ async def daskworkergroup_replica_update( if workers_needed < 0: worker_ids = await retire_workers( n_workers=-workers_needed, - scheduler_service_name=SCHEDULER_NAME_TEMPLATE.format(cluster_name), + scheduler_service_name=SCHEDULER_NAME_TEMPLATE.format( + cluster_name=cluster_name + ), worker_group_name=name, namespace=namespace, logger=logger, From 93fe171b8daf7c6b0eaf875a48d1f9454a623620 Mon Sep 17 00:00:00 2001 From: jonded94 Date: Tue, 2 Apr 2024 14:57:59 +0200 Subject: [PATCH 20/62] Enable overwrites of default environment variables (#874) * Enable overwrites of default environment variables * Black formatting * Include test for additional worker group; test overriding of environment variables * Black --------- Co-authored-by: Jonas Dedden --- .../operator/controller/controller.py | 32 ++++--- .../tests/resources/simpleworkergroup.yaml | 4 +- .../controller/tests/test_controller.py | 89 +++++++++++++++---- 3 files changed, 93 insertions(+), 32 deletions(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index efbd3887b..13702d97e 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -153,21 +153,25 @@ def build_worker_deployment_spec( "metadata": metadata, "spec": spec, } - env = [ - { - "name": "DASK_WORKER_NAME", - "value": worker_name, - }, - { - "name": "DASK_SCHEDULER_ADDRESS", - "value": f"tcp://{cluster_name}-scheduler.{namespace}.svc.cluster.local:8786", - }, - ] + worker_env = { + "name": "DASK_WORKER_NAME", + "value": worker_name, + } + scheduler_env = { + "name": "DASK_SCHEDULER_ADDRESS", + "value": f"tcp://{cluster_name}-scheduler.{namespace}.svc.cluster.local:8786", + } for container in deployment_spec["spec"]["template"]["spec"]["containers"]: - if "env" in container: - container["env"].extend(env) - else: - container["env"] = env + if "env" not in container: + container["env"] = [worker_env, scheduler_env] + continue + + container_env_names = [env_item["name"] for env_item in container["env"]] + + if "DASK_WORKER_NAME" not in container_env_names: + container["env"].append(worker_env) + if "DASK_SCHEDULER_ADDRESS" not in container_env_names: + container["env"].append(scheduler_env) return deployment_spec diff --git a/dask_kubernetes/operator/controller/tests/resources/simpleworkergroup.yaml b/dask_kubernetes/operator/controller/tests/resources/simpleworkergroup.yaml index cd7da0e92..e99ebe608 100644 --- a/dask_kubernetes/operator/controller/tests/resources/simpleworkergroup.yaml +++ b/dask_kubernetes/operator/controller/tests/resources/simpleworkergroup.yaml @@ -5,7 +5,7 @@ metadata: spec: cluster: simple worker: - replicas: 2 + replicas: 1 spec: containers: - name: worker @@ -23,3 +23,5 @@ spec: env: - name: WORKER_ENV value: hello-world # We dont test the value, just the name + - name: DASK_WORKER_NAME + value: test-worker diff --git a/dask_kubernetes/operator/controller/tests/test_controller.py b/dask_kubernetes/operator/controller/tests/test_controller.py index 144865955..33abf9c4f 100644 --- a/dask_kubernetes/operator/controller/tests/test_controller.py +++ b/dask_kubernetes/operator/controller/tests/test_controller.py @@ -20,7 +20,6 @@ DIR = pathlib.Path(__file__).parent.absolute() - _EXPECTED_ANNOTATIONS = {"test-annotation": "annotation-value"} _EXPECTED_LABELS = {"test-label": "label-value"} DEFAULT_CLUSTER_NAME = "simple" @@ -47,7 +46,6 @@ def gen_cluster(k8s_cluster, ns, gen_cluster_manifest): @asynccontextmanager async def cm(cluster_name=DEFAULT_CLUSTER_NAME): - cluster_path = gen_cluster_manifest(cluster_name) # Create cluster resource k8s_cluster.kubectl("apply", "-n", ns, "-f", cluster_path) @@ -95,6 +93,36 @@ async def cm(job_file): yield cm +@pytest.fixture() +def gen_worker_group(k8s_cluster, ns): + """Yields an instantiated context manager for creating/deleting a worker group.""" + + @asynccontextmanager + async def cm(worker_group_file): + worker_group_path = os.path.join(DIR, "resources", worker_group_file) + with open(worker_group_path) as f: + worker_group_name = yaml.load(f, yaml.Loader)["metadata"]["name"] + + # Create cluster resource + k8s_cluster.kubectl("apply", "-n", ns, "-f", worker_group_path) + while worker_group_name not in k8s_cluster.kubectl( + "get", "daskworkergroups.kubernetes.dask.org", "-n", ns + ): + await asyncio.sleep(0.1) + + try: + yield worker_group_name, ns + finally: + # Test: remove the wait=True, because I think this is blocking the operator + k8s_cluster.kubectl("delete", "-n", ns, "-f", worker_group_path) + while worker_group_name in k8s_cluster.kubectl( + "get", "daskworkergroups.kubernetes.dask.org", "-n", ns + ): + await asyncio.sleep(0.1) + + yield cm + + def test_customresources(k8s_cluster): assert "daskclusters.kubernetes.dask.org" in k8s_cluster.kubectl("get", "crd") assert "daskworkergroups.kubernetes.dask.org" in k8s_cluster.kubectl("get", "crd") @@ -671,32 +699,59 @@ async def test_object_dask_cluster(k8s_cluster, kopf_runner, gen_cluster): @pytest.mark.anyio -async def test_object_dask_worker_group(k8s_cluster, kopf_runner, gen_cluster): +async def test_object_dask_worker_group( + k8s_cluster, kopf_runner, gen_cluster, gen_worker_group +): with kopf_runner: - async with gen_cluster() as (cluster_name, ns): + async with ( + gen_cluster() as (cluster_name, ns), + gen_worker_group("simpleworkergroup.yaml") as ( + additional_workergroup_name, + _, + ), + ): cluster = await DaskCluster.get(cluster_name, namespace=ns) + additional_workergroup = await DaskWorkerGroup.get( + additional_workergroup_name, namespace=ns + ) worker_groups = [] while not worker_groups: worker_groups = await cluster.worker_groups() await asyncio.sleep(0.1) assert len(worker_groups) == 1 # Just the default worker group - wg = worker_groups[0] - assert isinstance(wg, DaskWorkerGroup) + worker_groups = worker_groups + [additional_workergroup] - pods = [] - while not pods: - pods = await wg.pods() - await asyncio.sleep(0.1) - assert all([isinstance(p, Pod) for p in pods]) + for wg in worker_groups: + assert isinstance(wg, DaskWorkerGroup) - deployments = [] - while not deployments: - deployments = await wg.deployments() - await asyncio.sleep(0.1) - assert all([isinstance(d, Deployment) for d in deployments]) + deployments = [] + while not deployments: + deployments = await wg.deployments() + await asyncio.sleep(0.1) + assert all([isinstance(d, Deployment) for d in deployments]) - assert (await wg.cluster()).name == cluster.name + pods = [] + while not pods: + pods = await wg.pods() + await asyncio.sleep(0.1) + assert all([isinstance(p, Pod) for p in pods]) + + assert (await wg.cluster()).name == cluster.name + + for deployment in deployments: + assert deployment.labels["dask.org/cluster-name"] == cluster.name + for env in deployment.spec["template"]["spec"]["containers"][0][ + "env" + ]: + if env["name"] == "DASK_WORKER_NAME": + if wg.name == additional_workergroup_name: + assert env["value"] == "test-worker" + else: + assert env["value"] == deployment.name + if env["name"] == "DASK_SCHEDULER_ADDRESS": + scheduler_service = await cluster.scheduler_service() + assert f"{scheduler_service.name}.{ns}" in env["value"] @pytest.mark.anyio From d3f0ef85f26077f88165d4cd134a84926f23c594 Mon Sep 17 00:00:00 2001 From: Jonas Dedden Date: Wed, 3 Apr 2024 11:41:05 +0200 Subject: [PATCH 21/62] Implement new container env mechanism also for Dask Jobs (#879) * Implement new container env mechanism also for Dask Jobs * Black fixes --------- Co-authored-by: Jonas Dedden --- .../operator/controller/controller.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 13702d97e..1254ee528 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -197,17 +197,19 @@ def build_job_pod_spec(job_name, cluster_name, namespace, spec, annotations, lab }, "spec": copy.deepcopy(spec), } - env = [ - { - "name": "DASK_SCHEDULER_ADDRESS", - "value": f"tcp://{cluster_name}-scheduler.{namespace}.svc.cluster.local:8786", - }, - ] + scheduler_env = { + "name": "DASK_SCHEDULER_ADDRESS", + "value": f"tcp://{cluster_name}-scheduler.{namespace}.svc.cluster.local:8786", + } for container in pod_spec["spec"]["containers"]: - if "env" in container: - container["env"].extend(env) - else: - container["env"] = env + if "env" not in container: + container["env"] = [scheduler_env] + continue + + container_env_names = [env_item["name"] for env_item in container["env"]] + + if "DASK_SCHEDULER_ADDRESS" not in container_env_names: + container["env"].append(scheduler_env) return pod_spec From 258d5562f8c958afda0d3b172bc8053e658f3b2d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:53:48 +0100 Subject: [PATCH 22/62] Bump google.golang.org/protobuf from 1.28.1 to 1.33.0 (#875) Bumps google.golang.org/protobuf from 1.28.1 to 1.33.0. --- updated-dependencies: - dependency-name: google.golang.org/protobuf dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d65b3e48f..708cdb787 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.1 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 5715c2565..4a58475fa 100644 --- a/go.sum +++ b/go.sum @@ -596,8 +596,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From b254dd27591847216bc76c57ebb9def48bf12c4d Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 16 Apr 2024 21:38:29 +0100 Subject: [PATCH 23/62] Add Python 3.12 to CI (#867) * Add Python 3.12 to CI * Add 3.12 to badge * Switch to importlib.metadata.entrypoints * Switch to pkg_resources.iter_entry_points --- .github/workflows/helmcluster.yaml | 2 +- .github/workflows/kubecluster.yaml | 2 +- .github/workflows/operator.yaml | 2 +- README.rst | 2 +- dask_kubernetes/operator/controller/controller.py | 4 ++-- doc/source/index.rst | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/helmcluster.yaml b/.github/workflows/helmcluster.yaml index a56b787b9..5e2f0ca70 100644 --- a/.github/workflows/helmcluster.yaml +++ b/.github/workflows/helmcluster.yaml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] kubernetes-version: ["1.29.2"] include: - python-version: '3.10' diff --git a/.github/workflows/kubecluster.yaml b/.github/workflows/kubecluster.yaml index 89714ae54..f2e6d81dd 100644 --- a/.github/workflows/kubecluster.yaml +++ b/.github/workflows/kubecluster.yaml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] kubernetes-version: ["1.29.2"] include: - python-version: '3.10' diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index 35e21a192..ba6b2dfa3 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -39,7 +39,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] kubernetes-version: ["1.29.2"] include: - python-version: '3.10' diff --git a/README.rst b/README.rst index 49d6f2249..6e3fd7511 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11-blue +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 1254ee528..6cd990e4d 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -10,9 +10,9 @@ import dask.config import kopf import kr8s +import pkg_resources from distributed.core import clean_exception, rpc from distributed.protocol.pickle import dumps -from importlib_metadata import entry_points from kr8s.asyncio.objects import Deployment, Pod, Service from dask_kubernetes.common.objects import validate_cluster_name @@ -38,7 +38,7 @@ # Load operator plugins from other packages PLUGINS = [] -for ep in entry_points(group="dask_operator_plugin"): +for ep in pkg_resources.iter_entry_points(group="dask_operator_plugin"): with suppress(AttributeError, ImportError): PLUGINS.append(ep.load()) diff --git a/doc/source/index.rst b/doc/source/index.rst index ab427fe47..3de09e815 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,7 +9,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11-blue +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support From 67a45e922f81ec713c1d56160101ed8cbcfa20f5 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 19 Apr 2024 13:18:56 +0100 Subject: [PATCH 24/62] Bump kr8s to 0.14.2 (#880) * Release 2024.4.0 * Bump kr8s to 0.14.1 * Update objects to use public async API * Bump to v0.14.2 --- dask_kubernetes/operator/_objects.py | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dask_kubernetes/operator/_objects.py b/dask_kubernetes/operator/_objects.py index 79b96f333..da34a44a1 100644 --- a/dask_kubernetes/operator/_objects.py +++ b/dask_kubernetes/operator/_objects.py @@ -71,7 +71,7 @@ async def scheduler_service(self) -> Service: return services[0] async def ready(self) -> bool: - await self._refresh() + await self.async_refresh() return ( "status" in self.raw and "phase" in self.status diff --git a/requirements.txt b/requirements.txt index 665275ceb..99abbd5be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ kubernetes-asyncio>=12.0.1 kopf>=1.35.3 pykube-ng>=22.9.0 rich>=12.5.1 -kr8s==0.9.0 +kr8s==0.14.2 From 7326d3c30a0933a02b5e45f9cb60cc5d700a9265 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 19 Apr 2024 13:19:31 +0100 Subject: [PATCH 25/62] Set a default value on idleTimeout (#884) --- dask_kubernetes/operator/controller/controller.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 6cd990e4d..07f33cbda 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -851,7 +851,8 @@ async def daskautoscaler_adapt(spec, name, namespace, logger, **kwargs): @kopf.timer("daskcluster.kubernetes.dask.org", interval=5.0) async def daskcluster_autoshutdown(spec, name, namespace, logger, **kwargs): - if spec["idleTimeout"]: + idle_timeout = spec.get("idleTimeout", 0) + if idle_timeout: try: idle_since = await check_scheduler_idle( scheduler_service_name=f"{name}-scheduler", @@ -861,6 +862,6 @@ async def daskcluster_autoshutdown(spec, name, namespace, logger, **kwargs): except Exception: logger.warn("Unable to connect to scheduler, skipping autoshutdown check.") return - if idle_since and time.time() > idle_since + spec["idleTimeout"]: + if idle_since and time.time() > idle_since + idle_timeout: cluster = await DaskCluster.get(name, namespace=namespace) await cluster.delete() From 95ceaca266d59dd2015fba0dc4938bccf43ac50c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:19:41 +0000 Subject: [PATCH 26/62] Bump golang.org/x/net from 0.17.0 to 0.23.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.17.0 to 0.23.0. - [Commits](https://github.com/golang/net/compare/v0.17.0...v0.23.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 708cdb787..8fdf010c7 100644 --- a/go.mod +++ b/go.mod @@ -30,11 +30,11 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/term v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index 4a58475fa..0c284af4f 100644 --- a/go.sum +++ b/go.sum @@ -347,8 +347,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -420,12 +420,12 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -435,8 +435,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 323e0d1188cde18901d596ff48a85d93b198ab36 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 19 Apr 2024 13:28:46 +0100 Subject: [PATCH 27/62] Add Release Drafter CI (#886) * Add Release Drafter CI * Fix tag selector --- .github/release-drafter.yml | 29 ++++++++++++++++++++++++ .github/workflows/release-drafter.yml | 23 +++++++++++++++++++ .github/workflows/release-publish.yml | 32 +++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/release-publish.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 000000000..963c95c95 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,29 @@ +# These will be overridden by the publish workflow and set to the new tag +name-template: 'Next Release' +tag-template: 'next' + +# Optionally configure your categories and other templates +exclude-labels: + - dependencies +categories: + - title: 'Enhancements' + labels: + - 'feature' + - 'enhancement' + - title: 'Bug Fixes' + labels: + - 'bug' + - title: 'Documentation' + label: 'documentation' + - title: 'Project Hygiene' + labels: + - hygiene + - ci + +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. + +template: | + ## Changes + + $CHANGES diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 000000000..49a08ef4a --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,23 @@ +name: Release Drafter + +on: + push: + branches: + - main + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + # Write permission is required to create a GitHub release + contents: write + pull-requests: read + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + with: + disable-autolabeler: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml new file mode 100644 index 000000000..089794add --- /dev/null +++ b/.github/workflows/release-publish.yml @@ -0,0 +1,32 @@ +name: Release Publisher + +on: + push: + tags: + - "*.*.*" + +permissions: + contents: read + +jobs: + publish_release: + permissions: + # Write permission is required to publish a GitHub release + contents: write + pull-requests: read + runs-on: ubuntu-latest + steps: + - name: Set version env + # Use a little bit of bash to extract the tag name from the GitHub ref + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - uses: release-drafter/release-drafter@v5 + with: + disable-autolabeler: true + # Override the Release name/tag/version with the actual tag name + name: ${{ env.RELEASE_VERSION }} + tag: ${{ env.RELEASE_VERSION }} + version: ${{ env.RELEASE_VERSION }} + # Publish the Release + publish: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 2a0465273f0ce539e8405c4a4eb1d25e8f92c3d8 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 19 Apr 2024 14:57:07 +0100 Subject: [PATCH 28/62] Add check to ensure release drafter doesn't run on forks (#887) --- .github/workflows/release-drafter.yml | 1 + .github/workflows/release-publish.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 49a08ef4a..2158381b8 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -10,6 +10,7 @@ permissions: jobs: update_release_draft: + if: github.repository == 'dask/dask-kubernetes' permissions: # Write permission is required to create a GitHub release contents: write diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 089794add..b2ffec609 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -10,6 +10,7 @@ permissions: jobs: publish_release: + if: github.repository == 'dask/dask-kubernetes' permissions: # Write permission is required to publish a GitHub release contents: write From e39d59cbee99b597dfeb82e8d18b046d251cd7c9 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Wed, 24 Apr 2024 15:34:51 +0100 Subject: [PATCH 29/62] Relax kr8s pin to v0.14.* (#888) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 99abbd5be..6674b93fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ kubernetes-asyncio>=12.0.1 kopf>=1.35.3 pykube-ng>=22.9.0 rich>=12.5.1 -kr8s==0.14.2 +kr8s==0.14.* From ef41984b54c6507a5a918921da8dfecb24ae4840 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 30 Apr 2024 09:39:26 +0100 Subject: [PATCH 30/62] Migrate to hatch (#889) * Migrate to hatch * Checkout full history * Install project * Remove clone depth * Build package in container multi-stage build to ensure correct versioning * Remove debugging pip install command * Fetch full depth to correctly calculate version * Reinstate entrypoints --- .dockerignore | 2 +- .github/workflows/release.yml | 13 +- .gitignore | 5 +- dask_kubernetes/__init__.py | 10 +- dask_kubernetes/_version.py | 716 ------ .../operator/deployment/Dockerfile | 15 +- pyproject.toml | 112 +- requirements.txt | 8 - setup.cfg | 41 - setup.py | 33 - versioneer.py | 2277 ----------------- 11 files changed, 113 insertions(+), 3119 deletions(-) delete mode 100644 dask_kubernetes/_version.py delete mode 100644 requirements.txt delete mode 100644 setup.cfg delete mode 100755 setup.py delete mode 100644 versioneer.py diff --git a/.dockerignore b/.dockerignore index 7eaa6632c..b5be99089 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ -.* Dockerfile +dist/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6c827c0b6..341fc1199 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,9 @@ jobs: steps: - name: Checkout source - uses: actions/checkout@v2 + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Python 3.10 uses: actions/setup-python@v1 @@ -16,7 +18,7 @@ jobs: python-version: "3.10" - name: Install pypa/build and chartpress - run: python -m pip install build wheel chartpress pyyaml + run: python -m pip install hatch build wheel chartpress pyyaml # chartpress pushes a packages Helm chart to dask/helm-chart's gh-pages # branch, so we need to have a git user.email and user.name configured @@ -27,14 +29,11 @@ jobs: - name: Build distributions shell: bash -l {0} - run: python setup.py sdist bdist_wheel + run: hatch build - name: Publish package to PyPI if: github.repository == 'dask/dask-kubernetes' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.pypi_password }} + uses: pypa/gh-action-pypi-publish@release/v1 - name: Get the version id: get_version diff --git a/.gitignore b/.gitignore index 91d755744..9fa3912da 100644 --- a/.gitignore +++ b/.gitignore @@ -141,4 +141,7 @@ credentials.csv # IDEs .idea/ -.vscode/ \ No newline at end of file +.vscode/ + +# Version +_version.py diff --git a/dask_kubernetes/__init__.py b/dask_kubernetes/__init__.py index 11a1ea333..09c37910c 100644 --- a/dask_kubernetes/__init__.py +++ b/dask_kubernetes/__init__.py @@ -2,7 +2,7 @@ from warnings import warn from . import config -from . import _version + from .common.auth import ( AutoRefreshConfiguration, AutoRefreshKubeConfigLoader, @@ -15,7 +15,13 @@ from .helm import HelmCluster __all__ = ["HelmCluster", "KubeCluster"] -__version__ = _version.get_versions()["version"] + +try: + from ._version import version as __version__ # noqa + from ._version import version_tuple as __version_tuple__ # noqa +except ImportError: + __version__ = "0.0.0" + __version_tuple__ = (0, 0, 0) def __getattr__(name): diff --git a/dask_kubernetes/_version.py b/dask_kubernetes/_version.py deleted file mode 100644 index 771a8a76d..000000000 --- a/dask_kubernetes/_version.py +++ /dev/null @@ -1,716 +0,0 @@ -# This file helps to compute a version number in source trees obtained from -# git-archive tarball (such as those provided by githubs download-from-tag -# feature). Distribution tarballs (built by setup.py sdist) and build -# directories (produced by setup.py build) will contain a much shorter file -# that just contains the computed version number. - -# This file is released into the public domain. -# Generated by versioneer-0.29 -# https://github.com/python-versioneer/python-versioneer - -"""Git implementation of _version.py.""" - -import errno -import functools -import os -import re -import subprocess -import sys -from typing import Any, Callable, Dict, List, Optional, Tuple - - -def get_keywords() -> Dict[str, str]: - """Get the keywords needed to look up the version information.""" - # these strings will be replaced by git during git-archive. - # setup.py/versioneer.py will grep for the variable names, so they must - # each be defined on a line of their own. _version.py will just call - # get_keywords(). - git_refnames = "$Format:%d$" - git_full = "$Format:%H$" - git_date = "$Format:%ci$" - keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} - return keywords - - -class VersioneerConfig: - """Container for Versioneer configuration parameters.""" - - VCS: str - style: str - tag_prefix: str - parentdir_prefix: str - versionfile_source: str - verbose: bool - - -def get_config() -> VersioneerConfig: - """Create, populate and return the VersioneerConfig() object.""" - # these strings are filled in when 'setup.py versioneer' creates - # _version.py - cfg = VersioneerConfig() - cfg.VCS = "git" - cfg.style = "pep440" - cfg.tag_prefix = "" - cfg.parentdir_prefix = "dask-kubernetes-" - cfg.versionfile_source = "dask_kubernetes/_version.py" - cfg.verbose = False - return cfg - - -class NotThisMethod(Exception): - """Exception raised if a method is not valid for the current scenario.""" - - -LONG_VERSION_PY: Dict[str, str] = {} -HANDLERS: Dict[str, Dict[str, Callable]] = {} - - -def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator - """Create decorator to mark a method as the handler of a VCS.""" - - def decorate(f: Callable) -> Callable: - """Store f in HANDLERS[vcs][method].""" - if vcs not in HANDLERS: - HANDLERS[vcs] = {} - HANDLERS[vcs][method] = f - return f - - return decorate - - -def run_command( - commands: List[str], - args: List[str], - cwd: Optional[str] = None, - verbose: bool = False, - hide_stderr: bool = False, - env: Optional[Dict[str, str]] = None, -) -> Tuple[Optional[str], Optional[int]]: - """Call the given command(s).""" - assert isinstance(commands, list) - process = None - - popen_kwargs: Dict[str, Any] = {} - if sys.platform == "win32": - # This hides the console window if pythonw.exe is used - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - popen_kwargs["startupinfo"] = startupinfo - - for command in commands: - try: - dispcmd = str([command] + args) - # remember shell=False, so use git.cmd on windows, not just git - process = subprocess.Popen( - [command] + args, - cwd=cwd, - env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr else None), - **popen_kwargs, - ) - break - except OSError as e: - if e.errno == errno.ENOENT: - continue - if verbose: - print("unable to run %s" % dispcmd) - print(e) - return None, None - else: - if verbose: - print("unable to find command, tried %s" % (commands,)) - return None, None - stdout = process.communicate()[0].strip().decode() - if process.returncode != 0: - if verbose: - print("unable to run %s (error)" % dispcmd) - print("stdout was %s" % stdout) - return None, process.returncode - return stdout, process.returncode - - -def versions_from_parentdir( - parentdir_prefix: str, - root: str, - verbose: bool, -) -> Dict[str, Any]: - """Try to determine the version from the parent directory name. - - Source tarballs conventionally unpack into a directory that includes both - the project name and a version string. We will also support searching up - two directory levels for an appropriately named parent directory - """ - rootdirs = [] - - for _ in range(3): - dirname = os.path.basename(root) - if dirname.startswith(parentdir_prefix): - return { - "version": dirname[len(parentdir_prefix) :], - "full-revisionid": None, - "dirty": False, - "error": None, - "date": None, - } - rootdirs.append(root) - root = os.path.dirname(root) # up a level - - if verbose: - print( - "Tried directories %s but none started with prefix %s" - % (str(rootdirs), parentdir_prefix) - ) - raise NotThisMethod("rootdir doesn't start with parentdir_prefix") - - -@register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: - """Extract version information from the given file.""" - # the code embedded in _version.py can just fetch the value of these - # keywords. When used from setup.py, we don't want to import _version.py, - # so we do it with a regexp instead. This function is not used from - # _version.py. - keywords: Dict[str, str] = {} - try: - with open(versionfile_abs, "r") as fobj: - for line in fobj: - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - except OSError: - pass - return keywords - - -@register_vcs_handler("git", "keywords") -def git_versions_from_keywords( - keywords: Dict[str, str], - tag_prefix: str, - verbose: bool, -) -> Dict[str, Any]: - """Get version information from git keywords.""" - if "refnames" not in keywords: - raise NotThisMethod("Short version file found") - date = keywords.get("date") - if date is not None: - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - - # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant - # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 - # -like" string, which we must then edit to make compliant), because - # it's been around since git-1.5.3, and it's too difficult to - # discover which version we're using, or to work around using an - # older one. - date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - refnames = keywords["refnames"].strip() - if refnames.startswith("$Format"): - if verbose: - print("keywords are unexpanded, not using") - raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = {r.strip() for r in refnames.strip("()").split(",")} - # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of - # just "foo-1.0". If we see a "tag: " prefix, prefer those. - TAG = "tag: " - tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)} - if not tags: - # Either we're using git < 1.8.3, or there really are no tags. We use - # a heuristic: assume all version tags have a digit. The old git %d - # expansion behaves like git log --decorate=short and strips out the - # refs/heads/ and refs/tags/ prefixes that would let us distinguish - # between branches and tags. By ignoring refnames without digits, we - # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "master". - tags = {r for r in refs if re.search(r"\d", r)} - if verbose: - print("discarding '%s', no digits" % ",".join(refs - tags)) - if verbose: - print("likely tags: %s" % ",".join(sorted(tags))) - for ref in sorted(tags): - # sorting will prefer e.g. "2.0" over "2.0rc1" - if ref.startswith(tag_prefix): - r = ref[len(tag_prefix) :] - # Filter out refs that exactly match prefix or that don't start - # with a number once the prefix is stripped (mostly a concern - # when prefix is '') - if not re.match(r"\d", r): - continue - if verbose: - print("picking %s" % r) - return { - "version": r, - "full-revisionid": keywords["full"].strip(), - "dirty": False, - "error": None, - "date": date, - } - # no suitable tags, so version is "0+unknown", but full hex is still there - if verbose: - print("no suitable tags, using unknown + full revision id") - return { - "version": "0+unknown", - "full-revisionid": keywords["full"].strip(), - "dirty": False, - "error": "no suitable tags", - "date": None, - } - - -@register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs( - tag_prefix: str, root: str, verbose: bool, runner: Callable = run_command -) -> Dict[str, Any]: - """Get version from 'git describe' in the root of the source tree. - - This only gets called if the git-archive 'subst' keywords were *not* - expanded, and _version.py hasn't already been rewritten with a short - version string, meaning we're inside a checked out source tree. - """ - GITS = ["git"] - if sys.platform == "win32": - GITS = ["git.cmd", "git.exe"] - - # GIT_DIR can interfere with correct operation of Versioneer. - # It may be intended to be passed to the Versioneer-versioned project, - # but that should not change where we get our version from. - env = os.environ.copy() - env.pop("GIT_DIR", None) - runner = functools.partial(runner, env=env) - - _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=not verbose) - if rc != 0: - if verbose: - print("Directory %s not under git control" % root) - raise NotThisMethod("'git rev-parse --git-dir' returned error") - - # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] - # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = runner( - GITS, - [ - "describe", - "--tags", - "--dirty", - "--always", - "--long", - "--match", - f"{tag_prefix}[[:digit:]]*", - ], - cwd=root, - ) - # --long was added in git-1.5.5 - if describe_out is None: - raise NotThisMethod("'git describe' failed") - describe_out = describe_out.strip() - full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) - if full_out is None: - raise NotThisMethod("'git rev-parse' failed") - full_out = full_out.strip() - - pieces: Dict[str, Any] = {} - pieces["long"] = full_out - pieces["short"] = full_out[:7] # maybe improved later - pieces["error"] = None - - branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root) - # --abbrev-ref was added in git-1.6.3 - if rc != 0 or branch_name is None: - raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") - branch_name = branch_name.strip() - - if branch_name == "HEAD": - # If we aren't exactly on a branch, pick a branch which represents - # the current commit. If all else fails, we are on a branchless - # commit. - branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) - # --contains was added in git-1.5.4 - if rc != 0 or branches is None: - raise NotThisMethod("'git branch --contains' returned error") - branches = branches.split("\n") - - # Remove the first line if we're running detached - if "(" in branches[0]: - branches.pop(0) - - # Strip off the leading "* " from the list of branches. - branches = [branch[2:] for branch in branches] - if "master" in branches: - branch_name = "master" - elif not branches: - branch_name = None - else: - # Pick the first branch that is returned. Good or bad. - branch_name = branches[0] - - pieces["branch"] = branch_name - - # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] - # TAG might have hyphens. - git_describe = describe_out - - # look for -dirty suffix - dirty = git_describe.endswith("-dirty") - pieces["dirty"] = dirty - if dirty: - git_describe = git_describe[: git_describe.rindex("-dirty")] - - # now we have TAG-NUM-gHEX or HEX - - if "-" in git_describe: - # TAG-NUM-gHEX - mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe) - if not mo: - # unparsable. Maybe git-describe is misbehaving? - pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out - return pieces - - # tag - full_tag = mo.group(1) - if not full_tag.startswith(tag_prefix): - if verbose: - fmt = "tag '%s' doesn't start with prefix '%s'" - print(fmt % (full_tag, tag_prefix)) - pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % ( - full_tag, - tag_prefix, - ) - return pieces - pieces["closest-tag"] = full_tag[len(tag_prefix) :] - - # distance: number of commits since tag - pieces["distance"] = int(mo.group(2)) - - # commit: short hex revision ID - pieces["short"] = mo.group(3) - - else: - # HEX: no tags - pieces["closest-tag"] = None - out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) - pieces["distance"] = len(out.split()) # total number of commits - - # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip() - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - - return pieces - - -def plus_or_dot(pieces: Dict[str, Any]) -> str: - """Return a + if we don't already have one, else return a .""" - if "+" in pieces.get("closest-tag", ""): - return "." - return "+" - - -def render_pep440(pieces: Dict[str, Any]) -> str: - """Build up version string, with post-release "local version identifier". - - Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you - get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty - - Exceptions: - 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += plus_or_dot(pieces) - rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_branch(pieces: Dict[str, Any]) -> str: - """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . - - The ".dev0" means not master branch. Note that .dev0 sorts backwards - (a feature branch will appear "older" than the master branch). - - Exceptions: - 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0" - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+untagged.%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: - """Split pep440 version string at the post-release segment. - - Returns the release segments before the post-release and the - post-release version number (or -1 if no post-release segment is present). - """ - vc = str.split(ver, ".post") - return vc[0], int(vc[1] or 0) if len(vc) == 2 else None - - -def render_pep440_pre(pieces: Dict[str, Any]) -> str: - """TAG[.postN.devDISTANCE] -- No -dirty. - - Exceptions: - 1: no tags. 0.post0.devDISTANCE - """ - if pieces["closest-tag"]: - if pieces["distance"]: - # update the post release segment - tag_version, post_version = pep440_split_post(pieces["closest-tag"]) - rendered = tag_version - if post_version is not None: - rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"]) - else: - rendered += ".post0.dev%d" % (pieces["distance"]) - else: - # no commits, use the tag as the version - rendered = pieces["closest-tag"] - else: - # exception #1 - rendered = "0.post0.dev%d" % pieces["distance"] - return rendered - - -def render_pep440_post(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX] . - - The ".dev0" means dirty. Note that .dev0 sorts backwards - (a dirty tree will appear "older" than the corresponding clean one), - but you shouldn't be releasing software with -dirty anyways. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%s" % pieces["short"] - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += "+g%s" % pieces["short"] - return rendered - - -def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . - - The ".dev0" means not master branch. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%s" % pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+g%s" % pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_old(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]] . - - The ".dev0" means dirty. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - return rendered - - -def render_git_describe(pieces: Dict[str, Any]) -> str: - """TAG[-DISTANCE-gHEX][-dirty]. - - Like 'git describe --tags --dirty --always'. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"]: - rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render_git_describe_long(pieces: Dict[str, Any]) -> str: - """TAG-DISTANCE-gHEX[-dirty]. - - Like 'git describe --tags --dirty --always -long'. - The distance/hash is unconditional. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: - """Render the given version pieces into the requested style.""" - if pieces["error"]: - return { - "version": "unknown", - "full-revisionid": pieces.get("long"), - "dirty": None, - "error": pieces["error"], - "date": None, - } - - if not style or style == "default": - style = "pep440" # the default - - if style == "pep440": - rendered = render_pep440(pieces) - elif style == "pep440-branch": - rendered = render_pep440_branch(pieces) - elif style == "pep440-pre": - rendered = render_pep440_pre(pieces) - elif style == "pep440-post": - rendered = render_pep440_post(pieces) - elif style == "pep440-post-branch": - rendered = render_pep440_post_branch(pieces) - elif style == "pep440-old": - rendered = render_pep440_old(pieces) - elif style == "git-describe": - rendered = render_git_describe(pieces) - elif style == "git-describe-long": - rendered = render_git_describe_long(pieces) - else: - raise ValueError("unknown style '%s'" % style) - - return { - "version": rendered, - "full-revisionid": pieces["long"], - "dirty": pieces["dirty"], - "error": None, - "date": pieces.get("date"), - } - - -def get_versions() -> Dict[str, Any]: - """Get version information or return default if unable to do so.""" - # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have - # __file__, we can work backwards from there to the root. Some - # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which - # case we can only use expanded keywords. - - cfg = get_config() - verbose = cfg.verbose - - try: - return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose) - except NotThisMethod: - pass - - try: - root = os.path.realpath(__file__) - # versionfile_source is the relative path from the top of the source - # tree (where the .git directory might live) to this file. Invert - # this to find the root from __file__. - for _ in cfg.versionfile_source.split("/"): - root = os.path.dirname(root) - except NameError: - return { - "version": "0+unknown", - "full-revisionid": None, - "dirty": None, - "error": "unable to find root of source tree", - "date": None, - } - - try: - pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) - return render(pieces, cfg.style) - except NotThisMethod: - pass - - try: - if cfg.parentdir_prefix: - return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) - except NotThisMethod: - pass - - return { - "version": "0+unknown", - "full-revisionid": None, - "dirty": None, - "error": "unable to compute version", - "date": None, - } diff --git a/dask_kubernetes/operator/deployment/Dockerfile b/dask_kubernetes/operator/deployment/Dockerfile index 03710735a..79f32c1e1 100644 --- a/dask_kubernetes/operator/deployment/Dockerfile +++ b/dask_kubernetes/operator/deployment/Dockerfile @@ -1,14 +1,23 @@ # This images needs to be built from the top level of the project # $ docker build -t ghcr.io/dask/dask-kubernetes-operator:latest -f dask_kubernetes/operator/deployment/Dockerfile . -FROM python:3.10 +FROM python:3.10 as builder # Copy source COPY . /src/dask_kubernetes WORKDIR /src/dask_kubernetes -# Install dependencies -RUN pip install . +# Build dask-kubernetes distribution +RUN pip install hatch && hatch build + +FROM python:3.10 + +# Copy wheel +COPY --from=builder /src/dask_kubernetes/dist /src/dask_kubernetes/dist +WORKDIR /src/dask_kubernetes + +# Install from wheel +RUN pip install /src/dask_kubernetes/dist/dask_kubernetes*.whl # Add non-root user RUN useradd -s /bin/bash dask diff --git a/pyproject.toml b/pyproject.toml index 6a5e3c394..2a35faf7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,39 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "dask-kubernetes" +dynamic = ["version"] +description = "Native Kubernetes integration for Dask" +readme = "README.rst" +license = { file = "LICENSE" } +requires-python = ">=3.9" +maintainers = [{ name = "Jacob Tomlinson" }] +keywords = ["dask", "distributed", "kubernetes"] +dependencies = [ + "dask>=2022.08.1", + "distributed>=2022.08.1", + "kopf>=1.35.3", + "kr8s==0.14.*", + "kubernetes-asyncio>=12.0.1", + "kubernetes>=12.0.1", + "pykube-ng>=22.9.0", + "rich>=12.5.1", +] + +[project.urls] +Homepage = "https://github.com/dask/dask-kubernetes" + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "dask_kubernetes/_version.py" + +[tool.hatch.build.targets.sdist] +include = ["/dask_kubernetes"] + [tool.ruff] # Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default. # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or @@ -10,41 +46,41 @@ unfixable = [] # Exclude a variety of commonly ignored directories. exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".mypy_cache", - ".nox", - ".pants.d", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "venv", - "__init__.py", - "versioneer.py", - "distributed/_concurrent_futures_thread.py", + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", + "__init__.py", + "versioneer.py", + "distributed/_concurrent_futures_thread.py", ] per-file-ignores = {} ignore = [ - "E4", # Import formatting - "E721", # Comparing types instead of isinstance - "E731", # Assigning lambda expression - "E741", # Ambiguous variable names - "F811", # redefinition of unused 'loop' from line 10 - "F841", # local variable is assigned to but never used + "E4", # Import formatting + "E721", # Comparing types instead of isinstance + "E731", # Assigning lambda expression + "E741", # Ambiguous variable names + "F811", # redefinition of unused 'loop' from line 10 + "F841", # local variable is assigned to but never used ] line-length = 120 @@ -54,3 +90,19 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Assume Python 3.8 target-version = "py39" + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-v --keep-cluster --durations=10" +timeout = 60 +timeout_func_only = true + +[project.entry-points.dask_cluster_discovery] +helmcluster = "dask_kubernetes.helm:discover" +kubecluster = "dask_kubernetes.operator:discover" + +[project.entry-points.dask_operator_plugin] +noop = "dask_kubernetes.operator.controller.plugins.noop" + +[project.entry-points.dask_cli] +kubernetes = "dask_kubernetes.cli:main" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 6674b93fc..000000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -dask>=2022.08.1 -distributed>=2022.08.1 -kubernetes>=12.0.1 -kubernetes-asyncio>=12.0.1 -kopf>=1.35.3 -pykube-ng>=22.9.0 -rich>=12.5.1 -kr8s==0.14.* diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index d07f1eb5b..000000000 --- a/setup.cfg +++ /dev/null @@ -1,41 +0,0 @@ -[flake8] -# References: -# https://flake8.readthedocs.io/en/latest/user/configuration.html -# https://flake8.readthedocs.io/en/latest/user/error-codes.html - -# Note: there cannot be spaces after comma's here -exclude = __init__.py,versioneer.py,distributed/_concurrent_futures_thread.py -ignore = - E20, # Extra space in brackets - E231,E241, # Multiple spaces around "," - E26, # Comments - E4, # Import formatting - E721, # Comparing types instead of isinstance - E731, # Assigning lambda expression - E121, # continuation line under-indented for hanging indent - E126, # continuation line over-indented for hanging indent - E127, # continuation line over-indented for visual indent - E128, # E128 continuation line under-indented for visual indent - E702, # multiple statements on one line (semicolon) - W503, # line break before binary operator - E129, # visually indented line with same indent as next logical line - E116, # unexpected indentation - F811, # redefinition of unused 'loop' from line 10 - F841, # local variable is assigned to but never used - E741 # Ambiguous variable names - W504, # line break after binary operator - -max-line-length = 120 - -[versioneer] -VCS = git -style = pep440 -versionfile_source = dask_kubernetes/_version.py -versionfile_build = dask_kubernetes/_version.py -tag_prefix = -parentdir_prefix = dask-kubernetes- - -[tool:pytest] -addopts = -v --keep-cluster --durations=10 -timeout = 60 -timeout_func_only = true diff --git a/setup.py b/setup.py deleted file mode 100755 index 00496efa4..000000000 --- a/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -from os.path import exists - -from setuptools import find_packages, setup - -import versioneer - -setup( - name="dask-kubernetes", - cmdclass=versioneer.get_cmdclass(), - version=versioneer.get_version(), - description="Native Kubernetes integration for Dask", - maintainer="Jacob Tomlinson", - url="https://github.com/dask/dask-kubernetes", - keywords="dask,kubernetes,distributed", - license="BSD", - packages=find_packages(), - include_package_data=True, - long_description=(open("README.rst").read() if exists("README.rst") else ""), - zip_safe=False, - install_requires=list(open("requirements.txt").read().strip().split("\n")), - python_requires=">=3.9", - entry_points=""" - [dask_cluster_discovery] - helmcluster=dask_kubernetes.helm:discover - kubecluster=dask_kubernetes.operator:discover - [dask_operator_plugin] - noop=dask_kubernetes.operator.controller.plugins.noop - [dask_cli] - kubernetes=dask_kubernetes.cli:main - """, -) diff --git a/versioneer.py b/versioneer.py deleted file mode 100644 index 1e3753e63..000000000 --- a/versioneer.py +++ /dev/null @@ -1,2277 +0,0 @@ - -# Version: 0.29 - -"""The Versioneer - like a rocketeer, but for versions. - -The Versioneer -============== - -* like a rocketeer, but for versions! -* https://github.com/python-versioneer/python-versioneer -* Brian Warner -* License: Public Domain (Unlicense) -* Compatible with: Python 3.7, 3.8, 3.9, 3.10, 3.11 and pypy3 -* [![Latest Version][pypi-image]][pypi-url] -* [![Build Status][travis-image]][travis-url] - -This is a tool for managing a recorded version number in setuptools-based -python projects. The goal is to remove the tedious and error-prone "update -the embedded version string" step from your release process. Making a new -release should be as easy as recording a new tag in your version-control -system, and maybe making new tarballs. - - -## Quick Install - -Versioneer provides two installation modes. The "classic" vendored mode installs -a copy of versioneer into your repository. The experimental build-time dependency mode -is intended to allow you to skip this step and simplify the process of upgrading. - -### Vendored mode - -* `pip install versioneer` to somewhere in your $PATH - * A [conda-forge recipe](https://github.com/conda-forge/versioneer-feedstock) is - available, so you can also use `conda install -c conda-forge versioneer` -* add a `[tool.versioneer]` section to your `pyproject.toml` or a - `[versioneer]` section to your `setup.cfg` (see [Install](INSTALL.md)) - * Note that you will need to add `tomli; python_version < "3.11"` to your - build-time dependencies if you use `pyproject.toml` -* run `versioneer install --vendor` in your source tree, commit the results -* verify version information with `python setup.py version` - -### Build-time dependency mode - -* `pip install versioneer` to somewhere in your $PATH - * A [conda-forge recipe](https://github.com/conda-forge/versioneer-feedstock) is - available, so you can also use `conda install -c conda-forge versioneer` -* add a `[tool.versioneer]` section to your `pyproject.toml` or a - `[versioneer]` section to your `setup.cfg` (see [Install](INSTALL.md)) -* add `versioneer` (with `[toml]` extra, if configuring in `pyproject.toml`) - to the `requires` key of the `build-system` table in `pyproject.toml`: - ```toml - [build-system] - requires = ["setuptools", "versioneer[toml]"] - build-backend = "setuptools.build_meta" - ``` -* run `versioneer install --no-vendor` in your source tree, commit the results -* verify version information with `python setup.py version` - -## Version Identifiers - -Source trees come from a variety of places: - -* a version-control system checkout (mostly used by developers) -* a nightly tarball, produced by build automation -* a snapshot tarball, produced by a web-based VCS browser, like github's - "tarball from tag" feature -* a release tarball, produced by "setup.py sdist", distributed through PyPI - -Within each source tree, the version identifier (either a string or a number, -this tool is format-agnostic) can come from a variety of places: - -* ask the VCS tool itself, e.g. "git describe" (for checkouts), which knows - about recent "tags" and an absolute revision-id -* the name of the directory into which the tarball was unpacked -* an expanded VCS keyword ($Id$, etc) -* a `_version.py` created by some earlier build step - -For released software, the version identifier is closely related to a VCS -tag. Some projects use tag names that include more than just the version -string (e.g. "myproject-1.2" instead of just "1.2"), in which case the tool -needs to strip the tag prefix to extract the version identifier. For -unreleased software (between tags), the version identifier should provide -enough information to help developers recreate the same tree, while also -giving them an idea of roughly how old the tree is (after version 1.2, before -version 1.3). Many VCS systems can report a description that captures this, -for example `git describe --tags --dirty --always` reports things like -"0.7-1-g574ab98-dirty" to indicate that the checkout is one revision past the -0.7 tag, has a unique revision id of "574ab98", and is "dirty" (it has -uncommitted changes). - -The version identifier is used for multiple purposes: - -* to allow the module to self-identify its version: `myproject.__version__` -* to choose a name and prefix for a 'setup.py sdist' tarball - -## Theory of Operation - -Versioneer works by adding a special `_version.py` file into your source -tree, where your `__init__.py` can import it. This `_version.py` knows how to -dynamically ask the VCS tool for version information at import time. - -`_version.py` also contains `$Revision$` markers, and the installation -process marks `_version.py` to have this marker rewritten with a tag name -during the `git archive` command. As a result, generated tarballs will -contain enough information to get the proper version. - -To allow `setup.py` to compute a version too, a `versioneer.py` is added to -the top level of your source tree, next to `setup.py` and the `setup.cfg` -that configures it. This overrides several distutils/setuptools commands to -compute the version when invoked, and changes `setup.py build` and `setup.py -sdist` to replace `_version.py` with a small static file that contains just -the generated version data. - -## Installation - -See [INSTALL.md](./INSTALL.md) for detailed installation instructions. - -## Version-String Flavors - -Code which uses Versioneer can learn about its version string at runtime by -importing `_version` from your main `__init__.py` file and running the -`get_versions()` function. From the "outside" (e.g. in `setup.py`), you can -import the top-level `versioneer.py` and run `get_versions()`. - -Both functions return a dictionary with different flavors of version -information: - -* `['version']`: A condensed version string, rendered using the selected - style. This is the most commonly used value for the project's version - string. The default "pep440" style yields strings like `0.11`, - `0.11+2.g1076c97`, or `0.11+2.g1076c97.dirty`. See the "Styles" section - below for alternative styles. - -* `['full-revisionid']`: detailed revision identifier. For Git, this is the - full SHA1 commit id, e.g. "1076c978a8d3cfc70f408fe5974aa6c092c949ac". - -* `['date']`: Date and time of the latest `HEAD` commit. For Git, it is the - commit date in ISO 8601 format. This will be None if the date is not - available. - -* `['dirty']`: a boolean, True if the tree has uncommitted changes. Note that - this is only accurate if run in a VCS checkout, otherwise it is likely to - be False or None - -* `['error']`: if the version string could not be computed, this will be set - to a string describing the problem, otherwise it will be None. It may be - useful to throw an exception in setup.py if this is set, to avoid e.g. - creating tarballs with a version string of "unknown". - -Some variants are more useful than others. Including `full-revisionid` in a -bug report should allow developers to reconstruct the exact code being tested -(or indicate the presence of local changes that should be shared with the -developers). `version` is suitable for display in an "about" box or a CLI -`--version` output: it can be easily compared against release notes and lists -of bugs fixed in various releases. - -The installer adds the following text to your `__init__.py` to place a basic -version in `YOURPROJECT.__version__`: - - from ._version import get_versions - __version__ = get_versions()['version'] - del get_versions - -## Styles - -The setup.cfg `style=` configuration controls how the VCS information is -rendered into a version string. - -The default style, "pep440", produces a PEP440-compliant string, equal to the -un-prefixed tag name for actual releases, and containing an additional "local -version" section with more detail for in-between builds. For Git, this is -TAG[+DISTANCE.gHEX[.dirty]] , using information from `git describe --tags ---dirty --always`. For example "0.11+2.g1076c97.dirty" indicates that the -tree is like the "1076c97" commit but has uncommitted changes (".dirty"), and -that this commit is two revisions ("+2") beyond the "0.11" tag. For released -software (exactly equal to a known tag), the identifier will only contain the -stripped tag, e.g. "0.11". - -Other styles are available. See [details.md](details.md) in the Versioneer -source tree for descriptions. - -## Debugging - -Versioneer tries to avoid fatal errors: if something goes wrong, it will tend -to return a version of "0+unknown". To investigate the problem, run `setup.py -version`, which will run the version-lookup code in a verbose mode, and will -display the full contents of `get_versions()` (including the `error` string, -which may help identify what went wrong). - -## Known Limitations - -Some situations are known to cause problems for Versioneer. This details the -most significant ones. More can be found on Github -[issues page](https://github.com/python-versioneer/python-versioneer/issues). - -### Subprojects - -Versioneer has limited support for source trees in which `setup.py` is not in -the root directory (e.g. `setup.py` and `.git/` are *not* siblings). The are -two common reasons why `setup.py` might not be in the root: - -* Source trees which contain multiple subprojects, such as - [Buildbot](https://github.com/buildbot/buildbot), which contains both - "master" and "slave" subprojects, each with their own `setup.py`, - `setup.cfg`, and `tox.ini`. Projects like these produce multiple PyPI - distributions (and upload multiple independently-installable tarballs). -* Source trees whose main purpose is to contain a C library, but which also - provide bindings to Python (and perhaps other languages) in subdirectories. - -Versioneer will look for `.git` in parent directories, and most operations -should get the right version string. However `pip` and `setuptools` have bugs -and implementation details which frequently cause `pip install .` from a -subproject directory to fail to find a correct version string (so it usually -defaults to `0+unknown`). - -`pip install --editable .` should work correctly. `setup.py install` might -work too. - -Pip-8.1.1 is known to have this problem, but hopefully it will get fixed in -some later version. - -[Bug #38](https://github.com/python-versioneer/python-versioneer/issues/38) is tracking -this issue. The discussion in -[PR #61](https://github.com/python-versioneer/python-versioneer/pull/61) describes the -issue from the Versioneer side in more detail. -[pip PR#3176](https://github.com/pypa/pip/pull/3176) and -[pip PR#3615](https://github.com/pypa/pip/pull/3615) contain work to improve -pip to let Versioneer work correctly. - -Versioneer-0.16 and earlier only looked for a `.git` directory next to the -`setup.cfg`, so subprojects were completely unsupported with those releases. - -### Editable installs with setuptools <= 18.5 - -`setup.py develop` and `pip install --editable .` allow you to install a -project into a virtualenv once, then continue editing the source code (and -test) without re-installing after every change. - -"Entry-point scripts" (`setup(entry_points={"console_scripts": ..})`) are a -convenient way to specify executable scripts that should be installed along -with the python package. - -These both work as expected when using modern setuptools. When using -setuptools-18.5 or earlier, however, certain operations will cause -`pkg_resources.DistributionNotFound` errors when running the entrypoint -script, which must be resolved by re-installing the package. This happens -when the install happens with one version, then the egg_info data is -regenerated while a different version is checked out. Many setup.py commands -cause egg_info to be rebuilt (including `sdist`, `wheel`, and installing into -a different virtualenv), so this can be surprising. - -[Bug #83](https://github.com/python-versioneer/python-versioneer/issues/83) describes -this one, but upgrading to a newer version of setuptools should probably -resolve it. - - -## Updating Versioneer - -To upgrade your project to a new release of Versioneer, do the following: - -* install the new Versioneer (`pip install -U versioneer` or equivalent) -* edit `setup.cfg` and `pyproject.toml`, if necessary, - to include any new configuration settings indicated by the release notes. - See [UPGRADING](./UPGRADING.md) for details. -* re-run `versioneer install --[no-]vendor` in your source tree, to replace - `SRC/_version.py` -* commit any changed files - -## Future Directions - -This tool is designed to make it easily extended to other version-control -systems: all VCS-specific components are in separate directories like -src/git/ . The top-level `versioneer.py` script is assembled from these -components by running make-versioneer.py . In the future, make-versioneer.py -will take a VCS name as an argument, and will construct a version of -`versioneer.py` that is specific to the given VCS. It might also take the -configuration arguments that are currently provided manually during -installation by editing setup.py . Alternatively, it might go the other -direction and include code from all supported VCS systems, reducing the -number of intermediate scripts. - -## Similar projects - -* [setuptools_scm](https://github.com/pypa/setuptools_scm/) - a non-vendored build-time - dependency -* [minver](https://github.com/jbweston/miniver) - a lightweight reimplementation of - versioneer -* [versioningit](https://github.com/jwodder/versioningit) - a PEP 518-based setuptools - plugin - -## License - -To make Versioneer easier to embed, all its code is dedicated to the public -domain. The `_version.py` that it creates is also in the public domain. -Specifically, both are released under the "Unlicense", as described in -https://unlicense.org/. - -[pypi-image]: https://img.shields.io/pypi/v/versioneer.svg -[pypi-url]: https://pypi.python.org/pypi/versioneer/ -[travis-image]: -https://img.shields.io/travis/com/python-versioneer/python-versioneer.svg -[travis-url]: https://travis-ci.com/github/python-versioneer/python-versioneer - -""" -# pylint:disable=invalid-name,import-outside-toplevel,missing-function-docstring -# pylint:disable=missing-class-docstring,too-many-branches,too-many-statements -# pylint:disable=raise-missing-from,too-many-lines,too-many-locals,import-error -# pylint:disable=too-few-public-methods,redefined-outer-name,consider-using-with -# pylint:disable=attribute-defined-outside-init,too-many-arguments - -import configparser -import errno -import json -import os -import re -import subprocess -import sys -from pathlib import Path -from typing import Any, Callable, cast, Dict, List, Optional, Tuple, Union -from typing import NoReturn -import functools - -have_tomllib = True -if sys.version_info >= (3, 11): - import tomllib -else: - try: - import tomli as tomllib - except ImportError: - have_tomllib = False - - -class VersioneerConfig: - """Container for Versioneer configuration parameters.""" - - VCS: str - style: str - tag_prefix: str - versionfile_source: str - versionfile_build: Optional[str] - parentdir_prefix: Optional[str] - verbose: Optional[bool] - - -def get_root() -> str: - """Get the project root directory. - - We require that all commands are run from the project root, i.e. the - directory that contains setup.py, setup.cfg, and versioneer.py . - """ - root = os.path.realpath(os.path.abspath(os.getcwd())) - setup_py = os.path.join(root, "setup.py") - pyproject_toml = os.path.join(root, "pyproject.toml") - versioneer_py = os.path.join(root, "versioneer.py") - if not ( - os.path.exists(setup_py) - or os.path.exists(pyproject_toml) - or os.path.exists(versioneer_py) - ): - # allow 'python path/to/setup.py COMMAND' - root = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) - setup_py = os.path.join(root, "setup.py") - pyproject_toml = os.path.join(root, "pyproject.toml") - versioneer_py = os.path.join(root, "versioneer.py") - if not ( - os.path.exists(setup_py) - or os.path.exists(pyproject_toml) - or os.path.exists(versioneer_py) - ): - err = ("Versioneer was unable to run the project root directory. " - "Versioneer requires setup.py to be executed from " - "its immediate directory (like 'python setup.py COMMAND'), " - "or in a way that lets it use sys.argv[0] to find the root " - "(like 'python path/to/setup.py COMMAND').") - raise VersioneerBadRootError(err) - try: - # Certain runtime workflows (setup.py install/develop in a setuptools - # tree) execute all dependencies in a single python process, so - # "versioneer" may be imported multiple times, and python's shared - # module-import table will cache the first one. So we can't use - # os.path.dirname(__file__), as that will find whichever - # versioneer.py was first imported, even in later projects. - my_path = os.path.realpath(os.path.abspath(__file__)) - me_dir = os.path.normcase(os.path.splitext(my_path)[0]) - vsr_dir = os.path.normcase(os.path.splitext(versioneer_py)[0]) - if me_dir != vsr_dir and "VERSIONEER_PEP518" not in globals(): - print("Warning: build in %s is using versioneer.py from %s" - % (os.path.dirname(my_path), versioneer_py)) - except NameError: - pass - return root - - -def get_config_from_root(root: str) -> VersioneerConfig: - """Read the project setup.cfg file to determine Versioneer config.""" - # This might raise OSError (if setup.cfg is missing), or - # configparser.NoSectionError (if it lacks a [versioneer] section), or - # configparser.NoOptionError (if it lacks "VCS="). See the docstring at - # the top of versioneer.py for instructions on writing your setup.cfg . - root_pth = Path(root) - pyproject_toml = root_pth / "pyproject.toml" - setup_cfg = root_pth / "setup.cfg" - section: Union[Dict[str, Any], configparser.SectionProxy, None] = None - if pyproject_toml.exists() and have_tomllib: - try: - with open(pyproject_toml, 'rb') as fobj: - pp = tomllib.load(fobj) - section = pp['tool']['versioneer'] - except (tomllib.TOMLDecodeError, KeyError) as e: - print(f"Failed to load config from {pyproject_toml}: {e}") - print("Try to load it from setup.cfg") - if not section: - parser = configparser.ConfigParser() - with open(setup_cfg) as cfg_file: - parser.read_file(cfg_file) - parser.get("versioneer", "VCS") # raise error if missing - - section = parser["versioneer"] - - # `cast`` really shouldn't be used, but its simplest for the - # common VersioneerConfig users at the moment. We verify against - # `None` values elsewhere where it matters - - cfg = VersioneerConfig() - cfg.VCS = section['VCS'] - cfg.style = section.get("style", "") - cfg.versionfile_source = cast(str, section.get("versionfile_source")) - cfg.versionfile_build = section.get("versionfile_build") - cfg.tag_prefix = cast(str, section.get("tag_prefix")) - if cfg.tag_prefix in ("''", '""', None): - cfg.tag_prefix = "" - cfg.parentdir_prefix = section.get("parentdir_prefix") - if isinstance(section, configparser.SectionProxy): - # Make sure configparser translates to bool - cfg.verbose = section.getboolean("verbose") - else: - cfg.verbose = section.get("verbose") - - return cfg - - -class NotThisMethod(Exception): - """Exception raised if a method is not valid for the current scenario.""" - - -# these dictionaries contain VCS-specific tools -LONG_VERSION_PY: Dict[str, str] = {} -HANDLERS: Dict[str, Dict[str, Callable]] = {} - - -def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator - """Create decorator to mark a method as the handler of a VCS.""" - def decorate(f: Callable) -> Callable: - """Store f in HANDLERS[vcs][method].""" - HANDLERS.setdefault(vcs, {})[method] = f - return f - return decorate - - -def run_command( - commands: List[str], - args: List[str], - cwd: Optional[str] = None, - verbose: bool = False, - hide_stderr: bool = False, - env: Optional[Dict[str, str]] = None, -) -> Tuple[Optional[str], Optional[int]]: - """Call the given command(s).""" - assert isinstance(commands, list) - process = None - - popen_kwargs: Dict[str, Any] = {} - if sys.platform == "win32": - # This hides the console window if pythonw.exe is used - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - popen_kwargs["startupinfo"] = startupinfo - - for command in commands: - try: - dispcmd = str([command] + args) - # remember shell=False, so use git.cmd on windows, not just git - process = subprocess.Popen([command] + args, cwd=cwd, env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr - else None), **popen_kwargs) - break - except OSError as e: - if e.errno == errno.ENOENT: - continue - if verbose: - print("unable to run %s" % dispcmd) - print(e) - return None, None - else: - if verbose: - print("unable to find command, tried %s" % (commands,)) - return None, None - stdout = process.communicate()[0].strip().decode() - if process.returncode != 0: - if verbose: - print("unable to run %s (error)" % dispcmd) - print("stdout was %s" % stdout) - return None, process.returncode - return stdout, process.returncode - - -LONG_VERSION_PY['git'] = r''' -# This file helps to compute a version number in source trees obtained from -# git-archive tarball (such as those provided by githubs download-from-tag -# feature). Distribution tarballs (built by setup.py sdist) and build -# directories (produced by setup.py build) will contain a much shorter file -# that just contains the computed version number. - -# This file is released into the public domain. -# Generated by versioneer-0.29 -# https://github.com/python-versioneer/python-versioneer - -"""Git implementation of _version.py.""" - -import errno -import os -import re -import subprocess -import sys -from typing import Any, Callable, Dict, List, Optional, Tuple -import functools - - -def get_keywords() -> Dict[str, str]: - """Get the keywords needed to look up the version information.""" - # these strings will be replaced by git during git-archive. - # setup.py/versioneer.py will grep for the variable names, so they must - # each be defined on a line of their own. _version.py will just call - # get_keywords(). - git_refnames = "%(DOLLAR)sFormat:%%d%(DOLLAR)s" - git_full = "%(DOLLAR)sFormat:%%H%(DOLLAR)s" - git_date = "%(DOLLAR)sFormat:%%ci%(DOLLAR)s" - keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} - return keywords - - -class VersioneerConfig: - """Container for Versioneer configuration parameters.""" - - VCS: str - style: str - tag_prefix: str - parentdir_prefix: str - versionfile_source: str - verbose: bool - - -def get_config() -> VersioneerConfig: - """Create, populate and return the VersioneerConfig() object.""" - # these strings are filled in when 'setup.py versioneer' creates - # _version.py - cfg = VersioneerConfig() - cfg.VCS = "git" - cfg.style = "%(STYLE)s" - cfg.tag_prefix = "%(TAG_PREFIX)s" - cfg.parentdir_prefix = "%(PARENTDIR_PREFIX)s" - cfg.versionfile_source = "%(VERSIONFILE_SOURCE)s" - cfg.verbose = False - return cfg - - -class NotThisMethod(Exception): - """Exception raised if a method is not valid for the current scenario.""" - - -LONG_VERSION_PY: Dict[str, str] = {} -HANDLERS: Dict[str, Dict[str, Callable]] = {} - - -def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator - """Create decorator to mark a method as the handler of a VCS.""" - def decorate(f: Callable) -> Callable: - """Store f in HANDLERS[vcs][method].""" - if vcs not in HANDLERS: - HANDLERS[vcs] = {} - HANDLERS[vcs][method] = f - return f - return decorate - - -def run_command( - commands: List[str], - args: List[str], - cwd: Optional[str] = None, - verbose: bool = False, - hide_stderr: bool = False, - env: Optional[Dict[str, str]] = None, -) -> Tuple[Optional[str], Optional[int]]: - """Call the given command(s).""" - assert isinstance(commands, list) - process = None - - popen_kwargs: Dict[str, Any] = {} - if sys.platform == "win32": - # This hides the console window if pythonw.exe is used - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - popen_kwargs["startupinfo"] = startupinfo - - for command in commands: - try: - dispcmd = str([command] + args) - # remember shell=False, so use git.cmd on windows, not just git - process = subprocess.Popen([command] + args, cwd=cwd, env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr - else None), **popen_kwargs) - break - except OSError as e: - if e.errno == errno.ENOENT: - continue - if verbose: - print("unable to run %%s" %% dispcmd) - print(e) - return None, None - else: - if verbose: - print("unable to find command, tried %%s" %% (commands,)) - return None, None - stdout = process.communicate()[0].strip().decode() - if process.returncode != 0: - if verbose: - print("unable to run %%s (error)" %% dispcmd) - print("stdout was %%s" %% stdout) - return None, process.returncode - return stdout, process.returncode - - -def versions_from_parentdir( - parentdir_prefix: str, - root: str, - verbose: bool, -) -> Dict[str, Any]: - """Try to determine the version from the parent directory name. - - Source tarballs conventionally unpack into a directory that includes both - the project name and a version string. We will also support searching up - two directory levels for an appropriately named parent directory - """ - rootdirs = [] - - for _ in range(3): - dirname = os.path.basename(root) - if dirname.startswith(parentdir_prefix): - return {"version": dirname[len(parentdir_prefix):], - "full-revisionid": None, - "dirty": False, "error": None, "date": None} - rootdirs.append(root) - root = os.path.dirname(root) # up a level - - if verbose: - print("Tried directories %%s but none started with prefix %%s" %% - (str(rootdirs), parentdir_prefix)) - raise NotThisMethod("rootdir doesn't start with parentdir_prefix") - - -@register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: - """Extract version information from the given file.""" - # the code embedded in _version.py can just fetch the value of these - # keywords. When used from setup.py, we don't want to import _version.py, - # so we do it with a regexp instead. This function is not used from - # _version.py. - keywords: Dict[str, str] = {} - try: - with open(versionfile_abs, "r") as fobj: - for line in fobj: - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - except OSError: - pass - return keywords - - -@register_vcs_handler("git", "keywords") -def git_versions_from_keywords( - keywords: Dict[str, str], - tag_prefix: str, - verbose: bool, -) -> Dict[str, Any]: - """Get version information from git keywords.""" - if "refnames" not in keywords: - raise NotThisMethod("Short version file found") - date = keywords.get("date") - if date is not None: - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - - # git-2.2.0 added "%%cI", which expands to an ISO-8601 -compliant - # datestamp. However we prefer "%%ci" (which expands to an "ISO-8601 - # -like" string, which we must then edit to make compliant), because - # it's been around since git-1.5.3, and it's too difficult to - # discover which version we're using, or to work around using an - # older one. - date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - refnames = keywords["refnames"].strip() - if refnames.startswith("$Format"): - if verbose: - print("keywords are unexpanded, not using") - raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = {r.strip() for r in refnames.strip("()").split(",")} - # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of - # just "foo-1.0". If we see a "tag: " prefix, prefer those. - TAG = "tag: " - tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} - if not tags: - # Either we're using git < 1.8.3, or there really are no tags. We use - # a heuristic: assume all version tags have a digit. The old git %%d - # expansion behaves like git log --decorate=short and strips out the - # refs/heads/ and refs/tags/ prefixes that would let us distinguish - # between branches and tags. By ignoring refnames without digits, we - # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "master". - tags = {r for r in refs if re.search(r'\d', r)} - if verbose: - print("discarding '%%s', no digits" %% ",".join(refs - tags)) - if verbose: - print("likely tags: %%s" %% ",".join(sorted(tags))) - for ref in sorted(tags): - # sorting will prefer e.g. "2.0" over "2.0rc1" - if ref.startswith(tag_prefix): - r = ref[len(tag_prefix):] - # Filter out refs that exactly match prefix or that don't start - # with a number once the prefix is stripped (mostly a concern - # when prefix is '') - if not re.match(r'\d', r): - continue - if verbose: - print("picking %%s" %% r) - return {"version": r, - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": None, - "date": date} - # no suitable tags, so version is "0+unknown", but full hex is still there - if verbose: - print("no suitable tags, using unknown + full revision id") - return {"version": "0+unknown", - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": "no suitable tags", "date": None} - - -@register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs( - tag_prefix: str, - root: str, - verbose: bool, - runner: Callable = run_command -) -> Dict[str, Any]: - """Get version from 'git describe' in the root of the source tree. - - This only gets called if the git-archive 'subst' keywords were *not* - expanded, and _version.py hasn't already been rewritten with a short - version string, meaning we're inside a checked out source tree. - """ - GITS = ["git"] - if sys.platform == "win32": - GITS = ["git.cmd", "git.exe"] - - # GIT_DIR can interfere with correct operation of Versioneer. - # It may be intended to be passed to the Versioneer-versioned project, - # but that should not change where we get our version from. - env = os.environ.copy() - env.pop("GIT_DIR", None) - runner = functools.partial(runner, env=env) - - _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, - hide_stderr=not verbose) - if rc != 0: - if verbose: - print("Directory %%s not under git control" %% root) - raise NotThisMethod("'git rev-parse --git-dir' returned error") - - # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] - # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = runner(GITS, [ - "describe", "--tags", "--dirty", "--always", "--long", - "--match", f"{tag_prefix}[[:digit:]]*" - ], cwd=root) - # --long was added in git-1.5.5 - if describe_out is None: - raise NotThisMethod("'git describe' failed") - describe_out = describe_out.strip() - full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) - if full_out is None: - raise NotThisMethod("'git rev-parse' failed") - full_out = full_out.strip() - - pieces: Dict[str, Any] = {} - pieces["long"] = full_out - pieces["short"] = full_out[:7] # maybe improved later - pieces["error"] = None - - branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], - cwd=root) - # --abbrev-ref was added in git-1.6.3 - if rc != 0 or branch_name is None: - raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") - branch_name = branch_name.strip() - - if branch_name == "HEAD": - # If we aren't exactly on a branch, pick a branch which represents - # the current commit. If all else fails, we are on a branchless - # commit. - branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) - # --contains was added in git-1.5.4 - if rc != 0 or branches is None: - raise NotThisMethod("'git branch --contains' returned error") - branches = branches.split("\n") - - # Remove the first line if we're running detached - if "(" in branches[0]: - branches.pop(0) - - # Strip off the leading "* " from the list of branches. - branches = [branch[2:] for branch in branches] - if "master" in branches: - branch_name = "master" - elif not branches: - branch_name = None - else: - # Pick the first branch that is returned. Good or bad. - branch_name = branches[0] - - pieces["branch"] = branch_name - - # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] - # TAG might have hyphens. - git_describe = describe_out - - # look for -dirty suffix - dirty = git_describe.endswith("-dirty") - pieces["dirty"] = dirty - if dirty: - git_describe = git_describe[:git_describe.rindex("-dirty")] - - # now we have TAG-NUM-gHEX or HEX - - if "-" in git_describe: - # TAG-NUM-gHEX - mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) - if not mo: - # unparsable. Maybe git-describe is misbehaving? - pieces["error"] = ("unable to parse git-describe output: '%%s'" - %% describe_out) - return pieces - - # tag - full_tag = mo.group(1) - if not full_tag.startswith(tag_prefix): - if verbose: - fmt = "tag '%%s' doesn't start with prefix '%%s'" - print(fmt %% (full_tag, tag_prefix)) - pieces["error"] = ("tag '%%s' doesn't start with prefix '%%s'" - %% (full_tag, tag_prefix)) - return pieces - pieces["closest-tag"] = full_tag[len(tag_prefix):] - - # distance: number of commits since tag - pieces["distance"] = int(mo.group(2)) - - # commit: short hex revision ID - pieces["short"] = mo.group(3) - - else: - # HEX: no tags - pieces["closest-tag"] = None - out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) - pieces["distance"] = len(out.split()) # total number of commits - - # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = runner(GITS, ["show", "-s", "--format=%%ci", "HEAD"], cwd=root)[0].strip() - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - - return pieces - - -def plus_or_dot(pieces: Dict[str, Any]) -> str: - """Return a + if we don't already have one, else return a .""" - if "+" in pieces.get("closest-tag", ""): - return "." - return "+" - - -def render_pep440(pieces: Dict[str, Any]) -> str: - """Build up version string, with post-release "local version identifier". - - Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you - get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty - - Exceptions: - 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += plus_or_dot(pieces) - rendered += "%%d.g%%s" %% (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0+untagged.%%d.g%%s" %% (pieces["distance"], - pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_branch(pieces: Dict[str, Any]) -> str: - """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . - - The ".dev0" means not master branch. Note that .dev0 sorts backwards - (a feature branch will appear "older" than the master branch). - - Exceptions: - 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "%%d.g%%s" %% (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0" - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+untagged.%%d.g%%s" %% (pieces["distance"], - pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: - """Split pep440 version string at the post-release segment. - - Returns the release segments before the post-release and the - post-release version number (or -1 if no post-release segment is present). - """ - vc = str.split(ver, ".post") - return vc[0], int(vc[1] or 0) if len(vc) == 2 else None - - -def render_pep440_pre(pieces: Dict[str, Any]) -> str: - """TAG[.postN.devDISTANCE] -- No -dirty. - - Exceptions: - 1: no tags. 0.post0.devDISTANCE - """ - if pieces["closest-tag"]: - if pieces["distance"]: - # update the post release segment - tag_version, post_version = pep440_split_post(pieces["closest-tag"]) - rendered = tag_version - if post_version is not None: - rendered += ".post%%d.dev%%d" %% (post_version + 1, pieces["distance"]) - else: - rendered += ".post0.dev%%d" %% (pieces["distance"]) - else: - # no commits, use the tag as the version - rendered = pieces["closest-tag"] - else: - # exception #1 - rendered = "0.post0.dev%%d" %% pieces["distance"] - return rendered - - -def render_pep440_post(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX] . - - The ".dev0" means dirty. Note that .dev0 sorts backwards - (a dirty tree will appear "older" than the corresponding clean one), - but you shouldn't be releasing software with -dirty anyways. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%%d" %% pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%%s" %% pieces["short"] - else: - # exception #1 - rendered = "0.post%%d" %% pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += "+g%%s" %% pieces["short"] - return rendered - - -def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . - - The ".dev0" means not master branch. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%%d" %% pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%%s" %% pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0.post%%d" %% pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+g%%s" %% pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_old(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]] . - - The ".dev0" means dirty. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%%d" %% pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - else: - # exception #1 - rendered = "0.post%%d" %% pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - return rendered - - -def render_git_describe(pieces: Dict[str, Any]) -> str: - """TAG[-DISTANCE-gHEX][-dirty]. - - Like 'git describe --tags --dirty --always'. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"]: - rendered += "-%%d-g%%s" %% (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render_git_describe_long(pieces: Dict[str, Any]) -> str: - """TAG-DISTANCE-gHEX[-dirty]. - - Like 'git describe --tags --dirty --always -long'. - The distance/hash is unconditional. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - rendered += "-%%d-g%%s" %% (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: - """Render the given version pieces into the requested style.""" - if pieces["error"]: - return {"version": "unknown", - "full-revisionid": pieces.get("long"), - "dirty": None, - "error": pieces["error"], - "date": None} - - if not style or style == "default": - style = "pep440" # the default - - if style == "pep440": - rendered = render_pep440(pieces) - elif style == "pep440-branch": - rendered = render_pep440_branch(pieces) - elif style == "pep440-pre": - rendered = render_pep440_pre(pieces) - elif style == "pep440-post": - rendered = render_pep440_post(pieces) - elif style == "pep440-post-branch": - rendered = render_pep440_post_branch(pieces) - elif style == "pep440-old": - rendered = render_pep440_old(pieces) - elif style == "git-describe": - rendered = render_git_describe(pieces) - elif style == "git-describe-long": - rendered = render_git_describe_long(pieces) - else: - raise ValueError("unknown style '%%s'" %% style) - - return {"version": rendered, "full-revisionid": pieces["long"], - "dirty": pieces["dirty"], "error": None, - "date": pieces.get("date")} - - -def get_versions() -> Dict[str, Any]: - """Get version information or return default if unable to do so.""" - # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have - # __file__, we can work backwards from there to the root. Some - # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which - # case we can only use expanded keywords. - - cfg = get_config() - verbose = cfg.verbose - - try: - return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, - verbose) - except NotThisMethod: - pass - - try: - root = os.path.realpath(__file__) - # versionfile_source is the relative path from the top of the source - # tree (where the .git directory might live) to this file. Invert - # this to find the root from __file__. - for _ in cfg.versionfile_source.split('/'): - root = os.path.dirname(root) - except NameError: - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, - "error": "unable to find root of source tree", - "date": None} - - try: - pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) - return render(pieces, cfg.style) - except NotThisMethod: - pass - - try: - if cfg.parentdir_prefix: - return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) - except NotThisMethod: - pass - - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, - "error": "unable to compute version", "date": None} -''' - - -@register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: - """Extract version information from the given file.""" - # the code embedded in _version.py can just fetch the value of these - # keywords. When used from setup.py, we don't want to import _version.py, - # so we do it with a regexp instead. This function is not used from - # _version.py. - keywords: Dict[str, str] = {} - try: - with open(versionfile_abs, "r") as fobj: - for line in fobj: - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - except OSError: - pass - return keywords - - -@register_vcs_handler("git", "keywords") -def git_versions_from_keywords( - keywords: Dict[str, str], - tag_prefix: str, - verbose: bool, -) -> Dict[str, Any]: - """Get version information from git keywords.""" - if "refnames" not in keywords: - raise NotThisMethod("Short version file found") - date = keywords.get("date") - if date is not None: - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - - # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant - # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 - # -like" string, which we must then edit to make compliant), because - # it's been around since git-1.5.3, and it's too difficult to - # discover which version we're using, or to work around using an - # older one. - date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - refnames = keywords["refnames"].strip() - if refnames.startswith("$Format"): - if verbose: - print("keywords are unexpanded, not using") - raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = {r.strip() for r in refnames.strip("()").split(",")} - # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of - # just "foo-1.0". If we see a "tag: " prefix, prefer those. - TAG = "tag: " - tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} - if not tags: - # Either we're using git < 1.8.3, or there really are no tags. We use - # a heuristic: assume all version tags have a digit. The old git %d - # expansion behaves like git log --decorate=short and strips out the - # refs/heads/ and refs/tags/ prefixes that would let us distinguish - # between branches and tags. By ignoring refnames without digits, we - # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "master". - tags = {r for r in refs if re.search(r'\d', r)} - if verbose: - print("discarding '%s', no digits" % ",".join(refs - tags)) - if verbose: - print("likely tags: %s" % ",".join(sorted(tags))) - for ref in sorted(tags): - # sorting will prefer e.g. "2.0" over "2.0rc1" - if ref.startswith(tag_prefix): - r = ref[len(tag_prefix):] - # Filter out refs that exactly match prefix or that don't start - # with a number once the prefix is stripped (mostly a concern - # when prefix is '') - if not re.match(r'\d', r): - continue - if verbose: - print("picking %s" % r) - return {"version": r, - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": None, - "date": date} - # no suitable tags, so version is "0+unknown", but full hex is still there - if verbose: - print("no suitable tags, using unknown + full revision id") - return {"version": "0+unknown", - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": "no suitable tags", "date": None} - - -@register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs( - tag_prefix: str, - root: str, - verbose: bool, - runner: Callable = run_command -) -> Dict[str, Any]: - """Get version from 'git describe' in the root of the source tree. - - This only gets called if the git-archive 'subst' keywords were *not* - expanded, and _version.py hasn't already been rewritten with a short - version string, meaning we're inside a checked out source tree. - """ - GITS = ["git"] - if sys.platform == "win32": - GITS = ["git.cmd", "git.exe"] - - # GIT_DIR can interfere with correct operation of Versioneer. - # It may be intended to be passed to the Versioneer-versioned project, - # but that should not change where we get our version from. - env = os.environ.copy() - env.pop("GIT_DIR", None) - runner = functools.partial(runner, env=env) - - _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, - hide_stderr=not verbose) - if rc != 0: - if verbose: - print("Directory %s not under git control" % root) - raise NotThisMethod("'git rev-parse --git-dir' returned error") - - # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] - # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = runner(GITS, [ - "describe", "--tags", "--dirty", "--always", "--long", - "--match", f"{tag_prefix}[[:digit:]]*" - ], cwd=root) - # --long was added in git-1.5.5 - if describe_out is None: - raise NotThisMethod("'git describe' failed") - describe_out = describe_out.strip() - full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) - if full_out is None: - raise NotThisMethod("'git rev-parse' failed") - full_out = full_out.strip() - - pieces: Dict[str, Any] = {} - pieces["long"] = full_out - pieces["short"] = full_out[:7] # maybe improved later - pieces["error"] = None - - branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], - cwd=root) - # --abbrev-ref was added in git-1.6.3 - if rc != 0 or branch_name is None: - raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") - branch_name = branch_name.strip() - - if branch_name == "HEAD": - # If we aren't exactly on a branch, pick a branch which represents - # the current commit. If all else fails, we are on a branchless - # commit. - branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) - # --contains was added in git-1.5.4 - if rc != 0 or branches is None: - raise NotThisMethod("'git branch --contains' returned error") - branches = branches.split("\n") - - # Remove the first line if we're running detached - if "(" in branches[0]: - branches.pop(0) - - # Strip off the leading "* " from the list of branches. - branches = [branch[2:] for branch in branches] - if "master" in branches: - branch_name = "master" - elif not branches: - branch_name = None - else: - # Pick the first branch that is returned. Good or bad. - branch_name = branches[0] - - pieces["branch"] = branch_name - - # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] - # TAG might have hyphens. - git_describe = describe_out - - # look for -dirty suffix - dirty = git_describe.endswith("-dirty") - pieces["dirty"] = dirty - if dirty: - git_describe = git_describe[:git_describe.rindex("-dirty")] - - # now we have TAG-NUM-gHEX or HEX - - if "-" in git_describe: - # TAG-NUM-gHEX - mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) - if not mo: - # unparsable. Maybe git-describe is misbehaving? - pieces["error"] = ("unable to parse git-describe output: '%s'" - % describe_out) - return pieces - - # tag - full_tag = mo.group(1) - if not full_tag.startswith(tag_prefix): - if verbose: - fmt = "tag '%s' doesn't start with prefix '%s'" - print(fmt % (full_tag, tag_prefix)) - pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" - % (full_tag, tag_prefix)) - return pieces - pieces["closest-tag"] = full_tag[len(tag_prefix):] - - # distance: number of commits since tag - pieces["distance"] = int(mo.group(2)) - - # commit: short hex revision ID - pieces["short"] = mo.group(3) - - else: - # HEX: no tags - pieces["closest-tag"] = None - out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) - pieces["distance"] = len(out.split()) # total number of commits - - # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip() - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - - return pieces - - -def do_vcs_install(versionfile_source: str, ipy: Optional[str]) -> None: - """Git-specific installation logic for Versioneer. - - For Git, this means creating/changing .gitattributes to mark _version.py - for export-subst keyword substitution. - """ - GITS = ["git"] - if sys.platform == "win32": - GITS = ["git.cmd", "git.exe"] - files = [versionfile_source] - if ipy: - files.append(ipy) - if "VERSIONEER_PEP518" not in globals(): - try: - my_path = __file__ - if my_path.endswith((".pyc", ".pyo")): - my_path = os.path.splitext(my_path)[0] + ".py" - versioneer_file = os.path.relpath(my_path) - except NameError: - versioneer_file = "versioneer.py" - files.append(versioneer_file) - present = False - try: - with open(".gitattributes", "r") as fobj: - for line in fobj: - if line.strip().startswith(versionfile_source): - if "export-subst" in line.strip().split()[1:]: - present = True - break - except OSError: - pass - if not present: - with open(".gitattributes", "a+") as fobj: - fobj.write(f"{versionfile_source} export-subst\n") - files.append(".gitattributes") - run_command(GITS, ["add", "--"] + files) - - -def versions_from_parentdir( - parentdir_prefix: str, - root: str, - verbose: bool, -) -> Dict[str, Any]: - """Try to determine the version from the parent directory name. - - Source tarballs conventionally unpack into a directory that includes both - the project name and a version string. We will also support searching up - two directory levels for an appropriately named parent directory - """ - rootdirs = [] - - for _ in range(3): - dirname = os.path.basename(root) - if dirname.startswith(parentdir_prefix): - return {"version": dirname[len(parentdir_prefix):], - "full-revisionid": None, - "dirty": False, "error": None, "date": None} - rootdirs.append(root) - root = os.path.dirname(root) # up a level - - if verbose: - print("Tried directories %s but none started with prefix %s" % - (str(rootdirs), parentdir_prefix)) - raise NotThisMethod("rootdir doesn't start with parentdir_prefix") - - -SHORT_VERSION_PY = """ -# This file was generated by 'versioneer.py' (0.29) from -# revision-control system data, or from the parent directory name of an -# unpacked source archive. Distribution tarballs contain a pre-generated copy -# of this file. - -import json - -version_json = ''' -%s -''' # END VERSION_JSON - - -def get_versions(): - return json.loads(version_json) -""" - - -def versions_from_file(filename: str) -> Dict[str, Any]: - """Try to determine the version from _version.py if present.""" - try: - with open(filename) as f: - contents = f.read() - except OSError: - raise NotThisMethod("unable to read _version.py") - mo = re.search(r"version_json = '''\n(.*)''' # END VERSION_JSON", - contents, re.M | re.S) - if not mo: - mo = re.search(r"version_json = '''\r\n(.*)''' # END VERSION_JSON", - contents, re.M | re.S) - if not mo: - raise NotThisMethod("no version_json in _version.py") - return json.loads(mo.group(1)) - - -def write_to_version_file(filename: str, versions: Dict[str, Any]) -> None: - """Write the given version number to the given _version.py file.""" - contents = json.dumps(versions, sort_keys=True, - indent=1, separators=(",", ": ")) - with open(filename, "w") as f: - f.write(SHORT_VERSION_PY % contents) - - print("set %s to '%s'" % (filename, versions["version"])) - - -def plus_or_dot(pieces: Dict[str, Any]) -> str: - """Return a + if we don't already have one, else return a .""" - if "+" in pieces.get("closest-tag", ""): - return "." - return "+" - - -def render_pep440(pieces: Dict[str, Any]) -> str: - """Build up version string, with post-release "local version identifier". - - Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you - get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty - - Exceptions: - 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += plus_or_dot(pieces) - rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0+untagged.%d.g%s" % (pieces["distance"], - pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_branch(pieces: Dict[str, Any]) -> str: - """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . - - The ".dev0" means not master branch. Note that .dev0 sorts backwards - (a feature branch will appear "older" than the master branch). - - Exceptions: - 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0" - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+untagged.%d.g%s" % (pieces["distance"], - pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: - """Split pep440 version string at the post-release segment. - - Returns the release segments before the post-release and the - post-release version number (or -1 if no post-release segment is present). - """ - vc = str.split(ver, ".post") - return vc[0], int(vc[1] or 0) if len(vc) == 2 else None - - -def render_pep440_pre(pieces: Dict[str, Any]) -> str: - """TAG[.postN.devDISTANCE] -- No -dirty. - - Exceptions: - 1: no tags. 0.post0.devDISTANCE - """ - if pieces["closest-tag"]: - if pieces["distance"]: - # update the post release segment - tag_version, post_version = pep440_split_post(pieces["closest-tag"]) - rendered = tag_version - if post_version is not None: - rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"]) - else: - rendered += ".post0.dev%d" % (pieces["distance"]) - else: - # no commits, use the tag as the version - rendered = pieces["closest-tag"] - else: - # exception #1 - rendered = "0.post0.dev%d" % pieces["distance"] - return rendered - - -def render_pep440_post(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX] . - - The ".dev0" means dirty. Note that .dev0 sorts backwards - (a dirty tree will appear "older" than the corresponding clean one), - but you shouldn't be releasing software with -dirty anyways. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%s" % pieces["short"] - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += "+g%s" % pieces["short"] - return rendered - - -def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . - - The ".dev0" means not master branch. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%s" % pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+g%s" % pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_old(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]] . - - The ".dev0" means dirty. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - return rendered - - -def render_git_describe(pieces: Dict[str, Any]) -> str: - """TAG[-DISTANCE-gHEX][-dirty]. - - Like 'git describe --tags --dirty --always'. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"]: - rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render_git_describe_long(pieces: Dict[str, Any]) -> str: - """TAG-DISTANCE-gHEX[-dirty]. - - Like 'git describe --tags --dirty --always -long'. - The distance/hash is unconditional. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: - """Render the given version pieces into the requested style.""" - if pieces["error"]: - return {"version": "unknown", - "full-revisionid": pieces.get("long"), - "dirty": None, - "error": pieces["error"], - "date": None} - - if not style or style == "default": - style = "pep440" # the default - - if style == "pep440": - rendered = render_pep440(pieces) - elif style == "pep440-branch": - rendered = render_pep440_branch(pieces) - elif style == "pep440-pre": - rendered = render_pep440_pre(pieces) - elif style == "pep440-post": - rendered = render_pep440_post(pieces) - elif style == "pep440-post-branch": - rendered = render_pep440_post_branch(pieces) - elif style == "pep440-old": - rendered = render_pep440_old(pieces) - elif style == "git-describe": - rendered = render_git_describe(pieces) - elif style == "git-describe-long": - rendered = render_git_describe_long(pieces) - else: - raise ValueError("unknown style '%s'" % style) - - return {"version": rendered, "full-revisionid": pieces["long"], - "dirty": pieces["dirty"], "error": None, - "date": pieces.get("date")} - - -class VersioneerBadRootError(Exception): - """The project root directory is unknown or missing key files.""" - - -def get_versions(verbose: bool = False) -> Dict[str, Any]: - """Get the project version from whatever source is available. - - Returns dict with two keys: 'version' and 'full'. - """ - if "versioneer" in sys.modules: - # see the discussion in cmdclass.py:get_cmdclass() - del sys.modules["versioneer"] - - root = get_root() - cfg = get_config_from_root(root) - - assert cfg.VCS is not None, "please set [versioneer]VCS= in setup.cfg" - handlers = HANDLERS.get(cfg.VCS) - assert handlers, "unrecognized VCS '%s'" % cfg.VCS - verbose = verbose or bool(cfg.verbose) # `bool()` used to avoid `None` - assert cfg.versionfile_source is not None, \ - "please set versioneer.versionfile_source" - assert cfg.tag_prefix is not None, "please set versioneer.tag_prefix" - - versionfile_abs = os.path.join(root, cfg.versionfile_source) - - # extract version from first of: _version.py, VCS command (e.g. 'git - # describe'), parentdir. This is meant to work for developers using a - # source checkout, for users of a tarball created by 'setup.py sdist', - # and for users of a tarball/zipball created by 'git archive' or github's - # download-from-tag feature or the equivalent in other VCSes. - - get_keywords_f = handlers.get("get_keywords") - from_keywords_f = handlers.get("keywords") - if get_keywords_f and from_keywords_f: - try: - keywords = get_keywords_f(versionfile_abs) - ver = from_keywords_f(keywords, cfg.tag_prefix, verbose) - if verbose: - print("got version from expanded keyword %s" % ver) - return ver - except NotThisMethod: - pass - - try: - ver = versions_from_file(versionfile_abs) - if verbose: - print("got version from file %s %s" % (versionfile_abs, ver)) - return ver - except NotThisMethod: - pass - - from_vcs_f = handlers.get("pieces_from_vcs") - if from_vcs_f: - try: - pieces = from_vcs_f(cfg.tag_prefix, root, verbose) - ver = render(pieces, cfg.style) - if verbose: - print("got version from VCS %s" % ver) - return ver - except NotThisMethod: - pass - - try: - if cfg.parentdir_prefix: - ver = versions_from_parentdir(cfg.parentdir_prefix, root, verbose) - if verbose: - print("got version from parentdir %s" % ver) - return ver - except NotThisMethod: - pass - - if verbose: - print("unable to compute version") - - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, "error": "unable to compute version", - "date": None} - - -def get_version() -> str: - """Get the short version string for this project.""" - return get_versions()["version"] - - -def get_cmdclass(cmdclass: Optional[Dict[str, Any]] = None): - """Get the custom setuptools subclasses used by Versioneer. - - If the package uses a different cmdclass (e.g. one from numpy), it - should be provide as an argument. - """ - if "versioneer" in sys.modules: - del sys.modules["versioneer"] - # this fixes the "python setup.py develop" case (also 'install' and - # 'easy_install .'), in which subdependencies of the main project are - # built (using setup.py bdist_egg) in the same python process. Assume - # a main project A and a dependency B, which use different versions - # of Versioneer. A's setup.py imports A's Versioneer, leaving it in - # sys.modules by the time B's setup.py is executed, causing B to run - # with the wrong versioneer. Setuptools wraps the sub-dep builds in a - # sandbox that restores sys.modules to it's pre-build state, so the - # parent is protected against the child's "import versioneer". By - # removing ourselves from sys.modules here, before the child build - # happens, we protect the child from the parent's versioneer too. - # Also see https://github.com/python-versioneer/python-versioneer/issues/52 - - cmds = {} if cmdclass is None else cmdclass.copy() - - # we add "version" to setuptools - from setuptools import Command - - class cmd_version(Command): - description = "report generated version string" - user_options: List[Tuple[str, str, str]] = [] - boolean_options: List[str] = [] - - def initialize_options(self) -> None: - pass - - def finalize_options(self) -> None: - pass - - def run(self) -> None: - vers = get_versions(verbose=True) - print("Version: %s" % vers["version"]) - print(" full-revisionid: %s" % vers.get("full-revisionid")) - print(" dirty: %s" % vers.get("dirty")) - print(" date: %s" % vers.get("date")) - if vers["error"]: - print(" error: %s" % vers["error"]) - cmds["version"] = cmd_version - - # we override "build_py" in setuptools - # - # most invocation pathways end up running build_py: - # distutils/build -> build_py - # distutils/install -> distutils/build ->.. - # setuptools/bdist_wheel -> distutils/install ->.. - # setuptools/bdist_egg -> distutils/install_lib -> build_py - # setuptools/install -> bdist_egg ->.. - # setuptools/develop -> ? - # pip install: - # copies source tree to a tempdir before running egg_info/etc - # if .git isn't copied too, 'git describe' will fail - # then does setup.py bdist_wheel, or sometimes setup.py install - # setup.py egg_info -> ? - - # pip install -e . and setuptool/editable_wheel will invoke build_py - # but the build_py command is not expected to copy any files. - - # we override different "build_py" commands for both environments - if 'build_py' in cmds: - _build_py: Any = cmds['build_py'] - else: - from setuptools.command.build_py import build_py as _build_py - - class cmd_build_py(_build_py): - def run(self) -> None: - root = get_root() - cfg = get_config_from_root(root) - versions = get_versions() - _build_py.run(self) - if getattr(self, "editable_mode", False): - # During editable installs `.py` and data files are - # not copied to build_lib - return - # now locate _version.py in the new build/ directory and replace - # it with an updated value - if cfg.versionfile_build: - target_versionfile = os.path.join(self.build_lib, - cfg.versionfile_build) - print("UPDATING %s" % target_versionfile) - write_to_version_file(target_versionfile, versions) - cmds["build_py"] = cmd_build_py - - if 'build_ext' in cmds: - _build_ext: Any = cmds['build_ext'] - else: - from setuptools.command.build_ext import build_ext as _build_ext - - class cmd_build_ext(_build_ext): - def run(self) -> None: - root = get_root() - cfg = get_config_from_root(root) - versions = get_versions() - _build_ext.run(self) - if self.inplace: - # build_ext --inplace will only build extensions in - # build/lib<..> dir with no _version.py to write to. - # As in place builds will already have a _version.py - # in the module dir, we do not need to write one. - return - # now locate _version.py in the new build/ directory and replace - # it with an updated value - if not cfg.versionfile_build: - return - target_versionfile = os.path.join(self.build_lib, - cfg.versionfile_build) - if not os.path.exists(target_versionfile): - print(f"Warning: {target_versionfile} does not exist, skipping " - "version update. This can happen if you are running build_ext " - "without first running build_py.") - return - print("UPDATING %s" % target_versionfile) - write_to_version_file(target_versionfile, versions) - cmds["build_ext"] = cmd_build_ext - - if "cx_Freeze" in sys.modules: # cx_freeze enabled? - from cx_Freeze.dist import build_exe as _build_exe # type: ignore - # nczeczulin reports that py2exe won't like the pep440-style string - # as FILEVERSION, but it can be used for PRODUCTVERSION, e.g. - # setup(console=[{ - # "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION - # "product_version": versioneer.get_version(), - # ... - - class cmd_build_exe(_build_exe): - def run(self) -> None: - root = get_root() - cfg = get_config_from_root(root) - versions = get_versions() - target_versionfile = cfg.versionfile_source - print("UPDATING %s" % target_versionfile) - write_to_version_file(target_versionfile, versions) - - _build_exe.run(self) - os.unlink(target_versionfile) - with open(cfg.versionfile_source, "w") as f: - LONG = LONG_VERSION_PY[cfg.VCS] - f.write(LONG % - {"DOLLAR": "$", - "STYLE": cfg.style, - "TAG_PREFIX": cfg.tag_prefix, - "PARENTDIR_PREFIX": cfg.parentdir_prefix, - "VERSIONFILE_SOURCE": cfg.versionfile_source, - }) - cmds["build_exe"] = cmd_build_exe - del cmds["build_py"] - - if 'py2exe' in sys.modules: # py2exe enabled? - try: - from py2exe.setuptools_buildexe import py2exe as _py2exe # type: ignore - except ImportError: - from py2exe.distutils_buildexe import py2exe as _py2exe # type: ignore - - class cmd_py2exe(_py2exe): - def run(self) -> None: - root = get_root() - cfg = get_config_from_root(root) - versions = get_versions() - target_versionfile = cfg.versionfile_source - print("UPDATING %s" % target_versionfile) - write_to_version_file(target_versionfile, versions) - - _py2exe.run(self) - os.unlink(target_versionfile) - with open(cfg.versionfile_source, "w") as f: - LONG = LONG_VERSION_PY[cfg.VCS] - f.write(LONG % - {"DOLLAR": "$", - "STYLE": cfg.style, - "TAG_PREFIX": cfg.tag_prefix, - "PARENTDIR_PREFIX": cfg.parentdir_prefix, - "VERSIONFILE_SOURCE": cfg.versionfile_source, - }) - cmds["py2exe"] = cmd_py2exe - - # sdist farms its file list building out to egg_info - if 'egg_info' in cmds: - _egg_info: Any = cmds['egg_info'] - else: - from setuptools.command.egg_info import egg_info as _egg_info - - class cmd_egg_info(_egg_info): - def find_sources(self) -> None: - # egg_info.find_sources builds the manifest list and writes it - # in one shot - super().find_sources() - - # Modify the filelist and normalize it - root = get_root() - cfg = get_config_from_root(root) - self.filelist.append('versioneer.py') - if cfg.versionfile_source: - # There are rare cases where versionfile_source might not be - # included by default, so we must be explicit - self.filelist.append(cfg.versionfile_source) - self.filelist.sort() - self.filelist.remove_duplicates() - - # The write method is hidden in the manifest_maker instance that - # generated the filelist and was thrown away - # We will instead replicate their final normalization (to unicode, - # and POSIX-style paths) - from setuptools import unicode_utils - normalized = [unicode_utils.filesys_decode(f).replace(os.sep, '/') - for f in self.filelist.files] - - manifest_filename = os.path.join(self.egg_info, 'SOURCES.txt') - with open(manifest_filename, 'w') as fobj: - fobj.write('\n'.join(normalized)) - - cmds['egg_info'] = cmd_egg_info - - # we override different "sdist" commands for both environments - if 'sdist' in cmds: - _sdist: Any = cmds['sdist'] - else: - from setuptools.command.sdist import sdist as _sdist - - class cmd_sdist(_sdist): - def run(self) -> None: - versions = get_versions() - self._versioneer_generated_versions = versions - # unless we update this, the command will keep using the old - # version - self.distribution.metadata.version = versions["version"] - return _sdist.run(self) - - def make_release_tree(self, base_dir: str, files: List[str]) -> None: - root = get_root() - cfg = get_config_from_root(root) - _sdist.make_release_tree(self, base_dir, files) - # now locate _version.py in the new base_dir directory - # (remembering that it may be a hardlink) and replace it with an - # updated value - target_versionfile = os.path.join(base_dir, cfg.versionfile_source) - print("UPDATING %s" % target_versionfile) - write_to_version_file(target_versionfile, - self._versioneer_generated_versions) - cmds["sdist"] = cmd_sdist - - return cmds - - -CONFIG_ERROR = """ -setup.cfg is missing the necessary Versioneer configuration. You need -a section like: - - [versioneer] - VCS = git - style = pep440 - versionfile_source = src/myproject/_version.py - versionfile_build = myproject/_version.py - tag_prefix = - parentdir_prefix = myproject- - -You will also need to edit your setup.py to use the results: - - import versioneer - setup(version=versioneer.get_version(), - cmdclass=versioneer.get_cmdclass(), ...) - -Please read the docstring in ./versioneer.py for configuration instructions, -edit setup.cfg, and re-run the installer or 'python versioneer.py setup'. -""" - -SAMPLE_CONFIG = """ -# See the docstring in versioneer.py for instructions. Note that you must -# re-run 'versioneer.py setup' after changing this section, and commit the -# resulting files. - -[versioneer] -#VCS = git -#style = pep440 -#versionfile_source = -#versionfile_build = -#tag_prefix = -#parentdir_prefix = - -""" - -OLD_SNIPPET = """ -from ._version import get_versions -__version__ = get_versions()['version'] -del get_versions -""" - -INIT_PY_SNIPPET = """ -from . import {0} -__version__ = {0}.get_versions()['version'] -""" - - -def do_setup() -> int: - """Do main VCS-independent setup function for installing Versioneer.""" - root = get_root() - try: - cfg = get_config_from_root(root) - except (OSError, configparser.NoSectionError, - configparser.NoOptionError) as e: - if isinstance(e, (OSError, configparser.NoSectionError)): - print("Adding sample versioneer config to setup.cfg", - file=sys.stderr) - with open(os.path.join(root, "setup.cfg"), "a") as f: - f.write(SAMPLE_CONFIG) - print(CONFIG_ERROR, file=sys.stderr) - return 1 - - print(" creating %s" % cfg.versionfile_source) - with open(cfg.versionfile_source, "w") as f: - LONG = LONG_VERSION_PY[cfg.VCS] - f.write(LONG % {"DOLLAR": "$", - "STYLE": cfg.style, - "TAG_PREFIX": cfg.tag_prefix, - "PARENTDIR_PREFIX": cfg.parentdir_prefix, - "VERSIONFILE_SOURCE": cfg.versionfile_source, - }) - - ipy = os.path.join(os.path.dirname(cfg.versionfile_source), - "__init__.py") - maybe_ipy: Optional[str] = ipy - if os.path.exists(ipy): - try: - with open(ipy, "r") as f: - old = f.read() - except OSError: - old = "" - module = os.path.splitext(os.path.basename(cfg.versionfile_source))[0] - snippet = INIT_PY_SNIPPET.format(module) - if OLD_SNIPPET in old: - print(" replacing boilerplate in %s" % ipy) - with open(ipy, "w") as f: - f.write(old.replace(OLD_SNIPPET, snippet)) - elif snippet not in old: - print(" appending to %s" % ipy) - with open(ipy, "a") as f: - f.write(snippet) - else: - print(" %s unmodified" % ipy) - else: - print(" %s doesn't exist, ok" % ipy) - maybe_ipy = None - - # Make VCS-specific changes. For git, this means creating/changing - # .gitattributes to mark _version.py for export-subst keyword - # substitution. - do_vcs_install(cfg.versionfile_source, maybe_ipy) - return 0 - - -def scan_setup_py() -> int: - """Validate the contents of setup.py against Versioneer's expectations.""" - found = set() - setters = False - errors = 0 - with open("setup.py", "r") as f: - for line in f.readlines(): - if "import versioneer" in line: - found.add("import") - if "versioneer.get_cmdclass()" in line: - found.add("cmdclass") - if "versioneer.get_version()" in line: - found.add("get_version") - if "versioneer.VCS" in line: - setters = True - if "versioneer.versionfile_source" in line: - setters = True - if len(found) != 3: - print("") - print("Your setup.py appears to be missing some important items") - print("(but I might be wrong). Please make sure it has something") - print("roughly like the following:") - print("") - print(" import versioneer") - print(" setup( version=versioneer.get_version(),") - print(" cmdclass=versioneer.get_cmdclass(), ...)") - print("") - errors += 1 - if setters: - print("You should remove lines like 'versioneer.VCS = ' and") - print("'versioneer.versionfile_source = ' . This configuration") - print("now lives in setup.cfg, and should be removed from setup.py") - print("") - errors += 1 - return errors - - -def setup_command() -> NoReturn: - """Set up Versioneer and exit with appropriate error code.""" - errors = do_setup() - errors += scan_setup_py() - sys.exit(1 if errors else 0) - - -if __name__ == "__main__": - cmd = sys.argv[1] - if cmd == "setup": - setup_command() From 30c22a59f92bc1a9b504a7e33eaddcb8eef4e8a6 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 30 Apr 2024 16:17:25 +0100 Subject: [PATCH 31/62] Remove classic KubeCluster and HelmCluster (#890) * Remove classic KubeCluster and HelmCluster * Be less specific in testing config * Remove deprecation warning test * Shift docs focus a little * Refactor docs a little more * Reinstate code example * doc -> docs --- .github/workflows/helmcluster.yaml | 57 -- .github/workflows/kubecluster.yaml | 57 -- .github/workflows/operator.yaml | 16 +- .gitignore | 2 +- .readthedocs.yaml | 4 +- dask_kubernetes/__init__.py | 24 +- dask_kubernetes/classic/__init__.py | 2 - dask_kubernetes/classic/kubecluster.py | 781 --------------- .../classic/tests/config-demo.yaml | 38 - dask_kubernetes/classic/tests/fake-ca-file | 0 dask_kubernetes/classic/tests/fake-cert-file | 0 dask_kubernetes/classic/tests/fake-key-file | 0 .../classic/tests/fake_gcp_auth.py | 25 - dask_kubernetes/classic/tests/test_async.py | 886 ------------------ dask_kubernetes/classic/tests/test_sync.py | 497 ---------- dask_kubernetes/common/auth.py | 493 ---------- dask_kubernetes/common/networking.py | 240 ----- dask_kubernetes/common/objects.py | 386 -------- dask_kubernetes/common/tests/test_kind.py | 25 - dask_kubernetes/common/tests/test_objects.py | 88 -- dask_kubernetes/common/utils.py | 47 - dask_kubernetes/conftest.py | 12 +- dask_kubernetes/experimental/__init__.py | 23 - dask_kubernetes/helm/__init__.py | 1 - dask_kubernetes/helm/helmcluster.py | 335 ------- .../helm/tests/resources/values.yaml | 20 - dask_kubernetes/helm/tests/test_helm.py | 241 ----- .../operator/controller/controller.py | 2 +- .../operator/kubecluster/kubecluster.py | 2 +- .../kubecluster/tests/test_kubecluster.py | 41 +- dask_kubernetes/operator/validation.py | 17 + doc/source/helmcluster.rst | 69 -- doc/source/index.rst | 105 --- doc/source/installing.rst | 71 -- doc/source/kubecluster.rst | 342 ------- {doc => docs}/Makefile | 0 {doc => docs}/make.bat | 0 {doc => docs}/requirements-docs.txt | 0 {doc => docs}/source/conf.py | 0 {doc => docs}/source/history.rst | 0 ...eflow-notebooks-configuration-selector.png | Bin .../source/images/operator-install.gif | Bin .../source/images/operator-install.tape | 2 +- .../operator.rst => docs/source/index.rst | 98 +- .../source/installing.rst | 89 +- .../source/kubecluster_migrating.rst | 31 +- {doc => docs}/source/operator_extending.rst | 0 {doc => docs}/source/operator_kubecluster.rst | 6 +- {doc => docs}/source/operator_resources.rst | 0 .../source/operator_troubleshooting.rst | 0 {doc => docs}/source/releasing.rst | 0 {doc => docs}/source/testing.rst | 0 52 files changed, 232 insertions(+), 4943 deletions(-) delete mode 100644 .github/workflows/helmcluster.yaml delete mode 100644 .github/workflows/kubecluster.yaml delete mode 100644 dask_kubernetes/classic/__init__.py delete mode 100644 dask_kubernetes/classic/kubecluster.py delete mode 100644 dask_kubernetes/classic/tests/config-demo.yaml delete mode 100644 dask_kubernetes/classic/tests/fake-ca-file delete mode 100644 dask_kubernetes/classic/tests/fake-cert-file delete mode 100644 dask_kubernetes/classic/tests/fake-key-file delete mode 100644 dask_kubernetes/classic/tests/fake_gcp_auth.py delete mode 100644 dask_kubernetes/classic/tests/test_async.py delete mode 100644 dask_kubernetes/classic/tests/test_sync.py delete mode 100644 dask_kubernetes/common/auth.py delete mode 100644 dask_kubernetes/common/networking.py delete mode 100644 dask_kubernetes/common/objects.py delete mode 100644 dask_kubernetes/common/tests/test_kind.py delete mode 100644 dask_kubernetes/common/tests/test_objects.py delete mode 100644 dask_kubernetes/common/utils.py delete mode 100644 dask_kubernetes/experimental/__init__.py delete mode 100644 dask_kubernetes/helm/__init__.py delete mode 100644 dask_kubernetes/helm/helmcluster.py delete mode 100644 dask_kubernetes/helm/tests/resources/values.yaml delete mode 100644 dask_kubernetes/helm/tests/test_helm.py create mode 100644 dask_kubernetes/operator/validation.py delete mode 100644 doc/source/helmcluster.rst delete mode 100644 doc/source/index.rst delete mode 100644 doc/source/installing.rst delete mode 100644 doc/source/kubecluster.rst rename {doc => docs}/Makefile (100%) rename {doc => docs}/make.bat (100%) rename {doc => docs}/requirements-docs.txt (100%) rename {doc => docs}/source/conf.py (100%) rename {doc => docs}/source/history.rst (100%) rename {doc => docs}/source/images/kubeflow-notebooks-configuration-selector.png (100%) rename {doc => docs}/source/images/operator-install.gif (100%) rename {doc => docs}/source/images/operator-install.tape (98%) rename doc/source/operator.rst => docs/source/index.rst (63%) rename doc/source/operator_installation.rst => docs/source/installing.rst (77%) rename {doc => docs}/source/kubecluster_migrating.rst (85%) rename {doc => docs}/source/operator_extending.rst (100%) rename {doc => docs}/source/operator_kubecluster.rst (94%) rename {doc => docs}/source/operator_resources.rst (100%) rename {doc => docs}/source/operator_troubleshooting.rst (100%) rename {doc => docs}/source/releasing.rst (100%) rename {doc => docs}/source/testing.rst (100%) diff --git a/.github/workflows/helmcluster.yaml b/.github/workflows/helmcluster.yaml deleted file mode 100644 index 5e2f0ca70..000000000 --- a/.github/workflows/helmcluster.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: "HelmCluster" -on: - pull_request: - paths: - - ".github/workflows/helmcluster.yaml" - - "requirements*" - - "ci/**" - - "dask_kubernetes/helm/**" - - "dask_kubernetes/common/**" - - "dask_kubernetes/*" - push: - paths: - - ".github/workflows/helmcluster.yaml" - - "requirements*" - - "ci/**" - - "dask_kubernetes/helm/**" - - "dask_kubernetes/common/**" - - "dask_kubernetes/*" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - test: - runs-on: ubuntu-latest - timeout-minutes: 15 - strategy: - fail-fast: false - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] - kubernetes-version: ["1.29.2"] - include: - - python-version: '3.10' - kubernetes-version: 1.28.7 - - python-version: '3.10' - kubernetes-version: 1.27.11 - - python-version: '3.10' - kubernetes-version: 1.26.14 - - env: - KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install deps - run: ./ci/install-deps.sh - - name: Run tests - env: - KUBERNETES_VERSION: ${{ matrix.kubernetes-version }} - run: pytest --reruns=5 dask_kubernetes/common/tests dask_kubernetes/helm/tests - - name: Debug k8s resources - if: success() || failure() - run: kubectl get all -A diff --git a/.github/workflows/kubecluster.yaml b/.github/workflows/kubecluster.yaml deleted file mode 100644 index f2e6d81dd..000000000 --- a/.github/workflows/kubecluster.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: "KubeCluster" -on: - pull_request: - paths: - - ".github/workflows/kubecluster.yaml" - - "requirements*" - - "ci/**" - - "dask_kubernetes/classic/**" - - "dask_kubernetes/common/**" - - "dask_kubernetes/*" - push: - paths: - - ".github/workflows/kubecluster.yaml" - - "requirements*" - - "ci/**" - - "dask_kubernetes/classic/**" - - "dask_kubernetes/common/**" - - "dask_kubernetes/*" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - test: - runs-on: ubuntu-latest - timeout-minutes: 45 - strategy: - fail-fast: false - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] - kubernetes-version: ["1.29.2"] - include: - - python-version: '3.10' - kubernetes-version: 1.28.7 - - python-version: '3.10' - kubernetes-version: 1.27.11 - - python-version: '3.10' - kubernetes-version: 1.26.14 - - env: - KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install deps - run: ./ci/install-deps.sh - - name: Run tests - env: - KUBERNETES_VERSION: ${{ matrix.kubernetes-version }} - run: pytest --reruns=5 dask_kubernetes/common/tests dask_kubernetes/classic/tests - - name: Debug k8s resources - if: success() || failure() - run: kubectl get all -A diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index ba6b2dfa3..8e3967c62 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -1,21 +1,7 @@ name: "Operator" on: pull_request: - paths: - - ".github/workflows/operator.yaml" - - "requirements*" - - "ci/**" - - "dask_kubernetes/operator/**" - - "dask_kubernetes/common/**" - - "dask_kubernetes/*" push: - paths: - - ".github/workflows/operator.yaml" - - "requirements*" - - "ci/**" - - "dask_kubernetes/operator/**" - - "dask_kubernetes/common/**" - - "dask_kubernetes/*" concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -64,7 +50,7 @@ jobs: KUBERNETES_VERSION: ${{ matrix.kubernetes-version }} TEST_ISTIO: "true" TEST_DASK_GATEWAY: "true" - run: pytest --maxfail=3 --reruns=5 dask_kubernetes/common dask_kubernetes/operator + run: pytest --maxfail=3 --reruns=5 dask_kubernetes - name: Debug kubernetes resources if: always() run: kubectl get all -A diff --git a/.gitignore b/.gitignore index 9fa3912da..fb6f9cc5d 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ instance/ .scrapy # Sphinx documentation -doc/_build/ +docs/_build/ # PyBuilder target/ diff --git a/.readthedocs.yaml b/.readthedocs.yaml index bd335a58e..9bfe5114f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -7,7 +7,7 @@ version: 2 # Set the version of Python and other tools you might need sphinx: - configuration: doc/source/conf.py + configuration: docs/source/conf.py formats: all @@ -20,7 +20,7 @@ python: install: - method: pip path: . - - requirements: doc/requirements-docs.txt + - requirements: docs/requirements-docs.txt submodules: include: all diff --git a/dask_kubernetes/__init__.py b/dask_kubernetes/__init__.py index 09c37910c..e88ac7c69 100644 --- a/dask_kubernetes/__init__.py +++ b/dask_kubernetes/__init__.py @@ -1,20 +1,6 @@ -from importlib import import_module -from warnings import warn - from . import config -from .common.auth import ( - AutoRefreshConfiguration, - AutoRefreshKubeConfigLoader, - ClusterAuth, - InCluster, - KubeAuth, - KubeConfig, -) -from .common.objects import clean_pod_template, make_pod_from_dict, make_pod_spec -from .helm import HelmCluster - -__all__ = ["HelmCluster", "KubeCluster"] +__all__ = [] try: from ._version import version as __version__ # noqa @@ -22,11 +8,3 @@ except ImportError: __version__ = "0.0.0" __version_tuple__ = (0, 0, 0) - - -def __getattr__(name): - if name == "KubeCluster": - new_module = import_module("dask_kubernetes.classic") - return getattr(new_module, name) - - raise AttributeError(f"module {__name__} has no attribute {name}") diff --git a/dask_kubernetes/classic/__init__.py b/dask_kubernetes/classic/__init__.py deleted file mode 100644 index d1aaad827..000000000 --- a/dask_kubernetes/classic/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from ..common.objects import make_pod_spec -from .kubecluster import KubeCluster diff --git a/dask_kubernetes/classic/kubecluster.py b/dask_kubernetes/classic/kubecluster.py deleted file mode 100644 index 6f5b8a299..000000000 --- a/dask_kubernetes/classic/kubecluster.py +++ /dev/null @@ -1,781 +0,0 @@ -import asyncio -import copy -import getpass -import logging -import os -import time -import uuid -import warnings - -import aiohttp -import dask -import dask.distributed -import distributed.security -import kubernetes_asyncio as kubernetes -import yaml -from distributed.deploy import ProcessInterface, SpecCluster -from distributed.utils import Log, Logs, format_dashboard_link -from kubernetes_asyncio.client.rest import ApiException - -from ..common.auth import ClusterAuth -from ..common.networking import ( - get_external_address_for_scheduler_service, - get_scheduler_address, -) -from ..common.objects import ( - clean_pdb_template, - clean_pod_template, - clean_service_template, - make_pdb_from_dict, - make_pod_from_dict, - make_service_from_dict, -) -from ..common.utils import ( - escape, - get_current_namespace, -) - -logger = logging.getLogger(__name__) - -SCHEDULER_PORT = 8786 - - -class Pod(ProcessInterface): - """A superclass for Kubernetes Pods - - See Also - -------- - Worker - Scheduler - """ - - def __init__( - self, - cluster, - core_api, - policy_api, - pod_template, - namespace, - loop=None, - **kwargs - ): - self._pod = None - self.cluster = cluster - self.core_api = core_api - self.policy_api = policy_api - self.pod_template = copy.deepcopy(pod_template) - self.base_labels = self.pod_template.metadata.labels - self.namespace = namespace - self.name = None - self.loop = loop - self.kwargs = kwargs - super().__init__() - - @property - def cluster_name(self): - return self.pod_template.metadata.labels["dask.org/cluster-name"] - - async def start(self, **kwargs): - retry_count = 0 # Retry 10 times - while True: - try: - self._pod = await self.core_api.create_namespaced_pod( - self.namespace, self.pod_template - ) - return await super().start(**kwargs) - except ApiException as e: - if retry_count < 10: - logger.debug("Error when creating pod, retrying... - %s", str(e)) - await asyncio.sleep(0.1) - retry_count += 1 - else: - raise e - - async def close(self, **kwargs): - if self._pod: - retry_count = 0 # Retry 10 times - while True: - name, namespace = self._pod.metadata.name, self.namespace - try: - await self.core_api.delete_namespaced_pod(name, namespace) - return await super().close(**kwargs) - except ApiException as e: - if e.reason == "Not Found": - logger.debug( - "Pod %s in namespace %s has been deleted already.", - name, - namespace, - ) - return await super().close(**kwargs) - else: - raise - except aiohttp.client_exceptions.ClientConnectorError as e: - if retry_count < 10: - logger.debug("Connection error, retrying... - %s", str(e)) - await asyncio.sleep(0.1) - retry_count += 1 - else: - raise e - - async def logs(self): - try: - log = await self.core_api.read_namespaced_pod_log( - self._pod.metadata.name, - self.namespace, - container=self.pod_template.spec.containers[0].name, - ) - except ApiException as e: - if "waiting to start" in str(e): - log = "" - else: - raise e - return Log(log) - - async def describe_pod(self): - self._pod = await self.core_api.read_namespaced_pod( - self._pod.metadata.name, self.namespace - ) - return self._pod - - def __repr__(self): - return "" % (type(self).__name__, self.status) - - -class Worker(Pod): - """A Remote Dask Worker controled by Kubernetes - Parameters - ---------- - scheduler: str - The address of the scheduler - name (optional): - The name passed to the dask-worker CLI at creation time. - """ - - def __init__(self, scheduler: str, name=None, **kwargs): - super().__init__(**kwargs) - - self.scheduler = scheduler - - self.pod_template.metadata.labels["dask.org/component"] = "worker" - self.pod_template.spec.containers[0].env.append( - kubernetes.client.V1EnvVar( - name="DASK_SCHEDULER_ADDRESS", value=self.scheduler - ) - ) - if name is not None: - worker_name_args = ["--name", str(name)] - self.pod_template.spec.containers[0].args += worker_name_args - - -class Scheduler(Pod): - """A Remote Dask Scheduler controled by Kubernetes - Parameters - ---------- - idle_timeout: str, optional - The scheduler task will exit after this amount of time - if there are no requests from the client. Default is to - never timeout. - service_wait_timeout_s: int (optional) - Timeout, in seconds, to wait for the remote scheduler service to be ready. - Defaults to 30 seconds. - Set to 0 to disable the timeout (not recommended). - """ - - def __init__( - self, - idle_timeout: str, - service_wait_timeout_s: int = None, - service_name_retries: int = None, - **kwargs - ): - super().__init__(**kwargs) - self.cluster._log("Creating scheduler pod on cluster. This may take some time.") - self.service = None - self._idle_timeout = idle_timeout - self._service_wait_timeout_s = service_wait_timeout_s - self._service_name_retries = service_name_retries - if self._idle_timeout is not None: - self.pod_template.spec.containers[0].args += [ - "--idle-timeout", - self._idle_timeout, - ] - self.pdb = None - - async def start(self, **kwargs): - await super().start(**kwargs) - - while (await self.describe_pod()).status.phase == "Pending": - await asyncio.sleep(0.1) - - while self.address is None: - logs = await self.logs() - for line in logs.splitlines(): - if "Scheduler at:" in line: - self.address = line.split("Scheduler at:")[1].strip() - await asyncio.sleep(0.1) - - self.service = await self._create_service() - self.address = "tcp://{name}.{namespace}:{port}".format( - name=self.service.metadata.name, - namespace=self.namespace, - port=SCHEDULER_PORT, - ) - self.external_address = await get_external_address_for_scheduler_service( - self.core_api, - self.service, - service_name_resolution_retries=self._service_name_retries, - ) - - self.pdb = await self._create_pdb() - - async def close(self, **kwargs): - if self.service: - await self.core_api.delete_namespaced_service( - self.cluster_name, self.namespace - ) - if self.pdb: - await self.policy_api.delete_namespaced_pod_disruption_budget( - self.cluster_name, self.namespace - ) - await super().close(**kwargs) - - async def _create_service(self): - service_template_dict = dask.config.get("kubernetes.scheduler-service-template") - self.service_template = clean_service_template( - make_service_from_dict(service_template_dict) - ) - self.service_template.metadata.name = self.cluster_name - self.service_template.metadata.labels = copy.deepcopy(self.base_labels) - - self.service_template.spec.selector["dask.org/cluster-name"] = self.cluster_name - if self.service_template.spec.type is None: - self.service_template.spec.type = dask.config.get( - "kubernetes.scheduler-service-type" - ) - await self.core_api.create_namespaced_service( - self.namespace, self.service_template - ) - service = await self.core_api.read_namespaced_service( - self.cluster_name, self.namespace - ) - if service.spec.type == "LoadBalancer": - # Wait for load balancer to be assigned - start = time.time() - while service.status.load_balancer.ingress is None: - if ( - self._service_wait_timeout_s > 0 - and time.time() > start + self._service_wait_timeout_s - ): - raise asyncio.TimeoutError( - "Timed out waiting for Load Balancer to be provisioned." - ) - service = await self.core_api.read_namespaced_service( - self.cluster_name, self.namespace - ) - await asyncio.sleep(0.2) - return service - - async def _create_pdb(self): - pdb_template_dict = dask.config.get("kubernetes.scheduler-pdb-template") - self.pdb_template = clean_pdb_template(make_pdb_from_dict(pdb_template_dict)) - self.pdb_template.metadata.name = self.cluster_name - self.pdb_template.metadata.labels = copy.deepcopy(self.base_labels) - self.pdb_template.spec.selector.match_labels[ - "dask.org/cluster-name" - ] = self.cluster_name - await self.policy_api.create_namespaced_pod_disruption_budget( - self.namespace, self.pdb_template - ) - return await self.policy_api.read_namespaced_pod_disruption_budget( - self.cluster_name, self.namespace - ) - - -class KubeCluster(SpecCluster): - """Launch a Dask cluster on Kubernetes - - This starts a local Dask scheduler and then dynamically launches - Dask workers on a Kubernetes cluster. The Kubernetes cluster is taken - to be either the current one on which this code is running, or as a - fallback, the default one configured in a kubeconfig file. - - **Environments** - - Your worker pod image should have a similar environment to your local - environment, including versions of Python, dask, cloudpickle, and any - libraries that you may wish to use (like NumPy, Pandas, or Scikit-Learn). - See examples below for suggestions on how to manage and check for this. - - **Network** - - Since the Dask scheduler is launched locally, for it to work, we need to - be able to open network connections between this local node and all the - workers nodes on the Kubernetes cluster. If the current process is not - already on a Kubernetes node, some network configuration will likely be - required to make this work. - - **Resources** - - Your Kubernetes resource limits and requests should match the - ``--memory-limit`` and ``--nthreads`` parameters given to the - ``dask-worker`` command. - - Parameters - ---------- - pod_template: (kubernetes.client.V1Pod, dict, str) - A Kubernetes specification for a Pod for a dask worker. Can be either a - ``V1Pod``, a dict representation of a pod, or a path to a yaml file - containing a pod specification. - scheduler_pod_template: kubernetes.client.V1Pod (optional) - A Kubernetes specification for a Pod for a dask scheduler. - Defaults to the pod_template. - name: str (optional) - Name given to the pods. Defaults to ``dask-$USER-random`` - namespace: str (optional) - Namespace in which to launch the workers. - Defaults to current namespace if available or "default" - n_workers: int - Number of workers on initial launch. - Use ``scale`` to change this number in the future - env: Dict[str, str] - Dictionary of environment variables to pass to worker pod - host: str - Listen address for local scheduler. Defaults to 0.0.0.0 - port: int - Port of local scheduler - auth: List[ClusterAuth] (optional) - Configuration methods to attempt in order. Defaults to - ``[InCluster(), KubeConfig()]``. - idle_timeout: str (optional) - The scheduler task will exit after this amount of time - if there are no requests from the client. Default is to - never timeout. - scheduler_service_wait_timeout: int (optional) - Timeout, in seconds, to wait for the remote scheduler service to be ready. - Defaults to 30 seconds. - Set to 0 to disable the timeout (not recommended). - scheduler_service_name_resolution_retries: int (optional) - Number of retries to resolve scheduler service name when running - from within the Kubernetes cluster. - Defaults to 20. - Must be set to 1 or greater. - deploy_mode: str (optional) - Run the scheduler as "local" or "remote". - Defaults to ``"remote"``. - apply_default_affinity: str (optional) - Apply a default affinity to pods: "required", "preferred" or "none" - Defaults to ``"preferred"``. - **kwargs: dict - Additional keyword arguments to pass to SpecCluster - - Examples - -------- - >>> from dask_kubernetes.classic import KubeCluster, make_pod_spec - >>> pod_spec = make_pod_spec(image='ghcr.io/dask/dask:latest', - ... memory_limit='4G', memory_request='4G', - ... cpu_limit=1, cpu_request=1, - ... env={'EXTRA_PIP_PACKAGES': 'fastparquet git+https://github.com/dask/distributed'}) - >>> cluster = KubeCluster(pod_spec) - >>> cluster.scale(10) - - You can also create clusters with worker pod specifications as dictionaries - or stored in YAML files - - >>> cluster = KubeCluster('worker-template.yml') - >>> cluster = KubeCluster({...}) - - Rather than explicitly setting a number of workers you can also ask the - cluster to allocate workers dynamically based on current workload - - >>> cluster.adapt() - - You can pass this cluster directly to a Dask client - - >>> from dask.distributed import Client - >>> client = Client(cluster) - - You can verify that your local environment matches your worker environments - by calling ``client.get_versions(check=True)``. This will raise an - informative error if versions do not match. - - >>> client.get_versions(check=True) - - The ``ghcr.io/dask/dask`` docker images support ``EXTRA_PIP_PACKAGES``, - ``EXTRA_APT_PACKAGES`` and ``EXTRA_CONDA_PACKAGES`` environment variables - to help with small adjustments to the worker environments. We recommend - the use of pip over conda in this case due to a much shorter startup time. - These environment variables can be modified directly from the KubeCluster - constructor methods using the ``env=`` keyword. You may list as many - packages as you like in a single string like the following: - - >>> pip = 'pyarrow gcsfs git+https://github.com/dask/distributed' - >>> conda = '-c conda-forge scikit-learn' - >>> KubeCluster(..., env={'EXTRA_PIP_PACKAGES': pip, - ... 'EXTRA_CONDA_PACKAGES': conda}) - - You can also start a KubeCluster with no arguments *if* the worker template - is specified in the Dask config files, either as a full template in - ``kubernetes.worker-template`` or a path to a YAML file in - ``kubernetes.worker-template-path``. - - See https://docs.dask.org/en/latest/configuration.html for more - information about setting configuration values.:: - - $ export DASK_KUBERNETES__WORKER_TEMPLATE_PATH=worker_template.yaml - - >>> cluster = KubeCluster() # automatically finds 'worker_template.yaml' - - See Also - -------- - KubeCluster.adapt - """ - - def __init__( - self, - pod_template=None, - name=None, - namespace=None, - n_workers=None, - host=None, - port=None, - env=None, - auth=ClusterAuth.DEFAULT, - idle_timeout=None, - deploy_mode=None, - interface=None, - protocol=None, - dashboard_address=None, - security=None, - scheduler_service_wait_timeout=None, - scheduler_service_name_resolution_retries=None, - scheduler_pod_template=None, - apply_default_affinity="preferred", - **kwargs - ): - warnings.warn( - "The classic KubeCluster is going away. " - "Please migrate to the new operator based implementation " - "https://kubernetes.dask.org/en/latest/kubecluster_migrating.html.", - DeprecationWarning, - stacklevel=2, - ) - if isinstance(pod_template, str): - with open(pod_template) as f: - pod_template = dask.config.expand_environment_variables( - yaml.safe_load(f) - ) - if isinstance(pod_template, dict): - pod_template = make_pod_from_dict(pod_template) - - if isinstance(scheduler_pod_template, str): - with open(scheduler_pod_template) as f: - scheduler_pod_template = dask.config.expand_environment_variables( - yaml.safe_load(f) - ) - if isinstance(scheduler_pod_template, dict): - scheduler_pod_template = make_pod_from_dict(scheduler_pod_template) - - self.pod_template = copy.deepcopy(pod_template) - self.scheduler_pod_template = copy.deepcopy(scheduler_pod_template) - self.apply_default_affinity = apply_default_affinity - self._generate_name = dask.config.get("kubernetes.name", override_with=name) - self.namespace = dask.config.get( - "kubernetes.namespace", override_with=namespace - ) - self._n_workers = dask.config.get( - "kubernetes.count.start", override_with=n_workers - ) - self._idle_timeout = dask.config.get( - "kubernetes.idle-timeout", override_with=idle_timeout - ) - self._deploy_mode = dask.config.get( - "kubernetes.deploy-mode", override_with=deploy_mode - ) - self._protocol = dask.config.get("kubernetes.protocol", override_with=protocol) - self._interface = dask.config.get( - "kubernetes.interface", override_with=interface - ) - self._dashboard_address = dask.config.get( - "kubernetes.dashboard_address", override_with=dashboard_address - ) - self._scheduler_service_wait_timeout = dask.config.get( - "kubernetes.scheduler-service-wait-timeout", - override_with=scheduler_service_wait_timeout, - ) - self._scheduler_service_name_resolution_retries = dask.config.get( - "kubernetes.scheduler-service-name-resolution-retries", - override_with=scheduler_service_name_resolution_retries, - ) - self.security = security - if self.security and not isinstance( - self.security, distributed.security.Security - ): - raise RuntimeError( - "Security object is not a valid distributed.security.Security object" - ) - self.host = dask.config.get("kubernetes.host", override_with=host) - self.port = dask.config.get("kubernetes.port", override_with=port) - self.env = dask.config.get("kubernetes.env", override_with=env) - self.auth = auth - self.kwargs = kwargs - super().__init__(**self.kwargs) - - @property - def dashboard_link(self): - host = self.scheduler_address.split("://")[1].split("/")[0].split(":")[0] - return format_dashboard_link(host, self.forwarded_dashboard_port) - - def _get_pod_template(self, pod_template, pod_type): - if not pod_template and dask.config.get( - "kubernetes.{}-template".format(pod_type), None - ): - d = dask.config.get("kubernetes.{}-template".format(pod_type)) - d = dask.config.expand_environment_variables(d) - pod_template = make_pod_from_dict(d) - - if not pod_template and dask.config.get( - "kubernetes.{}-template-path".format(pod_type), None - ): - import yaml - - fn = dask.config.get("kubernetes.{}-template-path".format(pod_type)) - fn = fn.format(**os.environ) - with open(fn) as f: - d = yaml.safe_load(f) - d = dask.config.expand_environment_variables(d) - pod_template = make_pod_from_dict(d) - return pod_template - - def _fill_pod_templates(self, pod_template, pod_type): - pod_template = copy.deepcopy(pod_template) - - # Default labels that can't be overwritten - pod_template.metadata.labels["dask.org/cluster-name"] = self._generate_name - pod_template.metadata.labels["dask.org/component"] = pod_type - pod_template.metadata.labels["user"] = escape(getpass.getuser()) - pod_template.metadata.labels["app"] = "dask" - pod_template.metadata.namespace = self.namespace - - if self.env: - pod_template.spec.containers[0].env.extend( - [ - kubernetes.client.V1EnvVar(name=k, value=str(v)) - for k, v in self.env.items() - ] - ) - pod_template.metadata.generate_name = self._generate_name - - return pod_template - - async def _start(self): - self.pod_template = self._get_pod_template(self.pod_template, pod_type="worker") - self.scheduler_pod_template = self._get_pod_template( - self.scheduler_pod_template, pod_type="scheduler" - ) - if not self.pod_template: - msg = ( - "Worker pod specification not provided. See KubeCluster " - "docstring for ways to specify workers" - ) - raise ValueError(msg) - - base_pod_template = self.pod_template - self.pod_template = clean_pod_template( - self.pod_template, - apply_default_affinity=self.apply_default_affinity, - pod_type="worker", - ) - - if not self.scheduler_pod_template: - self.scheduler_pod_template = base_pod_template - self.scheduler_pod_template.spec.containers[0].args = ["dask-scheduler"] - - self.scheduler_pod_template = clean_pod_template( - self.scheduler_pod_template, - apply_default_affinity=self.apply_default_affinity, - pod_type="scheduler", - ) - - await ClusterAuth.load_first(self.auth) - - self.core_api = kubernetes.client.CoreV1Api() - self.policy_api = kubernetes.client.PolicyV1Api() - - if self.namespace is None: - self.namespace = get_current_namespace() - - environ = {k: v for k, v in os.environ.items() if k not in ["user", "uuid"]} - self._generate_name = self._generate_name.format( - user=getpass.getuser(), uuid=str(uuid.uuid4())[:10], **environ - ) - self._generate_name = escape(self._generate_name) - - self.pod_template = self._fill_pod_templates( - self.pod_template, pod_type="worker" - ) - self.scheduler_pod_template = self._fill_pod_templates( - self.scheduler_pod_template, pod_type="scheduler" - ) - - common_options = { - "cluster": self, - "core_api": self.core_api, - "policy_api": self.policy_api, - "namespace": self.namespace, - "loop": self.loop, - } - - if self._deploy_mode == "local": - self.scheduler_spec = { - "cls": dask.distributed.Scheduler, - "options": { - "protocol": self._protocol, - "interface": self._interface, - "host": self.host, - "port": self.port, - "dashboard_address": self._dashboard_address, - "security": self.security, - }, - } - elif self._deploy_mode == "remote": - self.scheduler_spec = { - "cls": Scheduler, - "options": { - "idle_timeout": self._idle_timeout, - "service_wait_timeout_s": self._scheduler_service_wait_timeout, - "service_name_retries": self._scheduler_service_name_resolution_retries, - "pod_template": self.scheduler_pod_template, - **common_options, - }, - } - else: - raise RuntimeError("Unknown deploy mode %s" % self._deploy_mode) - - self.new_spec = { - "cls": Worker, - "options": {"pod_template": self.pod_template, **common_options}, - } - self.worker_spec = {i: self.new_spec for i in range(self._n_workers)} - - self.name = self.pod_template.metadata.generate_name - - await super()._start() - - if self._deploy_mode == "local": - self.forwarded_dashboard_port = self.scheduler.services["dashboard"].port - else: - dashboard_address = await get_scheduler_address( - self.scheduler.service.metadata.name, - self.namespace, - port_name="http-dashboard", - ) - self.forwarded_dashboard_port = dashboard_address.split(":")[-1] - - @classmethod - def from_dict(cls, pod_spec, **kwargs): - """Create cluster with worker pod spec defined by Python dictionary - - Deprecated, please use the `KubeCluster` constructor directly. - - Examples - -------- - >>> spec = { - ... 'metadata': {}, - ... 'spec': { - ... 'containers': [{ - ... 'args': ['dask-worker', '$(DASK_SCHEDULER_ADDRESS)', - ... '--nthreads', '1', - ... '--death-timeout', '60'], - ... 'command': None, - ... 'image': 'ghcr.io/dask/dask:latest', - ... 'name': 'dask-worker', - ... }], - ... 'restartPolicy': 'Never', - ... } - ... } - >>> cluster = KubeCluster.from_dict(spec, namespace='my-ns') # doctest: +SKIP - - See Also - -------- - KubeCluster.from_yaml - """ - warnings.warn( - "KubeCluster.from_dict is deprecated, use the constructor directly" - ) - return cls(pod_spec, **kwargs) - - @classmethod - def from_yaml(cls, yaml_path, **kwargs): - """Create cluster with worker pod spec defined by a YAML file - - Deprecated, please use the `KubeCluster` constructor directly. - - We can start a cluster with pods defined in an accompanying YAML file - like the following: - - .. code-block:: yaml - - kind: Pod - metadata: - labels: - foo: bar - baz: quux - spec: - containers: - - image: ghcr.io/dask/dask:latest - name: dask-worker - args: [dask-worker, $(DASK_SCHEDULER_ADDRESS), --nthreads, '2', --memory-limit, 8GB] - restartPolicy: Never - - Examples - -------- - >>> cluster = KubeCluster.from_yaml('pod.yaml', namespace='my-ns') # doctest: +SKIP - - See Also - -------- - KubeCluster.from_dict - """ - warnings.warn( - "KubeCluster.from_yaml is deprecated, use the constructor directly" - ) - return cls(yaml_path, **kwargs) - - def scale(self, n): - # A shim to maintain backward compatibility - # https://github.com/dask/distributed/issues/3054 - maximum = dask.config.get("kubernetes.count.max") - if maximum is not None and maximum < n: - logger.info( - "Tried to scale beyond maximum number of workers %d > %d", n, maximum - ) - n = maximum - return super().scale(n) - - async def _logs(self, scheduler=True, workers=True): - """Return logs for the scheduler and workers - Parameters - ---------- - scheduler : boolean - Whether or not to collect logs for the scheduler - workers : boolean or Iterable[str], optional - A list of worker addresses to select. - Defaults to all workers if `True` or no workers if `False` - Returns - ------- - logs: Dict[str] - A dictionary of logs, with one item for the scheduler and one for - each worker - """ - logs = Logs() - - if scheduler: - logs["Scheduler"] = await self.scheduler.logs() - - if workers: - worker_logs = await asyncio.gather( - *[w.logs() for w in self.workers.values()] - ) - for key, log in zip(self.workers, worker_logs): - logs[key] = log - - return logs diff --git a/dask_kubernetes/classic/tests/config-demo.yaml b/dask_kubernetes/classic/tests/config-demo.yaml deleted file mode 100644 index 262984b21..000000000 --- a/dask_kubernetes/classic/tests/config-demo.yaml +++ /dev/null @@ -1,38 +0,0 @@ -apiVersion: v1 -clusters: -- cluster: - certificate-authority: fake-ca-file - server: https://1.2.3.4 - name: development -- cluster: - insecure-skip-tls-verify: true - server: https://5.6.7.8 - name: scratch -contexts: -- context: - cluster: development - namespace: frontend - user: developer - name: dev-frontend -- context: - cluster: development - namespace: storage - user: developer - name: dev-storage -- context: - cluster: scratch - namespace: default - user: experimenter - name: exp-scratch -current-context: dev-frontend -kind: Config -preferences: {} -users: -- name: developer - user: - client-certificate: fake-cert-file - client-key: fake-key-file -- name: experimenter - user: - password: some-password - username: exp diff --git a/dask_kubernetes/classic/tests/fake-ca-file b/dask_kubernetes/classic/tests/fake-ca-file deleted file mode 100644 index e69de29bb..000000000 diff --git a/dask_kubernetes/classic/tests/fake-cert-file b/dask_kubernetes/classic/tests/fake-cert-file deleted file mode 100644 index e69de29bb..000000000 diff --git a/dask_kubernetes/classic/tests/fake-key-file b/dask_kubernetes/classic/tests/fake-key-file deleted file mode 100644 index e69de29bb..000000000 diff --git a/dask_kubernetes/classic/tests/fake_gcp_auth.py b/dask_kubernetes/classic/tests/fake_gcp_auth.py deleted file mode 100644 index bab976588..000000000 --- a/dask_kubernetes/classic/tests/fake_gcp_auth.py +++ /dev/null @@ -1,25 +0,0 @@ -import datetime -import json - -expiry = datetime.datetime.utcnow() + datetime.timedelta(seconds=5) -expiry.replace(tzinfo=datetime.timezone.utc) -expiry_str = expiry.isoformat("T") + "Z" - -fake_token = "0" * 137 -fake_id = "abcdefghijklmnopqrstuvwxyz.1234567890" * 37 + "." * 32 - -data = """ -{ - "credential": { - "access_token": "%s", - "id_token": "%s", - "token_expiry": "%s" - } -} -""" % ( - fake_token, - fake_id, - expiry_str, -) - -print(json.dumps(json.loads(data), indent=4)) diff --git a/dask_kubernetes/classic/tests/test_async.py b/dask_kubernetes/classic/tests/test_async.py deleted file mode 100644 index b6c2a6201..000000000 --- a/dask_kubernetes/classic/tests/test_async.py +++ /dev/null @@ -1,886 +0,0 @@ -import asyncio -import base64 -import getpass -import os -import random -import sys -from time import time - -import dask -import kubernetes_asyncio as kubernetes -import pytest -import yaml -from dask.distributed import Client, wait -from dask.utils import tmpfile -from distributed.utils_test import captured_logger - -import dask_kubernetes -from dask_kubernetes import ( - ClusterAuth, - KubeAuth, - KubeCluster, - KubeConfig, - clean_pod_template, - make_pod_spec, -) -from dask_kubernetes.common.utils import get_current_namespace -from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME - -TEST_DIR = os.path.abspath(os.path.join(__file__, "..")) -CONFIG_DEMO = os.path.join(TEST_DIR, "config-demo.yaml") -FAKE_CERT = os.path.join(TEST_DIR, "fake-cert-file") -FAKE_KEY = os.path.join(TEST_DIR, "fake-key-file") -FAKE_CA = os.path.join(TEST_DIR, "fake-ca-file") - - -@pytest.fixture -def pod_spec(docker_image): - yield clean_pod_template( - make_pod_spec( - image=docker_image, - extra_container_config={"imagePullPolicy": "IfNotPresent"}, - ) - ) - - -@pytest.fixture -def user_env(): - """The env var USER is not always set on non-linux systems.""" - if "USER" not in os.environ: - os.environ["USER"] = getpass.getuser() - yield - del os.environ["USER"] - else: - yield - - -cluster_kwargs = {"asynchronous": True} - - -@pytest.fixture -async def cluster(k8s_cluster, pod_spec): - async with KubeCluster(pod_spec, **cluster_kwargs) as cluster: - yield cluster - - -@pytest.fixture -async def remote_cluster(k8s_cluster, pod_spec): - async with KubeCluster(pod_spec, deploy_mode="remote", **cluster_kwargs) as cluster: - yield cluster - - -@pytest.fixture -async def client(cluster): - async with Client(cluster, asynchronous=True) as client: - yield client - - -@pytest.mark.anyio -async def test_fixtures(client): - """An initial test to get all the fixtures to run and check the cluster is usable.""" - assert client - - -@pytest.mark.anyio -async def test_versions(client): - await client.get_versions(check=True) - - -@pytest.mark.anyio -async def test_cluster_create(cluster): - cluster.scale(1) - await cluster - async with Client(cluster, asynchronous=True) as client: - result = await client.submit(lambda x: x + 1, 10) - assert result == 11 - - -@pytest.mark.anyio -async def test_basic(cluster, client): - cluster.scale(2) - future = client.submit(lambda x: x + 1, 10) - result = await future - assert result == 11 - - await client.wait_for_workers(2) - - # Ensure that inter-worker communication works well - futures = client.map(lambda x: x + 1, range(10)) - total = client.submit(sum, futures) - assert (await total) == sum(map(lambda x: x + 1, range(10))) - assert all((await client.has_what()).values()) - - -@pytest.mark.anyio -async def test_logs(remote_cluster): - cluster = remote_cluster - cluster.scale(2) - await cluster - - async with Client(cluster, asynchronous=True) as client: - await client.wait_for_workers(2) - - logs = await cluster.get_logs() - assert len(logs) == 4 - for _, log in logs.items(): - assert ( - "distributed.scheduler" in log - or "distributed.worker" in log - or "Creating scheduler pod" in log - ) - - -@pytest.mark.anyio -async def test_dask_worker_name_env_variable(k8s_cluster, pod_spec, user_env): - with dask.config.set({"kubernetes.name": "foo-{USER}-{uuid}"}): - async with KubeCluster(pod_spec, **cluster_kwargs) as cluster: - assert "foo-" + getpass.getuser() in cluster.name - - -@pytest.mark.anyio -async def test_diagnostics_link_env_variable(k8s_cluster, pod_spec, user_env): - pytest.importorskip("bokeh") - with dask.config.set({"distributed.dashboard.link": "foo-{USER}-{port}"}): - async with KubeCluster(pod_spec, asynchronous=True) as cluster: - port = cluster.forwarded_dashboard_port - - assert ( - "foo-" + getpass.getuser() + "-" + str(port) in cluster.dashboard_link - ) - - -@pytest.mark.skip(reason="Cannot run two closers locally as loadbalancer ports collide") -@pytest.mark.anyio -async def test_namespace(k8s_cluster, pod_spec): - async with KubeCluster(pod_spec, **cluster_kwargs) as cluster: - assert "dask" in cluster.name - assert getpass.getuser() in cluster.name - async with KubeCluster(pod_spec, **cluster_kwargs) as cluster2: - assert cluster.name != cluster2.name - - cluster2.scale(1) - while len(await cluster2.pods()) != 1: - await asyncio.sleep(0.1) - - -@pytest.mark.anyio -async def test_adapt(cluster): - cluster.adapt() - async with Client(cluster, asynchronous=True) as client: - future = client.submit(lambda x: x + 1, 10) - result = await future - assert result == 11 - - -@pytest.mark.xfail(reason="The widget has changed upstream") -@pytest.mark.anyio -async def test_ipython_display(cluster): - ipywidgets = pytest.importorskip("ipywidgets") - cluster.scale(1) - await cluster - cluster._ipython_display_() - box = cluster._cached_widget - assert isinstance(box, ipywidgets.Widget) - cluster._ipython_display_() - assert cluster._cached_widget is box - - start = time() - while "1" not in str(box): # one worker in a table - assert time() < start + 20 - await asyncio.sleep(0.5) - - -@pytest.mark.anyio -async def test_env(k8s_cluster, pod_spec): - async with KubeCluster(pod_spec, env={"ABC": "DEF"}, **cluster_kwargs) as cluster: - cluster.scale(1) - await cluster - async with Client(cluster, asynchronous=True) as client: - await client.wait_for_workers(1) - env = await client.run(lambda: dict(os.environ)) - assert all(v["ABC"] == "DEF" for v in env.values()) - - -@pytest.mark.anyio -async def test_pod_from_yaml(k8s_cluster, docker_image): - test_yaml = { - "kind": "Pod", - "metadata": {"labels": {"app": "dask", "component": "dask-worker"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": docker_image, - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with tmpfile(extension="yaml") as fn: - with open(fn, mode="w") as f: - yaml.dump(test_yaml, f) - async with KubeCluster(f.name, **cluster_kwargs) as cluster: - cluster.scale(2) - await cluster - async with Client(cluster, asynchronous=True) as client: - future = client.submit(lambda x: x + 1, 10) - result = await future.result(timeout=30) - assert result == 11 - - await client.wait_for_workers(2) - - # Ensure that inter-worker communication works well - futures = client.map(lambda x: x + 1, range(10)) - total = client.submit(sum, futures) - assert (await total) == sum(map(lambda x: x + 1, range(10))) - assert all((await client.has_what()).values()) - - -@pytest.mark.anyio -async def test_pod_expand_env_vars(k8s_cluster, docker_image): - try: - os.environ["FOO_IMAGE"] = docker_image - - test_yaml = { - "kind": "Pod", - "metadata": {"labels": {"app": "dask", "component": "dask-worker"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": "${FOO_IMAGE}", - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with tmpfile(extension="yaml") as fn: - with open(fn, mode="w") as f: - yaml.dump(test_yaml, f) - async with KubeCluster(f.name, **cluster_kwargs) as cluster: - assert cluster.pod_template.spec.containers[0].image == docker_image - finally: - del os.environ["FOO_IMAGE"] - - -@pytest.mark.anyio -async def test_pod_template_dict(docker_image): - spec = { - "metadata": {}, - "restartPolicy": "Never", - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - "--death-timeout", - "60", - ], - "command": None, - "image": docker_image, - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - async with KubeCluster(spec, port=32000, **cluster_kwargs) as cluster: - cluster.scale(2) - await cluster - async with Client(cluster, asynchronous=True) as client: - future = client.submit(lambda x: x + 1, 10) - result = await future - assert result == 11 - - await client.wait_for_workers(2) - - # Ensure that inter-worker communication works well - futures = client.map(lambda x: x + 1, range(10)) - total = client.submit(sum, futures) - assert (await total) == sum(map(lambda x: x + 1, range(10))) - assert all((await client.has_what()).values()) - - -@pytest.mark.anyio -async def test_pod_template_minimal_dict(k8s_cluster, docker_image): - spec = { - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - "--death-timeout", - "60", - ], - "command": None, - "image": docker_image, - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - } - } - - async with KubeCluster(spec, **cluster_kwargs) as cluster: - cluster.adapt() - async with Client(cluster, asynchronous=True) as client: - future = client.submit(lambda x: x + 1, 10) - result = await future - assert result == 11 - - -@pytest.mark.anyio -async def test_pod_template_from_conf(docker_image): - spec = { - "spec": { - "containers": [{"name": KUBECLUSTER_CONTAINER_NAME, "image": docker_image}] - } - } - - with dask.config.set({"kubernetes.worker-template": spec}): - async with KubeCluster(**cluster_kwargs) as cluster: - assert ( - cluster.pod_template.spec.containers[0].name - == KUBECLUSTER_CONTAINER_NAME - ) - - -@pytest.mark.anyio -async def test_pod_template_with_custom_container_name(docker_image): - container_name = "my-custom-container" - spec = {"spec": {"containers": [{"name": container_name, "image": docker_image}]}} - - with dask.config.set({"kubernetes.worker-template": spec}): - async with KubeCluster(**cluster_kwargs) as cluster: - assert cluster.pod_template.spec.containers[0].name == container_name - - -@pytest.mark.anyio -async def test_constructor_parameters(k8s_cluster, pod_spec): - env = {"FOO": "BAR", "A": 1} - async with KubeCluster( - pod_spec, name="myname", env=env, **cluster_kwargs - ) as cluster: - pod = cluster.pod_template - assert pod.metadata.namespace == get_current_namespace() - - var = [v for v in pod.spec.containers[0].env if v.name == "FOO"] - assert var and var[0].value == "BAR" - - var = [v for v in pod.spec.containers[0].env if v.name == "A"] - assert var and var[0].value == "1" - - assert pod.metadata.generate_name == "myname" - - -@pytest.mark.anyio -async def test_reject_evicted_workers(cluster): - cluster.scale(1) - await cluster - - start = time() - while len(cluster.scheduler_info["workers"]) != 1: - await asyncio.sleep(0.1) - assert time() < start + 60 - - # Evict worker - [worker] = cluster.workers.values() - await cluster.core_api.create_namespaced_pod_eviction( - (await worker.describe_pod()).metadata.name, - (await worker.describe_pod()).metadata.namespace, - kubernetes.client.V1Eviction( - delete_options=kubernetes.client.V1DeleteOptions(grace_period_seconds=300), - metadata=(await worker.describe_pod()).metadata, - ), - ) - - # Wait until worker removal has been picked up by scheduler - start = time() - while len(cluster.scheduler_info["workers"]) != 0: - delta = time() - start - assert delta < 60, f"Scheduler failed to remove worker in {delta:.0f}s" - await asyncio.sleep(0.1) - - # Wait until worker removal has been handled by cluster - while len(cluster.workers) != 0: - delta = time() - start - assert delta < 60, f"Cluster failed to remove worker in {delta:.0f}s" - await asyncio.sleep(0.1) - - -@pytest.mark.anyio -async def test_scale_up_down(cluster, client): - np = pytest.importorskip("numpy") - cluster.scale(2) - await cluster - - start = time() - while len(cluster.scheduler_info["workers"]) != 2: - await asyncio.sleep(0.1) - assert time() < start + 60 - - a, b = list(cluster.scheduler_info["workers"]) - x = client.submit(np.ones, 1, workers=a) - y = client.submit(np.ones, 50_000, workers=b) - - await wait([x, y]) - - cluster.scale(1) - await cluster - - start = time() - while len(cluster.scheduler_info["workers"]) != 1: - await asyncio.sleep(0.1) - assert time() < start + 60 - - # assert set(cluster.scheduler_info["workers"]) == {b} - - -@pytest.mark.xfail( - reason="The delay between scaling up, starting a worker, and then scale down causes issues" -) -@pytest.mark.anyio -async def test_scale_up_down_fast(cluster, client): - cluster.scale(1) - await cluster - - start = time() - await client.wait_for_workers(1) - - worker = next(iter(cluster.scheduler_info["workers"].values())) - - # Put some data on this worker - future = client.submit(lambda: b"\x00" * int(1e6)) - await wait(future) - assert worker in cluster.scheduler.tasks[future.key].who_has - - # Rescale the cluster many times without waiting: this should put some - # pressure on kubernetes but this should never fail nor delete our worker - # with the temporary result. - for i in range(10): - await cluster._scale_up(4) - await asyncio.sleep(random.random() / 2) - cluster.scale(1) - await asyncio.sleep(random.random() / 2) - - start = time() - while len(cluster.scheduler_info["workers"]) != 1: - await asyncio.sleep(0.1) - assert time() < start + 20 - - # The original task result is still stored on the original worker: this pod - # has never been deleted when rescaling the cluster and the result can - # still be fetched back. - assert worker in cluster.scheduler.tasks[future.key].who_has - assert len(await future) == int(1e6) - - -@pytest.mark.xfail(reason="scaling has some unfortunate state") -@pytest.mark.anyio -async def test_scale_down_pending(cluster, client, cleanup_namespaces): - # Try to scale the cluster to use more pods than available - nodes = (await cluster.core_api.list_node()).items - max_pods = sum(int(node.status.allocatable["pods"]) for node in nodes) - if max_pods > 50: - # It's probably not reasonable to run this test against a large - # kubernetes cluster. - pytest.skip("Require a small test kubernetes cluster (maxpod <= 50)") - extra_pods = 5 - requested_pods = max_pods + extra_pods - cluster.scale(requested_pods) - - start = time() - while len(cluster.scheduler_info["workers"]) < 2: - await asyncio.sleep(0.1) - # Wait a bit because the kubernetes cluster can take time to provision - # the requested pods as we requested a large number of pods. - assert time() < start + 60 - - pending_pods = [p for p in (await cluster.pods()) if p.status.phase == "Pending"] - assert len(pending_pods) >= extra_pods - - running_workers = list(cluster.scheduler_info["workers"].keys()) - assert len(running_workers) >= 2 - - # Put some data on those workers to make them important to keep as long - # as possible. - def load_data(i): - return b"\x00" * (i * int(1e6)) - - futures = [ - client.submit(load_data, i, workers=w) for i, w in enumerate(running_workers) - ] - await wait(futures) - - # Reduce the cluster size down to the actually useful nodes: pending pods - # and running pods without results should be shutdown and removed first: - cluster.scale(len(running_workers)) - - start = time() - pod_statuses = [p.status.phase for p in await cluster.pods()] - while len(pod_statuses) != len(running_workers): - if time() - start > 60: - raise AssertionError( - "Expected %d running pods but got %r" - % (len(running_workers), pod_statuses) - ) - await asyncio.sleep(0.1) - pod_statuses = [p.status.phase for p in await cluster.pods()] - - assert pod_statuses == ["Running"] * len(running_workers) - assert list(cluster.scheduler_info["workers"].keys()) == running_workers - - # Terminate everything - cluster.scale(0) - - start = time() - while len(cluster.scheduler_info["workers"]) > 0: - await asyncio.sleep(0.1) - assert time() < start + 60 - - -@pytest.mark.anyio -async def test_automatic_startup(k8s_cluster, docker_image): - test_yaml = { - "kind": "Pod", - "metadata": {"labels": {"foo": "bar"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": docker_image, - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with tmpfile(extension="yaml") as fn: - with open(fn, mode="w") as f: - yaml.dump(test_yaml, f) - with dask.config.set({"kubernetes.worker-template-path": fn}): - async with KubeCluster(**cluster_kwargs) as cluster: - assert cluster.pod_template.metadata.labels["foo"] == "bar" - - -@pytest.mark.anyio -async def test_repr(cluster): - for text in [repr(cluster), str(cluster)]: - assert "Box" not in text - assert ( - cluster.scheduler.address in text - or cluster.scheduler.external_address in text - ) - - -@pytest.mark.anyio -async def test_escape_username(k8s_cluster, pod_spec, monkeypatch): - monkeypatch.setenv("LOGNAME", "Foo!._") - - async with KubeCluster(pod_spec, **cluster_kwargs) as cluster: - assert "foo" in cluster.name - assert "!" not in cluster.name - assert "." not in cluster.name - assert "_" not in cluster.name - assert "foo" in cluster.pod_template.metadata.labels["user"] - - -@pytest.mark.anyio -async def test_escape_name(k8s_cluster, pod_spec): - async with KubeCluster(pod_spec, name="foo@bar", **cluster_kwargs) as cluster: - assert "@" not in str(cluster.pod_template) - - -@pytest.mark.anyio -async def test_maximum(cluster): - with dask.config.set({"kubernetes.count.max": 1}): - with captured_logger("dask_kubernetes") as logger: - cluster.scale(10) - await cluster - - start = time() - while len(cluster.scheduler_info["workers"]) <= 0: - await asyncio.sleep(0.1) - assert time() < start + 60 - await asyncio.sleep(0.5) - while len(cluster.scheduler_info["workers"]) != 1: - await asyncio.sleep(0.1) - assert time() < start + 60 - - result = logger.getvalue() - assert "scale beyond maximum number of workers" in result.lower() - - -def test_default_toleration(pod_spec): - tolerations = pod_spec.to_dict()["spec"]["tolerations"] - assert { - "key": "k8s.dask.org/dedicated", - "operator": "Equal", - "value": "worker", - "effect": "NoSchedule", - "toleration_seconds": None, - } in tolerations - assert { - "key": "k8s.dask.org_dedicated", - "operator": "Equal", - "value": "worker", - "effect": "NoSchedule", - "toleration_seconds": None, - } in tolerations - - -def test_default_toleration_preserved(docker_image): - pod_spec = clean_pod_template( - make_pod_spec( - image=docker_image, - extra_pod_config={ - "tolerations": [ - { - "key": "example.org/toleration", - "operator": "Exists", - "effect": "NoSchedule", - } - ] - }, - ) - ) - tolerations = pod_spec.to_dict()["spec"]["tolerations"] - assert { - "key": "k8s.dask.org/dedicated", - "operator": "Equal", - "value": "worker", - "effect": "NoSchedule", - "toleration_seconds": None, - } in tolerations - assert { - "key": "k8s.dask.org_dedicated", - "operator": "Equal", - "value": "worker", - "effect": "NoSchedule", - "toleration_seconds": None, - } in tolerations - assert { - "key": "example.org/toleration", - "operator": "Exists", - "effect": "NoSchedule", - } in tolerations - - -@pytest.mark.anyio -async def test_auth_missing(k8s_cluster, pod_spec): - with pytest.raises(kubernetes.config.ConfigException) as info: - await KubeCluster(pod_spec, auth=[], **cluster_kwargs) - - assert "No authorization methods were provided" in str(info.value) - - -@pytest.mark.anyio -async def test_auth_tries_all_methods(k8s_cluster, pod_spec): - fails = {"count": 0} - - class FailAuth(ClusterAuth): - def load(self): - fails["count"] += 1 - raise kubernetes.config.ConfigException("Fail #{count}".format(**fails)) - - with pytest.raises(kubernetes.config.ConfigException) as info: - await KubeCluster(pod_spec, auth=[FailAuth()] * 3, **cluster_kwargs) - - assert "Fail #3" in str(info.value) - assert fails["count"] == 3 - - -@pytest.mark.xfail( - reason="Updating the default client configuration is broken in kubernetes" -) -@pytest.mark.anyio -async def test_auth_kubeconfig_with_filename(): - await KubeConfig(config_file=CONFIG_DEMO).load() - - # we've set the default configuration, so check that it is default - config = kubernetes.client.Configuration() - assert config.host == "https://1.2.3.4/" - assert config.cert_file == FAKE_CERT - assert config.key_file == FAKE_KEY - assert config.ssl_ca_cert == FAKE_CA - - -@pytest.mark.xfail( - reason="Updating the default client configuration is broken in kubernetes" -) -@pytest.mark.anyio -async def test_auth_kubeconfig_with_context(): - await KubeConfig(config_file=CONFIG_DEMO, context="exp-scratch").load() - - # we've set the default configuration, so check that it is default - config = kubernetes.client.Configuration() - assert config.host == "https://5.6.7.8/" - assert config.api_key["authorization"] == "Basic {}".format( - base64.b64encode(b"exp:some-password").decode("ascii") - ) - - -@pytest.mark.xfail( - reason="Updating the default client configuration is broken in async kubernetes" -) -@pytest.mark.anyio -async def test_auth_explicit(): - await KubeAuth( - host="https://9.8.7.6/", username="abc", password="some-password" - ).load() - - config = kubernetes.client.Configuration() - assert config.host == "https://9.8.7.6/" - assert config.username == "abc" - assert config.password == "some-password" - assert config.get_basic_auth_token() == "Basic {}".format( - base64.b64encode(b"abc:some-password").decode("ascii") - ) - - -@pytest.mark.anyio -async def test_start_with_workers(k8s_cluster, pod_spec): - async with KubeCluster(pod_spec, n_workers=2, **cluster_kwargs) as cluster: - async with Client(cluster, asynchronous=True) as client: - await client.wait_for_workers(2) - - -@pytest.mark.anyio -@pytest.mark.xfail(reason="Flaky in CI and classic is deprecated anyway") -async def test_adapt_delete(cluster, ns): - """ - testing whether KubeCluster.adapt will bring - back deleted worker pod (issue #244) - """ - core_api = cluster.core_api - - async def get_worker_pods(): - pods_list = await core_api.list_namespaced_pod( - namespace=ns, - label_selector=f"dask.org/component=worker,dask.org/cluster-name={cluster.name}", - ) - return [x.metadata.name for x in pods_list.items] - - cluster.adapt(maximum=2, minimum=2) - start = time() - while len(cluster.scheduler_info["workers"]) != 2: - await asyncio.sleep(0.1) - assert time() < start + 60 - - worker_pods = await get_worker_pods() - assert len(worker_pods) == 2 - # delete one worker pod - to_delete = worker_pods[0] - await core_api.delete_namespaced_pod(name=to_delete, namespace=ns) - # wait until it is deleted - start = time() - while True: - worker_pods = await get_worker_pods() - if to_delete not in worker_pods: - break - await asyncio.sleep(0.1) - assert time() < start + 60 - # test whether adapt will bring it back - start = time() - while len(cluster.scheduler_info["workers"]) != 2: - await asyncio.sleep(0.1) - assert time() < start + 60 - assert len(cluster.scheduler_info["workers"]) == 2 - - -@pytest.mark.anyio -@pytest.mark.xfail(reason="Failing in CI with FileNotFoundError") -async def test_auto_refresh(cluster): - config = { - "apiVersion": "v1", - "clusters": [ - { - "cluster": {"certificate-authority-data": "", "server": ""}, - "name": "mock_gcp_config", - } - ], - "contexts": [ - { - "context": { - "cluster": "mock_gcp_config", - "user": "mock_gcp_config", - }, - "name": "mock_gcp_config", - } - ], - "current-context": "mock_gcp_config", - "kind": "config", - "preferences": {}, - "users": [ - { - "name": "mock_gcp_config", - "user": { - "auth-provider": { - "config": { - "access-token": "", - "cmd-args": "--fake-arg arg", - "cmd-path": f"{sys.executable} {TEST_DIR}/fake_gcp_auth.py", - "expiry": "", - "expiry-key": "{.credential.token_expiry}", - "toekn-key": "{.credential.access_token}", - }, - "name": "gcp", - } - }, - } - ], - } - config_persister = False - - loader = dask_kubernetes.AutoRefreshKubeConfigLoader( - config_dict=config, - config_base_path=None, - config_persister=config_persister, - ) - - await loader.load_gcp_token() - # Check that we get back a token - assert loader.token == f"Bearer {'0' * 137}" - - next_expire = loader.token_expire_ts - for task in asyncio.all_tasks(): - if task.get_name() == "dask_auth_auto_refresh": - await asyncio.wait_for(task, 10) - - # Ensure that our token expiration timer was refreshed - assert loader.token_expire_ts > next_expire - - # Ensure refresh task was re-created - for task in asyncio.all_tasks(): - if task.get_name() == "dask_auth_auto_refresh": - loader.auto_refresh = False - await asyncio.wait_for(task, 60) - break - else: - assert False diff --git a/dask_kubernetes/classic/tests/test_sync.py b/dask_kubernetes/classic/tests/test_sync.py deleted file mode 100644 index ce7fed9d1..000000000 --- a/dask_kubernetes/classic/tests/test_sync.py +++ /dev/null @@ -1,497 +0,0 @@ -import os -from time import sleep, time - -import dask -import pytest -import yaml -from dask.distributed import Client, wait -from dask.utils import tmpfile -from distributed.utils_test import captured_logger - -from dask_kubernetes.classic import KubeCluster, make_pod_spec -from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME - -TEST_DIR = os.path.abspath(os.path.join(__file__, "..")) -CONFIG_DEMO = os.path.join(TEST_DIR, "config-demo.yaml") -FAKE_CERT = os.path.join(TEST_DIR, "fake-cert-file") -FAKE_KEY = os.path.join(TEST_DIR, "fake-key-file") -FAKE_CA = os.path.join(TEST_DIR, "fake-ca-file") - - -@pytest.fixture -def pod_spec(docker_image): - yield make_pod_spec( - image=docker_image, extra_container_config={"imagePullPolicy": "IfNotPresent"} - ) - - -@pytest.fixture -def cluster(pod_spec): - with KubeCluster(pod_spec) as cluster: - yield cluster - - -@pytest.fixture -def client(cluster): - with Client(cluster) as client: - yield client - - -def test_fixtures(client, cluster): - client.scheduler_info() - cluster.scale(1) - assert client.submit(lambda x: x + 1, 10).result() == 11 - - -def test_basic(cluster, client): - cluster.scale(2) - future = client.submit(lambda x: x + 1, 10) - result = future.result() - assert result == 11 - - while len(cluster.scheduler_info["workers"]) < 2: - sleep(0.1) - - # Ensure that inter-worker communication works well - futures = client.map(lambda x: x + 1, range(10)) - total = client.submit(sum, futures) - assert total.result() == sum(map(lambda x: x + 1, range(10))) - assert all(client.has_what().values()) - - -@pytest.mark.xfail(reason="The widget has changed upstream") -def test_ipython_display(cluster): - ipywidgets = pytest.importorskip("ipywidgets") - cluster.scale(1) - cluster._ipython_display_() - box = cluster._cached_widget - assert isinstance(box, ipywidgets.Widget) - cluster._ipython_display_() - assert cluster._cached_widget is box - - start = time() - while "1" not in str(box): # one worker in a table - assert time() < start + 20 - sleep(0.5) - - -def test_env(pod_spec): - with KubeCluster(pod_spec, env={"ABC": "DEF"}) as cluster: - cluster.scale(1) - with Client(cluster) as client: - while not cluster.scheduler_info["workers"]: - sleep(0.1) - env = client.run(lambda: dict(os.environ)) - assert all(v["ABC"] == "DEF" for v in env.values()) - - -def dont_test_pod_template_yaml(docker_image): - test_yaml = { - "kind": "Pod", - "metadata": {"labels": {"app": "dask", "component": "dask-worker"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": docker_image, - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with tmpfile(extension="yaml") as fn: - with open(fn, mode="w") as f: - yaml.dump(test_yaml, f) - with KubeCluster(f.name) as cluster: - cluster.scale(2) - with Client(cluster) as client: - future = client.submit(lambda x: x + 1, 10) - result = future.result(timeout=10) - assert result == 11 - - start = time() - while len(cluster.scheduler_info["workers"]) < 2: - sleep(0.1) - assert time() < start + 20, "timeout" - - # Ensure that inter-worker communication works well - futures = client.map(lambda x: x + 1, range(10)) - total = client.submit(sum, futures) - assert total.result() == sum(map(lambda x: x + 1, range(10))) - assert all(client.has_what().values()) - - -def test_pod_template_yaml_expand_env_vars(docker_image): - try: - os.environ["FOO_IMAGE"] = docker_image - - test_yaml = { - "kind": "Pod", - "metadata": {"labels": {"app": "dask", "component": "dask-worker"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": "${FOO_IMAGE}", - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with tmpfile(extension="yaml") as fn: - with open(fn, mode="w") as f: - yaml.dump(test_yaml, f) - with KubeCluster(f.name) as cluster: - assert cluster.pod_template.spec.containers[0].image == docker_image - finally: - del os.environ["FOO_IMAGE"] - - -def test_pod_template_dict(docker_image): - spec = { - "metadata": {}, - "restartPolicy": "Never", - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - "--death-timeout", - "60", - ], - "command": None, - "image": docker_image, - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with KubeCluster(spec) as cluster: - cluster.scale(2) - with Client(cluster) as client: - future = client.submit(lambda x: x + 1, 10) - result = future.result() - assert result == 11 - - while len(cluster.scheduler_info["workers"]) < 2: - sleep(0.1) - - # Ensure that inter-worker communication works well - futures = client.map(lambda x: x + 1, range(10)) - total = client.submit(sum, futures) - assert total.result() == sum(map(lambda x: x + 1, range(10))) - assert all(client.has_what().values()) - - -def test_pod_template_minimal_dict(docker_image): - spec = { - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - "--death-timeout", - "60", - ], - "command": None, - "image": docker_image, - "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - } - } - - with KubeCluster(spec) as cluster: - cluster.adapt() - with Client(cluster) as client: - future = client.submit(lambda x: x + 1, 10) - result = future.result() - assert result == 11 - - -def test_worker_pod_template_spec_are_copied(docker_image): - worker_spec = make_pod_spec(docker_image) - worker_spec.spec.containers[0].args[0] = "fake-worker-cmd" - - with KubeCluster(pod_template=worker_spec): - assert worker_spec.spec.containers[0].args[0] == "fake-worker-cmd" - - -def test_scheduler_pod_template_spec_are_copied(docker_image): - scheduler_spec = make_pod_spec(docker_image) - scheduler_spec.spec.containers[0].args[0] = "fake-scheduler-cmd" - - with KubeCluster( - pod_template=make_pod_spec(docker_image), scheduler_pod_template=scheduler_spec - ): - assert scheduler_spec.spec.containers[0].args[0] == "fake-scheduler-cmd" - - -def test_pod_template_from_conf(docker_image): - spec = { - "spec": { - "containers": [{"name": KUBECLUSTER_CONTAINER_NAME, "image": docker_image}] - } - } - - with dask.config.set({"kubernetes.worker-template": spec}): - with KubeCluster() as cluster: - assert ( - cluster.pod_template.spec.containers[0].name - == KUBECLUSTER_CONTAINER_NAME - ) - - -def test_pod_template_with_custom_container_name(docker_image): - container_name = "my-custom-container" - spec = {"spec": {"containers": [{"name": container_name, "image": docker_image}]}} - - with dask.config.set({"kubernetes.worker-template": spec}): - with KubeCluster() as cluster: - assert cluster.pod_template.spec.containers[0].name == container_name - - -def test_bad_args(): - with pytest.raises(FileNotFoundError): - KubeCluster("myfile.yaml") - - with pytest.raises((ValueError, TypeError, AttributeError)): - KubeCluster({"kind": "Pod"}) - - -def test_constructor_parameters(pod_spec): - env = {"FOO": "BAR", "A": 1} - with KubeCluster(pod_spec, name="myname", env=env) as cluster: - pod = cluster.pod_template - - var = [v for v in pod.spec.containers[0].env if v.name == "FOO"] - assert var and var[0].value == "BAR" - - var = [v for v in pod.spec.containers[0].env if v.name == "A"] - assert var and var[0].value == "1" - - assert pod.metadata.generate_name == "myname" - - -def test_scale_up_down(cluster, client): - np = pytest.importorskip("numpy") - cluster.scale(2) - - start = time() - while len(cluster.scheduler_info["workers"]) != 2: - sleep(0.1) - assert time() < start + 30 - - a, b = list(cluster.scheduler_info["workers"]) - x = client.submit(np.ones, 1, workers=a) - y = client.submit(np.ones, 50_000, workers=b) - - wait([x, y]) - - # start = time() - # while ( - # cluster.scheduler_info["workers"][a].metrics["memory"] - # > cluster.scheduler_info["workers"][b].metrics["memory"] - # ): - # sleep(0.1) - # assert time() < start + 1 - - cluster.scale(1) - - start = time() - while len(cluster.scheduler_info["workers"]) != 1: - sleep(0.1) - assert time() < start + 60 - - # assert set(cluster.scheduler_info["workers"]) == {b} - - -def test_automatic_startup(docker_image): - test_yaml = { - "kind": "Pod", - "metadata": {"labels": {"foo": "bar"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": docker_image, - "name": KUBECLUSTER_CONTAINER_NAME, - } - ] - }, - } - - with tmpfile(extension="yaml") as fn: - with open(fn, mode="w") as f: - yaml.dump(test_yaml, f) - with dask.config.set({"kubernetes.worker-template-path": fn}): - with KubeCluster() as cluster: - assert cluster.pod_template.metadata.labels["foo"] == "bar" - - -def test_repr(cluster): - for text in [repr(cluster), str(cluster)]: - assert "Box" not in text - assert ( - cluster.scheduler.address in text - or cluster.scheduler.external_address in text - ) - assert "workers=0" in text - - -def test_escape_username(pod_spec, monkeypatch): - monkeypatch.setenv("LOGNAME", "Foo!") - - with KubeCluster(pod_spec) as cluster: - assert "foo" in cluster.name - assert "!" not in cluster.name - assert "foo" in cluster.pod_template.metadata.labels["user"] - - -def test_escape_name(pod_spec): - with KubeCluster(pod_spec, name="foo@bar") as cluster: - assert "@" not in str(cluster.pod_template) - - -def test_maximum(cluster): - with dask.config.set({"kubernetes.count.max": 1}): - with captured_logger("dask_kubernetes") as logger: - cluster.scale(10) - - start = time() - while len(cluster.scheduler_info["workers"]) <= 0: - sleep(0.1) - assert time() < start + 60 - - sleep(0.5) - assert len(cluster.scheduler_info["workers"]) == 1 - - result = logger.getvalue() - assert "scale beyond maximum number of workers" in result.lower() - - -def test_extra_pod_config(docker_image): - """ - Test that our pod config merging process works fine - """ - with KubeCluster( - make_pod_spec( - docker_image, extra_pod_config={"automountServiceAccountToken": False} - ), - n_workers=0, - ) as cluster: - - pod = cluster.pod_template - - assert pod.spec.automount_service_account_token is False - - -def test_extra_container_config(docker_image): - """ - Test that our container config merging process works fine - """ - with KubeCluster( - make_pod_spec( - docker_image, - extra_container_config={ - "imagePullPolicy": "IfNotPresent", - "securityContext": {"runAsUser": 0}, - }, - ), - n_workers=0, - ) as cluster: - - pod = cluster.pod_template - - assert pod.spec.containers[0].image_pull_policy == "IfNotPresent" - assert pod.spec.containers[0].security_context == {"runAsUser": 0} - - -def test_container_resources_config(docker_image): - """ - Test container resource requests / limits being set properly - """ - with KubeCluster( - make_pod_spec( - docker_image, memory_request="0.5G", memory_limit="1G", cpu_limit="1" - ), - n_workers=0, - ) as cluster: - - pod = cluster.pod_template - - assert pod.spec.containers[0].resources.requests["memory"] == "0.5G" - assert pod.spec.containers[0].resources.limits["memory"] == "1G" - assert pod.spec.containers[0].resources.limits["cpu"] == "1" - assert "cpu" not in pod.spec.containers[0].resources.requests - - -def test_extra_container_config_merge(docker_image): - """ - Test that our container config merging process works recursively fine - """ - with KubeCluster( - make_pod_spec( - docker_image, - env={"TEST": "HI"}, - extra_container_config={ - "env": [{"name": "BOO", "value": "FOO"}], - "args": ["last-item"], - }, - ), - n_workers=0, - ) as cluster: - - pod = cluster.pod_template - - for e in [{"name": "TEST", "value": "HI"}, {"name": "BOO", "value": "FOO"}]: - assert e in pod.spec.containers[0].env - - assert pod.spec.containers[0].args[-1] == "last-item" - - -def test_worker_args(docker_image): - """ - Test that dask-worker arguments are added to the container args - """ - with KubeCluster( - make_pod_spec( - docker_image, - memory_limit="5000M", - resources="FOO=1 BAR=2", - ), - n_workers=0, - ) as cluster: - - pod = cluster.pod_template - - for arg in ["--memory-limit", "5000M", "--resources", "FOO=1 BAR=2"]: - assert arg in pod.spec.containers[0].args diff --git a/dask_kubernetes/common/auth.py b/dask_kubernetes/common/auth.py deleted file mode 100644 index 1ebdff89f..000000000 --- a/dask_kubernetes/common/auth.py +++ /dev/null @@ -1,493 +0,0 @@ -""" -Defines different methods to configure a connection to a Kubernetes cluster. -""" -import asyncio -import base64 -import contextlib -import copy -import datetime -import json -import logging -import os - -import kubernetes -import kubernetes_asyncio -from kubernetes_asyncio.client import Configuration -from kubernetes_asyncio.config.dateutil import parse_rfc3339 -from kubernetes_asyncio.config.google_auth import google_auth_credentials -from kubernetes_asyncio.config.kube_config import KubeConfigLoader, KubeConfigMerger - -logger = logging.getLogger(__name__) - -tzUTC = datetime.timezone.utc - - -class AutoRefreshKubeConfigLoader(KubeConfigLoader): - """ - Extends KubeConfigLoader, automatically attempts to refresh authentication - credentials before they expire. - """ - - def __init__(self, *args, **kwargs): - super(AutoRefreshKubeConfigLoader, self).__init__(*args, **kwargs) - - self._retry_count = 0 - self._max_retries = float("Inf") - self.auto_refresh = True - self.refresh_task = None - self.last_refreshed = None - self.token_expire_ts = None - - def __del__(self): - self.auto_refresh = False - - def extract_oid_expiration_from_provider(self, provider): - """ - Extracts the expiration datestamp for the provider token - Parameters - ---------- - provider : authentication provider dictionary. - - Returns - ------- - expires : expiration timestamp - """ - parts = provider["config"]["id-token"].split(".") - - if len(parts) != 3: - raise ValueError("oidc: JWT tokens should contain 3 period-delimited parts") - - id_token = parts[1] - # Re-pad the unpadded JWT token - id_token += (4 - len(id_token) % 4) * "=" - jwt_attributes = json.loads(base64.b64decode(id_token).decode("utf8")) - expires = jwt_attributes.get("exp") - - return expires - - async def create_refresh_task_from_expiration_timestamp(self, expiration_timestamp): - """ - Takes an expiration timestamp, and creates a refresh task to ensure that the token - does not expire. - - Parameters - ---------- - expiration_timestamp : time at which the current authentication token will expire - - Returns - ------- - N/A - """ - # Set our token expiry to be actual expiry - 20% - expiry = parse_rfc3339(expiration_timestamp) - expiry_delta = datetime.timedelta( - seconds=(expiry - datetime.datetime.now(tz=tzUTC)).total_seconds() - ) - scaled_expiry_delta = datetime.timedelta( - seconds=0.8 * expiry_delta.total_seconds() - ) - - self.refresh_task = asyncio.create_task( - self.refresh_after( - when=scaled_expiry_delta.total_seconds(), reschedule_on_failure=True - ), - name="dask_auth_auto_refresh", - ) - - self.last_refreshed = datetime.datetime.now(tz=tzUTC) - self.token_expire_ts = self.last_refreshed + scaled_expiry_delta - - async def refresh_after(self, when, reschedule_on_failure=False): - """ - Refresh kuberenetes authentication - Parameters - ---------- - when : Seconds before we should refresh. This should be set to some delta before - the actual token expiration time, or you will likely see authentication race - / failure conditions. - - reschedule_on_failure : If the refresh task fails, re-try in 30 seconds, until - _max_retries is exceeded, then raise an exception. - """ - - if not self.auto_refresh: - return - - logger.debug( - msg=f"Refresh_at coroutine sleeping for " - f"{int(when // 60)} minutes {(when % 60):0.2f} seconds." - ) - try: - await asyncio.sleep(when) - if self.provider == "gcp": - await self.refresh_gcp_token() - elif self.provider == "oidc": - await self.refresh_oid_token() - return - elif "exec" in self._user: - logger.warning(msg="Auto-refresh doesn't support generic ExecProvider") - return - - except Exception as e: - logger.warning( - msg=f"Authentication refresh failed for provider '{self.provider}.'", - exc_info=e, - ) - if not reschedule_on_failure or self._retry_count > self._max_retries: - raise - - logger.warning(msg=f"Retrying '{self.provider}' in 30 seconds.") - self._retry_count += 1 - self.refresh_task = asyncio.create_task(self.refresh_after(30)) - - async def refresh_oid_token(self): - """ - Adapted from kubernetes_asyncio/config/kube_config:_load_oid_token - - Refreshes the existing oid token, if necessary, and creates a refresh task - that will keep the token from expiring. - - Returns - ------- - """ - provider = self._user["auth-provider"] - - logger.debug("Refreshing OID token.") - - if "config" not in provider: - raise ValueError("oidc: missing configuration") - - if (not self.token_expire_ts) or ( - self.token_expire_ts <= datetime.datetime.now(tz=tzUTC) - ): - await self._refresh_oidc(provider) - expires = datetime.datetime.fromtimestamp( - self.extract_oid_expiration_from_provider(provider=provider) - ) - - await self.create_refresh_task_from_expiration_timestamp( - expiration_timestamp=expires - ) - - self.token = "Bearer {}".format(provider["config"]["id-token"]) - - async def refresh_gcp_token(self): - """ - Adapted from kubernetes_asyncio/config/kube_config:load_gcp_token - - Refreshes the existing gcp token, if necessary, and creates a refresh task - that will keep the token from expiring. - - Returns - ------- - """ - if "config" not in self._user["auth-provider"]: - self._user["auth-provider"].value["config"] = {} - - config = self._user["auth-provider"]["config"] - - if (not self.token_expire_ts) or ( - self.token_expire_ts <= datetime.datetime.now(tz=tzUTC) - ): - - logger.debug("Refreshing GCP token.") - if self._get_google_credentials is not None: - if asyncio.iscoroutinefunction(self._get_google_credentials): - credentials = await self._get_google_credentials() - else: - credentials = self._get_google_credentials() - else: - # config is read-only. - extra_args = " --force-auth-refresh" - _config = { - "cmd-args": config["cmd-args"] + extra_args, - "cmd-path": config["cmd-path"], - } - credentials = await google_auth_credentials(_config) - - config.value["access-token"] = credentials.token - config.value["expiry"] = credentials.expiry - - # Set our token expiry to be actual expiry - 20% - await self.create_refresh_task_from_expiration_timestamp( - expiration_timestamp=config.value["expiry"] - ) - - if self._config_persister: - self._config_persister(self._config.value) - - self.token = "Bearer %s" % config["access-token"] - - async def _load_oid_token(self): - """ - Overrides KubeConfigLoader implementation. - Returns - ------- - Auth token - """ - await self.refresh_oid_token() - - return self.token - - async def load_gcp_token(self): - """ - Override KubeConfigLoader implementation so that we can keep track of the expiration timestamp - and automatically refresh auth tokens. - - Returns - ------- - GCP access token - """ - await self.refresh_gcp_token() - - return self.token - - -class AutoRefreshConfiguration(Configuration): - """ - Extends kubernetes_async Configuration to support automatic token refresh. - Lets us keep track of the original loader object, which can be used - to regenerate the authentication token. - """ - - def __init__(self, loader, refresh_frequency=None, *args, **kwargs): - super(AutoRefreshConfiguration, self).__init__(*args, **kwargs) - - # Set refresh api callback - self.refresh_api_key_hook = self.refresh_api_key - self.last_refreshed = datetime.datetime.now(tz=tzUTC) - self.loader = loader - - # Adapted from kubernetes_asyncio/client/configuration.py:__deepcopy__ - def __deepcopy__(self, memo): - """ - Modified so that we don't try to deep copy the loader off the config - """ - cls = self.__class__ - result = cls.__new__(cls) - memo[id(self)] = result - for k, v in self.__dict__.items(): - if k not in ("logger", "logger_file_handler", "loader"): - setattr(result, k, copy.deepcopy(v, memo)) - - # shallow copy loader object - result.loader = self.loader - # shallow copy of loggers - result.logger = copy.copy(self.logger) - # use setters to configure loggers - result.logger_file = self.logger_file - result.debug = self.debug - - return result - - def refresh_api_key(self, client_configuration): - """ - Checks to see if the loader has updated the authentication token. If it - has, the token is copied from the loader into the current configuration. - - This function is assigned to Configuration.refresh_api_key_hook, and will - fire when entering get_api_key_with_prefix, before the api_key is retrieved. - """ - if self.loader.last_refreshed is not None: - if ( - self.last_refreshed is None - or self.last_refreshed < self.loader.last_refreshed - ): - logger.debug("Entering refresh_api_key_hook") - client_configuration.api_key[ - "authorization" - ] = client_configuration.loader.token - self.last_refreshed = datetime.datetime.now(tz=tzUTC) - - -class ClusterAuth(object): - """ - An abstract base class for methods for configuring a connection to a - Kubernetes API server. - - Examples - -------- - >>> from dask_kubernetes import KubeConfig - >>> auth = KubeConfig(context='minikube') - - >>> from dask_kubernetes import KubeAuth - >>> auth = KubeAuth(host='https://localhost/', username='superuser', password='pass') - - """ - - async def load(self): - """ - Load Kubernetes configuration and set as default - - Raises - ------ - - kubernetes.client.KubeConfigException - """ - raise NotImplementedError() - - @staticmethod - async def load_first(auth=None): - """ - Load the first valid configuration in the list *auth*. A single - configuration method can be passed. - - Parameters - ---------- - auth: List[ClusterAuth] (optional) - Configuration methods to attempt in order. Defaults to - ``[InCluster(), KubeConfig()]``. - - """ - if auth is None: - auth = ClusterAuth.DEFAULT - elif isinstance(auth, ClusterAuth): - auth = [auth] - elif isinstance(auth, list): - if not auth: - raise kubernetes_asyncio.config.ConfigException( - "No authorization methods were provided" - ) - else: - msg = ( - "Invalid authorization method provided. See ClusterAuth " - "docstring for ways to specify authentication methods" - ) - raise ValueError(msg) - - auth_exc = None - for auth_instance in auth: - try: - await auth_instance.load() - except ( - kubernetes_asyncio.config.ConfigException, - kubernetes.config.ConfigException, - ) as exc: - logger.debug( - "Failed to load configuration with %s method: %s", - auth_instance.__class__, - exc, - ) - auth_exc = exc - else: - break - else: - raise auth_exc - - -class InCluster(ClusterAuth): - """Configure the Kubernetes connection from a container's environment. - - This authentication method is intended for use when the client is running - in a container started by Kubernetes with an authorized service account. - This loads the mounted service account token and discovers the Kubernetes - API via Kubernetes service discovery. - """ - - async def load(self): - kubernetes.config.load_incluster_config() - kubernetes_asyncio.config.load_incluster_config() - - -class KubeConfig(ClusterAuth): - """Configure the Kubernetes connection from a kubeconfig file. - - Parameters - ---------- - config_file: str (optional) - The path of the kubeconfig file to load. Defaults to the value of the - ``KUBECONFIG`` environment variable, or the string ``~/.kube/config``. - context: str (optional) - The kubeconfig context to use. Defaults to the value of ``current-context`` - in the configuration file. - persist_config: bool (optional) - Whether changes to the configuration will be saved back to disk (e.g. - GCP token refresh). Defaults to ``True``. - - """ - - def __init__(self, config_file=None, context=None, persist_config=True): - self.config_file = config_file - self.context = context - self.persist_config = persist_config - - async def load(self): - with contextlib.suppress(KeyError): - if self.config_file is None: - self.config_file = os.path.abspath( - os.path.expanduser(os.environ.get("KUBECONFIG", "~/.kube/config")) - ) - - await self.load_kube_config() - - # Adapted from from kubernetes_asyncio/config/kube_config.py:get_kube_config_loader_for_yaml_file - def get_kube_config_loader_for_yaml_file(self): - kcfg = KubeConfigMerger(self.config_file) - config_persister = None - if self.persist_config: - config_persister = kcfg.save_changes() - - return AutoRefreshKubeConfigLoader( - config_dict=kcfg.config, - config_base_path=None, - config_persister=config_persister, - ) - - # Adapted from kubernetes_asyncio/config/kube_config.py:load_kube_config - async def load_kube_config(self): - # Create a config loader, this will automatically refresh our credentials before they expire - loader = self.get_kube_config_loader_for_yaml_file() - - # Grab our async + callback aware configuration - config = AutoRefreshConfiguration(loader) - - await loader.load_and_set(config) - Configuration.set_default(config) - - -class KubeAuth(ClusterAuth): - """Configure the Kubernetes connection explicitly. - - Parameters - ---------- - host: str - The base URL of the Kubernetes host to connect - username: str (optional) - Username for HTTP basic authentication - password: str (optional) - Password for HTTP basic authentication - debug: bool (optional) - Debug switch - verify_ssl: bool (optional) - Set this to false to skip verifying SSL certificate when calling API - from https server. Defaults to ``True``. - ssl_ca_cert: str (optional) - Set this to customize the certificate file to verify the peer. - cert_file: str (optional) - Client certificate file - key_file: str (optional) - Client key file - assert_hostname: bool (optional) - Set this to True/False to enable/disable SSL hostname verification. - Defaults to True. - proxy: str (optional) - URL for a proxy to connect through - """ - - def __init__(self, host, **kwargs): - # We need to create a new configuration in this way, because if we just - # instantiate a new Configuration object we will get the default - # values. - config = type.__call__(kubernetes.client.Configuration) - config.host = host - - for key, value in kwargs.items(): - setattr(config, key, value) - self.config = config - - async def load(self): - kubernetes.client.Configuration.set_default(self.config) - await kubernetes_asyncio.client.Configuration.set_default(self.config) - - -ClusterAuth.DEFAULT = [InCluster(), KubeConfig()] diff --git a/dask_kubernetes/common/networking.py b/dask_kubernetes/common/networking.py deleted file mode 100644 index b789c2c06..000000000 --- a/dask_kubernetes/common/networking.py +++ /dev/null @@ -1,240 +0,0 @@ -import asyncio -import random -import socket -import subprocess -import time -from contextlib import suppress -from weakref import finalize - -import kr8s -import kubernetes_asyncio as kubernetes -from distributed.core import rpc -from kr8s.asyncio.objects import Pod -from tornado.iostream import StreamClosedError - -from dask_kubernetes.common.utils import check_dependency -from dask_kubernetes.exceptions import CrashLoopBackOffError - - -async def get_internal_address_for_scheduler_service( - service, - port_forward_cluster_ip=None, - service_name_resolution_retries=20, - port_name="tcp-comm", - local_port=None, -): - """Take a service object and return the scheduler address.""" - port = _get_port(service, port_name) - if not port_forward_cluster_ip: - with suppress(socket.gaierror): - # Try to resolve the service name. If we are inside the cluster this should succeed. - host = f"{service.metadata.name}.{service.metadata.namespace}" - if await _is_service_available( - host=host, port=port, retries=service_name_resolution_retries - ): - return f"tcp://{host}:{port}" - - # If the service name is unresolvable, we are outside the cluster and we need to port forward the service. - host = "localhost" - - port = await port_forward_service( - service.metadata.name, service.metadata.namespace, port, local_port - ) - return f"tcp://{host}:{port}" - - -async def get_external_address_for_scheduler_service( - core_api, - service, - port_forward_cluster_ip=None, - service_name_resolution_retries=20, - port_name="tcp-comm", - local_port=None, -): - """Take a service object and return the scheduler address.""" - if service.spec.type == "LoadBalancer": - port = _get_port(service, port_name) - lb = service.status.load_balancer.ingress[0] - host = lb.hostname or lb.ip - elif service.spec.type == "NodePort": - port = _get_port(service, port_name, is_node_port=True) - nodes = await core_api.list_node() - host = nodes.items[0].status.addresses[0].address - elif service.spec.type == "ClusterIP": - port = _get_port(service, port_name) - if not port_forward_cluster_ip: - with suppress(socket.gaierror): - # Try to resolve the service name. If we are inside the cluster this should succeed. - host = f"{service.metadata.name}.{service.metadata.namespace}" - if await _is_service_available( - host=host, port=port, retries=service_name_resolution_retries - ): - return f"tcp://{host}:{port}" - - # If the service name is unresolvable, we are outside the cluster and we need to port forward the service. - host = "localhost" - - port = await port_forward_service( - service.metadata.name, service.metadata.namespace, port, local_port - ) - return f"tcp://{host}:{port}" - - -def _get_port(service, port_name, is_node_port=False): - """NodePort is a special case when we have to use node_port instead of node""" - [port] = [ - port.port if not is_node_port else port.nodePort - for port in service.spec.ports - if port.name == service.metadata.name or port.name == port_name - ] - return port - - -async def _is_service_available(host, port, retries=20): - for i in range(retries): - try: - return await asyncio.get_event_loop().getaddrinfo(host, port) - except socket.gaierror as e: - if i >= retries - 1: - raise e - await asyncio.sleep(0.5) - - -def _port_in_use(port): - if port is None: - return True - conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - conn.bind(("", port)) - conn.close() - return False - except OSError: - return True - - -def _random_free_port(low, high, retries=20): - conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - while retries: - guess = random.randint(low, high) - try: - conn.bind(("", guess)) - conn.close() - return guess - except OSError: - retries -= 1 - raise ConnectionError("Not able to find a free port.") - - -async def port_forward_service(service_name, namespace, remote_port, local_port=None): - check_dependency("kubectl") - if not local_port: - local_port = _random_free_port(49152, 65535) # IANA suggested range - elif _port_in_use(local_port): - raise ConnectionError("Specified Port already in use.") - kproc = subprocess.Popen( - [ - "kubectl", - "port-forward", - "--address", - "0.0.0.0", - "--namespace", - f"{namespace}", - f"service/{service_name}", - f"{local_port}:{remote_port}", - ], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - finalize(kproc, kproc.kill) - - if await is_comm_open("localhost", local_port, retries=2000): - return local_port - raise ConnectionError("kubectl port forward failed") - - -async def is_comm_open(ip, port, retries=200): - while retries > 0: - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: - result = sock.connect_ex((ip, port)) - if result == 0: - return True - else: - time.sleep(0.1) - retries -= 1 - return False - - -async def port_forward_dashboard(service_name, namespace): - port = await port_forward_service(service_name, namespace, 8787) - return port - - -async def get_scheduler_address( - service_name, - namespace, - port_name="tcp-comm", - port_forward_cluster_ip=None, - local_port=None, - allow_external=True, -): - async with kubernetes.client.api_client.ApiClient() as api_client: - api = kubernetes.client.CoreV1Api(api_client) - service = await api.read_namespaced_service(service_name, namespace) - if allow_external: - address = await get_external_address_for_scheduler_service( - api, - service, - port_forward_cluster_ip=port_forward_cluster_ip, - port_name=port_name, - local_port=local_port, - ) - else: - address = await get_internal_address_for_scheduler_service( - service, - port_forward_cluster_ip=port_forward_cluster_ip, - port_name=port_name, - local_port=local_port, - ) - return address - - -async def wait_for_scheduler(cluster_name, namespace, timeout=None): - pod_start_time = None - while True: - try: - pod = await Pod.get( - label_selector=f"dask.org/component=scheduler,dask.org/cluster-name={cluster_name}", - field_selector="status.phase=Running", - namespace=namespace, - ) - except kr8s.NotFoundError: - await asyncio.sleep(0.25) - continue - if pod.status.phase == "Running": - if not pod_start_time: - pod_start_time = time.time() - if await pod.ready(): - return - if "containerStatuses" in pod.status: - for container in pod.status.containerStatuses: - if ( - "waiting" in container.state - and container.state.waiting.reason == "CrashLoopBackOff" - and timeout - and pod_start_time + timeout < time.time() - ): - raise CrashLoopBackOffError( - f"Scheduler in CrashLoopBackOff for more than {timeout} seconds." - ) - await asyncio.sleep(0.25) - - -async def wait_for_scheduler_comm(address): - while True: - try: - async with rpc(address) as scheduler_comm: - await scheduler_comm.versions() - except (StreamClosedError, OSError): - await asyncio.sleep(0.1) - continue - break diff --git a/dask_kubernetes/common/objects.py b/dask_kubernetes/common/objects.py deleted file mode 100644 index 1eedeebd7..000000000 --- a/dask_kubernetes/common/objects.py +++ /dev/null @@ -1,386 +0,0 @@ -""" -Convenience functions for creating pod templates. -""" - -import copy -import json -from collections import namedtuple - -from kubernetes import client -from kubernetes.client.configuration import Configuration - -from dask_kubernetes.constants import ( - KUBECLUSTER_CONTAINER_NAME, - MAX_CLUSTER_NAME_LEN, - VALID_CLUSTER_NAME, -) -from dask_kubernetes.exceptions import ValidationError - -_FakeResponse = namedtuple("_FakeResponse", ["data"]) - - -class DummyApiClient(client.ApiClient): - """A Dummy API client that is to be used solely for serialization/deserialization. - - This is to avoid starting a threadpool at initialization and for adapting the - deserialize method to accept a python dictionary instead of a Response-like - interface. - """ - - def __init__(self): - self.configuration = Configuration.get_default_copy() - - def deserialize(self, dict_, klass): - return super().deserialize(_FakeResponse(json.dumps(dict_)), klass) - - -SERIALIZATION_API_CLIENT = DummyApiClient() - - -def _set_k8s_attribute(obj, attribute, value): - """ - Set a specific value on a kubernetes object's attribute - - obj - an object from Kubernetes Python API client - attribute - Should be a Kubernetes API style attribute (with camelCase) - value - Can be anything (string, list, dict, k8s objects) that can be - accepted by the k8s python client - """ - current_value = None - attribute_name = None - # All k8s python client objects have an 'attribute_map' property - # which has as keys python style attribute names (api_client) - # and as values the kubernetes JSON API style attribute names - # (apiClient). We want to allow users to use the JSON API style attribute - # names only. - for python_attribute, json_attribute in obj.attribute_map.items(): - if json_attribute == attribute: - attribute_name = python_attribute - break - else: - raise ValueError( - "Attribute must be one of {}".format(obj.attribute_map.values()) - ) - - if hasattr(obj, attribute_name): - current_value = getattr(obj, attribute_name) - - if current_value is not None: - # This will ensure that current_value is something JSONable, - # so a dict, list, or scalar - current_value = SERIALIZATION_API_CLIENT.sanitize_for_serialization( - current_value - ) - - if isinstance(current_value, dict): - # Deep merge our dictionaries! - setattr(obj, attribute_name, merge_dictionaries(current_value, value)) - elif isinstance(current_value, list): - # Just append lists - setattr(obj, attribute_name, current_value + value) - else: - # Replace everything else - setattr(obj, attribute_name, value) - - -def merge_dictionaries(a, b, path=None, update=True): - """ - Merge two dictionaries recursively. - - From https://stackoverflow.com/a/25270947 - """ - if path is None: - path = [] - for key in b: - if key in a: - if isinstance(a[key], dict) and isinstance(b[key], dict): - merge_dictionaries(a[key], b[key], path + [str(key)]) - elif a[key] == b[key]: - pass # same leaf value - elif isinstance(a[key], list) and isinstance(b[key], list): - for idx, _ in enumerate(b[key]): - a[key][idx] = merge_dictionaries( - a[key][idx], - b[key][idx], - path + [str(key), str(idx)], - update=update, - ) - elif update: - a[key] = b[key] - else: - raise Exception("Conflict at %s" % ".".join(path + [str(key)])) - else: - a[key] = b[key] - return a - - -def make_pod_spec( - image, - labels={}, - threads_per_worker=1, - env={}, - extra_container_config={}, - extra_pod_config={}, - resources=None, - memory_limit=None, - memory_request=None, - cpu_limit=None, - cpu_request=None, - gpu_limit=None, - annotations={}, -): - """ - Create generic pod template from input parameters - - Parameters - ---------- - image : str - Docker image name - labels : dict - Dict of labels to pass to ``V1ObjectMeta`` - threads_per_worker : int - Number of threads per each worker - env : dict - Dict of environment variables to pass to ``V1Container`` - extra_container_config : dict - Extra config attributes to set on the container object - extra_pod_config : dict - Extra config attributes to set on the pod object - resources : str - Resources for task constraints like "GPU=2 MEM=10e9". Resources are applied - separately to each worker process (only relevant when starting multiple - worker processes. Passed to the `--resources` option in ``dask-worker``. - memory_limit : int, float, or str - Bytes of memory per process that the worker can use (applied to both - ``dask-worker --memory-limit`` and ``spec.containers[].resources.limits.memory``). - This can be: - - an integer (bytes), note 0 is a special case for no memory management. - - a float (bytes). Note: fraction of total system memory is not supported by k8s. - - a string (like 5GiB or 5000M). Note: 'GB' is not supported by k8s. - - 'auto' for automatically computing the memory limit. [default: auto] - memory_request : int, float, or str - Like ``memory_limit`` (applied only to ``spec.containers[].resources.requests.memory`` - and ignored by ``dask-worker``). - cpu_limit : float or str - CPU resource limits (applied to ``spec.containers[].resources.limits.cpu``). - cpu_request : float or str - CPU resource requests (applied to ``spec.containers[].resources.requests.cpu``). - gpu_limit : int - GPU resource limits (applied to ``spec.containers[].resources.limits."nvidia.com/gpu"``). - annotations : dict - Dict of annotations passed to ``V1ObjectMeta`` - - Returns - ------- - pod : V1PodSpec - - Examples - -------- - >>> make_pod_spec(image='ghcr.io/dask/dask:latest', memory_limit='4G', memory_request='4G') - """ - args = [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - str(threads_per_worker), - "--death-timeout", - "60", - ] - if memory_limit: - args.extend(["--memory-limit", str(memory_limit)]) - if resources: - args.extend(["--resources", str(resources)]) - pod = client.V1Pod( - metadata=client.V1ObjectMeta(labels=labels, annotations=annotations), - spec=client.V1PodSpec( - restart_policy="Never", - containers=[ - client.V1Container( - name=KUBECLUSTER_CONTAINER_NAME, - image=image, - args=args, - env=[client.V1EnvVar(name=k, value=v) for k, v in env.items()], - ) - ], - ), - ) - - resources = client.V1ResourceRequirements(limits={}, requests={}) - - if cpu_request: - resources.requests["cpu"] = cpu_request - if memory_request: - resources.requests["memory"] = memory_request - - if cpu_limit: - resources.limits["cpu"] = cpu_limit - if gpu_limit: - resources.limits["nvidia.com/gpu"] = gpu_limit - if memory_limit: - resources.limits["memory"] = memory_limit - - pod.spec.containers[0].resources = resources - - for key, value in extra_container_config.items(): - _set_k8s_attribute(pod.spec.containers[0], key, value) - - for key, value in extra_pod_config.items(): - _set_k8s_attribute(pod.spec, key, value) - return pod - - -def make_pod_from_dict(dict_): - containers = dict_.get("spec", {}).get("containers", []) - for i, container in enumerate(containers): - container.setdefault("name", f"dask-{i}") - return SERIALIZATION_API_CLIENT.deserialize(dict_, client.V1Pod) - - -def make_service_from_dict(dict_): - return SERIALIZATION_API_CLIENT.deserialize(dict_, client.V1Service) - - -def make_pdb_from_dict(dict_): - return SERIALIZATION_API_CLIENT.deserialize(dict_, client.V1PodDisruptionBudget) - - -def clean_pod_template( - pod_template, apply_default_affinity="preferred", pod_type="worker" -): - """Normalize pod template""" - pod_template = copy.deepcopy(pod_template) - - # Make sure metadata / labels / env objects exist, so they can be modified - # later without a lot of `is None` checks - if pod_template.metadata is None: - pod_template.metadata = client.V1ObjectMeta() - if pod_template.metadata.labels is None: - pod_template.metadata.labels = {} - - if pod_template.spec.containers[0].env is None: - pod_template.spec.containers[0].env = [] - - # add default tolerations - tolerations = [ - client.V1Toleration( - key="k8s.dask.org/dedicated", - operator="Equal", - value=pod_type, - effect="NoSchedule", - ), - # GKE currently does not permit creating taints on a node pool - # with a `/` in the key field - client.V1Toleration( - key="k8s.dask.org_dedicated", - operator="Equal", - value=pod_type, - effect="NoSchedule", - ), - ] - - if pod_template.spec.tolerations is None: - pod_template.spec.tolerations = tolerations - else: - pod_template.spec.tolerations.extend(tolerations) - - # add default node affinity to k8s.dask.org/node-purpose=worker - if apply_default_affinity != "none": - # for readability - affinity = pod_template.spec.affinity - - if affinity is None: - affinity = client.V1Affinity() - if affinity.node_affinity is None: - affinity.node_affinity = client.V1NodeAffinity() - - # a common object for both a preferred and a required node affinity - node_selector_term = client.V1NodeSelectorTerm( - match_expressions=[ - client.V1NodeSelectorRequirement( - key="k8s.dask.org/node-purpose", operator="In", values=[pod_type] - ) - ] - ) - - if apply_default_affinity == "required": - if ( - affinity.node_affinity.required_during_scheduling_ignored_during_execution - is None - ): - affinity.node_affinity.required_during_scheduling_ignored_during_execution = client.V1NodeSelector( - node_selector_terms=[] - ) - affinity.node_affinity.required_during_scheduling_ignored_during_execution.node_selector_terms.append( - node_selector_term - ) - elif apply_default_affinity == "preferred": - if ( - affinity.node_affinity.preferred_during_scheduling_ignored_during_execution - is None - ): - affinity.node_affinity.preferred_during_scheduling_ignored_during_execution = ( - [] - ) - preferred_scheduling_terms = [ - client.V1PreferredSchedulingTerm( - preference=node_selector_term, weight=100 - ) - ] - affinity.node_affinity.preferred_during_scheduling_ignored_during_execution.extend( - preferred_scheduling_terms - ) - else: - raise ValueError( - 'Attribute apply_default_affinity must be one of "none", "preferred", or "required".' - ) - pod_template.spec.affinity = affinity - - return pod_template - - -def clean_service_template(service_template): - """Normalize service template and check for type errors""" - - service_template = copy.deepcopy(service_template) - - # Make sure metadata / labels objects exist, so they can be modified - # later without a lot of `is None` checks - if service_template.metadata is None: - service_template.metadata = client.V1ObjectMeta() - if service_template.metadata.labels is None: - service_template.metadata.labels = {} - - return service_template - - -def clean_pdb_template(pdb_template): - """Normalize pdb template and check for type errors""" - - pdb_template = copy.deepcopy(pdb_template) - - # Make sure metadata / labels objects exist, so they can be modified - # later without a lot of `is None` checks - if pdb_template.metadata is None: - pdb_template.metadata = client.V1ObjectMeta() - if pdb_template.metadata.labels is None: - pdb_template.metadata.labels = {} - if pdb_template.spec.selector is None: - pdb_template.spec.selector = client.V1LabelSelector() - - return pdb_template - - -def validate_cluster_name(cluster_name: str) -> None: - """Raise exception if cluster name is too long and/or has invalid characters""" - if not VALID_CLUSTER_NAME.match(cluster_name): - raise ValidationError( - message=( - f"The DaskCluster {cluster_name} is invalid: a lowercase RFC 1123 subdomain must " - "consist of lower case alphanumeric characters, '-' or '.', and must start " - "and end with an alphanumeric character. DaskCluster name must also be under " - f"{MAX_CLUSTER_NAME_LEN} characters." - ) - ) diff --git a/dask_kubernetes/common/tests/test_kind.py b/dask_kubernetes/common/tests/test_kind.py deleted file mode 100644 index 2af77bfe6..000000000 --- a/dask_kubernetes/common/tests/test_kind.py +++ /dev/null @@ -1,25 +0,0 @@ -from subprocess import check_output - -import kubernetes_asyncio as kubernetes -import pytest - -from dask_kubernetes.common.auth import ClusterAuth -from dask_kubernetes.common.utils import get_current_namespace - - -def test_config_detection(k8s_cluster): - assert b"pytest-kind" in check_output(["kubectl", "config", "current-context"]) - - -@pytest.mark.anyio -@pytest.mark.xfail(reason="Has asyncio issues on CI") -async def test_auth(k8s_cluster): - await ClusterAuth.load_first(ClusterAuth.DEFAULT) - core_v1_api = kubernetes.client.CoreV1Api() - request = await core_v1_api.list_namespace() - assert get_current_namespace() in [ - namespace.metadata.name for namespace in request.items - ] - - request = await core_v1_api.list_node() - assert "pytest-kind-control-plane" in [node.metadata.name for node in request.items] diff --git a/dask_kubernetes/common/tests/test_objects.py b/dask_kubernetes/common/tests/test_objects.py deleted file mode 100644 index 23e318961..000000000 --- a/dask_kubernetes/common/tests/test_objects.py +++ /dev/null @@ -1,88 +0,0 @@ -import pytest - -from dask_kubernetes.common.objects import make_pod_from_dict, validate_cluster_name -from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME, MAX_CLUSTER_NAME_LEN -from dask_kubernetes.exceptions import ValidationError - - -def test_make_pod_from_dict(): - d = { - "kind": "Pod", - "metadata": {"labels": {"app": "dask", "dask.org/component": "dask-worker"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": "image-name", - "name": KUBECLUSTER_CONTAINER_NAME, - "securityContext": { - "capabilities": {"add": ["SYS_ADMIN"]}, - "privileged": True, - }, - } - ], - "restartPolicy": "Never", - }, - } - - pod = make_pod_from_dict(d) - - assert pod.spec.restart_policy == "Never" - assert pod.spec.containers[0].security_context.privileged - assert pod.spec.containers[0].security_context.capabilities.add == ["SYS_ADMIN"] - - -def test_make_pod_from_dict_default_container_name(): - d = { - "kind": "Pod", - "metadata": {"labels": {"app": "dask", "dask.org/component": "dask-worker"}}, - "spec": { - "containers": [ - { - "args": [ - "dask-worker", - "$(DASK_SCHEDULER_ADDRESS)", - "--nthreads", - "1", - ], - "image": "image-name", - "securityContext": { - "capabilities": {"add": ["SYS_ADMIN"]}, - "privileged": True, - }, - }, - {"image": "image-name2", "name": "sidecar"}, - {"image": "image-name3"}, - ], - "restartPolicy": "Never", - }, - } - - pod = make_pod_from_dict(d) - assert pod.spec.containers[0].name == "dask-0" - assert pod.spec.containers[1].name == "sidecar" - assert pod.spec.containers[2].name == "dask-2" - - -@pytest.mark.parametrize( - "cluster_name", - [ - (MAX_CLUSTER_NAME_LEN + 1) * "a", - "invalid.chars.in.name", - ], -) -def test_validate_cluster_name_raises_on_invalid_name( - cluster_name, -): - - with pytest.raises(ValidationError): - validate_cluster_name(cluster_name) - - -def test_validate_cluster_name_success_on_valid_name(): - assert validate_cluster_name("valid-cluster-name-123") is None diff --git a/dask_kubernetes/common/utils.py b/dask_kubernetes/common/utils.py deleted file mode 100644 index 8ad64f0bd..000000000 --- a/dask_kubernetes/common/utils.py +++ /dev/null @@ -1,47 +0,0 @@ -"""Utility functions.""" -import os -import shutil -import string - -import kubernetes_asyncio as kubernetes - - -def format_labels(labels): - """Convert a dictionary of labels into a comma separated string""" - if labels: - return ",".join(["{}={}".format(k, v) for k, v in labels.items()]) - else: - return "" - - -def escape(s): - valid_characters = string.ascii_letters + string.digits + "-" - return "".join(c for c in s if c in valid_characters).lower() - - -def get_current_namespace(): - """ - Get current namespace if running in a k8s cluster - - If not in a k8s cluster with service accounts enabled, default to - 'default' - - Taken from https://github.com/jupyterhub/kubespawner/blob/master/kubespawner/spawner.py#L125 - """ - ns_path = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" - if os.path.exists(ns_path): - with open(ns_path) as f: - return f.read().strip() - try: - _, active_context = kubernetes.config.list_kube_config_contexts() - return active_context["context"]["namespace"] - except KeyError: - return "default" - - -def check_dependency(dependency): - if shutil.which(dependency) is None: - raise RuntimeError( - f"Missing dependency {dependency}. " - f"Please install {dependency} following the instructions for your OS. " - ) diff --git a/dask_kubernetes/conftest.py b/dask_kubernetes/conftest.py index aadaa2aac..52a036f59 100644 --- a/dask_kubernetes/conftest.py +++ b/dask_kubernetes/conftest.py @@ -1,6 +1,7 @@ import logging import os import pathlib +import shutil import subprocess import sys import tempfile @@ -10,10 +11,17 @@ from kopf.testing import KopfRunner from pytest_kind.cluster import KindCluster -from dask_kubernetes.common.utils import check_dependency - DIR = pathlib.Path(__file__).parent.absolute() + +def check_dependency(dependency): + if shutil.which(dependency) is None: + raise RuntimeError( + f"Missing dependency {dependency}. " + f"Please install {dependency} following the instructions for your OS. " + ) + + check_dependency("helm") check_dependency("kubectl") check_dependency("docker") diff --git a/dask_kubernetes/experimental/__init__.py b/dask_kubernetes/experimental/__init__.py deleted file mode 100644 index 43aafdb0e..000000000 --- a/dask_kubernetes/experimental/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -from importlib import import_module -from warnings import warn - - -def __getattr__(name): - no_longer_experimental = [ - "KubeCluster", - "make_cluster_spec", - "make_scheduler_spec", - "make_worker_spec", - "discover", - ] - if name in no_longer_experimental: - warn( - f"Yay {name} is no longer experimental 🎉. " - "You can import it directly from dask_kubernetes or explicitly from dask_kubernetes.operator", - DeprecationWarning, - stacklevel=2, - ) - new_module = import_module("dask_kubernetes.operator") - return getattr(new_module, name) - - raise AttributeError(f"module {__name__} has no attribute {name}") diff --git a/dask_kubernetes/helm/__init__.py b/dask_kubernetes/helm/__init__.py deleted file mode 100644 index 761caccaa..000000000 --- a/dask_kubernetes/helm/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .helmcluster import HelmCluster, discover diff --git a/dask_kubernetes/helm/helmcluster.py b/dask_kubernetes/helm/helmcluster.py deleted file mode 100644 index b3390b664..000000000 --- a/dask_kubernetes/helm/helmcluster.py +++ /dev/null @@ -1,335 +0,0 @@ -import asyncio -import json -import subprocess -import warnings -from contextlib import suppress - -import aiohttp -import kubernetes_asyncio as kubernetes -from distributed.core import Status, rpc -from distributed.deploy import Cluster -from distributed.utils import Log, Logs - -from ..common.auth import ClusterAuth -from ..common.networking import get_external_address_for_scheduler_service -from ..common.utils import ( - check_dependency, - get_current_namespace, -) - - -class HelmCluster(Cluster): - """Connect to a Dask cluster deployed via the Helm Chart. - - This cluster manager connects to an existing Dask deployment that was - created by the Dask Helm Chart. Enabling you to perform basic cluster actions - such as scaling and log retrieval. - - Parameters - ---------- - release_name: str - Name of the helm release to connect to. - namespace: str (optional) - Namespace in which to launch the workers. - Defaults to current namespace if available or "default" - port_forward_cluster_ip: bool (optional) - If the chart uses ClusterIP type services, forward the ports locally. - If you are using ``HelmCluster`` from the Jupyter session that was installed - by the helm chart this should be ``False``. If you are running it locally it should - be the port you are forwarding to ````. - auth: List[ClusterAuth] (optional) - Configuration methods to attempt in order. Defaults to - ``[InCluster(), KubeConfig()]``. - scheduler_name: str (optional) - Name of the Dask scheduler deployment in the current release. - Defaults to "scheduler". - worker_name: str (optional) - Name of the Dask worker deployment in the current release. - Defaults to "worker". - node_host: str (optional) - A node address. Can be provided in case scheduler service type is - ``NodePort`` and you want to manually specify which node to connect to. - node_port: int (optional) - A node address. Can be provided in case scheduler service type is - ``NodePort`` and you want to manually specify which port to connect to. - **kwargs: dict - Additional keyword arguments to pass to Cluster. - - Examples - -------- - >>> from dask_kubernetes import HelmCluster - >>> cluster = HelmCluster(release_name="myhelmrelease") - - You can then resize the cluster with the scale method - - >>> cluster.scale(10) - - You can pass this cluster directly to a Dask client - - >>> from dask.distributed import Client - >>> client = Client(cluster) - - You can also access cluster logs - - >>> cluster.get_logs() - - See Also - -------- - HelmCluster.scale - HelmCluster.logs - """ - - def __init__( - self, - release_name=None, - auth=ClusterAuth.DEFAULT, - namespace=None, - port_forward_cluster_ip=False, - scheduler_name="scheduler", - worker_name="worker", - node_host=None, - node_port=None, - name=None, - **kwargs, - ): - warnings.warn( - "HelmCluster is going away. " - "Please migrate to the new operator based implementation " - "https://kubernetes.dask.org/en/latest/kubecluster_migrating.html.", - DeprecationWarning, - stacklevel=2, - ) - self.release_name = release_name - self.namespace = namespace or get_current_namespace() - if name is None: - name = self.release_name + "." + self.namespace - check_dependency("helm") - check_dependency("kubectl") - status = subprocess.run( - ["helm", "-n", self.namespace, "status", self.release_name], - capture_output=True, - encoding="utf-8", - ) - if status.returncode != 0: - raise RuntimeError(f"No such helm release {self.release_name}.") - self.auth = auth - self.core_api = None - self.scheduler_comm = None - self.port_forward_cluster_ip = port_forward_cluster_ip - self._supports_scaling = True - self.scheduler_name = scheduler_name - self.worker_name = worker_name - self.node_host = node_host - self.node_port = node_port - - super().__init__(name=name, **kwargs) - if not self.asynchronous: - self._loop_runner.start() - self.sync(self._start) - - async def _start(self): - await ClusterAuth.load_first(self.auth) - self.core_api = kubernetes.client.CoreV1Api() - self.apps_api = kubernetes.client.AppsV1Api() - self.scheduler_comm = rpc(await self._get_scheduler_address()) - await super()._start() - - async def _get_scheduler_address(self): - # Get the chart name - chart = subprocess.check_output( - [ - "helm", - "-n", - self.namespace, - "list", - "-f", - self.release_name, - "--output", - "json", - ], - encoding="utf-8", - ) - chart = json.loads(chart)[0]["chart"] - # extract name from {{.Chart.Name }}-{{ .Chart.Version }} - chart_name = "-".join(chart.split("-")[:-1]) - # Follow the spec in the dask/dask helm chart - self.chart_name = ( - f"{chart_name}-" if chart_name not in self.release_name else "" - ) - - service_name = f"{self.release_name}-{self.chart_name}{self.scheduler_name}" - service = await self.core_api.read_namespaced_service( - service_name, self.namespace - ) - address = await get_external_address_for_scheduler_service( - self.core_api, service, port_forward_cluster_ip=self.port_forward_cluster_ip - ) - if address is None: - raise RuntimeError("Unable to determine scheduler address.") - return address - - async def _wait_for_workers(self): - while True: - n_workers = len(self.scheduler_info["workers"]) - deployments = await self.apps_api.list_namespaced_deployment( - namespace=self.namespace - ) - deployment_replicas = 0 - for deployment in deployments.items: - if ( - f"{self.release_name}-{self.chart_name}{self.worker_name}" - in deployment.metadata.name - ): - deployment_replicas += deployment.spec.replicas - if n_workers == deployment_replicas: - return - else: - await asyncio.sleep(0.2) - - def get_logs(self): - """Get logs for Dask scheduler and workers. - - Examples - -------- - >>> cluster.get_logs() - {'testdask-scheduler-5c8ffb6b7b-sjgrg': ..., - 'testdask-worker-64c8b78cc-992z8': ..., - 'testdask-worker-64c8b78cc-hzpdc': ..., - 'testdask-worker-64c8b78cc-wbk4f': ...} - - Each log will be a string of all logs for that container. To view - it is recommeded that you print each log. - - >>> print(cluster.get_logs()["testdask-scheduler-5c8ffb6b7b-sjgrg"]) - ... - distributed.scheduler - INFO - ----------------------------------------------- - distributed.scheduler - INFO - Clear task state - distributed.scheduler - INFO - Scheduler at: tcp://10.1.6.131:8786 - distributed.scheduler - INFO - dashboard at: :8787 - ... - """ - return self.sync(self._get_logs) - - async def _get_logs(self): - logs = Logs() - - pods = await self.core_api.list_namespaced_pod( - namespace=self.namespace, - label_selector=f"release={self.release_name},app=dask", - ) - - for pod in pods.items: - if "scheduler" in pod.metadata.name or "worker" in pod.metadata.name: - try: - if pod.status.phase != "Running": - raise ValueError( - f"Cannot get logs for pod with status {pod.status.phase}.", - ) - log = Log( - await self.core_api.read_namespaced_pod_log( - pod.metadata.name, pod.metadata.namespace - ) - ) - except (ValueError, kubernetes.client.exceptions.ApiException): - log = Log(f"Cannot find logs. Pod is {pod.status.phase}.") - logs[pod.metadata.name] = log - - return logs - - def __await__(self): - async def _(): - if self.status == Status.created: - await self._start() - elif self.status == Status.running: - await self._wait_for_workers() - return self - - return _().__await__() - - def scale(self, n_workers, worker_group=None): - """Scale cluster to n workers. - - This sets the Dask worker deployment size to the requested number. - It also allows you to set the worker deployment size of another worker group. - Workers will not be terminated gracefull so be sure to only scale down - when all futures have been retrieved by the client and the cluster is idle. - - Examples - -------- - - >>> cluster - HelmCluster(my-dask.default, 'tcp://localhost:51481', workers=4, threads=241, memory=2.95 TiB) - >>> cluster.scale(4) - >>> cluster - HelmCluster(my-dask.default, 'tcp://localhost:51481', workers=5, threads=321, memory=3.94 TiB) - >>> cluster.scale(5, worker_group="high-mem-workers") - >>> cluster - HelmCluster(my-dask.default, 'tcp://localhost:51481', workers=9, threads=325, memory=3.94 TiB) - """ - return self.sync(self._scale, n_workers, worker_group=worker_group) - - async def _scale(self, n_workers, worker_group=None): - deployment = f"{self.release_name}-{self.chart_name}{self.worker_name}" - if worker_group: - deployment += f"-{worker_group}" - try: - await self.apps_api.patch_namespaced_deployment( - name=deployment, - namespace=self.namespace, - body={ - "spec": { - "replicas": n_workers, - } - }, - ) - except kubernetes.client.exceptions.ApiException as e: - if worker_group: - raise ValueError(f"No such worker group {worker_group}") from e - raise e - - def adapt(self, *args, **kwargs): - """Turn on adaptivity (Not recommended).""" - raise NotImplementedError( - "It is not recommended to run ``HelmCluster`` in adaptive mode. " - "When scaling down workers the decision on which worker to remove is left to Kubernetes, which " - "will not necessarily remove the same worker that Dask would choose. This may result in lost futures and " - "recalculation. It is recommended to manage scaling yourself with the ``HelmCluster.scale`` method." - ) - - async def _adapt(self, *args, **kwargs): - return super().adapt(*args, **kwargs) - - async def _close(self, *args, **kwargs): - """Close the cluster.""" - warnings.warn( - "It is not possible to close a HelmCluster object. \n" - "Please delete the cluster via the helm CLI: \n\n" - f" $ helm delete --namespace {self.namespace} {self.release_name}" - ) - - @classmethod - def from_name(cls, name): - release_name, namespace = name.split(".") - return cls(release_name=release_name, namespace=namespace) - - -async def discover( - auth=ClusterAuth.DEFAULT, - namespace=None, -): - await ClusterAuth.load_first(auth) - async with kubernetes.client.api_client.ApiClient() as api: - core_api = kubernetes.client.CoreV1Api(api) - namespace = namespace or get_current_namespace() - try: - pods = await core_api.list_pod_for_all_namespaces( - label_selector="app=dask,component=scheduler", - ) - for pod in pods.items: - with suppress(KeyError): - yield ( - pod.metadata.labels["release"] + "." + pod.metadata.namespace, - HelmCluster, - ) - except aiohttp.client_exceptions.ClientConnectorError: - warnings.warn("Unable to connect to Kubernetes cluster") diff --git a/dask_kubernetes/helm/tests/resources/values.yaml b/dask_kubernetes/helm/tests/resources/values.yaml deleted file mode 100644 index b742b060e..000000000 --- a/dask_kubernetes/helm/tests/resources/values.yaml +++ /dev/null @@ -1,20 +0,0 @@ -webUI: - servicePort: 8087 - -jupyter: - enabled: false - -scheduler: - serviceType: "ClusterIP" - image: - repository: "dask-kubernetes" # Container image repository. - tag: "dev" # Container image tag. - -worker: - image: - repository: "dask-kubernetes" # Container image repository. - tag: "dev" # Container image tag. - -additional_worker_groups: - - name: foo - replicas: 1 diff --git a/dask_kubernetes/helm/tests/test_helm.py b/dask_kubernetes/helm/tests/test_helm.py deleted file mode 100644 index 0ac9e824a..000000000 --- a/dask_kubernetes/helm/tests/test_helm.py +++ /dev/null @@ -1,241 +0,0 @@ -import os.path -import subprocess - -import dask.config -import pytest -from dask_ctl.discovery import ( - discover_cluster_names, - discover_clusters, - list_discovery_methods, -) -from distributed import Client -from distributed.core import Status - -############### -# Fixtures -## - - -@pytest.fixture(scope="session") -def chart_repo(): - repo_name = "dask" - repo_url = "https://helm.dask.org/" - output = subprocess.run(["helm", "repo", "list"], capture_output=True) - repo_lines = output.stdout.decode().splitlines()[1:] # First line is header - dask_repo_present = False - for repo_line in repo_lines: - repo, url = repo_line.replace(" ", "").split("\t") - if repo == repo_name: - if url.rstrip("/") != repo_url.rstrip("/"): - raise ValueError(f"Dask repo already present with different URL {url}") - dask_repo_present = True - if not dask_repo_present: - subprocess.run( - ["helm", "repo", "add", repo_name, repo_url], - check=True, - ) - subprocess.run(["helm", "repo", "update"], check=True) - return repo_name - - -@pytest.fixture(scope="session") -def chart_name(chart_repo): - chart = "dask" - return f"{chart_repo}/{chart}" - - -@pytest.fixture(scope="session") -def config_path(): - return os.path.join(os.path.dirname(__file__), "resources", "values.yaml") - - -@pytest.fixture(scope="session") -def release_name(): - return "testrelease" - - -@pytest.fixture(scope="session") -def test_namespace(): - return "testdaskns" - - -@pytest.fixture(scope="session") # Creating this fixture is slow so we should reuse it. -def release(k8s_cluster, chart_name, test_namespace, release_name, config_path): - subprocess.run( - [ - "helm", - "install", - "--create-namespace", - "-n", - test_namespace, - release_name, - chart_name, - "--wait", - "-f", - config_path, - ], - check=True, - ) - # Scale back the additional workers group for now - subprocess.run( - [ - "kubectl", - "scale", - "-n", - test_namespace, - "deployment", - f"{release_name}-dask-worker-foo", - "--replicas=0", - ], - check=True, - ) - yield release_name - subprocess.run(["helm", "delete", "-n", test_namespace, release_name], check=True) - - -@pytest.fixture -async def cluster(k8s_cluster, release, test_namespace): - from dask_kubernetes import HelmCluster - - tries = 5 - while True: - try: - cluster = await HelmCluster( - release_name=release, namespace=test_namespace, asynchronous=True - ) - break - except ConnectionError as e: - if tries > 0: - tries -= 1 - else: - raise e - - yield cluster - await cluster.close() - - -@pytest.fixture -def sync_cluster(k8s_cluster, release, test_namespace): - from dask_kubernetes import HelmCluster - - with HelmCluster( - release_name=release, namespace=test_namespace, asynchronous=False - ) as cluster: - yield cluster - - -############### -# Tests -## - - -def test_import(): - from distributed.deploy import Cluster - - from dask_kubernetes import HelmCluster - - assert issubclass(HelmCluster, Cluster) - - -def test_loop(k8s_cluster, release, test_namespace): - from dask_kubernetes import HelmCluster - - with Client(nthreads=[]) as client, HelmCluster( - release_name=release, namespace=test_namespace, loop=client.loop - ) as cluster: - assert cluster.loop is client.loop - - -def test_raises_on_non_existant_release(k8s_cluster): - from dask_kubernetes import HelmCluster - - with pytest.raises(RuntimeError): - HelmCluster(release_name="nosuchrelease", namespace="default") - - -@pytest.mark.anyio -async def test_create_helm_cluster(cluster, release_name): - assert cluster.status == Status.running - assert cluster.release_name == release_name - assert "id" in cluster.scheduler_info - - -def test_create_sync_helm_cluster(sync_cluster, release_name): - cluster = sync_cluster - assert cluster.status == Status.running - assert cluster.release_name == release_name - assert "id" in cluster.scheduler_info - - -@pytest.mark.anyio -async def test_scale_cluster(cluster): - # Scale up - await cluster.scale(4) - await cluster # Wait for workers - assert len(cluster.scheduler_info["workers"]) == 4 - - # Scale down - await cluster.scale(3) - await cluster # Wait for workers - assert len(cluster.scheduler_info["workers"]) == 3 - - # Scale up an additional worker group 'foo' - await cluster.scale(2, worker_group="foo") - await cluster # Wait for workers - assert len(cluster.scheduler_info["workers"]) == 5 - - # Scale down an additional worker group 'foo' - await cluster.scale(0, worker_group="foo") - await cluster # Wait for workers - assert len(cluster.scheduler_info["workers"]) == 3 - - # Scaling a non-existent eorker group 'bar' raises a ValueError - import kubernetes_asyncio as kubernetes - - with pytest.raises((ValueError, kubernetes.client.exceptions.ApiException)): - await cluster.scale(2, worker_group="bar") - - -@pytest.mark.anyio -async def test_logs(cluster): - from distributed.utils import Logs - - logs = await cluster.get_logs() - - assert isinstance(logs, Logs) - assert any(["scheduler" in log for log in logs]) - assert any(["worker" in log for log in logs]) - - [scheduler_logs] = [logs[log] for log in logs if "scheduler" in log] - assert "Scheduler at:" in scheduler_logs - - -@pytest.mark.anyio -async def test_adaptivity_warning(cluster): - with pytest.raises(NotImplementedError): - await cluster.adapt(minimum=3, maximum=3) - - -@pytest.mark.anyio -@pytest.mark.xfail(reason="Has asyncio issues on CI") -async def test_discovery(release, release_name): - discovery = "helmcluster" - methods = list_discovery_methods() - - assert discovery in methods - - methods.pop(discovery) - dask.config.set({"ctl.disable-discovery": methods}) - - clusters_names = [ - cluster async for cluster in discover_cluster_names(discovery=discovery) - ] - assert len(clusters_names) == 1 - - clusters = [cluster async for cluster in discover_clusters(discovery=discovery)] - assert len(clusters) == 1 - - [cluster] = clusters - assert cluster.status == Status.running - assert cluster.release_name == release_name - assert "id" in cluster.scheduler_info diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 07f33cbda..320ea7579 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -15,7 +15,6 @@ from distributed.protocol.pickle import dumps from kr8s.asyncio.objects import Deployment, Pod, Service -from dask_kubernetes.common.objects import validate_cluster_name from dask_kubernetes.constants import SCHEDULER_NAME_TEMPLATE from dask_kubernetes.exceptions import ValidationError from dask_kubernetes.operator._objects import ( @@ -25,6 +24,7 @@ DaskWorkerGroup, ) from dask_kubernetes.operator.networking import get_scheduler_address +from dask_kubernetes.operator.validation import validate_cluster_name _ANNOTATION_NAMESPACES_TO_IGNORE = ( "kopf.zalando.org", diff --git a/dask_kubernetes/operator/kubecluster/kubecluster.py b/dask_kubernetes/operator/kubecluster/kubecluster.py index 5b2b540d0..80aa22249 100644 --- a/dask_kubernetes/operator/kubecluster/kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/kubecluster.py @@ -29,7 +29,6 @@ from rich.table import Table from tornado.ioloop import IOLoop -from dask_kubernetes.common.objects import validate_cluster_name from dask_kubernetes.exceptions import CrashLoopBackOffError, SchedulerStartupError from dask_kubernetes.operator._objects import ( DaskAutoscaler, @@ -41,6 +40,7 @@ wait_for_scheduler, wait_for_scheduler_comm, ) +from dask_kubernetes.operator.validation import validate_cluster_name logger = logging.getLogger(__name__) diff --git a/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py b/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py index 662e711fa..60b8777d6 100644 --- a/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py @@ -7,13 +7,6 @@ from dask_kubernetes.operator import KubeCluster, make_cluster_spec -def test_experimental_shim(): - with pytest.deprecated_call(): - from dask_kubernetes.experimental import KubeCluster as ExperimentalKubeCluster - - assert ExperimentalKubeCluster is KubeCluster - - def test_kubecluster(kopf_runner, docker_image, ns): with kopf_runner: with KubeCluster( @@ -81,11 +74,14 @@ def test_clusters_with_custom_port_forward(kopf_runner, docker_image, ns): def test_multiple_clusters_simultaneously(kopf_runner, docker_image, ns): with kopf_runner: - with KubeCluster( - name="fizz", image=docker_image, n_workers=1, namespace=ns - ) as cluster1, KubeCluster( - name="buzz", image=docker_image, n_workers=1, namespace=ns - ) as cluster2: + with ( + KubeCluster( + name="fizz", image=docker_image, n_workers=1, namespace=ns + ) as cluster1, + KubeCluster( + name="buzz", image=docker_image, n_workers=1, namespace=ns + ) as cluster2, + ): with Client(cluster1) as client1, Client(cluster2) as client2: assert client1.submit(lambda x: x + 1, 10).result() == 11 assert client2.submit(lambda x: x + 1, 10).result() == 11 @@ -93,15 +89,18 @@ def test_multiple_clusters_simultaneously(kopf_runner, docker_image, ns): def test_multiple_clusters_simultaneously_same_loop(kopf_runner, docker_image, ns): with kopf_runner: - with KubeCluster( - name="fizz", image=docker_image, n_workers=1, namespace=ns - ) as cluster1, KubeCluster( - name="buzz", - image=docker_image, - loop=cluster1.loop, - n_workers=1, - namespace=ns, - ) as cluster2: + with ( + KubeCluster( + name="fizz", image=docker_image, n_workers=1, namespace=ns + ) as cluster1, + KubeCluster( + name="buzz", + image=docker_image, + loop=cluster1.loop, + n_workers=1, + namespace=ns, + ) as cluster2, + ): with Client(cluster1) as client1, Client(cluster2) as client2: assert cluster1.loop is cluster2.loop is client1.loop is client2.loop assert client1.submit(lambda x: x + 1, 10).result() == 11 diff --git a/dask_kubernetes/operator/validation.py b/dask_kubernetes/operator/validation.py new file mode 100644 index 000000000..efa5ac06e --- /dev/null +++ b/dask_kubernetes/operator/validation.py @@ -0,0 +1,17 @@ +"""Validate resources""" + +from dask_kubernetes.constants import MAX_CLUSTER_NAME_LEN, VALID_CLUSTER_NAME +from dask_kubernetes.exceptions import ValidationError + + +def validate_cluster_name(cluster_name: str) -> None: + """Raise exception if cluster name is too long and/or has invalid characters""" + if not VALID_CLUSTER_NAME.match(cluster_name): + raise ValidationError( + message=( + f"The DaskCluster {cluster_name} is invalid: a lowercase RFC 1123 subdomain must " + "consist of lower case alphanumeric characters, '-' or '.', and must start " + "and end with an alphanumeric character. DaskCluster name must also be under " + f"{MAX_CLUSTER_NAME_LEN} characters." + ) + ) diff --git a/doc/source/helmcluster.rst b/doc/source/helmcluster.rst deleted file mode 100644 index d44ea1c13..000000000 --- a/doc/source/helmcluster.rst +++ /dev/null @@ -1,69 +0,0 @@ -.. _helmcluster: - -HelmCluster -=========== - -:doc:`helmcluster` is for managing an existing Dask cluster which has been deployed using -`Helm `_. - -Quickstart ----------- - -.. currentmodule:: dask_kubernetes - -First you must install the `Dask Helm chart `_ with ``helm`` -and have the cluster running. - -.. code-block:: bash - - helm repo add dask https://helm.dask.org - helm repo update - - helm install myrelease dask/dask - -You can then create a :class:`HelmCluster` object in Python to manage scaling the cluster and retrieve logs. - -.. code-block:: python - - from dask_kubernetes import HelmCluster - - cluster = HelmCluster(release_name="myrelease") - cluster.scale(10) # specify number of workers explicitly - -With this cluster object you can conveniently connect a Dask :class:`dask.distributed.Client` object to the cluster -and perform your work. Provided you have API access to Kubernetes and can run the ``kubectl`` command then -connectivity to the Dask cluster is handled automatically for you via services or port forwarding. - -.. code-block:: python - - # Example usage - from dask.distributed import Client - import dask.array as da - - # Connect Dask to the cluster - client = Client(cluster) - - # Create a large array and calculate the mean - array = da.ones((1000, 1000, 1000)) - print(array.mean().compute()) # Should print 1.0 - -For more information see the :class:`HelmCluster` API reference. - -.. warning:: - It is not possible to use ``HelmCluster`` from the Jupyter session - which is deployed as part of the Helm Chart without first copying your - ``~/.kube/config`` file to that Jupyter session. - -API ---- - -.. currentmodule:: dask_kubernetes - -.. autosummary:: - HelmCluster - HelmCluster.scale - HelmCluster.adapt - HelmCluster.logs - -.. autoclass:: HelmCluster - :members: diff --git a/doc/source/index.rst b/doc/source/index.rst deleted file mode 100644 index 3de09e815..000000000 --- a/doc/source/index.rst +++ /dev/null @@ -1,105 +0,0 @@ -Dask Kubernetes -=============== - -.. image:: https://img.shields.io/pypi/v/dask-kubernetes - :target: https://pypi.org/project/dask-kubernetes/ - :alt: PyPI - -.. image:: https://img.shields.io/conda/vn/conda-forge/dask-kubernetes - :target: https://anaconda.org/conda-forge/dask-kubernetes - :alt: Conda Forge - -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue - :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions - :alt: Python Support - -.. image:: https://img.shields.io/badge/Kubernetes%20support-1.26%7C1.27%7C1.28%7C1.29-blue - :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions - :alt: Kubernetes Support - - -.. currentmodule:: dask_kubernetes - -Welcome to the documentation for ``dask-kubernetes``. - -.. note:: - - If you are looking for general documentation on deploying - Dask on Kubernetes new users should head to the - `Dask documentation page on Kubernetes `_. - -The package ``dask-kubernetes`` provides cluster managers for Kubernetes. ``dask-kubernetes`` is one of many options for deploying Dask clusters, see `Deploying Dask `_ in the Dask documentation for an overview of additional options. - -KubeCluster ------------ - -:class:`KubeCluster` deploys Dask clusters on Kubernetes clusters using custom -Kubernetes resources. It is designed to dynamically launch ad-hoc deployments. - -.. code-block:: console - - $ # Install operator CRDs and controller, needs to be done once on your Kubernetes cluster - $ helm install --repo https://helm.dask.org --create-namespace -n dask-operator --generate-name dask-kubernetes-operator - -.. code-block:: python - - from dask_kubernetes.operator import KubeCluster - cluster = KubeCluster(name="my-dask-cluster", image='ghcr.io/dask/dask:latest') - cluster.scale(10) - -HelmCluster ------------ - -:class:`HelmCluster` is for managing an existing Dask cluster which has been deployed using -`Helm `_. You must have already installed the `Dask Helm chart `_ -and have the cluster running. You can then use it to manage scaling and retrieve logs. - -.. code-block:: python - - from dask_kubernetes import HelmCluster - - cluster = HelmCluster(release_name="myrelease") - cluster.scale(10) - -.. toctree:: - :maxdepth: 2 - :hidden: - :caption: Overview - - installing - -.. toctree:: - :maxdepth: 2 - :hidden: - :caption: Cluster Managers - - operator_kubecluster - helmcluster - -.. toctree:: - :maxdepth: 2 - :hidden: - :caption: Operator - - operator - operator_installation - operator_resources - operator_extending - operator_troubleshooting - -.. toctree:: - :maxdepth: 2 - :hidden: - :caption: Classic - - kubecluster - kubecluster_migrating - -.. toctree:: - :maxdepth: 2 - :hidden: - :caption: Developer - - testing - releasing - history diff --git a/doc/source/installing.rst b/doc/source/installing.rst deleted file mode 100644 index 790d57bad..000000000 --- a/doc/source/installing.rst +++ /dev/null @@ -1,71 +0,0 @@ -Installing -========== - -.. currentmodule:: dask_kubernetes - -You can install dask-kubernetes with ``pip``, ``conda``, or by installing from source. - -Dependencies ------------- - -To use :class:`KubeCluster` you may need to have ``kubectl`` installed (`official install guide `_). - -To use :class:`HelmCluster` you will need to have ``helm`` installed (`official install guide `_). - -Pip ---- - -Pip can be used to install dask-kubernetes and its Python dependencies:: - - pip install dask-kubernetes --upgrade # Install everything from last released version - -Conda ------ - -To install the latest version of dask-kubernetes from the -`conda-forge `_ repository using -`conda `_:: - - conda install dask-kubernetes -c conda-forge - -Install from Source -------------------- - -To install dask-kubernetes from source, clone the repository from `github -`_:: - - git clone https://github.com/dask/dask-kubernetes.git - cd dask-kubernetes - python setup.py install - -or use ``pip`` locally if you want to install all dependencies as well:: - - pip install -e . - -You can also install directly from git main branch:: - - pip install git+https://github.com/dask/dask-kubernetes - -Supported Versions ------------------- - -Python -^^^^^^ - -All Dask projects generally follow the `NEP 29 `_ deprecation policy for Python where each Python minor version is support ed for 42 months. -Due to Python's 12 month release cycle this ensures at least the current version and two previous versions are supported. - -The Dask Kubernetes CI tests all PRs against all supported Python versions. - -Kubernetes -^^^^^^^^^^ - -For Kubernetes we follow the `yearly support KEP `_. -Due to the 4-6 month release cycle this also ensures that at least the current and two previous versions are supported. - -The Dask Kubernetes CI tests all PRs against all supported Kubernetes versions. - -.. note:: - - To keep the CI matrix smaller we test all Kubernetes versions against the latest Python, and all Python versions against the latest Kubernetes. - We do not test older versions of Python and Kubernetes together. See `dask/dask-kubernetes#559 `_ for more information. diff --git a/doc/source/kubecluster.rst b/doc/source/kubecluster.rst deleted file mode 100644 index 3495c55d9..000000000 --- a/doc/source/kubecluster.rst +++ /dev/null @@ -1,342 +0,0 @@ -.. _kubecluster: - -KubeCluster (classic) -===================== - -.. Warning:: - - This implementation of ``KubeCluster`` is being retired and we recommend :doc:`migrating to the operator based implementation `. - - -:class:`KubeCluster` deploys Dask clusters on Kubernetes clusters using native -Kubernetes APIs. It is designed to dynamically launch ad-hoc deployments. - -Quickstart ----------- - -.. currentmodule:: dask_kubernetes - -To launch a Dask cluster on Kubernetes with :class:`KubeCluster` you need to first configure your worker -pod specification. Then create a cluster with that spec. - -.. code-block:: python - - from dask_kubernetes.classic import KubeCluster, make_pod_spec - - pod_spec = make_pod_spec(image='ghcr.io/dask/dask:latest', - memory_limit='4G', memory_request='4G', - cpu_limit=1, cpu_request=1) - - cluster = KubeCluster(pod_spec) - - cluster.scale(10) # specify number of workers explicitly - cluster.adapt(minimum=1, maximum=100) # or dynamically scale based on current workload - -You can then connect a Dask :class:`dask.distributed.Client` object to the cluster and perform your work. - -.. code-block:: python - - # Example usage - from dask.distributed import Client - import dask.array as da - - # Connect Dask to the cluster - client = Client(cluster) - - # Create a large array and calculate the mean - array = da.ones((1000, 1000, 1000)) - print(array.mean().compute()) # Should print 1.0 - -You can alternatively define your worker specification via YAML by creating a `pod manifest `_ -that will be used as a template. - -.. code-block:: yaml - - # worker-spec.yml - - kind: Pod - metadata: - labels: - foo: bar - spec: - restartPolicy: Never - containers: - - image: ghcr.io/dask/dask:latest - imagePullPolicy: IfNotPresent - args: [dask-worker, --nthreads, '2', --no-dashboard, --memory-limit, 6GB, --death-timeout, '60'] - name: dask-worker - env: - - name: EXTRA_PIP_PACKAGES - value: git+https://github.com/dask/distributed - resources: - limits: - cpu: "2" - memory: 6G - requests: - cpu: "2" - memory: 6G - -.. code-block:: python - - from dask_kubernetes.classic import KubeCluster - - cluster = KubeCluster('worker-spec.yml') - cluster.scale(10) - -For more information see the :class:`KubeCluster` API reference. - -Best Practices --------------- - -1. Your worker pod image should have a similar environment to your local - environment, including versions of Python, dask, cloudpickle, and any - libraries that you may wish to use (like NumPy, Pandas, or Scikit-Learn). - See :py:class:`dask_kubernetes.classic.KubeCluster` docstring for guidance on how - to check and modify this. - -2. Your Kubernetes resource limits and requests should match the - ``--memory-limit`` and ``--nthreads`` parameters given to the - ``dask-worker`` command. Otherwise your workers may get killed by - Kubernetes as they pack into the same node and overwhelm that nodes' - available memory, leading to ``KilledWorker`` errors. - -3. We recommend adding the ``--death-timeout, '60'`` arguments and the - ``restartPolicy: Never`` attribute to your worker specification. - This ensures that these pods will clean themselves up if your Python - process disappears unexpectedly. - -GPUs ----- - -Because ``dask-kubernetes`` uses standard kubernetes pod specifications, we can -use `kubernetes device plugins -`_ -and add resource limits defining the number of GPUs per pod/worker. -Additionally, we can also use tools like `dask-cuda -`_ for optimized Dask/GPU interactions. - -.. code-block:: yaml - - kind: Pod - metadata: - labels: - foo: bar - spec: - restartPolicy: Never - containers: - - image: nvcr.io/nvidia/rapidsai/rapidsai-core:23.04-cuda11.8-runtime-ubuntu22.04-py3.10 - imagePullPolicy: IfNotPresent - args: [dask-cuda-worker, $(DASK_SCHEDULER_ADDRESS), --rmm-pool-size, 10GB] - name: dask-cuda - resources: - limits: - cpu: "2" - memory: 6G - nvidia.com/gpu: 1 # requesting 1 GPU - requests: - cpu: "2" - memory: 6G - nvidia.com/gpu: 1 # requesting 1 GPU - -.. _configuration: -Configuration -------------- - -You can use `Dask's configuration `_ -to control the behavior of Dask-kubernetes. You can see a full set of -configuration options -`here `_. -Some notable ones are described below: - -1. ``kubernetes.worker-template-path``: a path to a YAML file that holds a - Pod spec for the worker. If provided then this will be used when - :py:class:`dask_kubernetes.classic.KubeCluster` is called with no arguments:: - - cluster = KubeCluster() # reads provided yaml file - -2. ``distributed.dashboard.link``: a Python pre-formatted string that shows - the location of Dask's dashboard. This string will receive values for - ``host``, ``port``, and all environment variables. - - For example this is useful when using dask-kubernetes with JupyterHub and - `nbserverproxy `_ to route the - dashboard link to a proxied address as follows:: - - "{JUPYTERHUB_SERVICE_PREFIX}proxy/{port}/status" - -3. ``kubernetes.worker-name``: a Python pre-formatted string to use - when naming dask worker pods. This string will receive values for ``user``, - ``uuid``, and all environment variables. This is useful when you want to have - control over the naming convention for your pods and use other tokens from - the environment. For example when using zero-to-jupyterhub every user is - called ``jovyan`` and so you may wish to use ``dask-{JUPYTERHUB_USER}-{uuid}`` - instead of ``dask-{user}-{uuid}``. **Ensure you keep the ``uuid`` somewhere in - the template.** - -Role-Based Access Control (RBAC) --------------------------------- - -In order to spawn a Dask cluster, the service account creating those pods will require -a set of RBAC permissions. Create a service account you will use for Dask, and then attach the -following Role to that ServiceAccount via a RoleBinding: - -.. code-block:: yaml - - kind: Role - apiVersion: rbac.authorization.k8s.io/v1beta1 - metadata: - name: daskKubernetes - rules: - - apiGroups: - - "" # indicates the core API group - resources: - - "pods" - verbs: - - "get" - - "list" - - "watch" - - "create" - - "delete" - - apiGroups: - - "" # indicates the core API group - resources: - - "pods/log" - verbs: - - "get" - - "list" - - apiGroups: - - "" # indicates the core API group - resources: - - "services" - verbs: - - "get" - - "list" - - "watch" - - "create" - - "delete" - - apiGroups: - - "policy" # indicates the policy API group - resources: - - "poddisruptionbudgets" - verbs: - - "get" - - "list" - - "watch" - - "create" - - "delete" - - -Docker Images -------------- - -Example Dask docker images ghcr.io/dask/dask and ghcr.io/dask/dask-notebook -are available on https://github.com/orgs/dask/packages . -More information about these images is available at the -`Dask documentation `_. - -Note that these images can be further customized with extra packages using -``EXTRA_PIP_PACKAGES``, ``EXTRA_APT_PACKAGES``, and ``EXTRA_CONDA_PACKAGES`` -as described in the -`Extensibility section `_. - -Deployment Details ------------------- - -Scheduler -~~~~~~~~~ - -Before workers are created a scheduler will be deployed with the following resources: - -- A pod with a scheduler running -- A service (svc) to expose scheduler and dashboard ports -- A PodDisruptionBudget avoid voluntary disruptions of the scheduler pod - -By default the Dask configuration option ``kubernetes.scheduler-service-type`` is -set to ``ClusterIp``. In order to connect to the scheduler the ``KubeCluster`` will first attempt to connect directly, -but this will only be successful if ``dask-kubernetes`` is being run from within the Kubernetes cluster. -If it is unsuccessful it will attempt to port forward the service locally using the ``kubectl`` utility. - -If you update the service type to ``NodePort``. The scheduler will be exposed on the same random high port on all -nodes in the cluster. In this case ``KubeCluster`` will attempt to list nodes in order to get an IP to connect on -and requires additional permissions to do so. - -.. code-block:: yaml - - - apiGroups: - - "" # indicates the core API group - resources: - - "nodes" - verbs: - - "get" - - "list" - - -If you set the service type to ``LoadBalancer`` then ``KubeCluster`` will connect to the external address of the assigned -loadbalancer, but this does require that your Kubernetes cluster has the appropriate operator to assign loadbalancers. - -Legacy mode -^^^^^^^^^^^ - -For backward compatibility with previous versions of ``dask-kubernetes`` it is also possible to run the scheduler locally. -A ``local`` scheduler is created where the Dask client will be created. - -.. code-block:: python - - from dask_kubernetes.classic import KubeCluster - from dask.distributed import Client - - cluster = KubeCluster.from_yaml('worker-spec.yml', deploy_mode='local') - cluster.scale(10) - client = Client(cluster) - -In this mode the Dask workers will attempt to connect to the machine where you are running ``dask-kubernetes``. -Generally this will need to be within the Kubernetes cluster in order for the workers to make a successful connection. - -Workers -~~~~~~~ - -Workers are created directly as simple pods. These worker pods are configured -to shutdown if they are unable to connect to the scheduler for 60 seconds. -The pods are cleaned up when :meth:`~dask_kubernetes.classic.KubeCluster.close` is called, -or the scheduler process exits. - -The pods are created with two default `tolerations `_: - -* ``k8s.dask.org/dedicated=worker:NoSchedule`` -* ``k8s.dask.org_dedicated=worker:NoSchedule`` - -If you have nodes with the corresponding taints, then the worker pods will -schedule to those nodes (and no other pods will be able to schedule to those -nodes). - -API ---- - -.. currentmodule:: dask_kubernetes - -.. autosummary:: - KubeCluster - KubeCluster.adapt - KubeCluster.from_dict - KubeCluster.from_yaml - KubeCluster.get_logs - KubeCluster.pods - KubeCluster.scale - InCluster - KubeConfig - KubeAuth - make_pod_spec - -.. autoclass:: KubeCluster - :members: - -.. autoclass:: ClusterAuth - :members: - -.. autoclass:: InCluster - -.. autoclass:: KubeConfig - -.. autoclass:: KubeAuth - -.. autofunction:: make_pod_spec diff --git a/doc/Makefile b/docs/Makefile similarity index 100% rename from doc/Makefile rename to docs/Makefile diff --git a/doc/make.bat b/docs/make.bat similarity index 100% rename from doc/make.bat rename to docs/make.bat diff --git a/doc/requirements-docs.txt b/docs/requirements-docs.txt similarity index 100% rename from doc/requirements-docs.txt rename to docs/requirements-docs.txt diff --git a/doc/source/conf.py b/docs/source/conf.py similarity index 100% rename from doc/source/conf.py rename to docs/source/conf.py diff --git a/doc/source/history.rst b/docs/source/history.rst similarity index 100% rename from doc/source/history.rst rename to docs/source/history.rst diff --git a/doc/source/images/kubeflow-notebooks-configuration-selector.png b/docs/source/images/kubeflow-notebooks-configuration-selector.png similarity index 100% rename from doc/source/images/kubeflow-notebooks-configuration-selector.png rename to docs/source/images/kubeflow-notebooks-configuration-selector.png diff --git a/doc/source/images/operator-install.gif b/docs/source/images/operator-install.gif similarity index 100% rename from doc/source/images/operator-install.gif rename to docs/source/images/operator-install.gif diff --git a/doc/source/images/operator-install.tape b/docs/source/images/operator-install.tape similarity index 98% rename from doc/source/images/operator-install.tape rename to docs/source/images/operator-install.tape index 70b804b76..91b73727b 100644 --- a/doc/source/images/operator-install.tape +++ b/docs/source/images/operator-install.tape @@ -40,7 +40,7 @@ # Hide Hide the subsequent commands from the output # Show Show the subsequent commands in the output -Output doc/source/images/operator-install.gif +Output docs/source/images/operator-install.gif Set FontSize 36 Set Width 2400 diff --git a/doc/source/operator.rst b/docs/source/index.rst similarity index 63% rename from doc/source/operator.rst rename to docs/source/index.rst index bd756ebbd..de90cca24 100644 --- a/doc/source/operator.rst +++ b/docs/source/index.rst @@ -1,11 +1,61 @@ -Overview -======== -.. currentmodule:: dask_kubernetes.operator +Dask Kubernetes Operator +======================== + +.. image:: https://img.shields.io/pypi/v/dask-kubernetes + :target: https://pypi.org/project/dask-kubernetes/ + :alt: PyPI + +.. image:: https://img.shields.io/conda/vn/conda-forge/dask-kubernetes + :target: https://anaconda.org/conda-forge/dask-kubernetes + :alt: Conda Forge + +.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue + :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions + :alt: Python Support + +.. image:: https://img.shields.io/badge/Kubernetes%20support-1.26%7C1.27%7C1.28%7C1.29-blue + :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions + :alt: Kubernetes Support + + +.. currentmodule:: dask_kubernetes + +Welcome to the documentation for the Dask Kubernetes Operator. + +.. note:: + + If you are looking for high-level documentation on deploying + Dask on Kubernetes new users should head to the + `Dask documentation page on Kubernetes `_. + +The package ``dask-kubernetes`` provides a Dask operator for Kubernetes. ``dask-kubernetes`` is one of many options for deploying Dask clusters, see `Deploying Dask `_ in the Dask documentation for an overview of additional options. + +Quickstart +---------- + +:class:`KubeCluster` deploys Dask clusters on Kubernetes clusters using custom +Kubernetes resources. It is designed to dynamically launch ad-hoc deployments. + +.. code-block:: console + + $ # Install operator CRDs and controller, needs to be done once on your Kubernetes cluster + $ helm install --repo https://helm.dask.org --create-namespace -n dask-operator --generate-name dask-kubernetes-operator + +.. code-block:: console + + $ # Install dask-kubernetes + $ pip install dask-kubernetes + +.. code-block:: python + + from dask_kubernetes.operator import KubeCluster + cluster = KubeCluster(name="my-dask-cluster", image='ghcr.io/dask/dask:latest') + cluster.scale(10) What is the operator? --------------------- -The Dask Operator is a small service that runs on your Kubernetes cluster and allows you to create and manage your Dask clusters as Kubernetes resources. +The Dask Operator is a set of custom resources and a controller that runs on your Kubernetes cluster and allows you to create and manage your Dask clusters as Kubernetes resources. Creating clusters can either be done via the :doc:`Kubernetes API with kubectl ` or the :doc:`Python API with KubeCluster `. To :doc:`install the operator ` you need to apply some custom resource definitions that allow us to describe Dask resources and the operator itself which is a small Python application that @@ -101,3 +151,43 @@ Autoscalers ^^^^^^^^^^^ A ``DaskAutoscaler`` resource will communicate with the scheduler periodically and auto scale the default ``DaskWorkerGroup`` to the desired number of workers. + +.. code-block:: python + + from dask_kubernetes.operator import KubeCluster + cluster = KubeCluster(name="my-dask-cluster", image='ghcr.io/dask/dask:latest') + cluster.scale(10) + +.. toctree:: + :maxdepth: 2 + :hidden: + :caption: Getting Syarted + + Overview + installing + +.. toctree:: + :maxdepth: 2 + :hidden: + :caption: Operator + + operator_kubecluster + operator_resources + operator_extending + operator_troubleshooting + +.. toctree:: + :maxdepth: 2 + :hidden: + :caption: Classic + + kubecluster_migrating + +.. toctree:: + :maxdepth: 2 + :hidden: + :caption: Developer + + testing + releasing + history diff --git a/doc/source/operator_installation.rst b/docs/source/installing.rst similarity index 77% rename from doc/source/operator_installation.rst rename to docs/source/installing.rst index 6ef738ff6..804158ffd 100644 --- a/doc/source/operator_installation.rst +++ b/docs/source/installing.rst @@ -1,10 +1,54 @@ Installing -========== +=========== + +.. currentmodule:: dask_kubernetes + +Python package +-------------- + +You can install dask-kubernetes with ``pip``, ``conda``, or by installing from source. + +Pip +^^^ + +Pip can be used to install dask-kubernetes and its Python dependencies:: + + pip install dask-kubernetes --upgrade # Install everything from last released version + +Conda +^^^^^ + +To install the latest version of dask-kubernetes from the +`conda-forge `_ repository using +`conda `_:: + + conda install dask-kubernetes -c conda-forge + +Install from Source +^^^^^^^^^^^^^^^^^^^ + +To install dask-kubernetes from source, clone the repository from `github +`_:: + + git clone https://github.com/dask/dask-kubernetes.git + cd dask-kubernetes + python setup.py install + +or use ``pip`` locally if you want to install all dependencies as well:: + + pip install -e . + +You can also install directly from git main branch:: + + pip install git+https://github.com/dask/dask-kubernetes + +Operator +-------- To use the Dask Operator you must install the custom resource definitions, service account, roles, and the operator controller deployment. Quickstart ----------- +^^^^^^^^^^ .. code-block:: console @@ -14,7 +58,7 @@ Quickstart :align: left Installing with Helm --------------------- +^^^^^^^^^^^^^^^^^^^^ The operator has a Helm chart which can be used to manage the installation of the operator. The chart is published in the `Dask Helm repo `_ repository, and can be installed via: @@ -58,7 +102,7 @@ We can also check the operator pod is running: are made to the CRD templates in future releases (to support future k8s releases, for example) you may have to manually update the CRDs or delete/reinstall the Dask Operator. Single namespace -^^^^^^^^^^^^^^^^ +"""""""""""""""" By default the controller is installed with a ``ClusterRole`` and watches all namespaces. You can also just install it into a single namespace by setting the following options. @@ -75,7 +119,7 @@ You can also just install it into a single namespace by setting the following op Operator has been installed successfully. Prometheus -^^^^^^^^^^ +"""""""""" The operator helm chart also contains some optional `ServiceMonitor` and `PodMonitor` resources to enable Prometheus scraping of Dask components. As not all clusters have the Prometheus operator installed these are disabled by default. You can enable them with the following comfig options. @@ -101,12 +145,12 @@ If you're using the official Dask images you can install this at runtime. cluster = KubeCluster(name="monitored", env={"EXTRA_PIP_PACKAGES": "prometheus_client"}) Chart Configuration Reference -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +""""""""""""""""""""""""""""" .. frigate:: ../../dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator Installing with Manifests -------------------------- +^^^^^^^^^^^^^^^^^^^^^^^^^ If you prefer to install the operator from static manifests with ``kubectl`` and set configuration options with tools like ``kustomize`` you can generate the default manifests with:: @@ -114,12 +158,12 @@ If you prefer to install the operator from static manifests with ``kubectl`` and Kubeflow --------- +^^^^^^^^ In order to use the Dask Operator with `Kubeflow `_ you need to perform some extra installation steps. User permissions -^^^^^^^^^^^^^^^^ +"""""""""""""""" Kubeflow doesn't know anything about our Dask custom resource definitions so we need to update the ``kubeflow-kubernetes-edit`` cluster role. This role allows users with cluster edit permissions to create pods, jobs and other resources and we need to add the Dask custom resources to that list. Edit the @@ -131,7 +175,7 @@ existing ``clusterrole`` and add a new rule to the ``rules`` section for ``kuber clusterrole.rbac.authorization.k8s.io/kubeflow-kubernetes-edit patched Dashboard access -^^^^^^^^^^^^^^^^ +"""""""""""""""" If you are using the Jupyter Notebook service in KubeFlow there are a couple of extra steps you need to do to be able to access the Dask dashboard. The dashboard will be running on the scheduler pod and accessible via the scheduler service, so to access that your Jupyter container will need to @@ -194,3 +238,28 @@ Then when you launch your Jupyter Notebook server be sure to check the ``configu .. figure:: images/kubeflow-notebooks-configuration-selector.png :alt: The KubeFlow Notebook Configuration selector showing the "configure dask dashboard" option checked :align: center + + +Supported Versions +------------------ + +Python +^^^^^^ + +All Dask projects generally follow the `NEP 29 `_ deprecation policy for Python where each Python minor version is support ed for 42 months. +Due to Python's 12 month release cycle this ensures at least the current version and two previous versions are supported. + +The Dask Kubernetes CI tests all PRs against all supported Python versions. + +Kubernetes +^^^^^^^^^^ + +For Kubernetes we follow the `yearly support KEP `_. +Due to the 4-6 month release cycle this also ensures that at least the current and two previous versions are supported. + +The Dask Kubernetes CI tests all PRs against all supported Kubernetes versions. + +.. note:: + + To keep the CI matrix smaller we test all Kubernetes versions against the latest Python, and all Python versions against the latest Kubernetes. + We do not test older versions of Python and Kubernetes together. See `dask/dask-kubernetes#559 `_ for more information. diff --git a/doc/source/kubecluster_migrating.rst b/docs/source/kubecluster_migrating.rst similarity index 85% rename from doc/source/kubecluster_migrating.rst rename to docs/source/kubecluster_migrating.rst index b3cd28371..699865341 100644 --- a/doc/source/kubecluster_migrating.rst +++ b/docs/source/kubecluster_migrating.rst @@ -1,32 +1,7 @@ -Migrating to the operator -========================= +Migrating from classic +====================== -The ``KubeCluster`` class is being replaced with a new version that is built using the Kubernetes Operator pattern. -We encourage all users of the classic implementation to migrate to the new version as it is generally unmaintained and will be removed in a future release. - -Why should you migrate? ------------------------ - -You may be thinking "why do I have to do this?" and "the old version works just fine" so let's take a moment to unpack why we have rebuilt ``KubeCluster`` and to hopefully convince you that this is a good decision and worth the effort. - -The :doc:`original implementation ` of ``KubeCluster`` was created shortly after Kubernetes went ``1.0`` and best practice design patterns were still emerging. -While it has been updated over time it has been more and more difficult to maintain due to the way it was designed. - -We decided to completely rebuild ``dask-kubernetes`` with the `operator pattern in mind `_ which is now an established design pattern for building composable Kubernetes applications. - -Here are some reasons why we decided to make this change: - -- Top level ``DaskCluster`` resource - - Cascade deletion -- Simpler Python API -- More powerful YAML API - - Create, scale and delete clusters with ``kubectl`` -- Detatch and reattactch from running clusters -- New resource types like ``DaskJob`` -- Multiple worker groups -- Autoscaling handled by the controller and not the cluster manager - -For more information watch the Dask blog for the Dask Kubernetes Operator announcement blog post. +The classic ``KubeCluster`` class has been replaced with a new version that is built using the Kubernetes Operator pattern. Installing the operator diff --git a/doc/source/operator_extending.rst b/docs/source/operator_extending.rst similarity index 100% rename from doc/source/operator_extending.rst rename to docs/source/operator_extending.rst diff --git a/doc/source/operator_kubecluster.rst b/docs/source/operator_kubecluster.rst similarity index 94% rename from doc/source/operator_kubecluster.rst rename to docs/source/operator_kubecluster.rst index a15ad517b..e2e801f5a 100644 --- a/doc/source/operator_kubecluster.rst +++ b/docs/source/operator_kubecluster.rst @@ -3,14 +3,10 @@ KubeCluster .. currentmodule:: dask_kubernetes.operator -.. note:: - - As of ``2022.10.0`` the default ``KubeCluster`` class requires the :doc:`Dask Kubernetes Operator `. For documentation on the classic KubeCluster implementation :doc:`see here `. - Cluster manager --------------- -The operator has a new cluster manager called :class:`dask_kubernetes.operator.KubeCluster` that you can use to conveniently create and manage a Dask cluster in Python. Then connect a Dask :class:`distributed.Client` object to it directly and perform your work. +The operator has a cluster manager called :class:`dask_kubernetes.operator.KubeCluster` that you can use to conveniently create and manage a Dask cluster in Python. Then connect a Dask :class:`distributed.Client` object to it directly and perform your work. The goal of the cluster manager is to abstract away the complexity of the Kubernetes resources and provide a clean and simple Python API to manager clusters while still getting all the benefits of the operator. diff --git a/doc/source/operator_resources.rst b/docs/source/operator_resources.rst similarity index 100% rename from doc/source/operator_resources.rst rename to docs/source/operator_resources.rst diff --git a/doc/source/operator_troubleshooting.rst b/docs/source/operator_troubleshooting.rst similarity index 100% rename from doc/source/operator_troubleshooting.rst rename to docs/source/operator_troubleshooting.rst diff --git a/doc/source/releasing.rst b/docs/source/releasing.rst similarity index 100% rename from doc/source/releasing.rst rename to docs/source/releasing.rst diff --git a/doc/source/testing.rst b/docs/source/testing.rst similarity index 100% rename from doc/source/testing.rst rename to docs/source/testing.rst From 77b90433872938003bb42e20133aa6c09c66c185 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 30 Apr 2024 17:06:25 +0100 Subject: [PATCH 32/62] Fix publish permissions (#891) --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 341fc1199..54d58b4c9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,8 @@ on: [push, pull_request] jobs: build-distribution: runs-on: "ubuntu-latest" + permissions: + id-token: write steps: - name: Checkout source From 8836c2bb500096d4301e5f39d53e6186f1c3f62a Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Wed, 1 May 2024 10:52:08 +0100 Subject: [PATCH 33/62] Fix publish permissions for chart (#893) --- .github/workflows/release.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 54d58b4c9..cf1eda567 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,8 +5,7 @@ on: [push, pull_request] jobs: build-distribution: runs-on: "ubuntu-latest" - permissions: - id-token: write + permissions: write-all steps: - name: Checkout source From 3ff79890541a33d9f89d05fab081f795ec82ff8f Mon Sep 17 00:00:00 2001 From: Jonas Dedden Date: Mon, 3 Jun 2024 12:40:27 +0200 Subject: [PATCH 34/62] Introduce typehints in controller (#881) * General code quality improvements for the controller part of this repository. Make sure exported symbols are correctly set in __init__.py with __all__. Renamed pytest fixture for creating a k8s namespace from ns to namespace since ns is a bit overloaded, especially in test_controller.py Introduce typehints in controller.py and test_controller.py to massively improve developer experience (previously, one just really had to guess what functions are for and which types are expected) Removed unused function parameters Made function headers (i.e. parameter [type] defintion) compatible with what `kopf.on.[create/change/...]' expects Introduce mypy (and missing stubs of external packages if available) Introduce mypy ignores for (still) untyped parts of the codebase for now * Introduce mypy section in pyproject.toml, ignore untyped imports and untyped external calls * Black fixes --------- Co-authored-by: Jonas Dedden --- dask_kubernetes/conftest.py | 29 +- dask_kubernetes/operator/__init__.py | 8 + .../operator/controller/controller.py | 344 ++++++++++++------ .../operator/controller/plugins/noop/noop.py | 4 +- .../controller/tests/test_controller.py | 186 +++++++--- .../operator/kubecluster/__init__.py | 8 + .../kubecluster/tests/test_kubecluster.py | 73 ++-- pyproject.toml | 5 + requirements-test.txt | 2 + 9 files changed, 446 insertions(+), 213 deletions(-) diff --git a/dask_kubernetes/conftest.py b/dask_kubernetes/conftest.py index 52a036f59..ce165b9e3 100644 --- a/dask_kubernetes/conftest.py +++ b/dask_kubernetes/conftest.py @@ -6,12 +6,13 @@ import sys import tempfile import uuid +from typing import Final, Iterator import pytest from kopf.testing import KopfRunner from pytest_kind.cluster import KindCluster -DIR = pathlib.Path(__file__).parent.absolute() +DIR: Final[pathlib.Path] = pathlib.Path(__file__).parent.absolute() def check_dependency(dependency): @@ -26,24 +27,24 @@ def check_dependency(dependency): check_dependency("kubectl") check_dependency("docker") -DISABLE_LOGGERS = ["httpcore", "httpx"] +DISABLE_LOGGERS: Final[list[str]] = ["httpcore", "httpx"] -def pytest_configure(): +def pytest_configure() -> None: for logger_name in DISABLE_LOGGERS: logger = logging.getLogger(logger_name) logger.disabled = True @pytest.fixture() -def kopf_runner(k8s_cluster, ns): +def kopf_runner(k8s_cluster: KindCluster, namespace: str) -> KopfRunner: yield KopfRunner( - ["run", "-m", "dask_kubernetes.operator", "--verbose", "--namespace", ns] + ["run", "-m", "dask_kubernetes.operator", "--verbose", "--namespace", namespace] ) @pytest.fixture(scope="session") -def docker_image(): +def docker_image() -> str: image_name = "dask-kubernetes:dev" python_version = f"{sys.version_info.major}.{sys.version_info.minor}" subprocess.run( @@ -62,7 +63,9 @@ def docker_image(): @pytest.fixture(scope="session") -def k8s_cluster(request, docker_image): +def k8s_cluster( + request: pytest.FixtureRequest, docker_image: str +) -> Iterator[KindCluster]: image = None if version := os.environ.get("KUBERNETES_VERSION"): image = f"kindest/node:v{version}" @@ -81,7 +84,7 @@ def k8s_cluster(request, docker_image): @pytest.fixture(scope="session", autouse=True) -def install_istio(k8s_cluster): +def install_istio(k8s_cluster: KindCluster) -> None: if bool(os.environ.get("TEST_ISTIO", False)): check_dependency("istioctl") subprocess.run( @@ -93,7 +96,7 @@ def install_istio(k8s_cluster): @pytest.fixture(autouse=True) -def ns(k8s_cluster): +def namespace(k8s_cluster: KindCluster) -> Iterator[str]: ns = "dask-k8s-pytest-" + uuid.uuid4().hex[:10] k8s_cluster.kubectl("create", "ns", ns) yield ns @@ -101,7 +104,7 @@ def ns(k8s_cluster): @pytest.fixture(scope="session", autouse=True) -def install_gateway(k8s_cluster): +def install_gateway(k8s_cluster: KindCluster) -> Iterator[None]: if bool(os.environ.get("TEST_DASK_GATEWAY", False)): check_dependency("helm") # To ensure the operator can coexist with Gateway @@ -137,11 +140,11 @@ def install_gateway(k8s_cluster): @pytest.fixture(scope="session", autouse=True) -def customresources(k8s_cluster): +def customresources(k8s_cluster: KindCluster) -> Iterator[None]: temp_dir = tempfile.TemporaryDirectory() crd_path = os.path.join(DIR, "operator", "customresources") - def run_generate(crd_path, patch_path, temp_path): + def run_generate(crd_path: str, patch_path: str, temp_path: str) -> None: subprocess.run( ["k8s-crd-resolver", "-r", "-j", patch_path, crd_path, temp_path], check=True, @@ -162,5 +165,5 @@ def run_generate(crd_path, patch_path, temp_path): @pytest.fixture -def anyio_backend(): +def anyio_backend() -> str: return "asyncio" diff --git a/dask_kubernetes/operator/__init__.py b/dask_kubernetes/operator/__init__.py index 4afe88da7..98d418a17 100644 --- a/dask_kubernetes/operator/__init__.py +++ b/dask_kubernetes/operator/__init__.py @@ -5,3 +5,11 @@ make_worker_spec, discover, ) + +__all__ = [ + "KubeCluster", + "make_cluster_spec", + "make_scheduler_spec", + "make_worker_spec", + "discover", +] diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 320ea7579..c34aa0ce7 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -1,9 +1,12 @@ +from __future__ import annotations + import asyncio import copy import time from collections import defaultdict from contextlib import suppress from datetime import datetime +from typing import TYPE_CHECKING, Any, Final from uuid import uuid4 import aiohttp @@ -26,18 +29,23 @@ from dask_kubernetes.operator.networking import get_scheduler_address from dask_kubernetes.operator.validation import validate_cluster_name -_ANNOTATION_NAMESPACES_TO_IGNORE = ( +if TYPE_CHECKING: + from distributed import Scheduler + +_ANNOTATION_NAMESPACES_TO_IGNORE: Final[tuple[str, ...]] = ( "kopf.zalando.org", "kubectl.kubernetes.io", ) -_LABEL_NAMESPACES_TO_IGNORE = () +_LABEL_NAMESPACES_TO_IGNORE: Final[tuple[str, ...]] = () -KUBERNETES_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" +KUBERNETES_DATETIME_FORMAT: Final[str] = "%Y-%m-%dT%H:%M:%SZ" -DASK_AUTOSCALER_COOLDOWN_UNTIL_ANNOTATION = "kubernetes.dask.org/cooldown-until" +DASK_AUTOSCALER_COOLDOWN_UNTIL_ANNOTATION: Final[ + str +] = "kubernetes.dask.org/cooldown-until" # Load operator plugins from other packages -PLUGINS = [] +PLUGINS: list[Any] = [] for ep in pkg_resources.iter_entry_points(group="dask_operator_plugin"): with suppress(AttributeError, ImportError): PLUGINS.append(ep.load()) @@ -47,7 +55,7 @@ class SchedulerCommError(Exception): """Raised when unable to communicate with a scheduler.""" -def _get_annotations(meta): +def _get_annotations(meta: kopf.Meta) -> dict[str, str]: return { annotation_key: annotation_value for annotation_key, annotation_value in meta.annotations.items() @@ -58,7 +66,7 @@ def _get_annotations(meta): } -def _get_labels(meta): +def _get_labels(meta: kopf.Meta) -> dict[str, str]: return { label_key: label_value for label_key, label_value in meta.labels.items() @@ -69,15 +77,16 @@ def _get_labels(meta): def build_scheduler_deployment_spec( - cluster_name, namespace, pod_spec, annotations, labels -): - labels.update( - **{ - "dask.org/cluster-name": cluster_name, - "dask.org/component": "scheduler", - "sidecar.istio.io/inject": "false", - } - ) + cluster_name: str, + pod_spec: kopf.Spec, + annotations: kopf.Annotations, + labels: kopf.Labels, +) -> dict[str, Any]: + labels = dict(labels) | { + "dask.org/cluster-name": cluster_name, + "dask.org/component": "scheduler", + "sidecar.istio.io/inject": "false", + } metadata = { "name": SCHEDULER_NAME_TEMPLATE.format(cluster_name=cluster_name), "labels": labels, @@ -101,13 +110,16 @@ def build_scheduler_deployment_spec( } -def build_scheduler_service_spec(cluster_name, spec, annotations, labels): - labels.update( - **{ - "dask.org/cluster-name": cluster_name, - "dask.org/component": "scheduler", - } - ) +def build_scheduler_service_spec( + cluster_name: str, + spec: kopf.Spec, + annotations: kopf.Annotations, + labels: kopf.Labels, +) -> dict[str, Any]: + labels = dict(labels) | { + "dask.org/cluster-name": cluster_name, + "dask.org/component": "scheduler", + } return { "apiVersion": "v1", "kind": "Service", @@ -121,37 +133,40 @@ def build_scheduler_service_spec(cluster_name, spec, annotations, labels): def build_worker_deployment_spec( - worker_group_name, namespace, cluster_name, uuid, pod_spec, annotations, labels -): - labels.update( - **{ - "dask.org/cluster-name": cluster_name, - "dask.org/workergroup-name": worker_group_name, - "dask.org/component": "worker", - "sidecar.istio.io/inject": "false", - } - ) + worker_group_name: str, + namespace: str, + cluster_name: str, + uuid: str, + pod_spec: kopf.Spec, + annotations: kopf.Annotations, + labels: kopf.Labels, +) -> dict[str, Any]: + labels = dict(labels) | { + "dask.org/cluster-name": cluster_name, + "dask.org/workergroup-name": worker_group_name, + "dask.org/component": "worker", + "sidecar.istio.io/inject": "false", + } worker_name = f"{worker_group_name}-worker-{uuid}" metadata = { "name": worker_name, "labels": labels, "annotations": annotations, } - spec = { - "replicas": 1, - "selector": { - "matchLabels": labels, - }, - "template": { - "metadata": metadata, - "spec": copy.deepcopy(pod_spec), - }, - } - deployment_spec = { + deployment_spec: dict[str, Any] = { "apiVersion": "apps/v1", "kind": "Deployment", "metadata": metadata, - "spec": spec, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": labels, + }, + "template": { + "metadata": metadata, + "spec": copy.deepcopy(pod_spec), + }, + }, } worker_env = { "name": "DASK_WORKER_NAME", @@ -175,19 +190,24 @@ def build_worker_deployment_spec( return deployment_spec -def get_job_runner_pod_name(job_name): +def get_job_runner_pod_name(job_name: str) -> str: return f"{job_name}-runner" -def build_job_pod_spec(job_name, cluster_name, namespace, spec, annotations, labels): - labels.update( - **{ - "dask.org/cluster-name": cluster_name, - "dask.org/component": "job-runner", - "sidecar.istio.io/inject": "false", - } - ) - pod_spec = { +def build_job_pod_spec( + job_name: str, + cluster_name: str, + namespace: str, + spec: kopf.Spec, + annotations: kopf.Annotations, + labels: kopf.Labels, +) -> dict[str, Any]: + labels = dict(labels) | { + "dask.org/cluster-name": cluster_name, + "dask.org/component": "job-runner", + "sidecar.istio.io/inject": "false", + } + pod_spec: dict[str, Any] = { "apiVersion": "v1", "kind": "Pod", "metadata": { @@ -213,19 +233,22 @@ def build_job_pod_spec(job_name, cluster_name, namespace, spec, annotations, lab return pod_spec -def build_default_worker_group_spec(cluster_name, spec, annotations, labels): - labels.update( - **{ - "dask.org/cluster-name": cluster_name, - "dask.org/component": "workergroup", - } - ) +def build_default_worker_group_spec( + cluster_name: str, + spec: kopf.Spec, + annotations: kopf.Annotations, + labels: kopf.Labels, +) -> dict[str, Any]: return { "apiVersion": "kubernetes.dask.org/v1", "kind": "DaskWorkerGroup", "metadata": { "name": f"{cluster_name}-default", - "labels": labels, + "labels": dict(labels) + | { + "dask.org/cluster-name": cluster_name, + "dask.org/component": "workergroup", + }, "annotations": annotations, }, "spec": { @@ -235,18 +258,22 @@ def build_default_worker_group_spec(cluster_name, spec, annotations, labels): } -def build_cluster_spec(name, worker_spec, scheduler_spec, annotations, labels): - labels.update( - **{ - "dask.org/cluster-name": name, - } - ) +def build_cluster_spec( + name: str, + worker_spec: kopf.Spec, + scheduler_spec: kopf.Spec, + annotations: kopf.Annotations, + labels: kopf.Labels, +) -> dict[str, Any]: return { "apiVersion": "kubernetes.dask.org/v1", "kind": "DaskCluster", "metadata": { "name": name, - "labels": labels, + "labels": dict(labels) + | { + "dask.org/cluster-name": name, + }, "annotations": annotations, }, "spec": {"worker": worker_spec, "scheduler": scheduler_spec}, @@ -254,7 +281,7 @@ def build_cluster_spec(name, worker_spec, scheduler_spec, annotations, labels): @kopf.on.startup() -async def startup(settings: kopf.OperatorSettings, **kwargs): +async def startup(settings: kopf.OperatorSettings, **__: Any) -> None: # Set server and client timeouts to reconnect from time to time. # In rare occasions the connection might go idle we will no longer receive any events. # These timeouts should help in those cases. @@ -272,16 +299,24 @@ async def startup(settings: kopf.OperatorSettings, **kwargs): # There may be useful things for us to expose via the liveness probe # https://kopf.readthedocs.io/en/stable/probing/#probe-handlers @kopf.on.probe(id="now") -def get_current_timestamp(**kwargs): +def get_current_timestamp(**__: Any) -> str: return datetime.utcnow().isoformat() @kopf.on.create("daskcluster.kubernetes.dask.org") -async def daskcluster_create(name, namespace, logger, patch, **kwargs): +async def daskcluster_create( + name: str | None, + namespace: str | None, + patch: kopf.Patch, + logger: kopf.Logger, + **__: Any, +) -> None: """When DaskCluster resource is created set the status.phase. This allows us to track that the operator is running. """ + assert name + assert namespace logger.info(f"DaskCluster {name} created in {namespace}.") try: validate_cluster_name(name) @@ -294,9 +329,17 @@ async def daskcluster_create(name, namespace, logger, patch, **kwargs): @kopf.on.field("daskcluster.kubernetes.dask.org", field="status.phase", new="Created") async def daskcluster_create_components( - spec, name, namespace, logger, patch, meta, **kwargs -): + spec: kopf.Spec, + name: str | None, + namespace: str | None, + logger: kopf.Logger, + patch: kopf.Patch, + meta: kopf.Meta, + **__: Any, +) -> None: """When the DaskCluster status.phase goes into Created create the cluster components.""" + assert name + assert namespace logger.info("Creating Dask cluster components.") # Create scheduler deployment @@ -309,7 +352,7 @@ async def daskcluster_create_components( if "labels" in scheduler_spec["metadata"]: labels.update(**scheduler_spec["metadata"]["labels"]) data = build_scheduler_deployment_spec( - name, namespace, scheduler_spec.get("spec"), annotations, labels + name, scheduler_spec.get("spec"), annotations, labels ) kopf.adopt(data) scheduler_deployment = await Deployment(data, namespace=namespace) @@ -349,8 +392,13 @@ async def daskcluster_create_components( @kopf.on.field("service", field="status", labels={"dask.org/component": "scheduler"}) async def handle_scheduler_service_status( - spec, labels, status, namespace, logger, **kwargs -): + spec: kopf.Spec, + labels: kopf.Labels, + status: kopf.Status, + namespace: str | None, + **__: Any, +) -> None: + assert namespace # If the Service is a LoadBalancer with no ingress endpoints mark the cluster as Pending if spec["type"] == "LoadBalancer" and not len( status.get("load_balancer", {}).get("ingress", []) @@ -366,14 +414,17 @@ async def handle_scheduler_service_status( @kopf.on.create("daskworkergroup.kubernetes.dask.org") -async def daskworkergroup_create(body, namespace, logger, **kwargs): +async def daskworkergroup_create( + body: kopf.Body, namespace: str | None, logger: kopf.Logger, **kwargs: Any +) -> None: + assert namespace wg = await DaskWorkerGroup(body, namespace=namespace) cluster = await wg.cluster() await cluster.adopt(wg) logger.info(f"Successfully adopted by {cluster.name}") del kwargs["new"] - await daskworkergroup_replica_update( + await daskworkergroup_replica_update( # type: ignore[misc] body=body, logger=logger, new=wg.replicas, @@ -383,8 +434,13 @@ async def daskworkergroup_create(body, namespace, logger, **kwargs): async def retire_workers( - n_workers, scheduler_service_name, worker_group_name, namespace, logger -): + n_workers: int, + scheduler_service_name: str, + worker_group_name: str, + namespace: str | None, + logger: kopf.Logger, +) -> list[str]: + assert namespace # Try gracefully retiring via the HTTP API dashboard_address = await get_scheduler_address( scheduler_service_name, @@ -423,6 +479,7 @@ async def retire_workers( attribute="name", ) await scheduler_comm.retire_workers(names=workers_to_close) + assert isinstance(workers_to_close, list) return workers_to_close # Finally fall back to last-in-first-out scaling @@ -438,7 +495,10 @@ async def retire_workers( return [w.name for w in workers[:-n_workers]] -async def check_scheduler_idle(scheduler_service_name, namespace, logger): +async def check_scheduler_idle( + scheduler_service_name: str, namespace: str | None, logger: kopf.Logger +) -> float: + assert namespace # Try getting idle time via HTTP API dashboard_address = await get_scheduler_address( scheduler_service_name, @@ -453,7 +513,7 @@ async def check_scheduler_idle(scheduler_service_name, namespace, logger): idle_since = (await resp.json())["idle_since"] if idle_since: logger.debug("Scheduler idle since: %s", idle_since) - return idle_since + return float(idle_since) logger.debug( "Received %d response from scheduler API with body %s", resp.status, @@ -475,17 +535,18 @@ async def check_scheduler_idle(scheduler_service_name, namespace, logger): idle_since = await scheduler_comm.check_idle() if idle_since: logger.debug("Scheduler idle since: %s", idle_since) - return idle_since + return float(idle_since) # Finally fall back to code injection via the Dask RPC for distributed<=2023.3.1 logger.debug( f"Checking {scheduler_service_name} idleness failed via the Dask RPC, falling back to run_on_scheduler" ) - def idle_since(dask_scheduler=None): + def idle_since_func(dask_scheduler: Scheduler) -> float: if not dask_scheduler.idle_timeout: dask_scheduler.idle_timeout = 300 dask_scheduler.check_idle() + assert dask_scheduler.idle_since return dask_scheduler.idle_since comm_address = await get_scheduler_address( @@ -495,19 +556,23 @@ def idle_since(dask_scheduler=None): ) async with rpc(comm_address) as scheduler_comm: response = await scheduler_comm.run_function( - function=dumps(idle_since), + function=dumps(idle_since_func), ) if response["status"] == "error": typ, exc, tb = clean_exception(**response) + assert exc raise exc.with_traceback(tb) else: idle_since = response["result"] if idle_since: logger.debug("Scheduler idle since: %s", idle_since) - return idle_since + return float(idle_since) -async def get_desired_workers(scheduler_service_name, namespace, logger): +async def get_desired_workers( + scheduler_service_name: str, namespace: str | None +) -> Any: + assert namespace # Try gracefully retiring via the HTTP API dashboard_address = await get_scheduler_address( scheduler_service_name, @@ -538,22 +603,38 @@ async def get_desired_workers(scheduler_service_name, namespace, logger): ) from e -worker_group_scale_locks = defaultdict(lambda: asyncio.Lock()) +worker_group_scale_locks: dict[str, asyncio.Lock] = defaultdict(lambda: asyncio.Lock()) @kopf.on.field("daskcluster.kubernetes.dask.org", field="spec.worker.replicas") async def daskcluster_default_worker_group_replica_update( - name, namespace, old, new, **kwargs -): + name: str | None, + namespace: str | None, + old: Any | None, + new: Any | None, + **__: Any, +) -> None: + assert name + assert namespace if old is not None: wg = await DaskWorkerGroup.get(f"{name}-default", namespace=namespace) + assert isinstance(new, int) await wg.scale(new) @kopf.on.field("daskworkergroup.kubernetes.dask.org", field="spec.worker.replicas") async def daskworkergroup_replica_update( - name, namespace, meta, spec, new, body, logger, **kwargs -): + name: str | None, + namespace: str | None, + meta: kopf.Meta, + spec: kopf.Spec, + new: Any | None, + body: kopf.Body, + logger: kopf.Logger, + **__: Any, +) -> None: + assert name + assert namespace cluster_name = spec["cluster"] wg = await DaskWorkerGroup(body, namespace=namespace) try: @@ -572,6 +653,7 @@ async def daskworkergroup_replica_update( label_selector={"dask.org/workergroup-name": name}, ) ) + assert isinstance(new, int) desired_workers = new workers_needed = desired_workers - current_workers labels = _get_labels(meta) @@ -632,14 +714,26 @@ async def daskworkergroup_replica_update( @kopf.on.delete("daskworkergroup.kubernetes.dask.org", optional=True) -async def daskworkergroup_remove(name, namespace, **kwargs): +async def daskworkergroup_remove( + name: str | None, namespace: str | None, **__: Any +) -> None: + assert name + assert namespace lock_key = f"{name}/{namespace}" if lock_key in worker_group_scale_locks: del worker_group_scale_locks[lock_key] @kopf.on.create("daskjob.kubernetes.dask.org") -async def daskjob_create(name, namespace, logger, patch, **kwargs): +async def daskjob_create( + name: str | None, + namespace: str | None, + logger: kopf.Logger, + patch: kopf.Patch, + **__: Any, +) -> None: + assert name + assert namespace logger.info(f"A DaskJob has been created called {name} in {namespace}.") patch.status["jobStatus"] = "JobCreated" @@ -648,8 +742,16 @@ async def daskjob_create(name, namespace, logger, patch, **kwargs): "daskjob.kubernetes.dask.org", field="status.jobStatus", new="JobCreated" ) async def daskjob_create_components( - spec, name, namespace, logger, patch, meta, **kwargs -): + spec: kopf.Spec, + name: str | None, + namespace: str | None, + logger: kopf.Logger, + patch: kopf.Patch, + meta: kopf.Meta, + **__: Any, +) -> None: + assert name + assert namespace logger.info("Creating Dask job components.") cluster_name = f"{name}" labels = _get_labels(meta) @@ -704,7 +806,10 @@ async def daskjob_create_components( labels={"dask.org/component": "job-runner"}, new="Running", ) -async def handle_runner_status_change_running(meta, namespace, logger, **kwargs): +async def handle_runner_status_change_running( + meta: kopf.Meta, namespace: str | None, logger: kopf.Logger, **__: Any +) -> None: + assert namespace logger.info("Job now in running") name = meta["labels"]["dask.org/cluster-name"] job = await DaskJob.get(name, namespace=namespace) @@ -725,7 +830,10 @@ async def handle_runner_status_change_running(meta, namespace, logger, **kwargs) labels={"dask.org/component": "job-runner"}, new="Succeeded", ) -async def handle_runner_status_change_succeeded(meta, namespace, logger, **kwargs): +async def handle_runner_status_change_succeeded( + meta: kopf.Meta, namespace: str | None, logger: kopf.Logger, **__: Any +) -> None: + assert namespace logger.info("Job succeeded, deleting Dask cluster.") name = meta["labels"]["dask.org/cluster-name"] cluster = await DaskCluster.get(name, namespace=namespace) @@ -748,7 +856,10 @@ async def handle_runner_status_change_succeeded(meta, namespace, logger, **kwarg labels={"dask.org/component": "job-runner"}, new="Failed", ) -async def handle_runner_status_change_succeeded(meta, namespace, logger, **kwargs): +async def handle_runner_status_change_failed( + meta: kopf.Meta, namespace: str | None, logger: kopf.Logger, **__: Any +) -> None: + assert namespace logger.info("Job failed, deleting Dask cluster.") name = meta["labels"]["dask.org/cluster-name"] cluster = await DaskCluster.get(name, namespace=namespace) @@ -766,7 +877,9 @@ async def handle_runner_status_change_succeeded(meta, namespace, logger, **kwarg @kopf.on.create("daskautoscaler.kubernetes.dask.org") -async def daskautoscaler_create(body, logger, **_): +async def daskautoscaler_create( + body: kopf.Body, logger: kopf.Logger, **__: Any +) -> None: """When an autoscaler is created make it a child of the associated cluster for cascade deletion.""" autoscaler = await DaskAutoscaler(body) cluster = await autoscaler.cluster() @@ -775,7 +888,15 @@ async def daskautoscaler_create(body, logger, **_): @kopf.timer("daskautoscaler.kubernetes.dask.org", interval=5.0) -async def daskautoscaler_adapt(spec, name, namespace, logger, **kwargs): +async def daskautoscaler_adapt( + spec: kopf.Spec, + name: str | None, + namespace: str | None, + logger: kopf.Logger, + **__: Any, +) -> None: + assert name + assert namespace try: scheduler = await Pod.get( label_selector={ @@ -785,7 +906,7 @@ async def daskautoscaler_adapt(spec, name, namespace, logger, **kwargs): namespace=namespace, ) if not await scheduler.ready(): - raise ValueError() + raise ValueError except ValueError: logger.info("Scheduler not ready, skipping autoscaling") return @@ -812,7 +933,6 @@ async def daskautoscaler_adapt(spec, name, namespace, logger, **kwargs): desired_workers = await get_desired_workers( scheduler_service_name=f"{spec['cluster']}-scheduler", namespace=namespace, - logger=logger, ) except SchedulerCommError: logger.error("Unable to get desired number of workers from scheduler.") @@ -850,7 +970,13 @@ async def daskautoscaler_adapt(spec, name, namespace, logger, **kwargs): @kopf.timer("daskcluster.kubernetes.dask.org", interval=5.0) -async def daskcluster_autoshutdown(spec, name, namespace, logger, **kwargs): +async def daskcluster_autoshutdown( + spec: kopf.Spec, + name: str | None, + namespace: str | None, + logger: kopf.Logger, + **__: Any, +) -> None: idle_timeout = spec.get("idleTimeout", 0) if idle_timeout: try: @@ -859,8 +985,10 @@ async def daskcluster_autoshutdown(spec, name, namespace, logger, **kwargs): namespace=namespace, logger=logger, ) - except Exception: - logger.warn("Unable to connect to scheduler, skipping autoshutdown check.") + except Exception: # TODO: Not use broad "Exception" catch here + logger.warning( + "Unable to connect to scheduler, skipping autoshutdown check." + ) return if idle_since and time.time() > idle_since + idle_timeout: cluster = await DaskCluster.get(name, namespace=namespace) diff --git a/dask_kubernetes/operator/controller/plugins/noop/noop.py b/dask_kubernetes/operator/controller/plugins/noop/noop.py index fa3cef7cf..3c2b254f9 100644 --- a/dask_kubernetes/operator/controller/plugins/noop/noop.py +++ b/dask_kubernetes/operator/controller/plugins/noop/noop.py @@ -1,8 +1,10 @@ +from typing import Any + import kopf @kopf.on.startup() -async def noop_startup(logger, **kwargs): +async def noop_startup(logger: kopf.Logger, **__: Any) -> None: logger.info( "Plugin 'noop' running. This does nothing. " "See https://kubernetes.dask.org/en/latest/operator_extending.html " diff --git a/dask_kubernetes/operator/controller/tests/test_controller.py b/dask_kubernetes/operator/controller/tests/test_controller.py index 33abf9c4f..f8b5822ad 100644 --- a/dask_kubernetes/operator/controller/tests/test_controller.py +++ b/dask_kubernetes/operator/controller/tests/test_controller.py @@ -1,9 +1,20 @@ +from __future__ import annotations + import asyncio import json import os.path import pathlib from contextlib import asynccontextmanager from datetime import datetime, timedelta +from typing import ( + TYPE_CHECKING, + Any, + AsyncContextManager, + AsyncIterator, + Callable, + Final, + Iterator, +) import dask.config import pytest @@ -18,16 +29,20 @@ get_job_runner_pod_name, ) -DIR = pathlib.Path(__file__).parent.absolute() +if TYPE_CHECKING: + from kopf.testing import KopfRunner + from pytest_kind.cluster import KindCluster -_EXPECTED_ANNOTATIONS = {"test-annotation": "annotation-value"} -_EXPECTED_LABELS = {"test-label": "label-value"} -DEFAULT_CLUSTER_NAME = "simple" +DIR: Final[pathlib.Path] = pathlib.Path(__file__).parent.absolute() + +_EXPECTED_ANNOTATIONS: Final[dict[str, str]] = {"test-annotation": "annotation-value"} +_EXPECTED_LABELS: Final[dict[str, str]] = {"test-label": "label-value"} +DEFAULT_CLUSTER_NAME: Final[str] = "simple" @pytest.fixture() -def gen_cluster_manifest(tmp_path): - def factory(cluster_name=DEFAULT_CLUSTER_NAME): +def gen_cluster_manifest(tmp_path: pathlib.Path) -> Callable[..., pathlib.Path]: + def factory(cluster_name: str = DEFAULT_CLUSTER_NAME) -> pathlib.Path: original_manifest_path = os.path.join(DIR, "resources", "simplecluster.yaml") with open(original_manifest_path, "r") as original_manifest_file: manifest = yaml.safe_load(original_manifest_file) @@ -41,52 +56,60 @@ def factory(cluster_name=DEFAULT_CLUSTER_NAME): @pytest.fixture() -def gen_cluster(k8s_cluster, ns, gen_cluster_manifest): +def gen_cluster( + k8s_cluster: KindCluster, + namespace: str, + gen_cluster_manifest: Callable[..., pathlib.Path], +) -> Iterator[Callable[..., AsyncContextManager[tuple[str, str]]]]: """Yields an instantiated context manager for creating/deleting a simple cluster.""" @asynccontextmanager - async def cm(cluster_name=DEFAULT_CLUSTER_NAME): + async def cm( + cluster_name: str = DEFAULT_CLUSTER_NAME, + ) -> AsyncIterator[tuple[str, str]]: cluster_path = gen_cluster_manifest(cluster_name) # Create cluster resource - k8s_cluster.kubectl("apply", "-n", ns, "-f", cluster_path) + k8s_cluster.kubectl("apply", "-n", namespace, "-f", str(cluster_path)) while cluster_name not in k8s_cluster.kubectl( - "get", "daskclusters.kubernetes.dask.org", "-n", ns + "get", "daskclusters.kubernetes.dask.org", "-n", namespace ): await asyncio.sleep(0.1) try: - yield cluster_name, ns + yield cluster_name, namespace finally: # Test: remove the wait=True, because I think this is blocking the operator - k8s_cluster.kubectl("delete", "-n", ns, "-f", cluster_path) + k8s_cluster.kubectl("delete", "-n", namespace, "-f", str(cluster_path)) yield cm @pytest.fixture() -def gen_job(k8s_cluster, ns): +def gen_job( + k8s_cluster: KindCluster, namespace: str +) -> Iterator[Callable[[str], AsyncContextManager[tuple[str, str]]]]: """Yields an instantiated context manager for creating/deleting a simple job.""" @asynccontextmanager - async def cm(job_file): + async def cm(job_file: str) -> AsyncIterator[tuple[str, str]]: job_path = os.path.join(DIR, "resources", job_file) with open(job_path) as f: job_name = yaml.load(f, yaml.Loader)["metadata"]["name"] # Create cluster resource - k8s_cluster.kubectl("apply", "-n", ns, "-f", job_path) + k8s_cluster.kubectl("apply", "-n", namespace, "-f", job_path) while job_name not in k8s_cluster.kubectl( - "get", "daskjobs.kubernetes.dask.org", "-n", ns + "get", "daskjobs.kubernetes.dask.org", "-n", namespace ): await asyncio.sleep(0.1) try: - yield job_name, ns + yield job_name, namespace finally: # Test: remove the wait=True, because I think this is blocking the operator - k8s_cluster.kubectl("delete", "-n", ns, "-f", job_path) + k8s_cluster.kubectl("delete", "-n", namespace, "-f", job_path) while job_name in k8s_cluster.kubectl( - "get", "daskjobs.kubernetes.dask.org", "-n", ns + "get", "daskjobs.kubernetes.dask.org", "-n", namespace ): await asyncio.sleep(0.1) @@ -94,42 +117,44 @@ async def cm(job_file): @pytest.fixture() -def gen_worker_group(k8s_cluster, ns): +def gen_worker_group( + k8s_cluster: KindCluster, namespace: str +) -> Iterator[Callable[[str], AsyncContextManager[tuple[str, str]]]]: """Yields an instantiated context manager for creating/deleting a worker group.""" @asynccontextmanager - async def cm(worker_group_file): + async def cm(worker_group_file: str) -> AsyncIterator[tuple[str, str]]: worker_group_path = os.path.join(DIR, "resources", worker_group_file) with open(worker_group_path) as f: worker_group_name = yaml.load(f, yaml.Loader)["metadata"]["name"] # Create cluster resource - k8s_cluster.kubectl("apply", "-n", ns, "-f", worker_group_path) + k8s_cluster.kubectl("apply", "-n", namespace, "-f", worker_group_path) while worker_group_name not in k8s_cluster.kubectl( - "get", "daskworkergroups.kubernetes.dask.org", "-n", ns + "get", "daskworkergroups.kubernetes.dask.org", "-n", namespace ): await asyncio.sleep(0.1) try: - yield worker_group_name, ns + yield worker_group_name, namespace finally: # Test: remove the wait=True, because I think this is blocking the operator - k8s_cluster.kubectl("delete", "-n", ns, "-f", worker_group_path) + k8s_cluster.kubectl("delete", "-n", namespace, "-f", worker_group_path) while worker_group_name in k8s_cluster.kubectl( - "get", "daskworkergroups.kubernetes.dask.org", "-n", ns + "get", "daskworkergroups.kubernetes.dask.org", "-n", namespace ): await asyncio.sleep(0.1) yield cm -def test_customresources(k8s_cluster): +def test_customresources(k8s_cluster: KindCluster) -> None: assert "daskclusters.kubernetes.dask.org" in k8s_cluster.kubectl("get", "crd") assert "daskworkergroups.kubernetes.dask.org" in k8s_cluster.kubectl("get", "crd") assert "daskjobs.kubernetes.dask.org" in k8s_cluster.kubectl("get", "crd") -def test_operator_runs(kopf_runner): +def test_operator_runs(kopf_runner: KopfRunner) -> None: with kopf_runner as runner: pass @@ -137,7 +162,7 @@ def test_operator_runs(kopf_runner): assert runner.exception is None -def test_operator_plugins(kopf_runner): +def test_operator_plugins(kopf_runner: KopfRunner) -> None: with kopf_runner as runner: pass @@ -148,7 +173,11 @@ def test_operator_plugins(kopf_runner): @pytest.mark.timeout(180) @pytest.mark.anyio -async def test_simplecluster(k8s_cluster, kopf_runner, gen_cluster): +async def test_simplecluster( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster() as (cluster_name, ns): scheduler_deployment_name = "simple-scheduler" @@ -292,7 +321,11 @@ async def test_simplecluster(k8s_cluster, kopf_runner, gen_cluster): @pytest.mark.anyio -async def test_scalesimplecluster(k8s_cluster, kopf_runner, gen_cluster): +async def test_scalesimplecluster( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster() as (cluster_name, ns): scheduler_deployment_name = "simple-scheduler" @@ -338,8 +371,10 @@ async def test_scalesimplecluster(k8s_cluster, kopf_runner, gen_cluster): @pytest.mark.anyio async def test_scalesimplecluster_from_cluster_spec( - k8s_cluster, kopf_runner, gen_cluster -): + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster() as (cluster_name, ns): scheduler_deployment_name = "simple-scheduler" @@ -384,7 +419,11 @@ async def test_scalesimplecluster_from_cluster_spec( @pytest.mark.anyio -async def test_recreate_scheduler_pod(k8s_cluster, kopf_runner, gen_cluster): +async def test_recreate_scheduler_pod( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster() as (cluster_name, ns): scheduler_deployment_name = "simple-scheduler" @@ -423,7 +462,11 @@ async def test_recreate_scheduler_pod(k8s_cluster, kopf_runner, gen_cluster): @pytest.mark.anyio @pytest.mark.skip(reason="Flaky in CI") -async def test_recreate_worker_pods(k8s_cluster, kopf_runner, gen_cluster): +async def test_recreate_worker_pods( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster() as (cluster_name, ns): cluster = await DaskCluster.get(cluster_name, namespace=ns) @@ -453,8 +496,10 @@ async def test_recreate_worker_pods(k8s_cluster, kopf_runner, gen_cluster): @pytest.mark.anyio async def test_simplecluster_batched_worker_deployments( - k8s_cluster, kopf_runner, gen_cluster -): + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: with dask.config.set( { @@ -489,8 +534,8 @@ async def test_simplecluster_batched_worker_deployments( assert (await total) == sum(map(lambda x: x + 1, range(10))) -def _get_job_status(k8s_cluster, ns): - return json.loads( +def _get_job_status(k8s_cluster: KindCluster, ns: str) -> dict[str, Any]: + return json.loads( # type: ignore[no-any-return] k8s_cluster.kubectl( "get", "-n", @@ -502,17 +547,17 @@ def _get_job_status(k8s_cluster, ns): ) -def _assert_job_status_created(job_status): +def _assert_job_status_created(job_status: dict[str, Any]) -> None: assert "jobStatus" in job_status -def _assert_job_status_cluster_created(job, job_status): +def _assert_job_status_cluster_created(job: str, job_status: dict[str, Any]) -> None: assert "jobStatus" in job_status assert job_status["clusterName"] == job assert job_status["jobRunnerPodName"] == get_job_runner_pod_name(job) -def _assert_job_status_running(job, job_status): +def _assert_job_status_running(job: str, job_status: dict[str, Any]) -> None: assert "jobStatus" in job_status assert job_status["clusterName"] == job assert job_status["jobRunnerPodName"] == get_job_runner_pod_name(job) @@ -520,7 +565,9 @@ def _assert_job_status_running(job, job_status): assert datetime.utcnow() > start_time > (datetime.utcnow() - timedelta(seconds=10)) -def _assert_final_job_status(job, job_status, expected_status): +def _assert_final_job_status( + job: str, job_status: dict[str, Any], expected_status: str +) -> None: assert job_status["jobStatus"] == expected_status assert job_status["clusterName"] == job assert job_status["jobRunnerPodName"] == get_job_runner_pod_name(job) @@ -538,7 +585,11 @@ def _assert_final_job_status(job, job_status, expected_status): @pytest.mark.anyio -async def test_job(k8s_cluster, kopf_runner, gen_job): +async def test_job( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_job: Callable[[str], AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner as runner: async with gen_job("simplejob.yaml") as (job, ns): assert job @@ -609,7 +660,11 @@ async def test_job(k8s_cluster, kopf_runner, gen_job): @pytest.mark.anyio -async def test_failed_job(k8s_cluster, kopf_runner, gen_job): +async def test_failed_job( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_job: Callable[[str], AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner as runner: async with gen_job("failedjob.yaml") as (job, ns): assert job @@ -667,12 +722,16 @@ async def test_failed_job(k8s_cluster, kopf_runner, gen_job): @pytest.mark.anyio -async def test_object_dask_cluster(k8s_cluster, kopf_runner, gen_cluster): +async def test_object_dask_cluster( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster() as (cluster_name, ns): cluster = await DaskCluster.get(cluster_name, namespace=ns) - worker_groups = [] + worker_groups: list[DaskWorkerGroup] = [] while not worker_groups: worker_groups = await cluster.worker_groups() await asyncio.sleep(0.1) @@ -700,8 +759,11 @@ async def test_object_dask_cluster(k8s_cluster, kopf_runner, gen_cluster): @pytest.mark.anyio async def test_object_dask_worker_group( - k8s_cluster, kopf_runner, gen_cluster, gen_worker_group -): + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], + gen_worker_group: Callable[[str], AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with ( gen_cluster() as (cluster_name, ns), @@ -715,7 +777,7 @@ async def test_object_dask_worker_group( additional_workergroup_name, namespace=ns ) - worker_groups = [] + worker_groups: list[DaskWorkerGroup] = [] while not worker_groups: worker_groups = await cluster.worker_groups() await asyncio.sleep(0.1) @@ -725,13 +787,13 @@ async def test_object_dask_worker_group( for wg in worker_groups: assert isinstance(wg, DaskWorkerGroup) - deployments = [] + deployments: list[Deployment] = [] while not deployments: deployments = await wg.deployments() await asyncio.sleep(0.1) assert all([isinstance(d, Deployment) for d in deployments]) - pods = [] + pods: list[Pod] = [] while not pods: pods = await wg.pods() await asyncio.sleep(0.1) @@ -756,7 +818,11 @@ async def test_object_dask_worker_group( @pytest.mark.anyio @pytest.mark.skip(reason="Flaky in CI") -async def test_object_dask_job(k8s_cluster, kopf_runner, gen_job): +async def test_object_dask_job( + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_job: Callable[[str], AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_job("simplejob.yaml") as (job_name, ns): job = await DaskJob.get(job_name, namespace=ns) @@ -768,13 +834,15 @@ async def test_object_dask_job(k8s_cluster, kopf_runner, gen_job): assert isinstance(cluster, DaskCluster) -async def _get_cluster_status(k8s_cluster, ns, cluster_name): +async def _get_cluster_status( + k8s_cluster: KindCluster, ns: str, cluster_name: str +) -> str: """ Will loop infinitely in search of non-falsey cluster status. Make sure there is a timeout on any test which calls this. """ while True: - cluster_status = k8s_cluster.kubectl( + cluster_status: str = k8s_cluster.kubectl( "get", "-n", ns, @@ -799,8 +867,12 @@ async def _get_cluster_status(k8s_cluster, ns, cluster_name): ], ) async def test_create_cluster_validates_name( - cluster_name, expected_status, k8s_cluster, kopf_runner, gen_cluster -): + cluster_name: str, + expected_status: str, + k8s_cluster: KindCluster, + kopf_runner: KopfRunner, + gen_cluster: Callable[..., AsyncContextManager[tuple[str, str]]], +) -> None: with kopf_runner: async with gen_cluster(cluster_name=cluster_name) as (_, ns): actual_status = await _get_cluster_status(k8s_cluster, ns, cluster_name) diff --git a/dask_kubernetes/operator/kubecluster/__init__.py b/dask_kubernetes/operator/kubecluster/__init__.py index a7c4fde0f..ef9104129 100644 --- a/dask_kubernetes/operator/kubecluster/__init__.py +++ b/dask_kubernetes/operator/kubecluster/__init__.py @@ -5,3 +5,11 @@ make_worker_spec, ) from .discovery import discover + +__all__ = [ + "KubeCluster", + "make_cluster_spec", + "make_scheduler_spec", + "make_worker_spec", + "discover", +] diff --git a/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py b/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py index 60b8777d6..a834e0671 100644 --- a/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py @@ -7,10 +7,10 @@ from dask_kubernetes.operator import KubeCluster, make_cluster_spec -def test_kubecluster(kopf_runner, docker_image, ns): +def test_kubecluster(kopf_runner, docker_image, namespace): with kopf_runner: with KubeCluster( - name="cluster", namespace=ns, image=docker_image, n_workers=1 + name="cluster", namespace=namespace, image=docker_image, n_workers=1 ) as cluster: with Client(cluster) as client: client.scheduler_info() @@ -18,11 +18,11 @@ def test_kubecluster(kopf_runner, docker_image, ns): @pytest.mark.anyio -async def test_kubecluster_async(kopf_runner, docker_image, ns): +async def test_kubecluster_async(kopf_runner, docker_image, namespace): with kopf_runner: async with KubeCluster( name="async", - namespace=ns, + namespace=namespace, image=docker_image, n_workers=1, asynchronous=True, @@ -31,55 +31,55 @@ async def test_kubecluster_async(kopf_runner, docker_image, ns): assert await client.submit(lambda x: x + 1, 10).result() == 11 -def test_custom_worker_command(kopf_runner, docker_image, ns): +def test_custom_worker_command(kopf_runner, docker_image, namespace): with kopf_runner: with KubeCluster( name="customworker", image=docker_image, worker_command=["python", "-m", "distributed.cli.dask_worker"], n_workers=1, - namespace=ns, + namespace=namespace, ) as cluster: with Client(cluster) as client: assert client.submit(lambda x: x + 1, 10).result() == 11 -def test_multiple_clusters(kopf_runner, docker_image, ns): +def test_multiple_clusters(kopf_runner, docker_image, namespace): with kopf_runner: with KubeCluster( - name="bar", image=docker_image, n_workers=1, namespace=ns + name="bar", image=docker_image, n_workers=1, namespace=namespace ) as cluster1: with Client(cluster1) as client1: assert client1.submit(lambda x: x + 1, 10).result() == 11 with KubeCluster( - name="baz", image=docker_image, n_workers=1, namespace=ns + name="baz", image=docker_image, n_workers=1, namespace=namespace ) as cluster2: with Client(cluster2) as client2: assert client2.submit(lambda x: x + 1, 10).result() == 11 -def test_clusters_with_custom_port_forward(kopf_runner, docker_image, ns): +def test_clusters_with_custom_port_forward(kopf_runner, docker_image, namespace): with kopf_runner: with KubeCluster( name="bar", image=docker_image, n_workers=1, scheduler_forward_port=8888, - namespace=ns, + namespace=namespace, ) as cluster1: assert cluster1.forwarded_dashboard_port == "8888" with Client(cluster1) as client1: assert client1.submit(lambda x: x + 1, 10).result() == 11 -def test_multiple_clusters_simultaneously(kopf_runner, docker_image, ns): +def test_multiple_clusters_simultaneously(kopf_runner, docker_image, namespace): with kopf_runner: with ( KubeCluster( - name="fizz", image=docker_image, n_workers=1, namespace=ns + name="fizz", image=docker_image, n_workers=1, namespace=namespace ) as cluster1, KubeCluster( - name="buzz", image=docker_image, n_workers=1, namespace=ns + name="buzz", image=docker_image, n_workers=1, namespace=namespace ) as cluster2, ): with Client(cluster1) as client1, Client(cluster2) as client2: @@ -87,18 +87,20 @@ def test_multiple_clusters_simultaneously(kopf_runner, docker_image, ns): assert client2.submit(lambda x: x + 1, 10).result() == 11 -def test_multiple_clusters_simultaneously_same_loop(kopf_runner, docker_image, ns): +def test_multiple_clusters_simultaneously_same_loop( + kopf_runner, docker_image, namespace +): with kopf_runner: with ( KubeCluster( - name="fizz", image=docker_image, n_workers=1, namespace=ns + name="fizz", image=docker_image, n_workers=1, namespace=namespace ) as cluster1, KubeCluster( name="buzz", image=docker_image, loop=cluster1.loop, n_workers=1, - namespace=ns, + namespace=namespace, ) as cluster2, ): with Client(cluster1) as client1, Client(cluster2) as client2: @@ -108,27 +110,30 @@ def test_multiple_clusters_simultaneously_same_loop(kopf_runner, docker_image, n @pytest.mark.anyio -async def test_cluster_from_name(kopf_runner, docker_image, ns): +async def test_cluster_from_name(kopf_runner, docker_image, namespace): with kopf_runner: async with KubeCluster( name="abc", - namespace=ns, + namespace=namespace, image=docker_image, n_workers=1, asynchronous=True, ) as firstcluster: async with KubeCluster.from_name( - "abc", namespace=ns, asynchronous=True + "abc", namespace=namespace, asynchronous=True ) as secondcluster: assert firstcluster == secondcluster firstcluster.scale(2) assert firstcluster.scheduler_info == secondcluster.scheduler_info -def test_additional_worker_groups(kopf_runner, docker_image, ns): +def test_additional_worker_groups(kopf_runner, docker_image, namespace): with kopf_runner: with KubeCluster( - name="additionalgroups", n_workers=1, image=docker_image, namespace=ns + name="additionalgroups", + n_workers=1, + image=docker_image, + namespace=namespace, ) as cluster: cluster.add_worker_group(name="more", n_workers=1) with Client(cluster) as client: @@ -137,18 +142,18 @@ def test_additional_worker_groups(kopf_runner, docker_image, ns): cluster.delete_worker_group(name="more") -def test_cluster_without_operator(docker_image, ns): +def test_cluster_without_operator(docker_image, namespace): with pytest.raises(TimeoutError, match="is the Dask Operator running"): KubeCluster( name="noop", n_workers=1, image=docker_image, resource_timeout=1, - namespace=ns, + namespace=namespace, ) -def test_cluster_crashloopbackoff(kopf_runner, docker_image, ns): +def test_cluster_crashloopbackoff(kopf_runner, docker_image, namespace): with kopf_runner: with pytest.raises(SchedulerStartupError, match="Scheduler failed to start"): spec = make_cluster_spec(name="crashloopbackoff", n_workers=1) @@ -157,19 +162,19 @@ def test_cluster_crashloopbackoff(kopf_runner, docker_image, ns): ] = "dask-schmeduler" KubeCluster( custom_cluster_spec=spec, - namespace=ns, + namespace=namespace, resource_timeout=1, idle_timeout=2, ) -def test_adapt(kopf_runner, docker_image, ns): +def test_adapt(kopf_runner, docker_image, namespace): with kopf_runner: with KubeCluster( name="adaptive", image=docker_image, n_workers=0, - namespace=ns, + namespace=namespace, ) as cluster: cluster.adapt(minimum=0, maximum=1) with Client(cluster) as client: @@ -181,17 +186,17 @@ def test_adapt(kopf_runner, docker_image, ns): cluster.scale(0) -def test_custom_spec(kopf_runner, docker_image, ns): +def test_custom_spec(kopf_runner, docker_image, namespace): with kopf_runner: spec = make_cluster_spec("customspec", image=docker_image) with KubeCluster( - custom_cluster_spec=spec, n_workers=1, namespace=ns + custom_cluster_spec=spec, n_workers=1, namespace=namespace ) as cluster: with Client(cluster) as client: assert client.submit(lambda x: x + 1, 10).result() == 11 -def test_typo_resource_limits(ns): +def test_typo_resource_limits(namespace): with pytest.raises(ValueError): KubeCluster( name="foo", @@ -200,7 +205,7 @@ def test_typo_resource_limits(ns): "CPU": "1", }, }, - namespace=ns, + namespace=namespace, ) @@ -211,11 +216,11 @@ def test_typo_resource_limits(ns): "invalid.chars.in.name", ], ) -def test_invalid_cluster_name_fails(cluster_name, kopf_runner, docker_image, ns): +def test_invalid_cluster_name_fails(cluster_name, kopf_runner, docker_image, namespace): with kopf_runner: with pytest.raises(ValidationError): KubeCluster( name=cluster_name, - namespace=ns, + namespace=namespace, image=docker_image, ) diff --git a/pyproject.toml b/pyproject.toml index 2a35faf7c..afd139e8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -97,6 +97,11 @@ addopts = "-v --keep-cluster --durations=10" timeout = 60 timeout_func_only = true +[tool.mypy] +strict = true +follow_imports = "silent" +disable_error_code = ["import-untyped", "no-untyped-call"] + [project.entry-points.dask_cluster_discovery] helmcluster = "dask_kubernetes.helm:discover" kubecluster = "dask_kubernetes.operator:discover" diff --git a/requirements-test.txt b/requirements-test.txt index c44e8bbba..4d9b61c55 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -9,3 +9,5 @@ git+https://github.com/elemental-lf/k8s-crd-resolver@v0.14.0 jsonschema==4.17.3 dask[complete] anyio +mypy +types-PyYAML From 9bf00f6e0ab7f6e2e73381ad210163f296ed3667 Mon Sep 17 00:00:00 2001 From: Jordan Godau Date: Tue, 11 Jun 2024 08:53:33 -0700 Subject: [PATCH 35/62] Changed min and max data members in DaskAutoscalerSpec struct from 'string' to 'int' --- .../go_client/pkg/apis/kubernetes.dask.org/v1/types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/types.go b/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/types.go index d8527f809..0c5ae023b 100644 --- a/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/types.go +++ b/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/types.go @@ -124,9 +124,9 @@ type DaskAutoscalerSpec struct { // Name of the cluster to associate this autoscaler with Cluster string `json:"cluster"` // Minimum number of workers - Minimum string `json:"minimum"` + Minimum int `json:"minimum"` // Maximum number of workers - Maximum string `json:"maximum"` + Maximum int `json:"maximum"` } // +genclient From 734d001836fad228cca809093feec3d07cd634a6 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 5 Jul 2024 16:06:06 +0100 Subject: [PATCH 36/62] Bump kr8s to 0.17 and Kubernetes supported versions (#897) * Bump kr8s to 0.17 and use new_class for Dask resource classes * Remove unecessary class attributes * Bump supported Kubernetes versions * Bump README badges --- .github/workflows/operator.yaml | 8 ++-- README.rst | 2 +- dask_kubernetes/operator/_objects.py | 57 ++++++---------------------- docs/source/index.rst | 2 +- pyproject.toml | 2 +- 5 files changed, 18 insertions(+), 53 deletions(-) diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index 8e3967c62..85e8648ee 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -26,14 +26,12 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11", "3.12"] - kubernetes-version: ["1.29.2"] + kubernetes-version: ["1.30.2"] include: - python-version: '3.10' - kubernetes-version: 1.28.7 + kubernetes-version: 1.29.4 - python-version: '3.10' - kubernetes-version: 1.27.11 - - python-version: '3.10' - kubernetes-version: 1.26.14 + kubernetes-version: 1.28.9 env: KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig diff --git a/README.rst b/README.rst index 6e3fd7511..6bc21803a 100644 --- a/README.rst +++ b/README.rst @@ -34,7 +34,7 @@ Dask Kubernetes :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support -.. image:: https://img.shields.io/badge/Kubernetes%20support-1.26%7C1.27%7C1.28%7C1.29-blue +.. image:: https://img.shields.io/badge/Kubernetes%20support-1.28%7C1.29%7C1.30-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Kubernetes Support diff --git a/dask_kubernetes/operator/_objects.py b/dask_kubernetes/operator/_objects.py index da34a44a1..d9613cda9 100644 --- a/dask_kubernetes/operator/_objects.py +++ b/dask_kubernetes/operator/_objects.py @@ -2,22 +2,15 @@ from typing import List -from kr8s.asyncio.objects import APIObject, Deployment, Pod, Service +from kr8s.asyncio.objects import Deployment, Pod, Service, new_class -class DaskCluster(APIObject): - version = "kubernetes.dask.org/v1" - endpoint = "daskclusters" - kind = "DaskCluster" - plural = "daskclusters" - singular = "daskcluster" - namespaced = True +class DaskCluster(new_class("DaskCluster", "kubernetes.dask.org/v1")): scalable = True scalable_spec = "worker.replicas" async def worker_groups(self) -> List[DaskWorkerGroup]: - return await self.api.get( - DaskWorkerGroup.endpoint, + return await DaskWorkerGroup.list( label_selector=f"dask.org/cluster-name={self.name}", namespace=self.namespace, ) @@ -25,8 +18,7 @@ async def worker_groups(self) -> List[DaskWorkerGroup]: async def scheduler_pod(self) -> Pod: pods = [] while not pods: - pods = await self.api.get( - Pod.endpoint, + pods = await Pod.list( label_selector=",".join( [ f"dask.org/cluster-name={self.name}", @@ -41,8 +33,7 @@ async def scheduler_pod(self) -> Pod: async def scheduler_deployment(self) -> Deployment: deployments = [] while not deployments: - deployments = await self.api.get( - Deployment.endpoint, + deployments = await Deployment.list( label_selector=",".join( [ f"dask.org/cluster-name={self.name}", @@ -57,8 +48,7 @@ async def scheduler_deployment(self) -> Deployment: async def scheduler_service(self) -> Service: services = [] while not services: - services = await self.api.get( - Service.endpoint, + services = await Service.list( label_selector=",".join( [ f"dask.org/cluster-name={self.name}", @@ -79,19 +69,12 @@ async def ready(self) -> bool: ) -class DaskWorkerGroup(APIObject): - version = "kubernetes.dask.org/v1" - endpoint = "daskworkergroups" - kind = "DaskWorkerGroup" - plural = "daskworkergroups" - singular = "daskworkergroup" - namespaced = True +class DaskWorkerGroup(new_class("DaskWorkerGroup", "kubernetes.dask.org/v1")): scalable = True scalable_spec = "worker.replicas" async def pods(self) -> List[Pod]: - return await self.api.get( - Pod.endpoint, + return await Pod.list( label_selector=",".join( [ f"dask.org/cluster-name={self.spec.cluster}", @@ -103,8 +86,7 @@ async def pods(self) -> List[Pod]: ) async def deployments(self) -> List[Deployment]: - return await self.api.get( - Deployment.endpoint, + return await Deployment.list( label_selector=",".join( [ f"dask.org/cluster-name={self.spec.cluster}", @@ -119,34 +101,19 @@ async def cluster(self) -> DaskCluster: return await DaskCluster.get(self.spec.cluster, namespace=self.namespace) -class DaskAutoscaler(APIObject): - version = "kubernetes.dask.org/v1" - endpoint = "daskautoscalers" - kind = "DaskAutoscaler" - plural = "daskautoscalers" - singular = "daskautoscaler" - namespaced = True - +class DaskAutoscaler(new_class("DaskAutoscaler", "kubernetes.dask.org/v1")): async def cluster(self) -> DaskCluster: return await DaskCluster.get(self.spec.cluster, namespace=self.namespace) -class DaskJob(APIObject): - version = "kubernetes.dask.org/v1" - endpoint = "daskjobs" - kind = "DaskJob" - plural = "daskjobs" - singular = "daskjob" - namespaced = True - +class DaskJob(new_class("DaskJob", "kubernetes.dask.org/v1")): async def cluster(self) -> DaskCluster: return await DaskCluster.get(self.name, namespace=self.namespace) async def pod(self) -> Pod: pods = [] while not pods: - pods = await self.api.get( - Pod.endpoint, + pods = await Pod.list( label_selector=",".join( [ f"dask.org/cluster-name={self.name}", diff --git a/docs/source/index.rst b/docs/source/index.rst index de90cca24..8f749aef9 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -13,7 +13,7 @@ Dask Kubernetes Operator :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support -.. image:: https://img.shields.io/badge/Kubernetes%20support-1.26%7C1.27%7C1.28%7C1.29-blue +.. image:: https://img.shields.io/badge/Kubernetes%20support-1.28%7C1.29%7C1.30-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Kubernetes Support diff --git a/pyproject.toml b/pyproject.toml index afd139e8d..65bdcff46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ dependencies = [ "dask>=2022.08.1", "distributed>=2022.08.1", "kopf>=1.35.3", - "kr8s==0.14.*", + "kr8s==0.17.*", "kubernetes-asyncio>=12.0.1", "kubernetes>=12.0.1", "pykube-ng>=22.9.0", From 9bd8ea083b9642292a32fa6515a19f78b8762205 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Thu, 22 Aug 2024 11:19:49 +0200 Subject: [PATCH 37/62] Drop Python 3.9 (#902) --- .github/workflows/operator.yaml | 2 +- README.rst | 2 +- docs/source/index.rst | 2 +- pyproject.toml | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/operator.yaml b/.github/workflows/operator.yaml index 85e8648ee..c1acd8eac 100644 --- a/.github/workflows/operator.yaml +++ b/.github/workflows/operator.yaml @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] kubernetes-version: ["1.30.2"] include: - python-version: '3.10' diff --git a/README.rst b/README.rst index 6bc21803a..7ced4ccee 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ Dask Kubernetes :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue +.. image:: https://img.shields.io/badge/python%20support-3.10%7C3.11%7C3.12-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support diff --git a/docs/source/index.rst b/docs/source/index.rst index 8f749aef9..87e41aac7 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -9,7 +9,7 @@ Dask Kubernetes Operator :target: https://anaconda.org/conda-forge/dask-kubernetes :alt: Conda Forge -.. image:: https://img.shields.io/badge/python%20support-3.9%7C3.10%7C3.11%7C3.12-blue +.. image:: https://img.shields.io/badge/python%20support-3.10%7C3.11%7C3.12-blue :target: https://kubernetes.dask.org/en/latest/installing.html#supported-versions :alt: Python Support diff --git a/pyproject.toml b/pyproject.toml index 65bdcff46..c07e127f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ dynamic = ["version"] description = "Native Kubernetes integration for Dask" readme = "README.rst" license = { file = "LICENSE" } -requires-python = ">=3.9" +requires-python = ">=3.10" maintainers = [{ name = "Jacob Tomlinson" }] keywords = ["dask", "distributed", "kubernetes"] dependencies = [ @@ -88,8 +88,7 @@ line-length = 120 # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -# Assume Python 3.8 -target-version = "py39" +target-version = "py310" [tool.pytest.ini_options] minversion = "6.0" From 2ecfdcd41b0e09665d4ff98cb40528218fea10fe Mon Sep 17 00:00:00 2001 From: Marcelo Villa Date: Tue, 3 Sep 2024 15:40:07 -0500 Subject: [PATCH 38/62] Fix Autoscaler example code snippet on the docs index page (#905) * Remove duplicate snippet * Include fixed example --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 87e41aac7..5aa0e23d1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -156,7 +156,7 @@ A ``DaskAutoscaler`` resource will communicate with the scheduler periodically a from dask_kubernetes.operator import KubeCluster cluster = KubeCluster(name="my-dask-cluster", image='ghcr.io/dask/dask:latest') - cluster.scale(10) + cluster.adapt(minimum=1, maximum=10) .. toctree:: :maxdepth: 2 From ab1be696d03a8963f0db120e0de993f3eda12930 Mon Sep 17 00:00:00 2001 From: catzc Date: Wed, 18 Sep 2024 04:36:04 -0400 Subject: [PATCH 39/62] Fix loadBalancer attribute name (#908) Closes #906 --- dask_kubernetes/operator/controller/controller.py | 2 +- dask_kubernetes/operator/networking.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index c34aa0ce7..ce1f5a0a3 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -401,7 +401,7 @@ async def handle_scheduler_service_status( assert namespace # If the Service is a LoadBalancer with no ingress endpoints mark the cluster as Pending if spec["type"] == "LoadBalancer" and not len( - status.get("load_balancer", {}).get("ingress", []) + status.get("loadBalancer", {}).get("ingress", []) ): phase = "Pending" # Otherwise mark it as Running diff --git a/dask_kubernetes/operator/networking.py b/dask_kubernetes/operator/networking.py index 1e9916406..2978889bf 100644 --- a/dask_kubernetes/operator/networking.py +++ b/dask_kubernetes/operator/networking.py @@ -50,8 +50,8 @@ async def get_external_address_for_scheduler_service( """Take a service object and return the scheduler address.""" if service.spec.type == "LoadBalancer": port = _get_port(service, port_name) - lb = service.status.load_balancer.ingress[0] - host = lb.hostname or lb.ip + lb = service.status.loadBalancer.ingress[0] + host = lb.get("hostname", None) or lb.ip elif service.spec.type == "NodePort": port = _get_port(service, port_name, is_node_port=True) nodes = await kr8s.asyncio.get("nodes") From d4d41124ee065e556f3398daf4c9b74c60c8ab6f Mon Sep 17 00:00:00 2001 From: rossmacdonald-ow <140158251+rossmacdonald-ow@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:03:44 +0100 Subject: [PATCH 40/62] Add extra docs info on target duratiom (#911) --- docs/source/operator_resources.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/source/operator_resources.rst b/docs/source/operator_resources.rst index d6598dcff..b4b3ffb70 100644 --- a/docs/source/operator_resources.rst +++ b/docs/source/operator_resources.rst @@ -500,7 +500,10 @@ using dask's adaptive mode. By creating the resource the operator controller will periodically poll the scheduler and request the desired number of workers. The scheduler calculates this number by profiling the tasks it is processing and then extrapolating how many workers it would need -to complete the current graph within 5 seconds. +to complete the current graph within the target duration. +By default the target duration is 5 seconds but +`it can be adjusted via the "distributed.adaptive.target-duration" in the scheduler config `_. + .. mermaid:: From 46350db5b98c07d6018c9156fecae74b14f19db1 Mon Sep 17 00:00:00 2001 From: Ross MacDonald <42966821+RossmacD@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:21:42 +0100 Subject: [PATCH 41/62] Improve retire_worker fallback by using deployments instead of pods (#912) --- dask_kubernetes/operator/controller/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index ce1f5a0a3..19599e59d 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -488,7 +488,7 @@ async def retire_workers( "This can result in lost data, see https://kubernetes.dask.org/en/latest/operator_troubleshooting.html." ) workers = await kr8s.asyncio.get( - "pods", + "deployments", namespace=namespace, label_selector={"dask.org/workergroup-name": worker_group_name}, ) From f21605e9c57e0152b9b5d6d9a57389ea309b3ae8 Mon Sep 17 00:00:00 2001 From: Jacob Hall Date: Mon, 28 Oct 2024 09:44:03 -0400 Subject: [PATCH 42/62] Fix section header typo in documentation (#915) --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 5aa0e23d1..2e11f2141 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -161,7 +161,7 @@ A ``DaskAutoscaler`` resource will communicate with the scheduler periodically a .. toctree:: :maxdepth: 2 :hidden: - :caption: Getting Syarted + :caption: Getting Started Overview installing From f30da7208ef9d9fcd87cb34644e457fb4954b15e Mon Sep 17 00:00:00 2001 From: Brett Naul Date: Tue, 5 Nov 2024 13:21:49 -0500 Subject: [PATCH 43/62] feat: Add configurable liveness probe timeout (#918) * feat: Add configurable liveness probe timeout * Update dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml Co-authored-by: Jacob Tomlinson * Add livenessProbe timeout to README * Fix README typo --------- Co-authored-by: Jacob Tomlinson --- .../deployment/helm/dask-kubernetes-operator/README.md | 1 + .../helm/dask-kubernetes-operator/templates/deployment.yaml | 1 + .../deployment/helm/dask-kubernetes-operator/values.yaml | 3 +++ 3 files changed, 5 insertions(+) diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md index 1b4530df2..02bcacec6 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md @@ -36,6 +36,7 @@ The following table lists the configurable parameters of the Dask-kubernetes-ope | `tolerations` | Tolerations | `[]` | | `affinity` | Affinity | `{}` | | `priorityClassName` | Priority class | `null` | +| `livenessProbe.timeoutSeconds` | | `5` | | `kopfArgs` | Command line flags to pass to kopf on start up | `["--all-namespaces"]` | | `metrics.scheduler.enabled` | Enable scheduler metrics. Pip package [prometheus-client](https://pypi.org/project/prometheus-client/) should be present on scheduler. | `false` | | `metrics.scheduler.serviceMonitor.enabled` | Enable scheduler servicemonitor. | `false` | diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml index 285259c0c..357ecf61f 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml @@ -52,6 +52,7 @@ spec: httpGet: path: /healthz port: 8080 + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} volumeMounts: {{- toYaml .Values.volumeMounts | nindent 12 }} volumes: diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml index d4d863a55..12e62ecbe 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml @@ -54,6 +54,9 @@ affinity: {} # Affinity priorityClassName: null # Priority class +livenessProbe: + timeoutSeconds: 5 + kopfArgs: # Command line flags to pass to kopf on start up - --all-namespaces From ac5a3ce5c4011dace791f29f2fd13c89023fa69d Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Mon, 9 Dec 2024 12:41:49 +0000 Subject: [PATCH 44/62] Add DaskCluster.idleTimeout to the docs (#923) --- docs/source/operator_resources.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/operator_resources.rst b/docs/source/operator_resources.rst index b4b3ffb70..a41c175c3 100644 --- a/docs/source/operator_resources.rst +++ b/docs/source/operator_resources.rst @@ -655,6 +655,7 @@ Full ``DaskCluster`` spec reference. scheduler: spec: ... # PodSpec, standard k8s pod - https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#podspec-v1-core service: ... # ServiceSpec, standard k8s service - https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#servicespec-v1-core + idleTimeout: 5 # Number of seconds to time out scheduler liveness probe if no activity Full ``DaskWorkerGroup`` spec reference. From bfaecf447c88c1fc545efeaa04fa63bda017df4e Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Mon, 16 Dec 2024 17:42:26 +0000 Subject: [PATCH 45/62] Migrate from frigate to sphinx-helm (#924) * Migrate from frigate to sphinx-helm * Bump sphinx-helm to 0.2.1 --- .pre-commit-config.yaml | 6 +- .../operator/deployment/helm/README.md | 4 +- .../helm/dask-kubernetes-operator/README.md | 66 +------------------ docs/requirements-docs.txt | 2 +- docs/source/conf.py | 2 +- docs/source/installing.rst | 2 +- 6 files changed, 9 insertions(+), 73 deletions(-) mode change 120000 => 100644 dask_kubernetes/operator/deployment/helm/README.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebc658db8..8688e0aee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,10 +10,6 @@ repos: - id: black language_version: python3 exclude: versioneer.py - - repo: https://github.com/rapidsai/frigate/ - rev: v0.4.0 # pre-commit autoupdate - to keep the version up to date - hooks: - - id: frigate - repo: local hooks: - id: check-crd-updates @@ -50,4 +46,4 @@ repos: |go\.sum |dask_kubernetes/operator/go_client/.*\.go )$ - pass_filenames: false \ No newline at end of file + pass_filenames: false diff --git a/dask_kubernetes/operator/deployment/helm/README.md b/dask_kubernetes/operator/deployment/helm/README.md deleted file mode 120000 index 599400690..000000000 --- a/dask_kubernetes/operator/deployment/helm/README.md +++ /dev/null @@ -1 +0,0 @@ -dask-kubernetes-operator/README.md \ No newline at end of file diff --git a/dask_kubernetes/operator/deployment/helm/README.md b/dask_kubernetes/operator/deployment/helm/README.md new file mode 100644 index 000000000..c2c5650dc --- /dev/null +++ b/dask_kubernetes/operator/deployment/helm/README.md @@ -0,0 +1,3 @@ +# Dask Operator Helm Chart + +See the [documentation](https://kubernetes.dask.org/en/latest/installing.html#operator) for installation information. diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md index 02bcacec6..c2c5650dc 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/README.md @@ -1,65 +1,3 @@ +# Dask Operator Helm Chart -Dask-kubernetes-operator -=========== - -A helm chart for managing the deployment of the dask kubernetes operator and CRDs - - -## Configuration - -The following table lists the configurable parameters of the Dask-kubernetes-operator chart and their default values. - -| Parameter | Description | Default | -| ------------------------ | ----------------------- | -------------- | -| `image.name` | Docker image for the operator | `"ghcr.io/dask/dask-kubernetes-operator"` | -| `image.tag` | Release version | `"set-by-chartpress"` | -| `image.pullPolicy` | Pull policy | `"IfNotPresent"` | -| `imagePullSecrets` | Image pull secrets for private registries | `[]` | -| `nameOverride` | Override release name (not including random UUID) | `""` | -| `fullnameOverride` | Override full release name | `""` | -| `serviceAccount.create` | Create a service account for the operator to use | `true` | -| `serviceAccount.annotations` | Annotations to add to the service account | `{}` | -| `serviceAccount.name` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template. | `""` | -| `rbac.create` | Create a Role/ClusterRole needed by the operator and bind it to the service account | `true` | -| `rbac.cluster` | Creates a ClusterRole if true, else create a namespaced Role | `true` | -| `podAnnotations` | Extra annotations for the operator pod | `{}` | -| `podSecurityContext` | Security context for the operator pod | `{}` | -| `securityContext.capabilities.drop` | | `["ALL"]` | -| `securityContext.runAsNonRoot` | | `true` | -| `securityContext.runAsUser` | | `1000` | -| `securityContext.allowPrivilegeEscalation` | | `false` | -| `securityContext.readOnlyRootFilesystem` | | `true` | -| `resources` | Resources for the operator pod | `{}` | -| `volumes` | Volumes for the operator pod | `[]` | -| `volumeMounts` | Volume mounts for the operator container | `[]` | -| `nodeSelector` | Node selector | `{}` | -| `tolerations` | Tolerations | `[]` | -| `affinity` | Affinity | `{}` | -| `priorityClassName` | Priority class | `null` | -| `livenessProbe.timeoutSeconds` | | `5` | -| `kopfArgs` | Command line flags to pass to kopf on start up | `["--all-namespaces"]` | -| `metrics.scheduler.enabled` | Enable scheduler metrics. Pip package [prometheus-client](https://pypi.org/project/prometheus-client/) should be present on scheduler. | `false` | -| `metrics.scheduler.serviceMonitor.enabled` | Enable scheduler servicemonitor. | `false` | -| `metrics.scheduler.serviceMonitor.namespace` | Deploy servicemonitor in different namespace, e.g. monitoring. | `""` | -| `metrics.scheduler.serviceMonitor.namespaceSelector` | Selector to select which namespaces the Endpoints objects are discovered from. | `{}` | -| `metrics.scheduler.serviceMonitor.additionalLabels` | Additional labels to add to the ServiceMonitor metadata. | `{}` | -| `metrics.scheduler.serviceMonitor.interval` | Interval at which metrics should be scraped. | `"15s"` | -| `metrics.scheduler.serviceMonitor.jobLabel` | The label to use to retrieve the job name from. | `""` | -| `metrics.scheduler.serviceMonitor.targetLabels` | TargetLabels transfers labels on the Kubernetes Service onto the target. | `["dask.org/cluster-name"]` | -| `metrics.scheduler.serviceMonitor.metricRelabelings` | MetricRelabelConfigs to apply to samples before ingestion. | `[]` | -| `metrics.worker.enabled` | Enable workers metrics. Pip package [prometheus-client](https://pypi.org/project/prometheus-client/) should be present on workers. | `false` | -| `metrics.worker.podMonitor.enabled` | Enable workers podmonitor | `false` | -| `metrics.worker.podMonitor.namespace` | Deploy podmonitor in different namespace, e.g. monitoring. | `""` | -| `metrics.worker.podMonitor.namespaceSelector` | Selector to select which namespaces the Endpoints objects are discovered from. | `{}` | -| `metrics.worker.podMonitor.additionalLabels` | Additional labels to add to the PodMonitor metadata. | `{}` | -| `metrics.worker.podMonitor.interval` | Interval at which metrics should be scraped. | `"15s"` | -| `metrics.worker.podMonitor.jobLabel` | The label to use to retrieve the job name from. | `""` | -| `metrics.worker.podMonitor.podTargetLabels` | PodTargetLabels transfers labels on the Kubernetes Pod onto the target. | `["dask.org/cluster-name", "dask.org/workergroup-name"]` | -| `metrics.worker.podMonitor.metricRelabelings` | MetricRelabelConfigs to apply to samples before ingestion. | `[]` | -| `workerAllocation.size` | | `null` | -| `workerAllocation.delay` | | `null` | - - - ---- -_Documentation generated by [Frigate](https://frigate.readthedocs.io)._ +See the [documentation](https://kubernetes.dask.org/en/latest/installing.html#operator) for installation information. diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index e55c5484e..712768175 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -3,7 +3,7 @@ sphinx sphinx-reredirects sphinxcontrib-mermaid dask-sphinx-theme>=3.0.0 -frigate>=0.7.0 +sphinx-helm>=0.2.1 # FIXME: This workaround is required until we have sphinx>=5, as enabled by # dask-sphinx-theme no longer pinning sphinx-book-theme==0.2.0. This is diff --git a/docs/source/conf.py b/docs/source/conf.py index 2647d67c5..821fe85aa 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -43,7 +43,7 @@ "numpydoc", "sphinx_reredirects", "sphinxcontrib.mermaid", - "frigate.sphinx.ext", + "sphinx_helm.ext", ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/source/installing.rst b/docs/source/installing.rst index 804158ffd..a1d383aa7 100644 --- a/docs/source/installing.rst +++ b/docs/source/installing.rst @@ -147,7 +147,7 @@ If you're using the official Dask images you can install this at runtime. Chart Configuration Reference """"""""""""""""""""""""""""" -.. frigate:: ../../dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator +.. helm:: ../../dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator Installing with Manifests ^^^^^^^^^^^^^^^^^^^^^^^^^ From 27ef9592339fc095cdd6537d8e820eb9933dd48b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:18:11 +0000 Subject: [PATCH 46/62] Update major go package version (#925) Co-authored-by: jacobtomlinson --- .../operator/go_client/hack/regenerate-code.sh | 2 +- .../go_client/pkg/apis/kubernetes.dask.org/v1/register.go | 2 +- .../go_client/pkg/client/clientset/versioned/clientset.go | 2 +- .../clientset/versioned/fake/clientset_generated.go | 6 +++--- .../pkg/client/clientset/versioned/fake/register.go | 2 +- .../pkg/client/clientset/versioned/scheme/register.go | 2 +- .../typed/kubernetes.dask.org/v1/daskautoscaler.go | 4 ++-- .../versioned/typed/kubernetes.dask.org/v1/daskcluster.go | 4 ++-- .../versioned/typed/kubernetes.dask.org/v1/daskjob.go | 4 ++-- .../typed/kubernetes.dask.org/v1/daskworkergroup.go | 4 ++-- .../kubernetes.dask.org/v1/fake/fake_daskautoscaler.go | 2 +- .../typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go | 2 +- .../typed/kubernetes.dask.org/v1/fake/fake_daskjob.go | 2 +- .../kubernetes.dask.org/v1/fake/fake_daskworkergroup.go | 2 +- .../v1/fake/fake_kubernetes.dask.org_client.go | 2 +- .../kubernetes.dask.org/v1/kubernetes.dask.org_client.go | 4 ++-- .../pkg/client/informers/externalversions/factory.go | 6 +++--- .../pkg/client/informers/externalversions/generic.go | 2 +- .../internalinterfaces/factory_interfaces.go | 2 +- .../externalversions/kubernetes.dask.org/interface.go | 4 ++-- .../kubernetes.dask.org/v1/daskautoscaler.go | 8 ++++---- .../kubernetes.dask.org/v1/daskcluster.go | 8 ++++---- .../externalversions/kubernetes.dask.org/v1/daskjob.go | 8 ++++---- .../kubernetes.dask.org/v1/daskworkergroup.go | 8 ++++---- .../externalversions/kubernetes.dask.org/v1/interface.go | 2 +- .../listers/kubernetes.dask.org/v1/daskautoscaler.go | 2 +- .../client/listers/kubernetes.dask.org/v1/daskcluster.go | 2 +- .../pkg/client/listers/kubernetes.dask.org/v1/daskjob.go | 2 +- .../listers/kubernetes.dask.org/v1/daskworkergroup.go | 2 +- go.mod | 2 +- 30 files changed, 52 insertions(+), 52 deletions(-) diff --git a/dask_kubernetes/operator/go_client/hack/regenerate-code.sh b/dask_kubernetes/operator/go_client/hack/regenerate-code.sh index 04cd31db2..491edf1e8 100755 --- a/dask_kubernetes/operator/go_client/hack/regenerate-code.sh +++ b/dask_kubernetes/operator/go_client/hack/regenerate-code.sh @@ -2,7 +2,7 @@ CURRENT_DIR=$(dirname ${BASH_SOURCE}) REPO_DIR=$(realpath "$CURRENT_DIR/../../../..") -MAJOR_VERSION="v2024" +MAJOR_VERSION="v2025" PROJECT_MODULE="github.com/dask/dask-kubernetes/${MAJOR_VERSION}" IMAGE_NAME="kubernetes-codegen:latest" diff --git a/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go b/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go index 53861426e..344dc854e 100644 --- a/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go +++ b/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go @@ -1,7 +1,7 @@ package v1 import ( - daskoperator "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis" + daskoperator "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go index 7e4c4e586..e255b66a2 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/clientset.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" + kubernetesv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go index 6fc50fc92..f54df235c 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -3,9 +3,9 @@ package fake import ( - clientset "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" - fakekubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake" + clientset "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + kubernetesv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" + fakekubernetesv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go index 691f89cf3..63e9c198b 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/fake/register.go @@ -3,7 +3,7 @@ package fake import ( - kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go index f6a9ffd69..4e9b5fb76 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme/register.go @@ -3,7 +3,7 @@ package scheme import ( - kubernetesv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go index c3e734091..e6d2591f8 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskautoscaler.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go index 7c0aeb887..a63e5e4f6 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskcluster.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go index 9987237cd..c6d0ee5aa 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskjob.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go index 922ed414f..6fbb43f43 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/daskworkergroup.go @@ -6,8 +6,8 @@ import ( "context" "time" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - scheme "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + scheme "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go index bd88c6535..be5941f21 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskautoscaler.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go index 4296dc2f4..9e8830980 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskcluster.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go index 9a41bb5b1..45fde4835 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskjob.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go index 9580f0f26..7bbad4b91 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_daskworkergroup.go @@ -5,7 +5,7 @@ package fake import ( "context" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go index 47e97dfb2..080d01474 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/fake/fake_kubernetes.dask.org_client.go @@ -3,7 +3,7 @@ package fake import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1" rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go index a252dd206..47aaeceec 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go +++ b/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/typed/kubernetes.dask.org/v1/kubernetes.dask.org_client.go @@ -5,8 +5,8 @@ package v1 import ( "net/http" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned/scheme" rest "k8s.io/client-go/rest" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go index 296e234dd..62c0ada03 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/factory.go @@ -7,9 +7,9 @@ import ( sync "sync" time "time" - versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - kubernetesdaskorg "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org" + versioned "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + kubernetesdaskorg "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go index 7d1d14bc3..9cdc26dc2 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/generic.go @@ -5,7 +5,7 @@ package externalversions import ( "fmt" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go index 8ec55d7be..161e58a6d 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -5,7 +5,7 @@ package internalinterfaces import ( time "time" - versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + versioned "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go index 426e84954..7e6080faf 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/interface.go @@ -3,8 +3,8 @@ package kubernetes import ( - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1" ) // Interface provides access to each of this group's versions. diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go index c0726c785..e64ab9ea0 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskautoscaler.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go index 5b694db9e..55c587482 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskcluster.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go index 442da458e..e56ed71f8 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskjob.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go index 23dbd7700..324bd447a 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/daskworkergroup.go @@ -6,10 +6,10 @@ import ( "context" time "time" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - versioned "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" + kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + versioned "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/clientset/versioned" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" diff --git a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go index bb3577be7..33ce6e9aa 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go +++ b/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/kubernetes.dask.org/v1/interface.go @@ -3,7 +3,7 @@ package v1 import ( - internalinterfaces "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" + internalinterfaces "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/client/informers/externalversions/internalinterfaces" ) // Interface provides access to all the informers in this group version. diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go index 4f48ad342..548cf9607 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskautoscaler.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go index 7c383aff8..7ab095a20 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskcluster.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go index c2035d1ba..a2091f859 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskjob.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go index a7dd4da45..526e596c0 100644 --- a/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go +++ b/dask_kubernetes/operator/go_client/pkg/client/listers/kubernetes.dask.org/v1/daskworkergroup.go @@ -3,7 +3,7 @@ package v1 import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" + v1 "github.com/dask/dask-kubernetes/v2025/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/go.mod b/go.mod index 8fdf010c7..7c2940eb9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/dask/dask-kubernetes/v2024 +module github.com/dask/dask-kubernetes/v2025 go 1.18 From 8d38b07c14cb6c4e28c9c5c6d2c85593c054afae Mon Sep 17 00:00:00 2001 From: Bernhard Stadlbauer <11799671+bstadlbauer@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:42:05 +0100 Subject: [PATCH 47/62] Remove generated `go` code before regerneration (#928) --- .../workflows/update-go-package-version.yml | 7 + .../applyconfiguration/internal/internal.go | 46 ---- .../kubernetes.dask.org/v1/daskautoscaler.go | 194 ----------------- .../v1/daskautoscalerspec.go | 41 ---- .../kubernetes.dask.org/v1/daskcluster.go | 203 ------------------ .../kubernetes.dask.org/v1/daskclusterspec.go | 32 --- .../v1/daskclusterstatus.go | 27 --- .../kubernetes.dask.org/v1/daskjob.go | 203 ------------------ .../kubernetes.dask.org/v1/daskjobspec.go | 32 --- .../kubernetes.dask.org/v1/daskjobstatus.go | 64 ------ .../kubernetes.dask.org/v1/daskworkergroup.go | 194 ----------------- .../v1/daskworkergroupspec.go | 32 --- .../kubernetes.dask.org/v1/jobspec.go | 27 --- .../kubernetes.dask.org/v1/schedulerspec.go | 36 ---- .../kubernetes.dask.org/v1/workerspec.go | 36 ---- .../pkg/client/applyconfiguration/utils.go | 45 ---- 16 files changed, 7 insertions(+), 1212 deletions(-) delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/internal/internal.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscaler.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscalerspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskcluster.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjob.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroup.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroupspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/jobspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/schedulerspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/workerspec.go delete mode 100644 dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go diff --git a/.github/workflows/update-go-package-version.yml b/.github/workflows/update-go-package-version.yml index 8c2afb826..2406ff216 100644 --- a/.github/workflows/update-go-package-version.yml +++ b/.github/workflows/update-go-package-version.yml @@ -12,9 +12,16 @@ jobs: steps: - uses: actions/checkout@v2 - name: Update go package version + # We're removing the generated code first, as we've seen that the code + # generation is not always deterministic and might remove files that were there + # in the past. + # We couldn't pinpoint the root of the non-deterministic generation, but so far + # we've only seen minor changes. run: | PAST_YEAR=$(date -d "last year" '+%Y') CURRENT_YEAR=$(date '+%Y') + rm -rf dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/zz_generated.deepcopy.go + rm -rf /Users/bstadlbauer/workspace/bstadlbauer/dask-kubernetes/dask_kubernetes/operator/go_client/pkg/client sed -i "s/v${PAST_YEAR}/v${CURRENT_YEAR}/g" go.mod sed -i "s/v${PAST_YEAR}/v${CURRENT_YEAR}/g" dask_kubernetes/operator/go_client/hack/regenerate-code.sh sed -i "s/v${PAST_YEAR}/v${CURRENT_YEAR}/g" dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1/register.go diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/internal/internal.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/internal/internal.go deleted file mode 100644 index 47f29e51b..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/internal/internal.go +++ /dev/null @@ -1,46 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package internal - -import ( - "fmt" - "sync" - - typed "sigs.k8s.io/structured-merge-diff/v4/typed" -) - -func Parser() *typed.Parser { - parserOnce.Do(func() { - var err error - parser, err = typed.NewParser(schemaYAML) - if err != nil { - panic(fmt.Sprintf("Failed to parse schema: %v", err)) - } - }) - return parser -} - -var parserOnce sync.Once -var parser *typed.Parser -var schemaYAML = typed.YAMLObject(`types: -- name: __untyped_atomic_ - scalar: untyped - list: - elementType: - namedType: __untyped_atomic_ - elementRelationship: atomic - map: - elementType: - namedType: __untyped_atomic_ - elementRelationship: atomic -- name: __untyped_deduced_ - scalar: untyped - list: - elementType: - namedType: __untyped_atomic_ - elementRelationship: atomic - map: - elementType: - namedType: __untyped_deduced_ - elementRelationship: separable -`) diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscaler.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscaler.go deleted file mode 100644 index 6af0c6f33..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscaler.go +++ /dev/null @@ -1,194 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// DaskAutoscalerApplyConfiguration represents an declarative configuration of the DaskAutoscaler type for use -// with apply. -type DaskAutoscalerApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *DaskAutoscalerSpecApplyConfiguration `json:"spec,omitempty"` -} - -// DaskAutoscaler constructs an declarative configuration of the DaskAutoscaler type for use with -// apply. -func DaskAutoscaler(name, namespace string) *DaskAutoscalerApplyConfiguration { - b := &DaskAutoscalerApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("DaskAutoscaler") - b.WithAPIVersion("kubernetes.dask.org/v1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithKind(value string) *DaskAutoscalerApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithAPIVersion(value string) *DaskAutoscalerApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithName(value string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithGenerateName(value string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithNamespace(value string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithUID(value types.UID) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithResourceVersion(value string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithGeneration(value int64) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithCreationTimestamp(value metav1.Time) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *DaskAutoscalerApplyConfiguration) WithLabels(entries map[string]string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *DaskAutoscalerApplyConfiguration) WithAnnotations(entries map[string]string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *DaskAutoscalerApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *DaskAutoscalerApplyConfiguration) WithFinalizers(values ...string) *DaskAutoscalerApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *DaskAutoscalerApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *DaskAutoscalerApplyConfiguration) WithSpec(value *DaskAutoscalerSpecApplyConfiguration) *DaskAutoscalerApplyConfiguration { - b.Spec = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscalerspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscalerspec.go deleted file mode 100644 index 96d165405..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskautoscalerspec.go +++ /dev/null @@ -1,41 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -// DaskAutoscalerSpecApplyConfiguration represents an declarative configuration of the DaskAutoscalerSpec type for use -// with apply. -type DaskAutoscalerSpecApplyConfiguration struct { - Cluster *string `json:"cluster,omitempty"` - Minimum *string `json:"minimum,omitempty"` - Maximum *string `json:"maximum,omitempty"` -} - -// DaskAutoscalerSpecApplyConfiguration constructs an declarative configuration of the DaskAutoscalerSpec type for use with -// apply. -func DaskAutoscalerSpec() *DaskAutoscalerSpecApplyConfiguration { - return &DaskAutoscalerSpecApplyConfiguration{} -} - -// WithCluster sets the Cluster field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Cluster field is set to the value of the last call. -func (b *DaskAutoscalerSpecApplyConfiguration) WithCluster(value string) *DaskAutoscalerSpecApplyConfiguration { - b.Cluster = &value - return b -} - -// WithMinimum sets the Minimum field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Minimum field is set to the value of the last call. -func (b *DaskAutoscalerSpecApplyConfiguration) WithMinimum(value string) *DaskAutoscalerSpecApplyConfiguration { - b.Minimum = &value - return b -} - -// WithMaximum sets the Maximum field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Maximum field is set to the value of the last call. -func (b *DaskAutoscalerSpecApplyConfiguration) WithMaximum(value string) *DaskAutoscalerSpecApplyConfiguration { - b.Maximum = &value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskcluster.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskcluster.go deleted file mode 100644 index da3c09a22..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskcluster.go +++ /dev/null @@ -1,203 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// DaskClusterApplyConfiguration represents an declarative configuration of the DaskCluster type for use -// with apply. -type DaskClusterApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *DaskClusterSpecApplyConfiguration `json:"spec,omitempty"` - Status *DaskClusterStatusApplyConfiguration `json:"status,omitempty"` -} - -// DaskCluster constructs an declarative configuration of the DaskCluster type for use with -// apply. -func DaskCluster(name, namespace string) *DaskClusterApplyConfiguration { - b := &DaskClusterApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("DaskCluster") - b.WithAPIVersion("kubernetes.dask.org/v1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithKind(value string) *DaskClusterApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithAPIVersion(value string) *DaskClusterApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithName(value string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithGenerateName(value string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithNamespace(value string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithUID(value types.UID) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithResourceVersion(value string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithGeneration(value int64) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithCreationTimestamp(value metav1.Time) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *DaskClusterApplyConfiguration) WithLabels(entries map[string]string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *DaskClusterApplyConfiguration) WithAnnotations(entries map[string]string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *DaskClusterApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *DaskClusterApplyConfiguration) WithFinalizers(values ...string) *DaskClusterApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *DaskClusterApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithSpec(value *DaskClusterSpecApplyConfiguration) *DaskClusterApplyConfiguration { - b.Spec = value - return b -} - -// WithStatus sets the Status field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Status field is set to the value of the last call. -func (b *DaskClusterApplyConfiguration) WithStatus(value *DaskClusterStatusApplyConfiguration) *DaskClusterApplyConfiguration { - b.Status = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterspec.go deleted file mode 100644 index 1ce4f5e0f..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterspec.go +++ /dev/null @@ -1,32 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -// DaskClusterSpecApplyConfiguration represents an declarative configuration of the DaskClusterSpec type for use -// with apply. -type DaskClusterSpecApplyConfiguration struct { - Worker *WorkerSpecApplyConfiguration `json:"worker,omitempty"` - Scheduler *SchedulerSpecApplyConfiguration `json:"scheduler,omitempty"` -} - -// DaskClusterSpecApplyConfiguration constructs an declarative configuration of the DaskClusterSpec type for use with -// apply. -func DaskClusterSpec() *DaskClusterSpecApplyConfiguration { - return &DaskClusterSpecApplyConfiguration{} -} - -// WithWorker sets the Worker field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Worker field is set to the value of the last call. -func (b *DaskClusterSpecApplyConfiguration) WithWorker(value *WorkerSpecApplyConfiguration) *DaskClusterSpecApplyConfiguration { - b.Worker = value - return b -} - -// WithScheduler sets the Scheduler field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Scheduler field is set to the value of the last call. -func (b *DaskClusterSpecApplyConfiguration) WithScheduler(value *SchedulerSpecApplyConfiguration) *DaskClusterSpecApplyConfiguration { - b.Scheduler = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go deleted file mode 100644 index 5c5f31d00..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskclusterstatus.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" -) - -// DaskClusterStatusApplyConfiguration represents an declarative configuration of the DaskClusterStatus type for use -// with apply. -type DaskClusterStatusApplyConfiguration struct { - Phase *v1.DaskClusterPhase `json:"phase,omitempty"` -} - -// DaskClusterStatusApplyConfiguration constructs an declarative configuration of the DaskClusterStatus type for use with -// apply. -func DaskClusterStatus() *DaskClusterStatusApplyConfiguration { - return &DaskClusterStatusApplyConfiguration{} -} - -// WithPhase sets the Phase field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Phase field is set to the value of the last call. -func (b *DaskClusterStatusApplyConfiguration) WithPhase(value v1.DaskClusterPhase) *DaskClusterStatusApplyConfiguration { - b.Phase = &value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjob.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjob.go deleted file mode 100644 index e4ef7cf38..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjob.go +++ /dev/null @@ -1,203 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// DaskJobApplyConfiguration represents an declarative configuration of the DaskJob type for use -// with apply. -type DaskJobApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *DaskJobSpecApplyConfiguration `json:"spec,omitempty"` - Status *DaskJobStatusApplyConfiguration `json:"status,omitempty"` -} - -// DaskJob constructs an declarative configuration of the DaskJob type for use with -// apply. -func DaskJob(name, namespace string) *DaskJobApplyConfiguration { - b := &DaskJobApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("DaskJob") - b.WithAPIVersion("kubernetes.dask.org/v1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithKind(value string) *DaskJobApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithAPIVersion(value string) *DaskJobApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithName(value string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithGenerateName(value string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithNamespace(value string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithUID(value types.UID) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithResourceVersion(value string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithGeneration(value int64) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithCreationTimestamp(value metav1.Time) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *DaskJobApplyConfiguration) WithLabels(entries map[string]string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *DaskJobApplyConfiguration) WithAnnotations(entries map[string]string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *DaskJobApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *DaskJobApplyConfiguration) WithFinalizers(values ...string) *DaskJobApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *DaskJobApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithSpec(value *DaskJobSpecApplyConfiguration) *DaskJobApplyConfiguration { - b.Spec = value - return b -} - -// WithStatus sets the Status field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Status field is set to the value of the last call. -func (b *DaskJobApplyConfiguration) WithStatus(value *DaskJobStatusApplyConfiguration) *DaskJobApplyConfiguration { - b.Status = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobspec.go deleted file mode 100644 index afa1f8d63..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobspec.go +++ /dev/null @@ -1,32 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -// DaskJobSpecApplyConfiguration represents an declarative configuration of the DaskJobSpec type for use -// with apply. -type DaskJobSpecApplyConfiguration struct { - Job *JobSpecApplyConfiguration `json:"job,omitempty"` - Cluster *DaskClusterApplyConfiguration `json:"cluster,omitempty"` -} - -// DaskJobSpecApplyConfiguration constructs an declarative configuration of the DaskJobSpec type for use with -// apply. -func DaskJobSpec() *DaskJobSpecApplyConfiguration { - return &DaskJobSpecApplyConfiguration{} -} - -// WithJob sets the Job field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Job field is set to the value of the last call. -func (b *DaskJobSpecApplyConfiguration) WithJob(value *JobSpecApplyConfiguration) *DaskJobSpecApplyConfiguration { - b.Job = value - return b -} - -// WithCluster sets the Cluster field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Cluster field is set to the value of the last call. -func (b *DaskJobSpecApplyConfiguration) WithCluster(value *DaskClusterApplyConfiguration) *DaskJobSpecApplyConfiguration { - b.Cluster = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go deleted file mode 100644 index 387d03976..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskjobstatus.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// DaskJobStatusApplyConfiguration represents an declarative configuration of the DaskJobStatus type for use -// with apply. -type DaskJobStatusApplyConfiguration struct { - ClusterName *string `json:"clusterName,omitempty"` - EndTime *v1.Time `json:"endTime,omitempty"` - JobRunnerPodName *string `json:"jobRunnerPodName,omitempty"` - JobStatus *kubernetesdaskorgv1.JobStatus `json:"jobStatus,omitempty"` - StartTime *v1.Time `json:"startTime,omitempty"` -} - -// DaskJobStatusApplyConfiguration constructs an declarative configuration of the DaskJobStatus type for use with -// apply. -func DaskJobStatus() *DaskJobStatusApplyConfiguration { - return &DaskJobStatusApplyConfiguration{} -} - -// WithClusterName sets the ClusterName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ClusterName field is set to the value of the last call. -func (b *DaskJobStatusApplyConfiguration) WithClusterName(value string) *DaskJobStatusApplyConfiguration { - b.ClusterName = &value - return b -} - -// WithEndTime sets the EndTime field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the EndTime field is set to the value of the last call. -func (b *DaskJobStatusApplyConfiguration) WithEndTime(value v1.Time) *DaskJobStatusApplyConfiguration { - b.EndTime = &value - return b -} - -// WithJobRunnerPodName sets the JobRunnerPodName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the JobRunnerPodName field is set to the value of the last call. -func (b *DaskJobStatusApplyConfiguration) WithJobRunnerPodName(value string) *DaskJobStatusApplyConfiguration { - b.JobRunnerPodName = &value - return b -} - -// WithJobStatus sets the JobStatus field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the JobStatus field is set to the value of the last call. -func (b *DaskJobStatusApplyConfiguration) WithJobStatus(value kubernetesdaskorgv1.JobStatus) *DaskJobStatusApplyConfiguration { - b.JobStatus = &value - return b -} - -// WithStartTime sets the StartTime field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the StartTime field is set to the value of the last call. -func (b *DaskJobStatusApplyConfiguration) WithStartTime(value v1.Time) *DaskJobStatusApplyConfiguration { - b.StartTime = &value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroup.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroup.go deleted file mode 100644 index 7abab72ea..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroup.go +++ /dev/null @@ -1,194 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// DaskWorkerGroupApplyConfiguration represents an declarative configuration of the DaskWorkerGroup type for use -// with apply. -type DaskWorkerGroupApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *DaskWorkerGroupSpecApplyConfiguration `json:"spec,omitempty"` -} - -// DaskWorkerGroup constructs an declarative configuration of the DaskWorkerGroup type for use with -// apply. -func DaskWorkerGroup(name, namespace string) *DaskWorkerGroupApplyConfiguration { - b := &DaskWorkerGroupApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("DaskWorkerGroup") - b.WithAPIVersion("kubernetes.dask.org/v1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithKind(value string) *DaskWorkerGroupApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithAPIVersion(value string) *DaskWorkerGroupApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithName(value string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithGenerateName(value string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithNamespace(value string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithUID(value types.UID) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithResourceVersion(value string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithGeneration(value int64) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithCreationTimestamp(value metav1.Time) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *DaskWorkerGroupApplyConfiguration) WithLabels(entries map[string]string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *DaskWorkerGroupApplyConfiguration) WithAnnotations(entries map[string]string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *DaskWorkerGroupApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *DaskWorkerGroupApplyConfiguration) WithFinalizers(values ...string) *DaskWorkerGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *DaskWorkerGroupApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *DaskWorkerGroupApplyConfiguration) WithSpec(value *DaskWorkerGroupSpecApplyConfiguration) *DaskWorkerGroupApplyConfiguration { - b.Spec = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroupspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroupspec.go deleted file mode 100644 index 84fcbb625..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/daskworkergroupspec.go +++ /dev/null @@ -1,32 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -// DaskWorkerGroupSpecApplyConfiguration represents an declarative configuration of the DaskWorkerGroupSpec type for use -// with apply. -type DaskWorkerGroupSpecApplyConfiguration struct { - Cluster *string `json:"cluster,omitempty"` - Worker *WorkerSpecApplyConfiguration `json:"worker,omitempty"` -} - -// DaskWorkerGroupSpecApplyConfiguration constructs an declarative configuration of the DaskWorkerGroupSpec type for use with -// apply. -func DaskWorkerGroupSpec() *DaskWorkerGroupSpecApplyConfiguration { - return &DaskWorkerGroupSpecApplyConfiguration{} -} - -// WithCluster sets the Cluster field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Cluster field is set to the value of the last call. -func (b *DaskWorkerGroupSpecApplyConfiguration) WithCluster(value string) *DaskWorkerGroupSpecApplyConfiguration { - b.Cluster = &value - return b -} - -// WithWorker sets the Worker field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Worker field is set to the value of the last call. -func (b *DaskWorkerGroupSpecApplyConfiguration) WithWorker(value *WorkerSpecApplyConfiguration) *DaskWorkerGroupSpecApplyConfiguration { - b.Worker = value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/jobspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/jobspec.go deleted file mode 100644 index f531990fb..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/jobspec.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - v1 "k8s.io/api/core/v1" -) - -// JobSpecApplyConfiguration represents an declarative configuration of the JobSpec type for use -// with apply. -type JobSpecApplyConfiguration struct { - Spec *v1.PodSpec `json:"spec,omitempty"` -} - -// JobSpecApplyConfiguration constructs an declarative configuration of the JobSpec type for use with -// apply. -func JobSpec() *JobSpecApplyConfiguration { - return &JobSpecApplyConfiguration{} -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *JobSpecApplyConfiguration) WithSpec(value v1.PodSpec) *JobSpecApplyConfiguration { - b.Spec = &value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/schedulerspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/schedulerspec.go deleted file mode 100644 index 14c570d3a..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/schedulerspec.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - v1 "k8s.io/api/core/v1" -) - -// SchedulerSpecApplyConfiguration represents an declarative configuration of the SchedulerSpec type for use -// with apply. -type SchedulerSpecApplyConfiguration struct { - Spec *v1.PodSpec `json:"spec,omitempty"` - Service *v1.ServiceSpec `json:"service,omitempty"` -} - -// SchedulerSpecApplyConfiguration constructs an declarative configuration of the SchedulerSpec type for use with -// apply. -func SchedulerSpec() *SchedulerSpecApplyConfiguration { - return &SchedulerSpecApplyConfiguration{} -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *SchedulerSpecApplyConfiguration) WithSpec(value v1.PodSpec) *SchedulerSpecApplyConfiguration { - b.Spec = &value - return b -} - -// WithService sets the Service field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Service field is set to the value of the last call. -func (b *SchedulerSpecApplyConfiguration) WithService(value v1.ServiceSpec) *SchedulerSpecApplyConfiguration { - b.Service = &value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/workerspec.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/workerspec.go deleted file mode 100644 index 8ca1bf38a..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1/workerspec.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v1 - -import ( - v1 "k8s.io/api/core/v1" -) - -// WorkerSpecApplyConfiguration represents an declarative configuration of the WorkerSpec type for use -// with apply. -type WorkerSpecApplyConfiguration struct { - Replicas *int `json:"replicas,omitempty"` - Spec *v1.PodSpec `json:"spec,omitempty"` -} - -// WorkerSpecApplyConfiguration constructs an declarative configuration of the WorkerSpec type for use with -// apply. -func WorkerSpec() *WorkerSpecApplyConfiguration { - return &WorkerSpecApplyConfiguration{} -} - -// WithReplicas sets the Replicas field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Replicas field is set to the value of the last call. -func (b *WorkerSpecApplyConfiguration) WithReplicas(value int) *WorkerSpecApplyConfiguration { - b.Replicas = &value - return b -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *WorkerSpecApplyConfiguration) WithSpec(value v1.PodSpec) *WorkerSpecApplyConfiguration { - b.Spec = &value - return b -} diff --git a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go b/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go deleted file mode 100644 index a9955d761..000000000 --- a/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/utils.go +++ /dev/null @@ -1,45 +0,0 @@ -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package applyconfiguration - -import ( - v1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/apis/kubernetes.dask.org/v1" - kubernetesdaskorgv1 "github.com/dask/dask-kubernetes/v2024/dask_kubernetes/operator/go_client/pkg/client/applyconfiguration/kubernetes.dask.org/v1" - schema "k8s.io/apimachinery/pkg/runtime/schema" -) - -// ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no -// apply configuration type exists for the given GroupVersionKind. -func ForKind(kind schema.GroupVersionKind) interface{} { - switch kind { - // Group=kubernetes.dask.org, Version=v1 - case v1.SchemeGroupVersion.WithKind("DaskAutoscaler"): - return &kubernetesdaskorgv1.DaskAutoscalerApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskAutoscalerSpec"): - return &kubernetesdaskorgv1.DaskAutoscalerSpecApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskCluster"): - return &kubernetesdaskorgv1.DaskClusterApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskClusterSpec"): - return &kubernetesdaskorgv1.DaskClusterSpecApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskClusterStatus"): - return &kubernetesdaskorgv1.DaskClusterStatusApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskJob"): - return &kubernetesdaskorgv1.DaskJobApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskJobSpec"): - return &kubernetesdaskorgv1.DaskJobSpecApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskJobStatus"): - return &kubernetesdaskorgv1.DaskJobStatusApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskWorkerGroup"): - return &kubernetesdaskorgv1.DaskWorkerGroupApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("DaskWorkerGroupSpec"): - return &kubernetesdaskorgv1.DaskWorkerGroupSpecApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("JobSpec"): - return &kubernetesdaskorgv1.JobSpecApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("SchedulerSpec"): - return &kubernetesdaskorgv1.SchedulerSpecApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("WorkerSpec"): - return &kubernetesdaskorgv1.WorkerSpecApplyConfiguration{} - - } - return nil -} From cff5cc23bc517b786c754e10b1a3dfdb5210bff9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:37:23 +0000 Subject: [PATCH 48/62] Bump golang.org/x/net from 0.23.0 to 0.33.0 (#929) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.23.0 to 0.33.0. - [Commits](https://github.com/golang/net/compare/v0.23.0...v0.33.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 10 +++++----- go.sum | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 7c2940eb9..13bd70c8b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( k8s.io/api v0.24.1 k8s.io/apimachinery v0.24.1 k8s.io/client-go v0.24.1 - sigs.k8s.io/structured-merge-diff/v4 v4.2.3 ) require ( @@ -30,11 +29,11 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.23.0 // indirect + golang.org/x/net v0.33.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/term v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/term v0.27.0 // indirect + golang.org/x/text v0.21.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect @@ -45,5 +44,6 @@ require ( k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 0c284af4f..e891d06a8 100644 --- a/go.sum +++ b/go.sum @@ -347,8 +347,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -420,12 +420,12 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -435,8 +435,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 30cc719850afb6a5d4482e0df867d2368db000e0 Mon Sep 17 00:00:00 2001 From: Florian Courtial <173065277+fcourtial@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:48:26 +0100 Subject: [PATCH 49/62] =?UTF-8?q?=F0=9F=90=9B=20Fix=20retire=5Fworkers=20L?= =?UTF-8?q?IFO=20fallback=20issue.=20(#931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix LIFO retire_workers (all the workers are deleted). * Smaller u test. --- .../operator/controller/controller.py | 6 ++++- .../controller/tests/test_controller.py | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 19599e59d..05ce09008 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -492,7 +492,11 @@ async def retire_workers( namespace=namespace, label_selector={"dask.org/workergroup-name": worker_group_name}, ) - return [w.name for w in workers[:-n_workers]] + return retire_workers_lifo(workers, n_workers) + + +def retire_workers_lifo(workers, n_workers: int) -> list[str]: + return [w.name for w in workers[-n_workers:]] async def check_scheduler_idle( diff --git a/dask_kubernetes/operator/controller/tests/test_controller.py b/dask_kubernetes/operator/controller/tests/test_controller.py index f8b5822ad..4c758d7e9 100644 --- a/dask_kubernetes/operator/controller/tests/test_controller.py +++ b/dask_kubernetes/operator/controller/tests/test_controller.py @@ -27,6 +27,7 @@ from dask_kubernetes.operator.controller import ( KUBERNETES_DATETIME_FORMAT, get_job_runner_pod_name, + retire_workers_lifo, ) if TYPE_CHECKING: @@ -877,3 +878,24 @@ async def test_create_cluster_validates_name( async with gen_cluster(cluster_name=cluster_name) as (_, ns): actual_status = await _get_cluster_status(k8s_cluster, ns, cluster_name) assert expected_status == actual_status + + +@pytest.mark.anyio +async def test_retire_workers_lifo(): + class Worker: + def __init__(self, name): + self.name = name + + workers = [ + Worker(name="worker-1"), + Worker(name="worker-2"), + Worker(name="worker-3"), + Worker(name="worker-4"), + Worker(name="worker-5"), + ] + + retired_workers = retire_workers_lifo(workers, 2) + + # Verify we got back exactly 2 workers and they are the last ones + assert len(retired_workers) == 2 + assert retired_workers == ["worker-4", "worker-5"] From 4e8ab605dd9a8e03c725e9cbcbcff0719c745b30 Mon Sep 17 00:00:00 2001 From: Carter Fendley Date: Mon, 24 Feb 2025 12:28:48 -0500 Subject: [PATCH 50/62] Reflect that `env` will set on scheduler too (#934) --- dask_kubernetes/operator/kubecluster/kubecluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dask_kubernetes/operator/kubecluster/kubecluster.py b/dask_kubernetes/operator/kubecluster/kubecluster.py index 80aa22249..13ae285a7 100644 --- a/dask_kubernetes/operator/kubecluster/kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/kubecluster.py @@ -75,7 +75,7 @@ class KubeCluster(Cluster): Use ``scale`` to change this number in the future resources: Dict[str, str] env: List[dict] | Dict[str, str] - List of environment variables to pass to worker pod. + List of environment variables to set on scheduler and workers. Can be a list of dicts using the same structure as k8s envs or a single dictionary of key/value pairs worker_command: List[str] | str From 883f88943f41cff9cfb98ebc20fabbf3e32b3148 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 10:14:52 +0000 Subject: [PATCH 51/62] Bump golang.org/x/net from 0.33.0 to 0.36.0 (#935) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.33.0 to 0.36.0. - [Commits](https://github.com/golang/net/compare/v0.33.0...v0.36.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 13bd70c8b..241a17ac1 100644 --- a/go.mod +++ b/go.mod @@ -29,11 +29,11 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.33.0 // indirect + golang.org/x/net v0.36.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/term v0.27.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/term v0.29.0 // indirect + golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index e891d06a8..0d03e9686 100644 --- a/go.sum +++ b/go.sum @@ -347,8 +347,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= +golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -420,12 +420,12 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= -golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= +golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= +golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -435,8 +435,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From ba90177acbc200975fb3f027df2146ada9232890 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 11 Apr 2025 16:57:49 +0100 Subject: [PATCH 52/62] Pin dask-gateway version for tests on older Kubernetes versions (#939) --- dask_kubernetes/conftest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dask_kubernetes/conftest.py b/dask_kubernetes/conftest.py index ce165b9e3..9ebe794c7 100644 --- a/dask_kubernetes/conftest.py +++ b/dask_kubernetes/conftest.py @@ -8,8 +8,10 @@ import uuid from typing import Final, Iterator +import kr8s import pytest from kopf.testing import KopfRunner +from packaging.version import Version from pytest_kind.cluster import KindCluster DIR: Final[pathlib.Path] = pathlib.Path(__file__).parent.absolute() @@ -105,6 +107,7 @@ def namespace(k8s_cluster: KindCluster) -> Iterator[str]: @pytest.fixture(scope="session", autouse=True) def install_gateway(k8s_cluster: KindCluster) -> Iterator[None]: + kube_version = Version(kr8s.version().get("gitVersion")) if bool(os.environ.get("TEST_DASK_GATEWAY", False)): check_dependency("helm") # To ensure the operator can coexist with Gateway @@ -115,6 +118,8 @@ def install_gateway(k8s_cluster: KindCluster) -> Iterator[None]: "dask-gateway", "dask-gateway", "--install", + "--version", + "2024.1.0" if kube_version < Version("1.30.0") else ">=2024.1.0", "--repo=https://helm.dask.org", "--create-namespace", "--namespace", From c544fff43b1d4770c3211799250c7ba9335c1be2 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Mon, 14 Apr 2025 11:07:22 +0100 Subject: [PATCH 53/62] Bump kr8s to v0.20.* (#938) * Bump kr8s to v0.20.* * Switch to async for syntax * Move more things to async for * Revert one accidental async for --- dask_kubernetes/operator/_objects.py | 141 ++++++++++-------- .../operator/controller/controller.py | 26 ++-- .../operator/kubecluster/discovery.py | 3 +- .../operator/kubecluster/kubecluster.py | 6 +- dask_kubernetes/operator/networking.py | 2 +- pyproject.toml | 2 +- 6 files changed, 102 insertions(+), 78 deletions(-) diff --git a/dask_kubernetes/operator/_objects.py b/dask_kubernetes/operator/_objects.py index d9613cda9..dd2fca6c4 100644 --- a/dask_kubernetes/operator/_objects.py +++ b/dask_kubernetes/operator/_objects.py @@ -10,53 +10,65 @@ class DaskCluster(new_class("DaskCluster", "kubernetes.dask.org/v1")): scalable_spec = "worker.replicas" async def worker_groups(self) -> List[DaskWorkerGroup]: - return await DaskWorkerGroup.list( - label_selector=f"dask.org/cluster-name={self.name}", - namespace=self.namespace, - ) + return [ + wg + async for wg in DaskWorkerGroup.list( + label_selector=f"dask.org/cluster-name={self.name}", + namespace=self.namespace, + ) + ] async def scheduler_pod(self) -> Pod: pods = [] while not pods: - pods = await Pod.list( - label_selector=",".join( - [ - f"dask.org/cluster-name={self.name}", - "dask.org/component=scheduler", - ] - ), - namespace=self.namespace, - ) + pods = [ + pod + async for pod in Pod.list( + label_selector=",".join( + [ + f"dask.org/cluster-name={self.name}", + "dask.org/component=scheduler", + ] + ), + namespace=self.namespace, + ) + ] assert len(pods) == 1 return pods[0] async def scheduler_deployment(self) -> Deployment: deployments = [] while not deployments: - deployments = await Deployment.list( - label_selector=",".join( - [ - f"dask.org/cluster-name={self.name}", - "dask.org/component=scheduler", - ] - ), - namespace=self.namespace, - ) + deployments = [ + deployment + async for deployment in Deployment.list( + label_selector=",".join( + [ + f"dask.org/cluster-name={self.name}", + "dask.org/component=scheduler", + ] + ), + namespace=self.namespace, + ) + ] assert len(deployments) == 1 return deployments[0] async def scheduler_service(self) -> Service: services = [] while not services: - services = await Service.list( - label_selector=",".join( - [ - f"dask.org/cluster-name={self.name}", - "dask.org/component=scheduler", - ] - ), - namespace=self.namespace, - ) + services = [ + service + async for service in Service.list( + label_selector=",".join( + [ + f"dask.org/cluster-name={self.name}", + "dask.org/component=scheduler", + ] + ), + namespace=self.namespace, + ) + ] assert len(services) == 1 return services[0] @@ -74,28 +86,34 @@ class DaskWorkerGroup(new_class("DaskWorkerGroup", "kubernetes.dask.org/v1")): scalable_spec = "worker.replicas" async def pods(self) -> List[Pod]: - return await Pod.list( - label_selector=",".join( - [ - f"dask.org/cluster-name={self.spec.cluster}", - "dask.org/component=worker", - f"dask.org/workergroup-name={self.name}", - ] - ), - namespace=self.namespace, - ) + return [ + pod + async for pod in Pod.list( + label_selector=",".join( + [ + f"dask.org/cluster-name={self.spec.cluster}", + "dask.org/component=worker", + f"dask.org/workergroup-name={self.name}", + ] + ), + namespace=self.namespace, + ) + ] async def deployments(self) -> List[Deployment]: - return await Deployment.list( - label_selector=",".join( - [ - f"dask.org/cluster-name={self.spec.cluster}", - "dask.org/component=worker", - f"dask.org/workergroup-name={self.name}", - ] - ), - namespace=self.namespace, - ) + return [ + deployment + async for deployment in Deployment.list( + label_selector=",".join( + [ + f"dask.org/cluster-name={self.spec.cluster}", + "dask.org/component=worker", + f"dask.org/workergroup-name={self.name}", + ] + ), + namespace=self.namespace, + ) + ] async def cluster(self) -> DaskCluster: return await DaskCluster.get(self.spec.cluster, namespace=self.namespace) @@ -113,14 +131,17 @@ async def cluster(self) -> DaskCluster: async def pod(self) -> Pod: pods = [] while not pods: - pods = await Pod.list( - label_selector=",".join( - [ - f"dask.org/cluster-name={self.name}", - "dask.org/component=job-runner", - ] - ), - namespace=self.namespace, - ) + pods = [ + pod + async for pod in Pod.list( + label_selector=",".join( + [ + f"dask.org/cluster-name={self.name}", + "dask.org/component=job-runner", + ] + ), + namespace=self.namespace, + ) + ] assert len(pods) == 1 return pods[0] diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index 05ce09008..cc5df9942 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -487,11 +487,14 @@ async def retire_workers( f"Scaling {worker_group_name} failed via the HTTP API and the Dask RPC, falling back to LIFO scaling. " "This can result in lost data, see https://kubernetes.dask.org/en/latest/operator_troubleshooting.html." ) - workers = await kr8s.asyncio.get( - "deployments", - namespace=namespace, - label_selector={"dask.org/workergroup-name": worker_group_name}, - ) + workers = [ + deployment + async for deployment in kr8s.asyncio.get( + "deployments", + namespace=namespace, + label_selector={"dask.org/workergroup-name": worker_group_name}, + ) + ] return retire_workers_lifo(workers, n_workers) @@ -651,11 +654,14 @@ async def daskworkergroup_replica_update( # the number of workers ends in the correct state async with worker_group_scale_locks[f"{namespace}/{name}"]: current_workers = len( - await kr8s.asyncio.get( - "deployments", - namespace=namespace, - label_selector={"dask.org/workergroup-name": name}, - ) + [ + deployment + async for deployment in kr8s.asyncio.get( + "deployments", + namespace=namespace, + label_selector={"dask.org/workergroup-name": name}, + ) + ] ) assert isinstance(new, int) desired_workers = new diff --git a/dask_kubernetes/operator/kubecluster/discovery.py b/dask_kubernetes/operator/kubecluster/discovery.py index da31b911e..8ce0229b3 100644 --- a/dask_kubernetes/operator/kubecluster/discovery.py +++ b/dask_kubernetes/operator/kubecluster/discovery.py @@ -8,8 +8,7 @@ async def discover() -> AsyncIterator[Tuple[str, Callable]]: try: - clusters = await kr8s.asyncio.get("daskclusters", namespace=kr8s.ALL) - for cluster in clusters: + async for cluster in kr8s.asyncio.get("daskclusters", namespace=kr8s.ALL): yield (cluster.name, KubeCluster) except Exception: return diff --git a/dask_kubernetes/operator/kubecluster/kubecluster.py b/dask_kubernetes/operator/kubecluster/kubecluster.py index 13ae285a7..b5572d8e0 100644 --- a/dask_kubernetes/operator/kubecluster/kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/kubecluster.py @@ -574,13 +574,11 @@ def get_logs(self): async def _get_logs(self): logs = Logs() - pods = await kr8s.asyncio.get( + async for pod in kr8s.asyncio.get( "pods", namespace=self.namespace, label_selector=f"dask.org/cluster-name={self.name}", - ) - - for pod in pods: + ): if "scheduler" in pod.name or "worker" in pod.name: try: if pod.status.phase != "Running": diff --git a/dask_kubernetes/operator/networking.py b/dask_kubernetes/operator/networking.py index 2978889bf..b8d1cff22 100644 --- a/dask_kubernetes/operator/networking.py +++ b/dask_kubernetes/operator/networking.py @@ -54,7 +54,7 @@ async def get_external_address_for_scheduler_service( host = lb.get("hostname", None) or lb.ip elif service.spec.type == "NodePort": port = _get_port(service, port_name, is_node_port=True) - nodes = await kr8s.asyncio.get("nodes") + nodes = [node async for node in kr8s.asyncio.get("nodes")] host = nodes[0].status.addresses[0].address elif service.spec.type == "ClusterIP": port = _get_port(service, port_name) diff --git a/pyproject.toml b/pyproject.toml index c07e127f8..657cffd2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ dependencies = [ "dask>=2022.08.1", "distributed>=2022.08.1", "kopf>=1.35.3", - "kr8s==0.17.*", + "kr8s==0.20.*", "kubernetes-asyncio>=12.0.1", "kubernetes>=12.0.1", "pykube-ng>=22.9.0", From 78499cb67ef0bdb7b48e9b10ca4ec27c9cca9fab Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Thu, 17 Apr 2025 10:32:50 +0100 Subject: [PATCH 54/62] Skip Job cluster creation if already exists (#941) * Skip Job cluster creation if already exists * Bump pre-commit action --- .github/workflows/lint.yaml | 2 +- dask_kubernetes/operator/controller/controller.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 446aa0b0d..d93a1c64f 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -11,4 +11,4 @@ jobs: python-version: "3.10" - name: Install deps run: ./ci/install-deps.sh - - uses: pre-commit/action@v2.0.0 + - uses: pre-commit/action@v3.0.1 diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index cc5df9942..d5de6a702 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -781,10 +781,11 @@ async def daskjob_create_components( ) kopf.adopt(cluster_spec) cluster = await DaskCluster(cluster_spec, namespace=namespace) - await cluster.create() - logger.info( - f"Cluster {cluster_spec['metadata']['name']} for job {name} created in {namespace}." - ) + if not await cluster.exists(): + await cluster.create() + logger.info( + f"Cluster {cluster_spec['metadata']['name']} for job {name} created in {namespace}." + ) labels = _get_labels(meta) annotations = _get_annotations(meta) @@ -804,7 +805,8 @@ async def daskjob_create_components( ) kopf.adopt(job_pod_spec) job_pod = await Pod(job_pod_spec, namespace=namespace) - await job_pod.create() + if not await job_pod.exists(): + await job_pod.create() patch.status["clusterName"] = cluster_name patch.status["jobStatus"] = "ClusterCreated" patch.status["jobRunnerPodName"] = get_job_runner_pod_name(name) From dcdbaf3130d58fb3bd478cb88d7fa582dc360be6 Mon Sep 17 00:00:00 2001 From: Bernhard Stadlbauer <11799671+bstadlbauer@users.noreply.github.com> Date: Thu, 17 Apr 2025 11:34:39 +0200 Subject: [PATCH 55/62] Update pre-commit GH action to 3.0.1 (#943) Co-authored-by: Jacob Tomlinson From 75fe3b9a2dcc8e8ca669225e28aa0bbd5e83854a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 10:55:02 +0100 Subject: [PATCH 56/62] Bump golang.org/x/net from 0.36.0 to 0.38.0 (#942) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.36.0 to 0.38.0. - [Commits](https://github.com/golang/net/compare/v0.36.0...v0.38.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.38.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jacob Tomlinson --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 241a17ac1..1aad429c1 100644 --- a/go.mod +++ b/go.mod @@ -29,11 +29,11 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/sys v0.30.0 // indirect - golang.org/x/term v0.29.0 // indirect - golang.org/x/text v0.22.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/term v0.30.0 // indirect + golang.org/x/text v0.23.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index 0d03e9686..bb4c8ab23 100644 --- a/go.sum +++ b/go.sum @@ -347,8 +347,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= -golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -420,12 +420,12 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= -golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= +golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= +golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -435,8 +435,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 036bd02c26070882bf76b22ba0b82179d8424724 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 22 Apr 2025 21:43:50 +0100 Subject: [PATCH 57/62] Allow configuring the event emit level (#946) --- dask_kubernetes/kubernetes.yaml | 4 ++++ dask_kubernetes/operator/controller/controller.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/dask_kubernetes/kubernetes.yaml b/dask_kubernetes/kubernetes.yaml index bc1f67021..f43d0ab78 100644 --- a/dask_kubernetes/kubernetes.yaml +++ b/dask_kubernetes/kubernetes.yaml @@ -37,6 +37,10 @@ kubernetes: worker-allocation: batch-size: null delay: null + # Configure whether logs should be emitted as Kubernetes events and minimum level to emit + events: + enabled: true + level: INFO # Timeout to wait for the scheduler service to be up (in seconds) # Set it to 0 to wait indefinitely (not recommended) diff --git a/dask_kubernetes/operator/controller/controller.py b/dask_kubernetes/operator/controller/controller.py index d5de6a702..00968d36b 100644 --- a/dask_kubernetes/operator/controller/controller.py +++ b/dask_kubernetes/operator/controller/controller.py @@ -2,6 +2,7 @@ import asyncio import copy +import logging import time from collections import defaultdict from contextlib import suppress @@ -295,6 +296,15 @@ async def startup(settings: kopf.OperatorSettings, **__: Any) -> None: # https://kopf.readthedocs.io/en/latest/configuration/#networking-timeouts settings.networking.request_timeout = 10 + # Configure events + event_enabled = dask.config.get("kubernetes.controller.events.enabled", True) + settings.posting.enabled = event_enabled + event_level = dask.config.get("kubernetes.controller.events.level", "INFO") + if isinstance(event_level, str) and hasattr(logging, event_level): + event_level = getattr(logging, event_level) + if isinstance(event_level, int): + settings.posting.level = event_level + # There may be useful things for us to expose via the liveness probe # https://kopf.readthedocs.io/en/stable/probing/#probe-handlers From 547c911efc58fa003d4cb8d49fcd58a7536fa7e7 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Wed, 23 Apr 2025 10:40:17 +0100 Subject: [PATCH 58/62] Add ability to set additional environment variables on the operator controller (#948) --- .../helm/dask-kubernetes-operator/templates/deployment.yaml | 3 +++ .../deployment/helm/dask-kubernetes-operator/values.yaml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml index 357ecf61f..73cf60a7d 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/templates/deployment.yaml @@ -41,6 +41,9 @@ spec: - name: DASK_KUBERNETES__CONTROLLER__WORKER_ALLOCATION__DELAY value: {{ . | quote }} {{- end }} + {{- with .Values.extraEnv }} + {{- toYaml . | nindent 12 }} + {{- end }} args: - --liveness=http://0.0.0.0:8080/healthz {{- with .Values.kopfArgs }} diff --git a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml index 12e62ecbe..573349926 100644 --- a/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml +++ b/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/values.yaml @@ -46,6 +46,8 @@ volumes: [] # Volumes for the operator pod volumeMounts: [] # Volume mounts for the operator container +extraEnv: [] # Extra environment variables for the operator container + nodeSelector: {} # Node selector tolerations: [] # Tolerations From c9f228b85364d9dc45b6232bad20f74888a935f1 Mon Sep 17 00:00:00 2001 From: Montes-L <70810012+Montes-L@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:40:29 +0200 Subject: [PATCH 59/62] Add instructions for accessing Dask Scheduler Dashboard from JupyterHub (#953) * docs: add instructions for accessing Dask Scheduler dashboard from JupyterHub * Add warning note to docs about using `c.ServerProxy.host_allowlist = lambda app, host: True` for accessing Dask Scheduler Dashboard from Jupyter notebook --------- Co-authored-by: Lilian Montes --- docs/source/installing.rst | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/docs/source/installing.rst b/docs/source/installing.rst index a1d383aa7..047a05710 100644 --- a/docs/source/installing.rst +++ b/docs/source/installing.rst @@ -157,6 +157,88 @@ If you prefer to install the operator from static manifests with ``kubectl`` and $ helm template --include-crds --repo https://helm.dask.org release dask-kubernetes-operator | kubectl apply -f - +Working with JupyterHub +^^^^^^^^^^^^^^^^^^^^^^^^ + +In order to access the Dask Operator’s dashboard with `JupyterHub `_, some additional configuration is needed. + +Configuring JupyterHub Network Policy +""""""""""""""""""""""""""""""""""""" + +The default JupyterHub configuration doesn’t allow communication between notebook pods and the Kubernetes API. +Consider that `kubeconfig` is already `configured for your notebook pods `_, and in order to enable the creation of ``DaskCluster`` resources directly from a notebook, you should add the following section to your JupyterHub ``values.yaml``: + +.. code-block:: yaml + + singleuser: + serviceAccountName: my-serviceaccount + networkPolicy: + enabled: True + ingress: [] + egress: + - ports: + - port: 443 + protocol: TCP + to: + - namespaceSelector: + matchLabels: + name: kube-system + egressAllowRules: + cloudMetadataServer: false + dnsPortsCloudMetadataServer: true + dnsPortsKubeSystemNamespace: true + dnsPortsPrivateIPs: true + nonPrivateIPs: true + privateIPs: true + +Then apply your updated configuration: + +.. code-block:: console + + $ helm upgrade --cleanup-on-fail --install jupyterhub/jupyterhub --namespace -f values.yaml + +And restart your notebook pod: + +.. code-block:: console + + $ kubectl delete po -n jupyter- + +Creating Dask clusters is now possible directly from your notebook. See `KubeCluster `_ for more details. + +Accessing Dask Scheduler Dashboard from JupyterLab +"""""""""""""""""""""""""""""""""""""""""""""""""" + +In order for your notebook pod to reach its own Dask Scheduler’s dashboard, you should add the following files to your JupyterHub configuration: + +.. code-block:: yaml + + singleuser: + extraFiles: + # Allow proxy requests to the Dask Scheduler’s dashboard + jupyter-server-config: + mountPath: /etc/jupyter/jupyter_server_config.py + stringData: | + # WARNING: This setting is inherently insecure and should be used with care. + # Ideally, restrict this to only allow your Dask Scheduler’s domain instead of allowing everything. + c.ServerProxy.host_allowlist = lambda app, host: True + + # Configure the default path to reach Dask Scheduler’s dashboard + dask-dashboard-config: + mountPath: /home/jovyan/.config/dask/distributed.yaml + stringData: | + distributed: + dashboard: + link: "/user/{JUPYTERHUB_USER}/proxy/{host}:{port}/status" + +Then, apply your updated configuration and restart your notebook pod as previously described. + + + +.. warning:: + + Setting `c.ServerProxy.host_allowlist = lambda app, host: True` is inherently insecure and may enable unintended access to other services within your network. + Ideally, you should modify this condition to restrict the host to your Dask Scheduler’s domain or service name (for instance, dask-cluster-name.default.svc.cluster.local) instead of allowing everything. + Kubeflow ^^^^^^^^ From b2099bcdcd0d047ab64c8ef0c360276a8992f660 Mon Sep 17 00:00:00 2001 From: Montes-L <70810012+Montes-L@users.noreply.github.com> Date: Thu, 19 Jun 2025 15:43:40 +0200 Subject: [PATCH 60/62] Docs: Add example of network policy configuration for accessing Dask scheduler dashboard (#955) --- docs/source/installing.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/source/installing.rst b/docs/source/installing.rst index 047a05710..c7122229e 100644 --- a/docs/source/installing.rst +++ b/docs/source/installing.rst @@ -236,8 +236,15 @@ Then, apply your updated configuration and restart your notebook pod as previous .. warning:: - Setting `c.ServerProxy.host_allowlist = lambda app, host: True` is inherently insecure and may enable unintended access to other services within your network. - Ideally, you should modify this condition to restrict the host to your Dask Scheduler’s domain or service name (for instance, dask-cluster-name.default.svc.cluster.local) instead of allowing everything. + Setting ``c.ServerProxy.host_allowlist = lambda app, host: True`` is inherently insecure and may enable unintended access to other services within your network. + Ideally, you should restrict the host to your Dask Scheduler’s namespace or cluster name and namespace (for instance, "."). + However, depending on your configuration, matching by suffix may be sufficient. + For example: + + .. code-block:: python + + # Authorize network flows to the Kubernetes namespace in which your Dask cluster will be deployed. + c.ServerProxy.host_allowlist = lambda app, host: host.endswith('.your-dask-operator-namespace') Kubeflow ^^^^^^^^ From 1daa175f33554549a65530a26300f46368083e7e Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 4 Jul 2025 15:59:06 +0100 Subject: [PATCH 61/62] Bump the minimum kopf version to 1.38.0 (#956) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 657cffd2e..d01ac4911 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ keywords = ["dask", "distributed", "kubernetes"] dependencies = [ "dask>=2022.08.1", "distributed>=2022.08.1", - "kopf>=1.35.3", + "kopf>=1.38.0", "kr8s==0.20.*", "kubernetes-asyncio>=12.0.1", "kubernetes>=12.0.1", From f4e3b1079f643622464fe1c382da58f05fd23821 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Tue, 14 Oct 2025 13:41:19 +0100 Subject: [PATCH 62/62] Update docs theme and remove docs env pins (#963) --- .readthedocs.yaml | 2 +- docs/requirements-docs.txt | 12 +----------- docs/source/conf.py | 4 ++-- docs/source/index.rst | 4 ++-- docs/source/kubecluster_migrating.rst | 2 +- docs/source/operator_extending.rst | 9 +++------ 6 files changed, 10 insertions(+), 23 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 9bfe5114f..0fcc73dbe 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -14,7 +14,7 @@ formats: all build: os: ubuntu-22.04 tools: - python: "3.10" + python: "3.12" python: install: diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 712768175..4579760ad 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -2,15 +2,5 @@ numpydoc sphinx sphinx-reredirects sphinxcontrib-mermaid -dask-sphinx-theme>=3.0.0 +dask-sphinx-theme>=4.0.0 sphinx-helm>=0.2.1 - -# FIXME: This workaround is required until we have sphinx>=5, as enabled by -# dask-sphinx-theme no longer pinning sphinx-book-theme==0.2.0. This is -# tracked in https://github.com/dask/dask-sphinx-theme/issues/68. -# -sphinxcontrib-applehelp<1.0.5 -sphinxcontrib-devhelp<1.0.6 -sphinxcontrib-htmlhelp<2.0.5 -sphinxcontrib-serializinghtml<1.1.10 -sphinxcontrib-qthelp<1.0.7 diff --git a/docs/source/conf.py b/docs/source/conf.py index 821fe85aa..3178dee65 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -79,7 +79,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -112,7 +112,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +html_static_path = [] # Custom sidebar templates, must be a dictionary that maps document names # to template names. diff --git a/docs/source/index.rst b/docs/source/index.rst index 2e11f2141..442949bf9 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -58,11 +58,11 @@ What is the operator? The Dask Operator is a set of custom resources and a controller that runs on your Kubernetes cluster and allows you to create and manage your Dask clusters as Kubernetes resources. Creating clusters can either be done via the :doc:`Kubernetes API with kubectl ` or the :doc:`Python API with KubeCluster `. -To :doc:`install the operator ` you need to apply some custom resource definitions that allow us to describe Dask resources and the operator itself which is a small Python application that +To :doc:`install the operator ` you need to apply some custom resource definitions that allow us to describe Dask resources and the operator itself which is a small Python application that watches the Kubernetes API for events related to our custom resources and creates other resources such as ``Pods`` and ``Services`` accordingly. What resources does the operator manage? ---------------------------------------- +---------------------------------------- The operator manages a hierarchy of resources, some custom resources to represent Dask primitives like clusters and worker groups, and native Kubernetes resources such as pods and services to run the cluster processes and facilitate communication. diff --git a/docs/source/kubecluster_migrating.rst b/docs/source/kubecluster_migrating.rst index 699865341..2fc5ed6c2 100644 --- a/docs/source/kubecluster_migrating.rst +++ b/docs/source/kubecluster_migrating.rst @@ -7,7 +7,7 @@ The classic ``KubeCluster`` class has been replaced with a new version that is b Installing the operator ----------------------- -To use the new implementation of ``KubeCluster`` you need to :doc:`install the Dask operator custom resources and controller `. +To use the new implementation of ``KubeCluster`` you need to :doc:`install the Dask operator custom resources and controller `. The custom resources allow us to describe our Dask cluster components as native Kubernetes resources rather than directly creating ``Pod`` and ``Service`` resources like the classic implementation does. diff --git a/docs/source/operator_extending.rst b/docs/source/operator_extending.rst index 40b58ab14..1002bd4fd 100644 --- a/docs/source/operator_extending.rst +++ b/docs/source/operator_extending.rst @@ -93,11 +93,8 @@ Then you need to ensure that your ``pyproject.toml`` registers the plugin as a ` .. code-block:: toml - ... - - [option.entry_points] - dask_operator_plugin = - my_controller_plugin = my_controller_plugin.plugin + [option.entry-points.dask_operator_plugin] + my_controller_plugin = "my_controller_plugin.plugin" Then you can package this up and push it to your preferred Python package repository. @@ -115,7 +112,7 @@ The controller uses the ``ghcr.io/dask/dask-kubernetes-operator:latest`` contain RUN pip install my-controller-plugin -Then when you :doc:`install the controller deployment ` either via the manifest or with helm you would specify your custom container image instead. +Then when you :doc:`install the controller deployment ` either via the manifest or with helm you would specify your custom container image instead. .. code-block:: bash