Skip to content

Commit

Permalink
Updates examples to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
petermorrowdev committed Apr 10, 2024
1 parent f831459 commit cef82c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
39 changes: 15 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ that makes it easier to develop modest kubernetes deployments.

## Reqiurements

Python 3.7+

Gybe uses [pydantic](https://github.com/samuelcolvin/pydantic) for type-hint
validation and [click](https://github.com/pallets/click) for the CLI.
Python 3.10+

## Install

Expand All @@ -25,7 +22,7 @@ pip install gybe
Create a simple `values.yaml` file:

```yaml
image: python:3.9
image: python:3
command:
- python
- -m
Expand All @@ -35,35 +32,29 @@ command:
Create a `chart.py` file:

```python
from typing import List
from gybe.favorites.kubernetes import Pod, PodSpec, Container
import gybe
def create_standard_container(image: str, command: List[str]) -> Container:
return Container(image=image, command=command, name='standard-server')
def create_standard_container(image: str, command: List[str]):
return gybe.k8s.Container(image=image, command=command, name='my-python-server')
@gybe.transpiler
def two_pods(image: str, command: List[str], port: int=8080) -> gybe.Manifest:
pod_spec = PodSpec(
containers=[
create_standard_container(image=image, command=command)
],
ports=[dict(port=port)]
def two_pods(image: str, command: list[str]) -> gybe.Manifest:
pod_spec = gybe.k8s.PodSpec(
containers=[create_standard_container(image=image, command=command)],
)
return [
Pod(
gybe.k8s.Pod(
kind='Pod',
apiVersion='v1',
metadata=dict(name='pod-1'),
metadata=gybe.k8s.ObjectMeta(name='pod-1'),
spec=pod_spec,
),
Pod(
gybe.k8s.Pod(
kind='Pod',
apiVersion='v1',
metadata=dict(name='pod-2'),
metadata=gybe.k8s.ObjectMeta(name='pod-2'),
spec=pod_spec,
),
]
Expand All @@ -90,8 +81,8 @@ spec:
- python
- -m
- http.server
image: python:3.9
name: standard-server
image: python:3
name: my-python-server
---
apiVersion: v1
kind: Pod
Expand All @@ -103,8 +94,8 @@ spec:
- python
- -m
- http.server
image: python:3.9
name: standard-server
image: python:3
name: my-python-server
```

If you're feeling lucky, you can pipe that into `kubectl`:
Expand Down
14 changes: 6 additions & 8 deletions tests/test_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import List

import gybe


def create_standard_container(image: str, command: List[str]):
def create_standard_container(image: str, command: list[str]):
return gybe.k8s.Container(image=image, command=command, name='standard-server')


@gybe.transpiler
def two_pods(image: str, command: List[str], port: int = 8080) -> gybe.Manifest:
def two_pods(image: str, command: list[str], port: int = 8080) -> gybe.Manifest:
pod_spec = gybe.k8s.PodSpec(
containers=[create_standard_container(image=image, command=command)],
)
Expand All @@ -29,7 +27,7 @@ def two_pods(image: str, command: List[str], port: int = 8080) -> gybe.Manifest:


VALID_TWO_POD_YAML = """
image: python:3.9
image: python:3
command:
- python
- -m
Expand All @@ -47,7 +45,7 @@ def two_pods(image: str, command: List[str], port: int = 8080) -> gybe.Manifest:
- python
- -m
- http.server
image: python:3.9
image: python:3
name: standard-server
---
apiVersion: v1
Expand All @@ -60,12 +58,12 @@ def two_pods(image: str, command: List[str], port: int = 8080) -> gybe.Manifest:
- python
- -m
- http.server
image: python:3.9
image: python:3
name: standard-server
"""

INVALID_VALID_TWO_POD_YAML = """
image: python:3.9
image: python:3
command: false
"""

Expand Down

0 comments on commit cef82c4

Please sign in to comment.