-
Notifications
You must be signed in to change notification settings - Fork 9
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
test: Add integration tests for Kubernetes docker-registry deployment #328
base: main
Are you sure you want to change the base?
Changes from all commits
2d1aa64
8252951
020cb77
d9177d5
ed102c5
08b2a3d
429cc30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2025 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
apiVersion: v1 | ||
bschimke95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kind: Pod | ||
metadata: | ||
name: test-pod | ||
spec: | ||
containers: | ||
- name: test-container | ||
#image: set by test | ||
command: ["sleep", "100"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2025 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
name: integration-test-docker-registry | ||
description: |- | ||
Used to deploy or refresh within an integration test model | ||
series: jammy | ||
applications: | ||
k8s: | ||
charm: k8s | ||
constraints: cores=2 mem=8G root-disk=16G | ||
num_units: 1 | ||
docker-registry: | ||
charm: docker-registry | ||
channel: latest/edge | ||
num_units: 1 |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||||||
#!/usr/bin/env python3 | ||||||||||
|
||||||||||
# Copyright 2025 Canonical Ltd. | ||||||||||
# See LICENSE file for licensing details. | ||||||||||
|
||||||||||
# pylint: disable=duplicate-code | ||||||||||
"""Integration tests.""" | ||||||||||
|
||||||||||
import json | ||||||||||
import logging | ||||||||||
import random | ||||||||||
import string | ||||||||||
from pathlib import Path | ||||||||||
from typing import List | ||||||||||
|
||||||||||
import pytest | ||||||||||
import yaml | ||||||||||
from juju import model | ||||||||||
from kubernetes.utils import create_from_yaml | ||||||||||
|
||||||||||
from . import helpers | ||||||||||
|
||||||||||
# This pytest mark configures the test environment to use the Canonical Kubernetes | ||||||||||
# bundle with ceph, for all the test within this module. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment does not fit |
||||||||||
pytestmark = [ | ||||||||||
pytest.mark.bundle(file="test_registries/test-bundle-docker-registry.yaml", apps_local=["k8s"]) | ||||||||||
] | ||||||||||
|
||||||||||
log = logging.getLogger(__name__) | ||||||||||
|
||||||||||
|
||||||||||
def _get_data_file_path(name) -> Path: | ||||||||||
"""Retrieve the full path of the specified test data file.""" | ||||||||||
return Path(__file__).parent / "data" / "test_registries" / name | ||||||||||
Comment on lines
+32
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this can just be a
Suggested change
|
||||||||||
|
||||||||||
|
||||||||||
@pytest.mark.abort_on_fail | ||||||||||
async def test_custom_registry(kubernetes_cluster: model.Model, api_client): | ||||||||||
"""Test that the charm configures the correct directory and can access a custom registry.""" | ||||||||||
# List of resources created during the test | ||||||||||
created: List = [] | ||||||||||
eaudetcobello marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
docker_registry_unit = kubernetes_cluster.applications["docker-registry"].units[0] | ||||||||||
docker_registry_ip = await docker_registry_unit.get_public_address() | ||||||||||
|
||||||||||
config_string = json.dumps( | ||||||||||
[{"url": f"http://{docker_registry_ip}:5000", "host": f"{docker_registry_ip}:5000"}] | ||||||||||
) | ||||||||||
|
||||||||||
custom_registry_config = {"containerd-custom-registries": config_string} | ||||||||||
|
||||||||||
await kubernetes_cluster.applications["k8s"].set_config(custom_registry_config) | ||||||||||
await kubernetes_cluster.wait_for_idle(status="active") | ||||||||||
|
||||||||||
action = await docker_registry_unit.run_action("push", image="busybox:latest", pull=True) | ||||||||||
await action.wait() | ||||||||||
|
||||||||||
# Create a pod that uses the busybox image from the custom registry | ||||||||||
# Image: {docker_registry_ip}:5000/busybox:latest | ||||||||||
test_pod_manifest = list(yaml.safe_load_all(_get_data_file_path("pod.yaml").open())) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's inline this path. It is only used once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
random_pod_name = "test-pod-" + "".join( | ||||||||||
random.choices(string.ascii_lowercase + string.digits, k=5) | ||||||||||
) | ||||||||||
test_pod_manifest[0]["metadata"]["name"] = random_pod_name | ||||||||||
|
||||||||||
test_pod_manifest[0]["spec"]["containers"][0]["image"] = ( | ||||||||||
f"{docker_registry_ip}:5000/busybox:latest" | ||||||||||
) | ||||||||||
|
||||||||||
k8s_unit = kubernetes_cluster.applications["k8s"].units[0] | ||||||||||
try: | ||||||||||
created.extend(*create_from_yaml(api_client, yaml_objects=test_pod_manifest)) | ||||||||||
eaudetcobello marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
await helpers.wait_pod_phase(k8s_unit, random_pod_name, "Running") | ||||||||||
finally: | ||||||||||
# Cleanup | ||||||||||
for resource in created: | ||||||||||
kind = resource.kind | ||||||||||
name = resource.metadata.name | ||||||||||
event = await k8s_unit.run(f"k8s kubectl delete {kind} {name}") | ||||||||||
_ = await event.wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addyess why do we need to explicitly list each test? That feels like it just waits to be forgotten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operator workflows run a unique gh runner for every item in this list. We run all the tests on a unique runner for these 5 test modules b/c they deploy 5 different SKUs. If we pushed the
registry
tests into another module, they wouldn't have to be added to this list. you COULD push this into thetest_k8s
module. Or leave it as is and add this modules here.we could detect this list i suppose. Not good for this PR though