Skip to content

Commit

Permalink
Adds other versions of Whereabouts (#9)
Browse files Browse the repository at this point in the history
Added support for versions 0.5.4 and 0.6.1. Added rockcraft.yaml
files based on their Dockerfiles.

Adds /host folder in the rocks. The /install-cni.sh script requires
this folder. It does mkdir it, but the bitnami helm chart creates
the daemonsets with read-only filesystem, making it impossible to
create the folder.
  • Loading branch information
claudiubelu authored Jul 19, 2024
1 parent d2cbe77 commit f73a54f
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 27 deletions.
50 changes: 50 additions & 0 deletions 0.5.4/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Dockerfile: https://github.com/k8snetworkplumbingwg/whereabouts/blob/v0.5.4/Dockerfile
name: whereabouts
summary: Whereabouts rock
description: |
A rock containing Whereabouts, an IP Address Management (IPAM) CNI plugin
that assigns IP addresses cluster-wide.
license: Apache-2.0
version: 0.5.4

base: [email protected]
build-base: [email protected]

platforms:
amd64:
arm64:

environment:
APP_VERSION: 0.5.4

# Services to be loaded by the Pebble entrypoint
services:
install-cni:
override: replace
startup: enabled
command: bash /install-cni.sh
on-success: shutdown
on-failure: shutdown

parts:
build-binary:
plugin: nil
source: https://github.com/k8snetworkplumbingwg/whereabouts.git
source-type: git
source-tag: v${CRAFT_PROJECT_VERSION}
source-depth: 1
build-snaps:
- go/1.16/stable
build-environment:
- GOARCH: $CRAFT_ARCH_BUILD_FOR
override-build: |
bash -x "hack/build-go.sh"
cp bin/* "${CRAFT_PART_INSTALL}/"
cp script/install-cni.sh "${CRAFT_PART_INSTALL}/"
bitnami-compatibility:
plugin: nil
override-build: |
# install-cni.sh requires this folder to exist.
mkdir -p "${CRAFT_PART_INSTALL}/bitnami/whereabouts/host"
ln -sf /bitnami/whereabouts/host "${CRAFT_PART_INSTALL}/host"
50 changes: 50 additions & 0 deletions 0.6.1/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Dockerfile: https://github.com/k8snetworkplumbingwg/whereabouts/blob/v0.6.1Dockerfile
name: whereabouts
summary: Whereabouts rock
description: |
A rock containing Whereabouts, an IP Address Management (IPAM) CNI plugin
that assigns IP addresses cluster-wide.
license: Apache-2.0
version: 0.6.1

base: [email protected]
build-base: [email protected]

platforms:
amd64:
arm64:

environment:
APP_VERSION: 0.6.1

# Services to be loaded by the Pebble entrypoint
services:
install-cni:
override: replace
startup: enabled
command: bash /install-cni.sh
on-success: shutdown
on-failure: shutdown

parts:
build-binary:
plugin: nil
source: https://github.com/k8snetworkplumbingwg/whereabouts.git
source-type: git
source-tag: v${CRAFT_PROJECT_VERSION}
source-depth: 1
build-snaps:
- go/1.19/stable
build-environment:
- GOARCH: $CRAFT_ARCH_BUILD_FOR
override-build: |
bash -x "hack/build-go.sh"
cp bin/* "${CRAFT_PART_INSTALL}/"
cp script/install-cni.sh "${CRAFT_PART_INSTALL}/"
bitnami-compatibility:
plugin: nil
override-build: |
# install-cni.sh requires this folder to exist.
mkdir -p "${CRAFT_PART_INSTALL}/bitnami/whereabouts/host"
ln -sf /bitnami/whereabouts/host "${CRAFT_PART_INSTALL}/host"
File renamed without changes.
1 change: 1 addition & 0 deletions tests/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage[toml]==7.2.5
pytest==7.3.1
PyYAML==6.0.1
tenacity==8.2.3
git+https://github.com/claudiubelu/k8s-test-harness.git@main
54 changes: 27 additions & 27 deletions tests/sanity/test_whereabouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright 2024 Canonical, Ltd.
#
import os
import subprocess

import pytest
from k8s_test_harness.util import docker_util

ROCK_EXPECTED_FILES = [
"/host",
Expand All @@ -14,42 +14,42 @@
]


def _run_in_docker(image, check_exit_code, *command):
return subprocess.run(
[
"docker",
"run",
"--rm",
"-i",
"--entrypoint",
command[0],
image,
*command[1:],
],
check=check_exit_code,
capture_output=True,
text=True,
)


@pytest.mark.abort_on_fail
def test_whereabouts_rock():
def _test_whereabouts_rock(image_variable, expected_files):
"""Test Whereabouts rock."""
image_variable = "ROCK_WHEREABOUTS"
image = os.getenv(image_variable)
assert image is not None, f"${image_variable} is not set"

# check rock filesystem
_run_in_docker(image, True, "ls", "-la", *ROCK_EXPECTED_FILES)
docker_util.ensure_image_contains_paths(image, expected_files)

# check binary name and version.
process = _run_in_docker(image, True, "/whereabouts", "version")
version = docker_util.get_image_version(image)
process = docker_util.run_in_docker(image, True, "/whereabouts", "version")
output = process.stderr
assert "whereabouts" in output and "0.6.3" in output
assert "whereabouts" in output and version in output

# check other binary. It expects KUBERNETES_SERVICE_HOST to be defined.
process = _run_in_docker(image, False, "/ip-control-loop")
process = docker_util.run_in_docker(image, False, "/ip-control-loop")
assert "KUBERNETES_SERVICE_HOST" in process.stderr

# check script. It expects serviceaccount token to exist.
process = _run_in_docker(image, False, "/install-cni.sh")
process = docker_util.run_in_docker(image, False, "/install-cni.sh")
"cat: /var/run/secrets/kubernetes.io/serviceaccount/token: No such file or directory" in process.stderr

# whereabouts:0.5.4 also has a /ip-reconciler
if version == "0.5.4":
process = docker_util.run_in_docker(image, False, "/ip-reconciler")
expected_message = "failed to instantiate the Kubernetes client"
assert expected_message in process.stderr


def test_whereabouts_rock_0_6_3():
_test_whereabouts_rock("ROCK_WHEREABOUTS_0_6_3", ROCK_EXPECTED_FILES)


def test_whereabouts_rock_0_6_1():
_test_whereabouts_rock("ROCK_WHEREABOUTS_0_6_1", ROCK_EXPECTED_FILES)


def test_whereabouts_rock_0_5_4():
_test_whereabouts_rock("ROCK_WHEREABOUTS_0_5_4", ROCK_EXPECTED_FILES + ["/ip-reconciler"])

0 comments on commit f73a54f

Please sign in to comment.