Skip to content

Commit

Permalink
Various fixes to ROCK files and integration tests. (#21)
Browse files Browse the repository at this point in the history
* Set registry entrypoint-service for upstream Helm chart compatibility.
* Re-enable integration tests deployments checks.
* Fix postresql 13 binary symlinks for harbor-db:v2.6.3.
* Increase backoff-limit for harbor-jobservice images.
* Switch integration tests to function-scoped fixture for inter-test cleanup.
* Add generous wait period to integration tests.
* Add copyright template.
* Fix formatting for all test files.
* Build trivy parts in sequence to avoid Go version races.
* Ensure harbor_jobservice doesn't crash too quickly for Pebble to restart it.
* Remove integration checks for harbor-trivy StatefulSet.

---------

Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
  • Loading branch information
aznashwan authored Jul 30, 2024
1 parent 29f105f commit 81b3980
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 183 deletions.
1 change: 1 addition & 0 deletions tests/.copyright.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copyright ${years} ${owner}.
1 change: 0 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#
# Copyright 2024 Canonical, Ltd.
# See LICENSE file for licensing details
#
pytest_plugins = ["k8s_test_harness.plugin"]
83 changes: 54 additions & 29 deletions tests/integration/test_harbor_rocks_in_helm_chart.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#
# Copyright 2024 Canonical, Ltd.
# See LICENSE file for licensing details
#

import json
import logging
import sys

import pytest

from k8s_test_harness import harness
from k8s_test_harness.util import constants
from k8s_test_harness.util import env_util
from k8s_test_harness.util import k8s_util
from k8s_test_harness.util import platform_util

from k8s_test_harness.util import constants, env_util, k8s_util, platform_util

LOG: logging.Logger = logging.getLogger(__name__)

Expand All @@ -24,7 +18,8 @@

IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]
CHART_RELEASE_URL = (
"https://github.com/goharbor/harbor-helm/archive/refs/tags/v1.15.0.tar.gz")
"https://github.com/goharbor/harbor-helm/archive/refs/tags/v1.15.0.tar.gz"
)
INSTALL_NAME = "harbor"

# This mapping indicates which fields of the upstream Harbor Helm chart
Expand All @@ -47,7 +42,8 @@

@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_harbor_chart_deployment(
module_instance: harness.Instance, image_version: str):
function_instance: harness.Instance, image_version: str
):

architecture = platform_util.get_current_rockcraft_platform_architecture()

Expand All @@ -60,46 +56,75 @@ def test_harbor_chart_deployment(
# NOTE(aznashwan): GitHub actions UI sometimes truncates env values:
LOG.info(
f"All built rocks metadata from env was: "
f"{json.dumps([rmi.__dict__ for rmi in all_rocks_meta_info])}")
f"{json.dumps([rmi.__dict__ for rmi in all_rocks_meta_info])}"
)

for rmi in all_rocks_meta_info:
if rmi.name in IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP and (
rmi.version == image_version and rmi.arch == architecture):
rmi.version == image_version and rmi.arch == architecture
):
chart_section = IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP[rmi.name]
repo, tag = rmi.image.split(':')
all_chart_value_overrides_args.extend([
"--set", f"{chart_section}.image.repository={repo}",
"--set", f"{chart_section}.image.tag={tag}"
])
repo, tag = rmi.image.split(":")
all_chart_value_overrides_args.extend(
[
"--set",
f"{chart_section}.image.repository={repo}",
"--set",
f"{chart_section}.image.tag={tag}",
]
)
found_env_rocks_metadata.append(rmi.name)

missing = [
img
for img in IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP
if img not in found_env_rocks_metadata]
if img not in found_env_rocks_metadata
]
if missing:
pytest.fail(
f"Failed to find built ROCK metadata for images {missing} "
f"of version '{image_version}' and architecture '{architecture}'. "
f"All built images metadata was: {all_rocks_meta_info}")
f"All built images metadata was: {all_rocks_meta_info}"
)

install_name = f"{INSTALL_NAME}-{image_version.replace('.', '-')}"
helm_command = [
"sudo",
"k8s",
"helm",
"install",
install_name,
INSTALL_NAME,
CHART_RELEASE_URL,
]
helm_command.extend(all_chart_value_overrides_args)

module_instance.exec(helm_command)

# TODO(aznashwan): determine why integration tests don't work on the GH runners:
# deployments = [
# "harbor-core", "harbor-jobservice", "harbor-portal", "harbor-registry"]
# for deployment in deployments:
# k8s_util.wait_for_deployment(
# module_instance, deployment,
# condition=constants.K8S_CONDITION_AVAILABLE)
function_instance.exec(helm_command)

