Skip to content

Commit

Permalink
add templating to mlflow deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-scribner committed Mar 4, 2024
1 parent 7600847 commit 08fbd69
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/dss/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
DSS_CLI_MANAGER_LABELS = {"app.kubernetes.io/managed-by": "dss-cli"}

FIELD_MANAGER = "dss-cli"
DSS_NAMESPACE = "dss"
MANIFEST_TEMPLATES_LOCATION = "./manifest_templates"
MLFLOW_DEPLOYMENT_NAME = "mlflow"
15 changes: 11 additions & 4 deletions src/dss/initialize.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
from pathlib import Path

from charmed_kubeflow_chisme.kubernetes import KubernetesResourceHandler
from lightkube import Client
from lightkube.resources.apps_v1 import Deployment
from lightkube.resources.core_v1 import Namespace, PersistentVolumeClaim, Service

from dss.config import DSS_CLI_MANAGER_LABELS, FIELD_MANAGER
from dss.config import DSS_CLI_MANAGER_LABELS, FIELD_MANAGER, MANIFEST_TEMPLATES_LOCATION
from dss.logger import setup_logger
from dss.utils import wait_for_deployment_ready

Expand All @@ -24,13 +25,19 @@ def initialize(lightkube_client: Client) -> None:
None
"""
# Path to the manifests YAML file
manifests_file = os.path.join(os.path.dirname(__file__), "manifests.yaml")

manifests_files = [
Path(
Path(__file__).parent, MANIFEST_TEMPLATES_LOCATION, "dss_core.yaml.j2"
),
Path(
Path(__file__).parent, MANIFEST_TEMPLATES_LOCATION, "mlflow_deployment.yaml.j2"
),
]
# Initialize KubernetesResourceHandler
k8s_resource_handler = KubernetesResourceHandler(
field_manager=FIELD_MANAGER,
labels=DSS_CLI_MANAGER_LABELS,
template_files=[manifests_file],
template_files=manifests_files,
context={},
resource_types={Deployment, Service, PersistentVolumeClaim, Namespace},
lightkube_client=lightkube_client,
Expand Down
7 changes: 7 additions & 0 deletions src/dss/manifest_templates/dss_core.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: {{ namespace }}
labels:
app.kubernetes.io/part-of: dss
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: dss
labels:
app.kubernetes.io/part-of: dss

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mlflow
namespace: dss
name: {{ name }}
namespace: {{ namespace }}
labels:
app.kubernetes.io/name: mlflow
app.kubernetes.io/name: {{ name }}
app.kubernetes.io/part-of: dss
spec:
accessModes:
Expand All @@ -26,21 +19,21 @@ spec:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mlflow
namespace: dss
name: {{ name }}
namespace: {{ namespace }}
labels:
app.kubernetes.io/name: mlflow
app.kubernetes.io/name: {{ name }}
app.kubernetes.io/part-of: dss
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: mlflow
app.kubernetes.io/name: {{ name }}
app.kubernetes.io/part-of: dss
template:
metadata:
labels:
app.kubernetes.io/name: mlflow
app.kubernetes.io/name: {{ name }}
app.kubernetes.io/part-of: dss
spec:
containers:
Expand All @@ -55,20 +48,20 @@ spec:
volumes:
- name: mlflow
persistentVolumeClaim:
claimName: mlflow
claimName: {{ name }}

---
apiVersion: v1
kind: Service
metadata:
name: mlflow
namespace: dss
name: {{ name }}
namespace: {{ namespace }}
labels:
app.kubernetes.io/name: mlflow
app.kubernetes.io/name: {{ name }}
app.kubernetes.io/part-of: dss
spec:
selector:
app.kubernetes.io/name: mlflow
app.kubernetes.io/name: {{ name }}
app.kubernetes.io/part-of: dss
ports:
- protocol: TCP
Expand Down

0 comments on commit 08fbd69

Please sign in to comment.