Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/github/codeql-acti…
Browse files Browse the repository at this point in the history
…on-3
  • Loading branch information
desertaxle authored Mar 12, 2024
2 parents 2a411af + 56a426e commit 4ba9ff7
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 234 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ Any relevant screenshots
- Run `pre-commit install && pre-commit run --all` locally for formatting and linting.
- [ ] Includes screenshots of documentation updates.
- Run `mkdocs serve` view documentation locally.
- [ ] Summarizes PR's changes in [CHANGELOG.md](https://github.com/PrefectHQ/prefect-kubernetes/blob/main/CHANGELOG.md)
2 changes: 1 addition & 1 deletion .github/workflows/kubernetes-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
helm repo update
- name: Create kind cluster
uses: helm/kind-action@v1.7.0
uses: helm/kind-action@v1.9.0
with:
cluster_name: kind
version: v0.18.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
mkdocs build
- name: Publish docs
uses: JamesIves/github-pages-deploy-action@v4.4.3
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
branch: docs
folder: site
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
mkdocs build
- name: Publish docs
uses: JamesIves/github-pages-deploy-action@v4.4.3
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
branch: docs
folder: site
174 changes: 0 additions & 174 deletions CHANGELOG.md

This file was deleted.

17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

<p align="center">
<a href="https://pypi.python.org/pypi/prefect-kubernetes/" alt="PyPI version">
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-kubernetes?color=0052FF&labelColor=090422"></a>
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-kubernetes?color=26272B&labelColor=090422"></a>
<a href="https://github.com/PrefectHQ/prefect-kubernetes/" alt="Stars">
<img src="https://img.shields.io/github/stars/PrefectHQ/prefect-kubernetes?color=0052FF&labelColor=090422" /></a>
<img src="https://img.shields.io/github/stars/PrefectHQ/prefect-kubernetes?color=26272B&labelColor=090422" /></a>
<a href="https://pypistats.org/packages/prefect-kubernetes/" alt="Downloads">
<img src="https://img.shields.io/pypi/dm/prefect-kubernetes?color=0052FF&labelColor=090422" /></a>
<img src="https://img.shields.io/pypi/dm/prefect-kubernetes?color=26272B&labelColor=090422" /></a>
<a href="https://github.com/PrefectHQ/prefect-kubernetes/pulse" alt="Activity">
<img src="https://img.shields.io/github/commit-activity/m/PrefectHQ/prefect-kubernetes?color=0052FF&labelColor=090422" /></a>
<img src="https://img.shields.io/github/commit-activity/m/PrefectHQ/prefect-kubernetes?color=26272B&labelColor=090422" /></a>
<br>
<a href="https://prefect-community.slack.com" alt="Slack">
<img src="https://img.shields.io/badge/slack-join_community-red.svg?color=0052FF&labelColor=090422&logo=slack" /></a>
<a href="https://discourse.prefect.io/" alt="Discourse">
<img src="https://img.shields.io/badge/discourse-browse_forum-red.svg?color=0052FF&labelColor=090422&logo=discourse" /></a>
<img src="https://img.shields.io/badge/slack-join_community-red.svg?color=26272B&labelColor=090422&logo=slack" /></a>

</p>


Expand All @@ -33,7 +32,7 @@ Install `prefect-kubernetes` with `pip`:
pip install prefect-kubernetes
```

Requires an installation of Python 3.7+.
Requires an installation of Python 3.8+.

We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.

Expand All @@ -45,7 +44,7 @@ Then, to register [blocks](https://docs.prefect.io/ui/blocks/) on Prefect Cloud:
prefect block register -m prefect_kubernetes
```

