Skip to content

Commit

Permalink
Updated katib-controller (#46)
Browse files Browse the repository at this point in the history
* Updated `katib-controller`

* fixed tests
  • Loading branch information
TakoB222 authored Aug 23, 2024
1 parent 92cd6d9 commit af31ca1
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 12 deletions.
21 changes: 9 additions & 12 deletions katib-controller/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -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: |
Expand All @@ -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: [email protected]
base: bare
base: [email protected]
run-user: _daemon_
services:
katib-controller:
Expand All @@ -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:
Expand All @@ -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
48 changes: 48 additions & 0 deletions katib-controller/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -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,
)
51 changes: 51 additions & 0 deletions katib-controller/tox.ini
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit af31ca1

Please sign in to comment.