Skip to content

Commit

Permalink
Add support for mariadb (#28)
Browse files Browse the repository at this point in the history
* Add support for mariadb

* Update ocp_utils dependency

* Change TrustyAIService to use DB instead of PVC

* Revert "Ensure observations are registered by Trusty when sending data (#29)"

This reverts commit 75f58a3.

* Reapply "Ensure observations are registered by Trusty when sending data (#29)"

This reverts commit 8fc8c49.

* Update poetry.lock

* Set modelmesh tag to fast
  • Loading branch information
adolfo-ab authored Sep 19, 2024
1 parent 75b23bf commit 5f35f70
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 23 deletions.
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions trustyai_tests/manifests/mariadb-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# TODO: Replace with wrapper resource
kind: MariadbOperator
apiVersion: helm.mariadb.mmontes.io/v1alpha1
metadata:
name: mariadb-operator
namespace: openshift-operators
spec:
affinity: {}
certController:
affinity: {}
caValidity: 35064h
certValidity: 8766h
enabled: true
extrArgs: []
extraVolumeMounts: []
extraVolumes: []
ha:
enabled: false
replicas: 3
image:
pullPolicy: IfNotPresent
repository: ghcr.io/mariadb-operator/mariadb-operator
tag: ''
imagePullSecrets: []
lookaheadValidity: 2160h
nodeSelector: {}
podAnnotations: {}
podSecurityContext: {}
requeueDuration: 5m
resources: {}
securityContext: {}
serviceAccount:
annotations: {}
automount: true
enabled: true
extraLabels: {}
name: ''
serviceMonitor:
additionalLabels: {}
enabled: true
interval: 30s
scrapeTimeout: 25s
tolerations: []
clusterName: cluster.local
extrArgs: []
extraVolumeMounts: []
extraVolumes: []
fullnameOverride: ''
ha:
enabled: false
replicas: 3
image:
pullPolicy: IfNotPresent
repository: ghcr.io/mariadb-operator/mariadb-operator
tag: ''
imagePullSecrets: []
logLevel: INFO
metrics:
enabled: false
serviceMonitor:
additionalLabels: {}
enabled: true
interval: 30s
scrapeTimeout: 25s
nameOverride: ''
nodeSelector: {}
podAnnotations: {}
podSecurityContext: {}
rbac:
enabled: true
resources: {}
securityContext: {}
serviceAccount:
annotations: {}
automount: true
enabled: true
extraLabels: {}
name: ''
tolerations: []
webhook:
affinity: {}
annotations: {}
cert:
caPath: /tmp/k8s-webhook-server/certificate-authority
certManager:
duration: ''
enabled: false
issuerRef: {}
renewBefore: ''
path: /tmp/k8s-webhook-server/serving-certs
secretAnnotations: {}
extrArgs: []
extraVolumeMounts: []
extraVolumes: []
ha:
enabled: false
replicas: 3
hostNetwork: false
image:
pullPolicy: IfNotPresent
repository: ghcr.io/mariadb-operator/mariadb-operator
tag: ''
imagePullSecrets: []
nodeSelector: {}
podAnnotations: {}
podSecurityContext: {}
port: 10250
resources: {}
securityContext: {}
serviceAccount:
annotations: {}
automount: true
enabled: true
extraLabels: {}
name: ''
serviceMonitor:
additionalLabels: {}
enabled: true
interval: 30s
scrapeTimeout: 25s
56 changes: 56 additions & 0 deletions trustyai_tests/manifests/mariadb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# TODO: Replace with wrapper resource
kind: MariaDB
apiVersion: k8s.mariadb.com/v1alpha1
metadata:
name: mariadb
namespace: test-namespace
spec:
connection:
secretName: mariadb-conn
secretTemplate:
key: dsn
database: trustyai_database
galera:
enabled: false
metrics:
enabled: false
passwordSecretKeyRef:
generate: true
key: password
name: mariadb-metrics
myCnf: |
[mariadb]
bind-address=*
default_storage_engine=InnoDB
binlog_format=row
innodb_autoinc_lock_mode=2
innodb_buffer_pool_size=1024M
max_allowed_packet=256M
passwordSecretKeyRef:
generate: false
key: databasePassword
name: db-credentials
primaryConnection:
secretName: mariadb-conn-primary
secretTemplate:
key: dsn
primaryService:
type: ClusterIP
replicas: 1
rootPasswordSecretKeyRef:
generate: false
key: databasePassword
name: db-credentials
secondaryConnection:
secretName: mariadb-conn-secondary
secretTemplate:
key: dsn
secondaryService:
type: ClusterIP
service:
type: ClusterIP
storage:
size: 1Gi
updateStrategy:
type: ReplicasFirstPrimaryLast
username: quarkus
88 changes: 87 additions & 1 deletion trustyai_tests/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from time import sleep
from typing import Any, Generator, Optional

import pytest
import yaml
from kubernetes.dynamic import DynamicClient
from kubernetes.dynamic.exceptions import ConflictError
from ocp_resources.configmap import ConfigMap
from ocp_resources.maria_db import MariaDB
from ocp_resources.namespace import Namespace
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client
Expand All @@ -12,12 +15,18 @@
from ocp_resources.service import Service
from ocp_resources.service_account import ServiceAccount
from ocp_resources.trustyai_service import TrustyAIService
from ocp_resources.mariadb_operator import MariadbOperator
from ocp_utilities.operators import install_operator, uninstall_operator

from trustyai_tests.tests.constants import (
TRUSTYAI_SERVICE,
ODH_OPERATOR,
)
from trustyai_tests.tests.minio import create_minio_secret, create_minio_pod, create_minio_service
from trustyai_tests.tests.utils import (
wait_for_mariadb_operator_pods,
wait_for_mariadb_pods,
)
from trustyai_tests.tests.utils import logger, is_odh_or_rhoai, wait_for_trustyai_pod_running


Expand Down Expand Up @@ -98,6 +107,63 @@ def model_namespace(client: DynamicClient) -> Namespace:
yield ns


@pytest.fixture(scope="class")
def db_credentials(model_namespace):
with Secret(
name="db-credentials",
namespace=model_namespace.name,
string_data={
"databaseKind": "mariadb",
"databaseName": "trustyai_database",
"databaseUsername": "quarkus",
"databasePassword": "quarkus",
"databaseService": "mariadb",
"databasePort": "3306",
"databaseGeneration": "update",
},
) as db_credentials:
yield db_credentials


@pytest.fixture(scope="session")
def mariadb_operator() -> Generator:
client = get_client()
name = "mariadb-operator"
namespace = "openshift-operators"
install_operator(
admin_client=client,
target_namespaces=[namespace],
name=name,
channel="alpha",
source="community-operators",
operator_namespace=namespace,
timeout=600,
install_plan_approval="Manual",
)
sleep(60)
yield
uninstall_operator(admin_client=client, name=name, operator_namespace=namespace, clean_up_namespace=False)


@pytest.fixture(scope="session")
def mariadb_operator_cr(mariadb_operator: None) -> MariadbOperator:
with MariadbOperator(yaml_file="trustyai_tests/manifests/mariadb-operator.yaml") as mariadb_operator:
mariadb_operator.wait_for_condition(
condition="Deployed", status=mariadb_operator.Condition.Status.TRUE, timeout=10 * 60
)
wait_for_mariadb_operator_pods(mariadb_operator=mariadb_operator)
sleep(60)
yield mariadb_operator


@pytest.fixture(scope="class")
def mariadb(model_namespace, db_credentials, mariadb_operator_cr: MariadbOperator) -> MariaDB:
with MariaDB(yaml_file="trustyai_tests/manifests/mariadb.yaml") as mariadb:
wait_for_mariadb_pods(mariadb=mariadb)
sleep(60)
yield mariadb


@pytest.fixture(scope="class")
def modelmesh_serviceaccount(client: DynamicClient, model_namespace: Namespace) -> Any:
with ServiceAccount(client=client, name="modelmesh-serving-sa", namespace=model_namespace.name):
Expand Down Expand Up @@ -137,7 +203,7 @@ def user_workload_monitoring_config(client: DynamicClient) -> ConfigMap:


@pytest.fixture(scope="class")
def trustyai_service(
def trustyai_service_pvc(
client: DynamicClient,
model_namespace: Namespace,
modelmesh_serviceaccount: Any,
Expand All @@ -156,6 +222,26 @@ def trustyai_service(
yield trusty


@pytest.fixture(scope="class")
def trustyai_service_db(
client: DynamicClient,
model_namespace: Namespace,
mariadb,
modelmesh_serviceaccount: Any,
cluster_monitoring_config: ConfigMap,
user_workload_monitoring_config: ConfigMap,
) -> TrustyAIService:
with TrustyAIService(
client=client,
name=TRUSTYAI_SERVICE,
namespace=model_namespace.name,
storage={"format": "DATABASE", "databaseConfigurations": "db-credentials"},
metrics={"schedule": "5s"},
) as trusty:
wait_for_trustyai_pod_running(namespace=model_namespace)
yield trusty


@pytest.fixture(scope="class")
def minio_service(client: DynamicClient, model_namespace: Namespace) -> Generator[Service, Any, None]:
with create_minio_service(namespace=model_namespace) as minio_service:
Expand Down
Loading

0 comments on commit 5f35f70

Please sign in to comment.