Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add controller rock (v0.11.2) #48

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions controller/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Dockerfile https://github.com/kserve/kserve/blob/v0.11.2/Dockerfile
name: kserve-controller
summary: KServe controller
description: "KServe controller manager"
version: "0.11.2"
license: Apache-2.0
base: [email protected]
platforms:
amd64:
run-user: _daemon_

services:
kserve-controller:
override: replace
summary: "KServe controller manager service"
startup: enabled
command: "/manager"

parts:
security-team-requirement:
plugin: nil
override-build: |
mkdir -p ${CRAFT_PART_INSTALL}/usr/share/rocks
(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

controller:
plugin: go
source: https://github.com/kserve/kserve
source-type: git
source-tag: v0.11.2
build-snaps:
- go/1.20/stable
build-environment:
- CGO_ENABLED: 0
- GOOS: linux
override-build: |

# Empty the build directory and copy the build files that are
# specified in the upstream Dockerfile.
rm -rf ./*

# Copy in the go src
cp $CRAFT_PART_SRC/go.mod $CRAFT_PART_SRC/go.sum ./

go mod download

cp -r $CRAFT_PART_SRC/cmd ./cmd
cp -r $CRAFT_PART_SRC/pkg ./pkg

# Build
go build -a -o manager ./cmd/manager
DnPlas marked this conversation as resolved.
Show resolved Hide resolved

# Copy the files to the install directory
cp -r $CRAFT_PART_SRC/third_party/ $CRAFT_PART_INSTALL/third_party/
cp -r manager $CRAFT_PART_INSTALL/manager
27 changes: 27 additions & 0 deletions controller/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import pytest
import subprocess

from charmed_kubeflow_chisme.rock import CheckRock


@pytest.mark.abort_on_fail
def test_rock():
"""Test rock."""
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}"

# assert the rock contains the expected files
subprocess.run(
["docker", "run", LOCAL_ROCK_IMAGE, "exec", "ls", "-la", "/third_party"],
check=True,
)

subprocess.run(
["docker", "run", LOCAL_ROCK_IMAGE, "exec", "ls", "-la", "/manager"],
check=True,
)
54 changes: 54 additions & 0 deletions controller/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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
CHARM_REPO=https://github.com/canonical/kserve-operators.git
CHARM_BRANCH=main
LOCAL_CHARM_DIR=charm_repo

[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."
Loading