# NOTE(aznashwan): The harbor-jobservice depends on harbor-core which
# depends on harbor-db which needs a PVC allocated for it and also has an
# InitContainer to `chown -R` said PVC, so we add a generous retry period:
retry_kwargs = {"retry_times": 30, "retry_delay_s": 10}

# HACK(aznashwan): the `harbor-trivy` StatefulSet should be in this list
# too, but it consistently fails to have its PVC provisioned on the GitHub
# amd64 runners despite it seemingly working consistently in local testing.
stateful_sets = ["harbor-database", "harbor-redis"]
for stateful_set in stateful_sets:
k8s_util.wait_for_statefulset(
function_instance,
stateful_set,
**retry_kwargs,
)

deployments = [
"harbor-core",
"harbor-jobservice",
"harbor-portal",
"harbor-registry",
]
for deployment in deployments:
k8s_util.wait_for_deployment(
function_instance,
deployment,
condition=constants.K8S_CONDITION_AVAILABLE,
**retry_kwargs,
)
28 changes: 15 additions & 13 deletions tests/sanity/test_harbor_core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
#
# Copyright 2024 Canonical, Ltd.
#

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util

import pytest
from k8s_test_harness.util import docker_util, env_util, platform_util

LOG: logging.Logger = logging.getLogger(__name__)

Expand All @@ -29,27 +27,31 @@ def test_compare_rock_files_to_original(image_version):
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, image_version, architecture)
IMAGE_NAME, image_version, architecture
)
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
original_image, root_dir=dir_to_check)
original_image, root_dir=dir_to_check
)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)
rock_image, root_dir=dir_to_check
)

rock_fileset = set(rock_image_files)
original_fileset = set(original_image_files)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")
f"Missing some files from the original image: " f"{original_extra_files}"
)

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")
f"{rock_extra_files}"
)
18 changes: 8 additions & 10 deletions tests/sanity/test_harbor_db.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
#
# Copyright 2024 Canonical, Ltd.
#

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util

import pytest
from k8s_test_harness.util import docker_util, env_util, platform_util

LOG: logging.Logger = logging.getLogger(__name__)

Expand All @@ -28,7 +26,8 @@ def test_check_rock_contains_files(image_version):
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, image_version, architecture)
IMAGE_NAME, image_version, architecture
)
rock_image = rock_meta.image

image_files_to_check = [
Expand All @@ -40,5 +39,4 @@ def test_check_rock_contains_files(image_version):
"/docker-healthcheck.sh",
"/docker-entrypoint-initdb.d/initial-registry.sql",
]
docker_util.ensure_image_contains_paths(
rock_image, image_files_to_check)
docker_util.ensure_image_contains_paths(rock_image, image_files_to_check)
28 changes: 15 additions & 13 deletions tests/sanity/test_harbor_exporter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
#
# Copyright 2024 Canonical, Ltd.
#

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util

import pytest
from k8s_test_harness.util import docker_util, env_util, platform_util

LOG: logging.Logger = logging.getLogger(__name__)

Expand All @@ -29,27 +27,31 @@ def test_compare_rock_files_to_original(image_version):
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, image_version, architecture)
IMAGE_NAME, image_version, architecture
)
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
original_image, root_dir=dir_to_check)
original_image, root_dir=dir_to_check
)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)
rock_image, root_dir=dir_to_check
)

rock_fileset = set(rock_image_files)
original_fileset = set(original_image_files)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")
f"Missing some files from the original image: " f"{original_extra_files}"
)

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")
f"{rock_extra_files}"
)
28 changes: 15 additions & 13 deletions tests/sanity/test_harbor_jobservice.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
#
# Copyright 2024 Canonical, Ltd.
#

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util

import pytest
from k8s_test_harness.util import docker_util, env_util, platform_util

LOG: logging.Logger = logging.getLogger(__name__)

Expand All @@ -29,27 +27,31 @@ def test_compare_rock_files_to_original(image_version):
original_image = f"docker.io/goharbor/{IMAGE_NAME}:{image_version}"

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, image_version, architecture)
IMAGE_NAME, image_version, architecture
)
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
original_image, root_dir=dir_to_check)
original_image, root_dir=dir_to_check
)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)
rock_image, root_dir=dir_to_check
)

rock_fileset = set(rock_image_files)
original_fileset = set(original_image_files)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")
f"Missing some files from the original image: " f"{original_extra_files}"
)

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")
f"{rock_extra_files}"
)
Loading

0 comments on commit 81b3980

Please sign in to comment.