Note, to use the `load` method on Blocks, you must already have a block document [saved through code](https://docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://docs.prefect.io/ui/blocks/).
Note, to use the `load` method on Blocks, you must already have a block document [saved through code](https://docs.prefect.io/concepts/blocks/#saving-blocks) or saved through the UI.


### Example Usage
Expand Down
Binary file modified docs/img/favicon.ico
Binary file not shown.
Binary file removed docs/img/prefect-logo-mark-solid-white-500.png
Binary file not shown.
Binary file added docs/img/prefect-logo-mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/prefect-logo-white.png
Binary file not shown.
18 changes: 9 additions & 9 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* theme */
:root > * {
/* theme */
--md-primary-fg-color: #115AF4;
--md-primary-fg-color--light: #115AF4;
--md-primary-fg-color--dark: #115AF4;
--md-primary-fg-color: #26272B;
--md-primary-fg-color--light: #26272B;
--md-primary-fg-color--dark: #26272B;
}

/* Table formatting */
Expand Down Expand Up @@ -44,9 +44,9 @@ to force column width */
border-radius: 5px;
}

.beta::before {
.experimental::before {
background-color: #FCD14E;
content: "Beta";
content: "Experimental";
}

.cloud::before {
Expand All @@ -72,7 +72,7 @@ to force column width */
/* dark mode slate theme */
/* dark mode code overrides */
[data-md-color-scheme="slate"] {
--md-code-bg-color: #252a33;
--md-code-bg-color: #1c1d20;
--md-code-fg-color: #eee;
--md-code-hl-color: #3b3d54;
--md-code-hl-name-color: #eee;
Expand Down Expand Up @@ -100,15 +100,15 @@ to force column width */

/* dark mode collection catalog overrides */
[data-md-color-scheme="slate"] .collection-item {
background-color: #3b3d54;
background-color: #26272B;
}

/* dark mode recipe collection overrides */
[data-md-color-scheme="slate"] .recipe-item {
background-color: #3b3d54;
background-color: #26272B;
}

/* dark mode API doc overrides */
[data-md-color-scheme="slate"] .prefect-table th {
background-color: #3b3d54;
background-color: #26272B;
}
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ theme:
icon:
repo: fontawesome/brands/github
logo:
img/prefect-logo-mark-solid-white-500.png
img/prefect-logo-mark.png
font:
text: Inter
code: Source Code Pro
Expand Down
31 changes: 23 additions & 8 deletions prefect_kubernetes/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,29 @@ async def wait_for_completion(self):
await sleep(self._kubernetes_job.interval_seconds)
if self._kubernetes_job.timeout_seconds:
elapsed_time += self._kubernetes_job.interval_seconds
elif v1_job_status.status.failed:
raise RuntimeError(
f"Job {v1_job_status.metadata.name!r} failed, check the "
"Kubernetes pod logs for more information."
)
elif v1_job_status.status.succeeded:
self._completed = True
self.logger.info(f"Job {v1_job_status.metadata.name!r} has completed.")
elif v1_job_status.status.conditions:
final_completed_conditions = [
condition.type == "Complete"
for condition in v1_job_status.status.conditions
if condition.status == "True"
]
if final_completed_conditions and any(final_completed_conditions):
self._completed = True
self.logger.info(
f"Job {v1_job_status.metadata.name!r} has "
f"completed with {v1_job_status.status.succeeded} pods."
)
elif final_completed_conditions:
failed_conditions = [
condition.reason
for condition in v1_job_status.status.conditions
if condition.type == "Failed"
]
raise RuntimeError(
f"Job {v1_job_status.metadata.name!r} failed due to "
f"{failed_conditions}, check the Kubernetes pod logs "
f"for more information."
)

if self._kubernetes_job.delete_after_completion:
await self._cleanup()
Expand Down
34 changes: 34 additions & 0 deletions prefect_kubernetes/utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
""" Utilities for working with the Python Kubernetes API. """

import socket
import sys
from pathlib import Path
from typing import Optional, TypeVar, Union

from kubernetes.client import ApiClient
from kubernetes.client import models as k8s_models
from prefect.infrastructure.kubernetes import KubernetesJob, KubernetesManifest
from slugify import slugify
Expand All @@ -13,6 +17,36 @@
V1KubernetesModel = TypeVar("V1KubernetesModel")


def enable_socket_keep_alive(client: ApiClient) -> None:
"""
Setting the keep-alive flags on the kubernetes client object.
Unfortunately neither the kubernetes library nor the urllib3 library which
kubernetes is using internally offer the functionality to enable keep-alive
messages. Thus the flags are added to be used on the underlying sockets.
"""

socket_options = [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)]

if hasattr(socket, "TCP_KEEPINTVL"):
socket_options.append((socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 30))

if hasattr(socket, "TCP_KEEPCNT"):
socket_options.append((socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 6))

if hasattr(socket, "TCP_KEEPIDLE"):
socket_options.append((socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 6))

if sys.platform == "darwin":
# TCP_KEEP_ALIVE not available on socket module in macOS, but defined in
# https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/tcp.h#L215
TCP_KEEP_ALIVE = 0x10
socket_options.append((socket.IPPROTO_TCP, TCP_KEEP_ALIVE, 30))

client.rest_client.pool_manager.connection_pool_kw[
"socket_options"
] = socket_options


def convert_manifest_to_model(
manifest: Union[Path, str, KubernetesManifest], v1_model_name: str
) -> V1KubernetesModel:
Expand Down
Loading

0 comments on commit 4ba9ff7

Please sign in to comment.