Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI action #271

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
file: ./docker/Dockerfile.interlink
platforms: linux/amd64, linux/arm64

virtual-kubelet-refrest-token:
virtual-kubelet-refresh-token:
runs-on: ubuntu-latest
#env:
# DOCKER_TARGET_PLATFORM: linux/arm64
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/build_openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Update OpenAPI

on:
push:
tags:
- '*'

jobs:
update-openapi:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x' # specify the Python version you need

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r example/requirements.txt # if you have a requirements file

- name: Run script to generate OpenAPI JSON
run: python example/create_openapi.py

- name: Create a new release
id: create_release
uses: softprops/action-gh-release@v2
with:
files: docs/openapi/openapi.json
tag_name: ${{ github.ref_name }}
release_name: 'Release ${{ github.ref_name }}'
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


- name: Upload OpenAPI JSON as an artifact
uses: actions/upload-artifact@v4
with:
name: openapi.json
path: ./docs/openapi/openapi.json
2 changes: 1 addition & 1 deletion docs/openapi/openapi.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/create_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@app.post("/create")
async def create_pod(pod: interlink.Pod) -> interlink.CreateStruct:
async def create_pod(pod: List[interlink.Pod]) -> interlink.CreateStruct:
raise NotImplementedError


Expand Down Expand Up @@ -45,4 +45,4 @@ async def get_logs(req: interlink.LogRequest) -> bytes:
routes=app.routes,
),
f,
)
)
18 changes: 9 additions & 9 deletions example/interlink/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ def __init__(
self,
docker_client,
):
self.DOCKER = docker_client
self.CONTAINER_POD_MAP = {}
self.docker = docker_client
self.container_pod_map = {}

def Create(self, pod: Pod) -> CreateStruct:
def create(self, pod: Pod) -> CreateStruct:
raise HTTPException(status_code=500, detail="NOT IMPLEMENTED YET")

def Delete(self, pod: PodRequest) -> None:
def delete(self, pod: PodRequest) -> None:
raise HTTPException(status_code=500, detail="NOT IMPLEMENTED YET")

def Status(self, pod: PodRequest) -> PodStatus:
def status(self, pod: PodRequest) -> PodStatus:
raise HTTPException(status_code=500, detail="NOT IMPLEMENTED YET")

def Logs(self, req: LogRequest) -> bytes:
def logs(self, req: LogRequest) -> bytes:
raise HTTPException(status_code=500, detail="NOT IMPLEMENTED YET")

def create_pod(self, pod: Pod) -> CreateStruct:
try:
self.Create(pod)
self.create(pod)
except Exception as ex:
raise ex

return "Containers created"

def delete_pod(self, pod: PodRequest) -> str:
try:
self.Delete(pod)
self.delete(pod)
except Exception as ex:
raise ex

Expand All @@ -50,4 +50,4 @@ def get_logs(self, req: LogRequest) -> bytes:
except Exception as ex:
raise ex

return logContent
return logContent
92 changes: 46 additions & 46 deletions example/interlink/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class Metadata(BaseModel):
uid: Optional[str] = None
annotations: Optional[Dict[str, str]] = Field({})
labels: Optional[Dict[str, str]] = Field({})
generateName: Optional[str] = None
generate_name: Optional[str] = None


class VolumeMount(BaseModel):
name: str
mountPath: str
subPath: Optional[str] = None
readOnly: Optional[bool] = False
mountPropagation: Optional[str] = None
mount_path: str
sub_path: Optional[str] = None
read_only: Optional[bool] = False
mount_propagation: Optional[str] = None


class ConfigMapKeySelector(BaseModel):
Expand All @@ -33,24 +33,24 @@ class SecretKeySelector(BaseModel):


class EnvVarSource(BaseModel):
configMapKeyRef: Optional[ConfigMapKeySelector] = None
secretKeyRef: Optional[SecretKeySelector] = None
config_map_key_ref: Optional[ConfigMapKeySelector] = None
secret_key_ref: Optional[SecretKeySelector] = None


class EnvVar(BaseModel):
name: str
value: Optional[str] = None
valueFrom: Optional[EnvVarSource] = None
value_from: Optional[EnvVarSource] = None


class SecurityContext(BaseModel):
allowPrivilegeEscalation: Optional[bool] = None
allow_privilege_escalation: Optional[bool] = None
privileged: Optional[bool] = None
procMount: Optional[str] = None
readOnlyFileSystem: Optional[bool] = None
runAsGroup: Optional[int] = None
runAsNonRoot: Optional[bool] = None
runAsUser: Optional[int] = None
proc_mount: Optional[str] = None
read_only_file_system: Optional[bool] = None
run_as_group: Optional[int] = None
run_as_non_root: Optional[bool] = None
run_as_user: Optional[int] = None


