From 765a07dc77111144ff21a4b347cb36428f191ada Mon Sep 17 00:00:00 2001 From: tonyxrmdavidson Date: Fri, 29 Mar 2024 13:28:57 +0000 Subject: [PATCH] This commit removes the need to clone model-registry-operator by creating the config files in model-registry --- .../modelregistry_v1alpha1_modelregistry.yaml | 24 ++++ .../model-registry-operator/mysql-db.yaml | 126 ++++++++++++++++++ openshift-ci/scripts/install_yq.sh | 32 ----- .../scripts/oci-model-registry-deploy.sh | 28 +--- 4 files changed, 155 insertions(+), 55 deletions(-) create mode 100644 openshift-ci/resources/model-registry-operator/modelregistry_v1alpha1_modelregistry.yaml create mode 100644 openshift-ci/resources/model-registry-operator/mysql-db.yaml delete mode 100755 openshift-ci/scripts/install_yq.sh diff --git a/openshift-ci/resources/model-registry-operator/modelregistry_v1alpha1_modelregistry.yaml b/openshift-ci/resources/model-registry-operator/modelregistry_v1alpha1_modelregistry.yaml new file mode 100644 index 00000000..b77ecfdd --- /dev/null +++ b/openshift-ci/resources/model-registry-operator/modelregistry_v1alpha1_modelregistry.yaml @@ -0,0 +1,24 @@ +apiVersion: modelregistry.opendatahub.io/v1alpha1 +kind: ModelRegistry +metadata: + labels: + app.kubernetes.io/name: modelregistry + app.kubernetes.io/instance: modelregistry-sample + app.kubernetes.io/part-of: model-registry-operator + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: model-registry-operator + name: modelregistry-sample +spec: + # TODO(user): Add fields here + grpc: + port: 9090 + rest: + port: 8080 + serviceRoute: enabled + mysql: + host: model-registry-db + database: model_registry + username: mlmduser + passwordSecret: + name: model-registry-db + key: database-password diff --git a/openshift-ci/resources/model-registry-operator/mysql-db.yaml b/openshift-ci/resources/model-registry-operator/mysql-db.yaml new file mode 100644 index 00000000..3fda2ef4 --- /dev/null +++ b/openshift-ci/resources/model-registry-operator/mysql-db.yaml @@ -0,0 +1,126 @@ +apiVersion: v1 +items: +- apiVersion: v1 + kind: Service + metadata: + annotations: + template.openshift.io/expose-uri: mysql://{.spec.clusterIP}:{.spec.ports[?(.name==\mysql\)].port} + name: model-registry-db + spec: + ports: + - name: mysql + nodePort: 0 + port: 3306 + protocol: TCP + targetPort: 3306 + selector: + name: model-registry-db + sessionAffinity: None + type: ClusterIP +- apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: model-registry-db + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +- apiVersion: apps/v1 + kind: Deployment + metadata: + annotations: + template.alpha.openshift.io/wait-for-ready: "true" + name: model-registry-db + spec: + replicas: 1 + revisionHistoryLimit: 0 + selector: + matchLabels: + name: model-registry-db + strategy: + type: Recreate + template: + metadata: + annotations: + sidecar.istio.io/inject: "false" + labels: + name: model-registry-db + spec: + containers: + - env: + - name: MYSQL_USER + valueFrom: + secretKeyRef: + key: database-user + name: model-registry-db + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + key: database-password + name: model-registry-db + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + key: database-password + name: model-registry-db + - name: MYSQL_DATABASE + valueFrom: + secretKeyRef: + key: database-name + name: model-registry-db + args: + - --datadir + - /var/lib/mysql/datadir + - --default-authentication-plugin=mysql_native_password + image: mysql:8.3.0 + imagePullPolicy: IfNotPresent + livenessProbe: + exec: + command: + - /bin/bash + - -c + - mysqladmin -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} ping + initialDelaySeconds: 15 + periodSeconds: 10 + timeoutSeconds: 5 + name: mysql + ports: + - containerPort: 3306 + protocol: TCP + readinessProbe: + exec: + command: + - /bin/bash + - -c + - mysql -D ${MYSQL_DATABASE} -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} -e 'SELECT 1' + initialDelaySeconds: 10 + timeoutSeconds: 5 + securityContext: + capabilities: {} + privileged: false + terminationMessagePath: /dev/termination-log + volumeMounts: + - mountPath: /var/lib/mysql + name: model-registry-db-data + dnsPolicy: ClusterFirst + restartPolicy: Always + volumes: + - name: model-registry-db-data + persistentVolumeClaim: + claimName: model-registry-db +- apiVersion: v1 + kind: Secret + metadata: + annotations: + template.openshift.io/expose-database_name: '{.data[''database-name'']}' + template.openshift.io/expose-password: '{.data[''database-password'']}' + template.openshift.io/expose-username: '{.data[''database-user'']}' + name: model-registry-db + stringData: + database-name: "model_registry" + database-password: "TheBlurstOfTimes" + database-user: "mlmduser" +kind: List +metadata: {} diff --git a/openshift-ci/scripts/install_yq.sh b/openshift-ci/scripts/install_yq.sh deleted file mode 100755 index d389b2ae..00000000 --- a/openshift-ci/scripts/install_yq.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -install_yq_if_not_installed() { - # Check operating system - os=$(uname -s) - case $os in - Linux*) - if ! command -v yq &>/dev/null; then - echo "yq is not installed. Installing..." - # Linux installation using curl - curl -L https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq - else - echo "yq is already installed." - fi - ;; - Darwin*) - if ! command -v yq &>/dev/null; then - echo "yq is not installed. Installing..." - # macOS installation using Homebrew - brew install yq - else - echo "yq is already installed." - fi - ;; - *) - echo "Unsupported operating system: $os" - ;; - esac -} - -# Call the function when the script is sourced -install_yq_if_not_installed \ No newline at end of file diff --git a/openshift-ci/scripts/oci-model-registry-deploy.sh b/openshift-ci/scripts/oci-model-registry-deploy.sh index 5ec44526..9afa6ede 100755 --- a/openshift-ci/scripts/oci-model-registry-deploy.sh +++ b/openshift-ci/scripts/oci-model-registry-deploy.sh @@ -4,9 +4,10 @@ OPENDATAHUB_SUBSCRIPTION="openshift-ci/resources/opendatahub-subscription.yaml" DSC_INITIALIZATION_MANIFEST="openshift-ci/resources/model-registry-DSCInitialization.yaml" DATA_SCIENCE_CLUSTER_MANIFEST="openshift-ci/resources/opendatahub-data-science-cluster.yaml" -MODEL_REGISTRY_OPERATOR_GIT_URL="https://github.com/opendatahub-io/model-registry-operator.git" +MODEL_REGISTRY_DB_MANIFEST="openshift-ci/resources/model-registry-operator/mysql-db.yaml" +MODEL_REGISTRY_SAMPLE_MANIFEST="openshift-ci/resources/model-registry-operator/modelregistry_v1alpha1_modelregistry.yaml" source "openshift-ci/scripts/colour_text_variables.sh" -source "openshift-ci/scripts/install_yq.sh" + # Function to deploy and wait for deployment deploy_and_wait() { @@ -23,26 +24,6 @@ deploy_and_wait() { fi } -# Function to clone a Git repository and deploy the appropriate -clone_deploy_model_registry_operator_crd_files() { - local url="temp_repo/config/samples/mysql/" - local files=("mysql-db.yaml" "modelregistry_v1alpha1_modelregistry.yaml") - # Clone the Git repository - git clone "$MODEL_REGISTRY_OPERATOR_GIT_URL" temp_repo - - #Change the deployment serviceRoute to enabled - yq eval '.spec.rest.serviceRoute = "enabled"' -i "$url${files[1]}" - - # Deploy the model-registry crd files - for file in "${files[@]}"; do - local path_and_file="$url$file" - oc apply -f "$path_and_file" --wait=true --timeout=300s >/tmp/oc_output 2>&1 && rm /tmp/oc_output - done - - # Remove temp_repo - rm -rf temp_repo -} - check_deployment_availability() { local namespace="$1" local deployment="$2" @@ -162,7 +143,8 @@ main() { deploy_and_wait $DSC_INITIALIZATION_MANIFEST check_pod_status "opendatahub" "-l component.opendatahub.io/name=model-registry-operator" 2 deploy_and_wait $DATA_SCIENCE_CLUSTER_MANIFEST - clone_deploy_model_registry_operator_crd_files + deploy_and_wait $MODEL_REGISTRY_DB_MANIFEST + deploy_and_wait $MODEL_REGISTRY_SAMPLE_MANIFEST run_deployment_tests }