Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
orfeas-k committed Oct 11, 2023
1 parent 9e0742a commit 19c9feb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
17 changes: 17 additions & 0 deletions charms/kfp-metadata-writer/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ resources:
type: oci-image
description: OCI image for KFP Metadata Writer
upstream-source: gcr.io/ml-pipeline/metadata-writer:2.0.1
requires:
grpc:
interface: grpc
schema:
v1:
provides:
type: object
properties:
service:
type: string
port:
type: string
required:
- service
- port
versions: [v1]
__schema_source: https://raw.githubusercontent.com/canonical/operator-schemas/master/grpc.yaml
1 change: 1 addition & 0 deletions charms/kfp-metadata-writer/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
charmed-kubeflow-chisme >= 0.2.0
lightkube
ops
serialized-data-interface
20 changes: 16 additions & 4 deletions charms/kfp-metadata-writer/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
from charmed_kubeflow_chisme.components.charm_reconciler import CharmReconciler
from charmed_kubeflow_chisme.components.kubernetes_component import KubernetesComponent
from charmed_kubeflow_chisme.components.leadership_gate_component import LeadershipGateComponent
from charmed_kubeflow_chisme.components.serialised_data_interface_components import (
SdiRelationDataReceiverComponent,
)
from charmed_kubeflow_chisme.kubernetes import create_charm_default_labels
from lightkube.resources.core_v1 import ServiceAccount
from lightkube.resources.rbac_authorization_v1 import ClusterRole, ClusterRoleBinding
from ops.charm import CharmBase
from ops.main import main

from components.pebble_component import KfpMetadataWriterPebbleService
from components.pebble_component import KfpMetadataWriterPebbleService, KfpMetadataWriterInputs

logger = logging.getLogger(__name__)

Expand All @@ -42,6 +45,13 @@ def __init__(self, *args):
depends_on=[],
)

self.mlmd_relation = self.charm_reconciler.add(
component=SdiRelationDataReceiverComponent(
charm=self, name="relation:grpc", relation_name="grpc"
),
depends_on=[self.leadership_gate],
)

self.kubernetes_resources = self.charm_reconciler.add(
component=KubernetesComponent(
charm=self,
Expand All @@ -65,10 +75,12 @@ def __init__(self, *args):
service_name="kfp-metadata-writer",
namespace_to_watch="",
# TODO: Should be taken from relation to mlmd-operator
metadata_grpc_service_host="metadata-grpc-service",
metadata_grpc_service_port=8080,
inputs_getter=lambda: KfpMetadataWriterInputs(
METADATA_GRPC_SERVICE_SERVICE_HOST=self.mlmd_relation.component.get_data()["service"],
METADATA_GRPC_SERVICE_SERVICE_PORT=self.mlmd_relation.component.get_data()["port"],
),
),
depends_on=[self.kubernetes_resources],
depends_on=[self.kubernetes_resources, self.mlmd_relation],
)

self.charm_reconciler.install_default_event_handlers()
Expand Down
28 changes: 20 additions & 8 deletions charms/kfp-metadata-writer/src/components/pebble_component.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
import dataclasses
import logging

from charmed_kubeflow_chisme.components.pebble_component import PebbleServiceComponent
from ops.pebble import Layer

logger = logging.getLogger(__name__)

@dataclasses.dataclass
class KfpMetadataWriterInputs:
"""Defines the required inputs for KfpMetadataWriterInputs."""
METADATA_GRPC_SERVICE_SERVICE_HOST: str
METADATA_GRPC_SERVICE_SERVICE_PORT: str

class KfpMetadataWriterPebbleService(PebbleServiceComponent):
def __init__(
self,
*args,
namespace_to_watch: str,
metadata_grpc_service_host: str,
metadata_grpc_service_port: int,
**kwargs,
):
"""Pebble service container component in order to configure Pebble layer"""
self.namespace_to_watch = namespace_to_watch
super().__init__(*args, **kwargs)
self.environment = {
"NAMESPACE_TO_WATCH": namespace_to_watch,
"METADATA_GRPC_SERVICE_SERVICE_HOST": metadata_grpc_service_host,
"METADATA_GRPC_SERVICE_SERVICE_PORT": metadata_grpc_service_port,
}


def get_layer(self) -> Layer:
"""Defines and returns Pebble layer configuration
This method is required for subclassing PebbleServiceContainer
"""
logger.info("PebbleServiceComponent.get_layer executing")

try:
inputs: KfpMetadataWriterInputs = self._inputs_getter()
except Exception as err:
raise ValueError("Failed to get inputs for Pebble container.") from err

environment = {
"NAMESPACE_TO_WATCH": self.namespace_to_watch,
"METADATA_GRPC_SERVICE_SERVICE_HOST": inputs.METADATA_GRPC_SERVICE_SERVICE_HOST,
"METADATA_GRPC_SERVICE_SERVICE_PORT": inputs.METADATA_GRPC_SERVICE_SERVICE_PORT,
}
return Layer(
{
"summary": "kfp-metadata-writer layer",
Expand All @@ -41,7 +53,7 @@ def get_layer(self) -> Layer:
"summary": "Entry point for kfp-metadata-writer oci-image",
"command": "python3 -u /kfp/metadata_writer/metadata_writer.py",
"startup": "enabled",
"environment": self.environment,
"environment": environment,
}
},
}
Expand Down

0 comments on commit 19c9feb

Please sign in to comment.