From 1ab64a0b96366ae266a992a9bbbf2f1abd0bc7e4 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Thu, 18 Apr 2024 22:33:41 +0800 Subject: [PATCH] switch to local_dev_cluster Signed-off-by: Sam Yuan --- .gitignore | 3 +- model_training/custom-cluster/LICENSE | 201 ------------------ model_training/custom-cluster/README.md | 43 ---- model_training/custom-cluster/common.sh | 116 ---------- model_training/custom-cluster/kind/kind.sh | 126 ----------- .../custom-cluster/kind/manifests/kind.yml | 19 -- .../kind/manifests/local-registry.yml | 10 - model_training/custom-cluster/main.sh | 19 -- model_training/custom-cluster/prometheus.sh | 85 -------- model_training/custom-cluster/verify.sh | 76 ------- 10 files changed, 2 insertions(+), 696 deletions(-) delete mode 100644 model_training/custom-cluster/LICENSE delete mode 100644 model_training/custom-cluster/README.md delete mode 100755 model_training/custom-cluster/common.sh delete mode 100755 model_training/custom-cluster/kind/kind.sh delete mode 100644 model_training/custom-cluster/kind/manifests/kind.yml delete mode 100644 model_training/custom-cluster/kind/manifests/local-registry.yml delete mode 100755 model_training/custom-cluster/main.sh delete mode 100755 model_training/custom-cluster/prometheus.sh delete mode 100755 model_training/custom-cluster/verify.sh diff --git a/.gitignore b/.gitignore index 64f90991..1ec8e4db 100644 --- a/.gitignore +++ b/.gitignore @@ -146,4 +146,5 @@ tests/data/isolator_output tests/data/offline_trainer_output tests/data/plot_output model_training/*data* -model_training/tekton/secret \ No newline at end of file +model_training/tekton/secret +local-dev-cluster \ No newline at end of file diff --git a/model_training/custom-cluster/LICENSE b/model_training/custom-cluster/LICENSE deleted file mode 100644 index 261eeb9e..00000000 --- a/model_training/custom-cluster/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/model_training/custom-cluster/README.md b/model_training/custom-cluster/README.md deleted file mode 100644 index 01b8585f..00000000 --- a/model_training/custom-cluster/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# local-dev-cluster - -![GitHub](https://img.shields.io/github/license/sustainable-computing-io/local-dev-cluster) -[![units-test](https://github.com/sustainable-computing-io/local-dev-cluster/actions/workflows/test.yml/badge.svg)](https://github.com/sustainable-computing-io/local-dev-cluster/actions/workflows/test.yml) - -This repo provides the scripts to create a local [kubernetes](kind/kind.sh)/[openshift](microshift/microshift.sh) cluster to be used for development or integration tests. It is also used in [Github action](https://github.com/sustainable-computing-io/kepler-action) for kepler. - -## Prerequisites -- Locate your BCC lib and linux header. -- [`kubectl`](https://dl.k8s.io/release/v1.25.4) - -## Start up -1. Modify kind [config](./kind/manifests/kind.yml) to make sure `extraMounts:` cover the linux header and BCC. -2. Export `CLUSTER_PROVIDER` env variable: -``` -export CLUSTER_PROVIDER=kind/microshift -``` -3. To setup local env run: -``` -./main.sh up -``` -4. To tear down local env run: -``` -./main.sh down -``` -## Container registry -There's a container registry available which is exposed at `localhost:5001`. - -## For kepler contributor -To set up a local cluster for kepler development We need to make the cluster connected with a local container registry. - -### Bump version step for this repo -1. Check kubectl version. -2. Check k8s cluster provider's version(as KIND). -3. Check prometheus operator version. - -## How to contribute to this repo -### A new k8s cluster provider -You are free to ref kind to contribute a k8s cluster, but we will have a checklist as kepler feature. -1. Set up the k8s cluster. -2. The connection between the specific registry and cluster, as for local development usage. We hope to pull the development image to the registry instead of a public registry. -3. Able to get k8s cluster config, for the test case. -4. Mount local path for linux kenerl and ebpf(BCC) inside kepler pod. diff --git a/model_training/custom-cluster/common.sh b/model_training/custom-cluster/common.sh deleted file mode 100755 index b18e2943..00000000 --- a/model_training/custom-cluster/common.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2022 The Kepler Contributors -# - -set -ex -set -o pipefail - -_registry_port="5001" -REGISTRY_PORT=${REGISTRY_PORT:-5001} - -CTR_CMD=${CTR_CMD-docker} -CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-"kind"} - -. ./prometheus.sh -. ./kind/kind.sh -if [ ${CLUSTER_PROVIDER} != "kind" ]; then - . ./microshift/microshift.sh -fi - -# check CPU arch -CPUArch=$(uname -m) -case ${CPUArch} in -x86_64* | i?86_64* | amd64*) - ARCH="amd64" - ;; -ppc64le) - ARCH="ppc64le" - ;; -aarch64* | arm64*) - ARCH="arm64" - ;; -*) - echo "invalid Arch, only support x86_64, ppc64le, aarch64" - exit 1 - ;; -esac - -function _wait_containers_ready { - echo "Waiting for all containers to become ready ..." - namespace=$1 - kubectl wait --for=condition=Ready pod --all -n "$namespace" --timeout 12m -} - -function _get_nodes() { - kubectl get nodes --no-headers -} - -function _get_pods() { - kubectl get pods --all-namespaces --no-headers -} - -function main() { - case $1 in - up) - case $CLUSTER_PROVIDER in - microshift) - _microshift_up - _wait_for_clusterReady - ;; - *) - _kind_up - _wait_for_clusterReady - _run_kind_registry - ;; - esac - echo "cluster is ready" - if [ ${PROMETHEUS_ENABLE} == "true" ] || [ ${PROMETHEUS_ENABLE} == "True" ]; then - _deploy_prometheus_operator - fi - ;; - down) - case $CLUSTER_PROVIDER in - microshift) - _microshift_down - ;; - *) - _kind_down - ;; - esac - ;; - *) - echo "by default set up kind cluster" - _kind_up - _wait_for_clusterReady - _run_kind_registry - echo "cluster is ready" - ;; - esac -} - -function _wait_for_clusterReady() { - kubectl cluster-info - while [ -n "$(_get_pods | grep -v Running)" ]; do - echo "Waiting for all pods to enter the Running state ..." - _get_pods | >&2 grep -v Running || true - sleep 10 - done - _wait_containers_ready kube-system -} - -main "$@" diff --git a/model_training/custom-cluster/kind/kind.sh b/model_training/custom-cluster/kind/kind.sh deleted file mode 100755 index df0da88a..00000000 --- a/model_training/custom-cluster/kind/kind.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2022 The Kepler Contributors -# - -set -ex -set -o pipefail - -kind_registry_name="kind-registry" -KIND_DEFAULT_NETWORK="kind" -KIND_REGISTRY_NAME=${KIND_REGISTRY_NAME:-kind-registry} -CONFIG_PATH="kind" -KIND_VERSION=${KIND_VERSION:-0.20.0} -KIND_MANIFESTS_DIR="$CONFIG_PATH/manifests" -CLUSTER_NAME=${KIND_CLUSTER_NAME:-kind} - -IMAGE_REPO=${IMAGE_REPO:-localhost:5001} -ESTIMATOR_REPO=${ESTIMATOR_REPO:-quay.io/sustainable_computing_io} -MODEL_SERVER_REPO=${MODEL_SERVER_REPO:-quay.io/sustainable_computing_io} - -CONFIG_OUT_DIR=${CONFIG_OUT_DIR:-"_output/generated-manifest"} -KIND_DIR=${KIND_DIR:-"kind"} -rm -rf ${CONFIG_OUT_DIR} -mkdir -p ${CONFIG_OUT_DIR} - -function _wait_kind_up { - echo "Waiting for kind to be ready ..." - - while [ -z "$($CTR_CMD exec --privileged "${CLUSTER_NAME}"-control-plane kubectl --kubeconfig=/etc/kubernetes/admin.conf get nodes -o=jsonpath='{.items..status.conditions[-1:].status}' | grep True)" ]; do - echo "Waiting for kind to be ready ..." - sleep 10 - done - echo "Waiting for dns to be ready ..." - kubectl wait -n kube-system --timeout=12m --for=condition=Ready -l k8s-app=kube-dns pods -} - -function _fetch_kind() { - mkdir -p "${KIND_DIR}" - KIND="${KIND_DIR}"/.kind - if [ -f "$KIND" ]; then - current_kind_version=$($KIND --version | awk '{print $3}') - fi - if [[ $current_kind_version != $KIND_VERSION ]]; then - echo "Downloading kind v$KIND_VERSION" - if [[ "$OSTYPE" == "darwin"* ]]; then - curl -LSs https://github.com/kubernetes-sigs/kind/releases/download/v$KIND_VERSION/kind-darwin-${ARCH} -o "$KIND" - else - curl -LSs https://github.com/kubernetes-sigs/kind/releases/download/v$KIND_VERSION/kind-linux-${ARCH} -o "$KIND" - fi - chmod +x "$KIND" - fi -} - -function _prepare_config() { - echo "Building manifests..." - - cp $KIND_MANIFESTS_DIR/kind.yml "${KIND_DIR}"/kind.yml - sed "s/$kind_registry_name/${KIND_REGISTRY_NAME}/g" "${KIND_DIR}"/kind.yml > "${KIND_DIR}"/kind.yml.tmp && mv "${KIND_DIR}"/kind.yml.tmp "${KIND_DIR}"/kind.yml - sed "s/$_registry_port/${REGISTRY_PORT}/g" "${KIND_DIR}"/kind.yml > "${KIND_DIR}"/kind.yml.tmp && mv "${KIND_DIR}"/kind.yml.tmp "${KIND_DIR}"/kind.yml - - cp $KIND_MANIFESTS_DIR/local-registry.yml "${KIND_DIR}"/local-registry.yml - sed "s/$kind_registry_name/${KIND_REGISTRY_NAME}/g" "${KIND_DIR}"/local-registry.yml > "${KIND_DIR}"/local-registry.yml.tmp && \ - mv "${KIND_DIR}"/local-registry.yml.tmp "${KIND_DIR}"/local-registry.yml - sed "s/$_registry_port/${REGISTRY_PORT}/g" "${KIND_DIR}"/local-registry.yml > "${KIND_DIR}"/local-registry.yml.tmp && \ - mv "${KIND_DIR}"/local-registry.yml.tmp "${KIND_DIR}"/local-registry.yml -} - -function _setup_kind() { - echo "Starting kind with cluster name \"${CLUSTER_NAME}\"" - - $KIND create cluster --name="${CLUSTER_NAME}" -v6 --config=${KIND_DIR}/kind.yml - $KIND get kubeconfig --name="${CLUSTER_NAME}" > ${KIND_DIR}/.kubeconfig - - _wait_kind_up - # wait until k8s pods are running -} - -function _run_kind_registry() { - until [ -z "$($CTR_CMD ps -a | grep "${KIND_REGISTRY_NAME}")" ]; do - $CTR_CMD stop "${KIND_REGISTRY_NAME}" || true - $CTR_CMD rm "${KIND_REGISTRY_NAME}" || true - sleep 5 - done - - $CTR_CMD run \ - -d --restart=always \ - -p "127.0.0.1:${REGISTRY_PORT}:5000" \ - --name "${KIND_REGISTRY_NAME}" \ - registry:2 - # connect the registry to the cluster network if not already connected - $CTR_CMD network connect "${KIND_DEFAULT_NETWORK}" "${KIND_REGISTRY_NAME}" || true - kubectl apply -f "${KIND_DIR}"/local-registry.yml -} - -function _kind_up() { - _fetch_kind - _prepare_config - _setup_kind -} - -function _kind_down() { - _fetch_kind - if [ -z "$($KIND get clusters | grep ${CLUSTER_NAME})" ]; then - return - fi - # Avoid failing an entire test run just because of a deletion error - $KIND delete cluster --name=${CLUSTER_NAME} || "true" - $CTR_CMD rm -f ${KIND_REGISTRY_NAME} >> /dev/null - find ${KIND_DIR} -name kind.yml -maxdepth 1 -delete - find ${KIND_DIR} -name local-registry.yml -maxdepth 1 -delete - find ${KIND_DIR} -name '.*' -maxdepth 1 -delete -} diff --git a/model_training/custom-cluster/kind/manifests/kind.yml b/model_training/custom-cluster/kind/manifests/kind.yml deleted file mode 100644 index fb29f43b..00000000 --- a/model_training/custom-cluster/kind/manifests/kind.yml +++ /dev/null @@ -1,19 +0,0 @@ -kind: Cluster -apiVersion: kind.x-k8s.io/v1alpha4 -networking: - ipFamily: ipv4 -# create a cluster with the local registry enabled in containerd -containerdConfigPatches: -- |- - [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5101"] - endpoint = ["http://kind-registry:5000"] -nodes: - - role: control-plane - extraMounts: - - hostPath: /proc - containerPath: /proc-host - - hostPath: /usr/src - containerPath: /usr/src - extraPortMappings: - - containerPort: 30090 - hostPort: 9090 \ No newline at end of file diff --git a/model_training/custom-cluster/kind/manifests/local-registry.yml b/model_training/custom-cluster/kind/manifests/local-registry.yml deleted file mode 100644 index 1b697b9d..00000000 --- a/model_training/custom-cluster/kind/manifests/local-registry.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: local-registry-hosting - namespace: kube-public -data: - localRegistryHosting.v1: | - host: "localhost:5101" - help: "https://kind.sigs.k8s.io/docs/user/local-registry/" \ No newline at end of file diff --git a/model_training/custom-cluster/main.sh b/model_training/custom-cluster/main.sh deleted file mode 100755 index b0aeac67..00000000 --- a/model_training/custom-cluster/main.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2023 The Kepler Contributors -# -./common.sh $1 diff --git a/model_training/custom-cluster/prometheus.sh b/model_training/custom-cluster/prometheus.sh deleted file mode 100755 index 5521ba91..00000000 --- a/model_training/custom-cluster/prometheus.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2022 The Kepler Contributors -# - -PROMETHEUS_OPERATOR_VERSION=${PROMETHEUS_OPERATOR_VERSION:-v0.11.0} -PROMETHEUS_ENABLE=${PROMETHEUS_ENABLE:-true} -PROMETHEUS_REPLICAS=${PROMETHEUS_REPLICAS:-1} -GRAFANA_ENABLE=${GRAFANA_ENABLE:-false} - - -function _deploy_prometheus_operator { - if [ ! -d $(pwd)/kube-prometheus ] - then - git clone -b "${PROMETHEUS_OPERATOR_VERSION}" --depth 1 https://github.com/prometheus-operator/kube-prometheus.git - fi - sed "s/replicas: 2/replicas: ${PROMETHEUS_REPLICAS}/g" kube-prometheus/manifests/prometheus-prometheus.yaml > \ - kube-prometheus/manifests/prometheus-prometheus.yaml.tmp && mv kube-prometheus/manifests/prometheus-prometheus.yaml.tmp \ - kube-prometheus/manifests/prometheus-prometheus.yaml - - _load_prometheus_operator_images_to_local_registry - - kubectl create -f kube-prometheus/manifests/setup - kubectl wait \ - --for condition=Established \ - --all CustomResourceDefinition \ - --namespace=monitoring - for file in $(ls kube-prometheus/manifests/prometheusOperator-*); do - kubectl create -f "$file" - done - for file in $(ls kube-prometheus/manifests/prometheus-*); do - kubectl create -f $file - done - if [ "${GRAFANA_ENABLE}" == "true" ] || [ "${GRAFANA_ENABLE}" == "True" ]; then - for file in $(ls kube-prometheus/manifests/grafana-*); do - kubectl create -f "$file" - done - fi - rm -rf kube-prometheus - _wait_containers_ready monitoring -} - -function _get_prometheus_operator_images { - grep -R "image:" kube-prometheus/manifests/*prometheus-* | awk '{print $3}' - grep -R "image:" kube-prometheus/manifests/*prometheusOperator* | awk '{print $3}' - grep -R "prometheus-config-reloader=" kube-prometheus/manifests/ | sed 's/.*=//g' - if [ ${GRAFANA_ENABLE} == "true" ] || [ ${GRAFANA_ENABLE} == "True" ] ; then - grep -R "image:" kube-prometheus/manifests/*grafana* | awk '{print $3}' - fi -} - -function _trim_prometheus_operator_image { - echo "${1}" | awk -F "/" '{ print $NF }' -} - -function _load_prometheus_operator_images_to_local_registry { - if [ $CLUSTER_PROVIDER == "kind" ]; then - registry="localhost:${REGISTRY_PORT}" - else - registry="${MICROSHIFT_REGISTRY_NAME}:${REGISTRY_PORT}" - fi - for img in $(_get_prometheus_operator_images); do - $CTR_CMD pull "$img" - updated_image=$(_trim_prometheus_operator_image $img) - $CTR_CMD tag "$img" ${registry}/${updated_image} - $CTR_CMD push ${registry}/${updated_image} - for file in $(grep -R "${img}" kube-prometheus/manifests/* | awk '{print $1}' | cut -d ':' -f 1); do - sed "s#${img}#${registry}/${updated_image}#g" ${file} > "${file}.tmp" && mv "${file}.tmp" "${file}" - done - done -} diff --git a/model_training/custom-cluster/verify.sh b/model_training/custom-cluster/verify.sh deleted file mode 100755 index 645d892c..00000000 --- a/model_training/custom-cluster/verify.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2023 The Kepler Contributors -# -set -x - -NAMESPACE=${NAMESPACE-"monitoring"} - -function rollout_status() { - kubectl rollout status $1 --namespace $2 --timeout=5m || { - echo "fail to check status of ${1} inside namespace ${2}" - exit 1 - } -} - -function verify_bcc() { - # basic check for bcc - if [ $(dpkg -l | grep bcc | wc -l) == 0 ]; then - echo "no bcc package found" - exit 1 - fi -} - -function verify_cluster() { - # basic check for k8s cluster info - if [ $(kubectl cluster-info) !=0 ]; then - echo "fail to get the cluster-info" - exit 1 - fi - - # check k8s system pod is there... - if [ $(kubectl get pods --all-namespaces | wc -l) == 0 ]; then - echo "it seems k8s cluster is not started" - exit 1 - fi - - # check rollout status - resources=$( - kubectl get deployments --namespace=$NAMESPACE -o name - kubectl get statefulsets --namespace=$NAMESPACE -o name - ) - for res in $resources; do - rollout_status $res $NAMESPACE - done -} - -function main() { - # verify the deployment of cluster - case $1 in - bcc) - verify_bcc - ;; - cluster) - verify_cluster - ;; - *) - verify_bcc - verify_cluster - ;; - esac -} -main $1