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

Commit

Permalink
Merge pull request #32 from PrefectHQ/prep-v0.2.0
Browse files Browse the repository at this point in the history
Prep v0.2.0
  • Loading branch information
zzstoatzz authored Dec 24, 2022
2 parents ce4c08a + 1b5dc26 commit f4c7e73
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/PrefectHQ/prefect-collection-template",
"commit": "61a4158a76515426f7a1736215565d486b379045",
"commit": "6e1088097a7ce4c9156c38dc59ce0b8faa65986f",
"context": {
"cookiecutter": {
"full_name": "Prefect Technologies",
Expand Down
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `KubernetesJob` block for running a Kubernetes job from a manifest - [#28](https://github.com/PrefectHQ/prefect-kubernetes/pull/28)
- `run_namespaced_job` flow allowing easy execution of a well-specified `KubernetesJob` block on a cluster specified by `KubernetesCredentials` - [#28](https://github.com/PrefectHQ/prefect-kubernetes/pull/28)
- `convert_manifest_to_model` utility function for converting a Kubernetes manifest to a model object - [#28](https://github.com/PrefectHQ/prefect-kubernetes/pull/28)

### Changed

### Deprecated
Expand All @@ -23,6 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## 0.2.0

Released December 23, 2022.

### Added
- `KubernetesJob` block for running a Kubernetes job from a manifest - [#28](https://github.com/PrefectHQ/prefect-kubernetes/pull/28)
- `run_namespaced_job` flow allowing easy execution of a well-specified `KubernetesJob` block on a cluster specified by `KubernetesCredentials` - [#28](https://github.com/PrefectHQ/prefect-kubernetes/pull/28)
- `convert_manifest_to_model` utility function for converting a Kubernetes manifest to a model object - [#28](https://github.com/PrefectHQ/prefect-kubernetes/pull/28)

## 0.1.0

Released November 21, 2022.
Expand Down
8 changes: 2 additions & 6 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Getting Started

Now that you've bootstrapped a project, follow the steps below to get started developing your Prefect Collection!

### Python setup

Requires an installation of Python 3.7+
Expand All @@ -10,12 +12,6 @@ We recommend using a Python virtual environment manager such as pipenv, conda or

### GitHub setup

Generate a Prefect Collection project in the terminal:

```bash
cookiecutter https://github.com/PrefectHQ/prefect-collection-template
```

Create a Git respoitory for the newly generated collection and create the first commit:

```bash
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ Note, to use the `load` method on Blocks, you must already have a block document

### Example Usage

#### Use `with_options` to customize options on any existing task or flow

```python
from prefect_kubernetes.flows import run_namespaced_job

customized_run_namespaced_job = run_namespaced_job.with_options(
name="My flow running a Kubernetes Job",
retries=2,
retry_delay_seconds=10,
) # this is now a new flow object that can be called
```

For more tips on how to use tasks and flows in a Collection, check out [Using Collections](https://orion-docs.prefect.io/collections/usage/)!


#### Specify and run a Kubernetes Job from a yaml file

```python
Expand Down
39 changes: 2 additions & 37 deletions prefect_kubernetes/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,12 @@ class KubernetesCredentials(Block):
cluster_config: A `KubernetesClusterConfig` block holding a JSON kube
config for a specific kubernetes context.
Examples:
Example:
Load stored Kubernetes credentials:
```python
from prefect_kubernetes.credentials import KubernetesCredentials
kubernetes_credentials = KubernetesCredentials.load("my-k8s-credentials")
```
Create resource-specific API clients from KubernetesCredentials:
```python
from kubernetes.client.models import AppsV1Api, BatchV1Api, CoreV1Api
from prefect_kubernetes import KubernetesCredentials
kubernetes_credentials = KubernetesCredentials.load("my-k8s-credentials")
with kubernetes_credentials.get_client("apps") as v1_apps_client:
assert isinstance(v1_apps_client, AppsV1Api)
with kubernetes_credentials.get_client("batch") as v1_batch_client:
assert isinstance(v1_batch_client, BatchV1Api)
with kubernetes_credentials.get_client("core") as v1_core_client:
assert isinstance(v1_core_client, CoreV1Api)
```
Create a namespaced job:
```python
from prefect import flow
from prefect_kubernetes import KubernetesCredentials
from prefect_kubernetes.job import create_namespaced_job
from kubernetes.client.models import V1Job
kubernetes_credentials = KubernetesCredentials.load("my-k8s-credentials")
@flow
def kubernetes_orchestrator():
create_namespaced_job(
kubernetes_credentials=kubernetes_credentials,
body=V1Job(**{"metadata": {"name": "my-job"}}),
)
kubernetes_credentials = KubernetesCredentials.load("BLOCK_NAME")
```
"""

Expand Down
2 changes: 1 addition & 1 deletion prefect_kubernetes/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class KubernetesJob(JobBlock):

_block_type_name = "Kubernetes Job"
_block_type_slug = "k8s-job"
_logo_url = "https://images.ctfassets.net/zscdif0zqppk/531JKlIwMeEXcBnoK0yeB8/e304dc11a9d25c831901e9cd668433fa/Kubernetes_logo_without_workmark.svg.png?h=250" # noqa: E501
_logo_url = "https://images.ctfassets.net/zscdif0zqppk/35vNcprr3MmIlkrKxxCiah/1d720b4b50dfa8876198cf21730cf123/Kubernetes_logo_without_workmark.svg.png?h=250" # noqa: E501

async def trigger(self):
"""Create a Kubernetes job and return a `KubernetesJobRun` object."""
Expand Down
22 changes: 22 additions & 0 deletions tests/test_block_standards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from prefect.blocks.core import Block
from prefect.testing.standard_test_suites import BlockStandardTestSuite
from prefect.utilities.dispatch import get_registry_for_type
from prefect.utilities.importtools import to_qualified_name


def find_module_blocks():
blocks = get_registry_for_type(Block)
module_blocks = [
block
for block in blocks.values()
if to_qualified_name(block).startswith("prefect_kubernetes")
]
return module_blocks


@pytest.mark.parametrize("block", find_module_blocks())
class TestAllBlocksAdhereToStandards(BlockStandardTestSuite):
@pytest.fixture
def block(self, block):
return block

0 comments on commit f4c7e73

Please sign in to comment.