class Container(BaseModel):
Expand All @@ -60,9 +60,9 @@ class Container(BaseModel):
command: List[str]
args: Optional[List[str]] = Field([])
resources: Optional[dict] = Field({})
volumeMounts: Optional[List[VolumeMount]] = Field([])
volume_mounts: Optional[List[VolumeMount]] = Field([])
env: Optional[List[EnvVar]] = None
securityContext: Optional[SecurityContext] = None
security_context: Optional[SecurityContext] = None


class KeyToPath(BaseModel):
Expand All @@ -72,17 +72,17 @@ class KeyToPath(BaseModel):


class SecretVolumeSource(BaseModel):
secretName: str
secret_name: str
items: Optional[List[KeyToPath]] = Field([])
optional: Optional[bool] = None
defaultMode: Optional[int] = None
default_mode: Optional[int] = None


class ConfigMapVolumeSource(BaseModel):
name: str
items: Optional[List[KeyToPath]] = Field([])
optional: Optional[bool] = None
defaultMode: Optional[int] = None
default_mode: Optional[int] = None


# class VolumeSource(BaseModel):
Expand All @@ -94,20 +94,20 @@ class ConfigMapVolumeSource(BaseModel):
class PodVolume(BaseModel):
name: str
# volumeSource: Optional[VolumeSource] = None
emptyDir: Optional[dict] = None
empty_dir: Optional[dict] = None
secret: Optional[SecretVolumeSource] = None
configMap: Optional[ConfigMapVolumeSource] = None
config_map: Optional[ConfigMapVolumeSource] = None


class PodSpec(BaseModel):
containers: List[Container]
initContainers: Optional[List[Container]] = None
init_containers: Optional[List[Container]] = None
volumes: Optional[List[PodVolume]] = None
preemptionPolicy: Optional[str] = None
priorityClassName: Optional[str] = None
preemption_policy: Optional[str] = None
priority_class_name: Optional[str] = None
priority: Optional[int] = None
restartPolicy: Optional[str] = None
terminationGracePeriodSeconds: Optional[int] = None
restart_policy: Optional[str] = None
termination_grace_period_seconds: Optional[int] = None


class PodRequest(BaseModel):
Expand All @@ -118,24 +118,24 @@ class PodRequest(BaseModel):
class ConfigMap(BaseModel):
metadata: Metadata
data: Optional[dict]
binaryData: Optional[dict] = None
binary_data: Optional[dict] = None
type: Optional[str] = None
immutable: Optional[bool] = None


class Secret(BaseModel):
metadata: Metadata
data: Optional[dict] = None
stringData: Optional[dict] = None
string_data: Optional[dict] = None
type: Optional[str] = None
immutable: Optional[bool] = None


class Volume(BaseModel):
name: str
configMaps: Optional[List[ConfigMap]] = None
config_maps: Optional[List[ConfigMap]] = None
secrets: Optional[List[Secret]] = None
emptyDirs: Optional[List[str]] = None
empty_dirs: Optional[List[str]] = None


class Pod(BaseModel):
Expand All @@ -144,12 +144,12 @@ class Pod(BaseModel):


class StateTerminated(BaseModel):
exitCode: int
exit_code: int
reason: Optional[str] = None


class StateRunning(BaseModel):
startedAt: Optional[str] = None
started_at: Optional[str] = None


class StateWaiting(BaseModel):
Expand All @@ -170,27 +170,27 @@ class ContainerStatus(BaseModel):

class PodStatus(BaseModel):
name: str
UID: str
uid: str
namespace: str
containers: List[ContainerStatus]


class LogOpts(BaseModel):
Tail: Optional[int] = None
LimitBytes: Optional[int] = None
Timestamps: Optional[bool] = None
Previous: Optional[bool] = None
SinceSeconds: Optional[int] = None
SinceTime: Optional[datetime.datetime] = None
tail: Optional[int] = None
limit_bytes: Optional[int] = None
timestamps: Optional[bool] = None
previous: Optional[bool] = None
since_seconds: Optional[int] = None
since_time: Optional[datetime.datetime] = None


class LogRequest(BaseModel):
Namespace: str
PodUID: str
PodName: str
ContainerName: str
Opts: LogOpts
namespace: str
pod_uid: str
pod_name: str
container_name: str
opts: LogOpts

class CreateStruct(BaseModel):
PodUID: str
PodJID: str
pod_uid: str
pod_jid: str
Loading
Loading