From af31ca1735cdfa64b3149c095d4c89f1aa74945c Mon Sep 17 00:00:00 2001 From: Artem Yevsiukov Date: Fri, 23 Aug 2024 12:33:55 +0300 Subject: [PATCH] Updated `katib-controller` (#46) * Updated `katib-controller` * fixed tests --- katib-controller/rockcraft.yaml | 21 +++++------- katib-controller/tests/test_rock.py | 48 +++++++++++++++++++++++++++ katib-controller/tox.ini | 51 +++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 katib-controller/tests/test_rock.py create mode 100644 katib-controller/tox.ini diff --git a/katib-controller/rockcraft.yaml b/katib-controller/rockcraft.yaml index 148bcea..6d681e7 100644 --- a/katib-controller/rockcraft.yaml +++ b/katib-controller/rockcraft.yaml @@ -1,4 +1,4 @@ -# Based on https://github.com/kubeflow/katib/blob/v0.16.0/cmd/katib-controller/v1beta1/Dockerfile +# Based on https://github.com/kubeflow/katib/blob/v0.17.0/cmd/katib-controller/v1beta1/Dockerfile name: katib-controller summary: Katib AutoML Controller description: | @@ -8,10 +8,9 @@ description: | Katib can perform training jobs using any Kubernetes Custom Resources with out of the box support for Kubeflow Training Operator, Argo Workflows, Tekton Pipelines and many more. -version: v0.16.0-22.04-2 +version: v0.17.0 license: Apache-2.0 -build-base: ubuntu@22.04 -base: bare +base: ubuntu@22.04 run-user: _daemon_ services: katib-controller: @@ -27,7 +26,8 @@ parts: plugin: go source: https://github.com/kubeflow/katib source-type: git - source-tag: v0.16.0 + source-tag: v0.17.0 + source-subdir: cmd/katib-controller/v1beta1 build-snaps: - go stage-packages: @@ -37,17 +37,14 @@ parts: - GOOS: "linux" - GOARCH: "amd64" override-build: | - set -xe - cd ${CRAFT_PART_SRC}/ + cd $CRAFT_PART_SRC_WORK go mod download all - go build -a -o katib-controller ./cmd/katib-controller/v1beta1 - install -D -m755 katib-controller ${CRAFT_PART_INSTALL}/katib-controller + go build -a -o ${CRAFT_PART_INSTALL}/katib-controller $CRAFT_PART_SRC_WORK security-team-requirement: plugin: nil override-build: | - # security requirement - # there are no packages installed in `bare` base which is used in this rock mkdir -p ${CRAFT_PART_INSTALL}/usr/share/rocks - (echo "# os-release" && cat /etc/os-release && echo "# dpkg-query") \ + (echo "# os-release" && cat /etc/os-release && echo "# dpkg-query" && \ + dpkg-query --root=${CRAFT_PROJECT_DIR}/../bundles/ubuntu-22.04/rootfs/ -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) \ > ${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query diff --git a/katib-controller/tests/test_rock.py b/katib-controller/tests/test_rock.py new file mode 100644 index 0000000..c6a597b --- /dev/null +++ b/katib-controller/tests/test_rock.py @@ -0,0 +1,48 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. +# +# + +import pytest +import random +import string +import subprocess +from charmed_kubeflow_chisme.rock import CheckRock + + +@pytest.fixture() +def rock_test_env(tmpdir): + """Yields a temporary directory and random docker container name, then cleans them up after.""" + container_name = "".join( + [str(i) for i in random.choices(string.ascii_lowercase, k=8)] + ) + yield tmpdir, container_name + + try: + subprocess.run(["docker", "rm", container_name]) + except Exception: + pass + # tmpdir fixture we use here should clean up the other files for us + + +@pytest.mark.abort_on_fail +def test_rock(rock_test_env): + """Test rock.""" + temp_dir, container_name = rock_test_env + check_rock = CheckRock("rockcraft.yaml") + rock_image = check_rock.get_name() + rock_version = check_rock.get_version() + LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}" + + subprocess.run( + [ + "docker", + "run", + LOCAL_ROCK_IMAGE, + "exec", + "ls", + "-la", + "/katib-controller", + ], + check=True, + ) diff --git a/katib-controller/tox.ini b/katib-controller/tox.ini new file mode 100644 index 0000000..5866c2b --- /dev/null +++ b/katib-controller/tox.ini @@ -0,0 +1,51 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. +[tox] +skipsdist = True +skip_missing_interpreters = True +envlist = pack, export-to-docker, sanity, integration + +[testenv] +setenv = + PYTHONPATH={toxinidir} + PYTHONBREAKPOINT=ipdb.set_trace + +[testenv:pack] +passenv = * +allowlist_externals = + rockcraft +commands = + rockcraft pack + +[testenv:export-to-docker] +passenv = * +allowlist_externals = + bash + skopeo + yq +commands = +# export rock to docker + bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \ + VERSION=$(yq eval .version rockcraft.yaml) && \ + ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \ + ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \ + DOCKER_IMAGE=$NAME:$VERSION && \ + echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \ + skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE' + +[testenv:sanity] +passenv = * +deps = + pytest + charmed-kubeflow-chisme +commands = +# run rock tests + pytest -s -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests + +[testenv:integration] +passenv = * +allowlist_externals = + echo +commands = +# TODO: Implement integration tests here + echo "WARNING: This is a placeholder test - no test is implemented here."