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

Refactor tests and add 1.10.1 support #8

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# pinning to use rockcraft 1.3.0 feature `entrypoint-service`
rockcraft-revisions: '{"amd64": "1783", "arm64": "1784"}'
arch-skipping-maximize-build-space: '["arm64"]'
platform-labels: '{"arm64": ["self-hosted", "Linux", "ARM64", "jammy", "large"]}'
platform-labels: '{"arm64": ["self-hosted", "Linux", "ARM64", "jammy"]}'
run-tests:
uses: canonical/k8s-workflows/.github/workflows/run_tests.yaml@main
needs: [build-and-push-arch-specifics]
Expand Down
39 changes: 39 additions & 0 deletions acmesolver/1.10.1/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: cert-manager-acmesolver
summary: ROCK for the cert-manager-acmesolver Project.
description: |
This ROCK is a drop-in replacement for the autoscaling/cert-manager-acmesolver image.
version: "1.10.1"
license: Apache-2.0

base: bare
build-base: [email protected]
platforms:
amd64:
arm64:

run-user: _daemon_
entrypoint-service: cert-manager-acmesolver
services:
cert-manager-acmesolver:
override: replace
summary: "cert-manager-acmesolver service"
startup: enabled
command: "/acmesolver-linux [ -h ]"
on-failure: shutdown

parts:
cert-manager-acmesolver:
plugin: nil
source: https://github.com/cert-manager/cert-manager.git
source-type: git
source-tag: v1.10.1
source-depth: 1
build-snaps:
- jq
- go/1.22/stable
override-build: |
# CTR=echo is hacky way of passing docker check not required for build
make CTR=echo _bin/server/acmesolver-linux-${CRAFT_PLATFORM}
cp _bin/server/acmesolver-linux-${CRAFT_PLATFORM} ${CRAFT_PART_INSTALL}/acmesolver-linux
prime:
- acmesolver-linux
File renamed without changes.
39 changes: 39 additions & 0 deletions cainjector/1.10.1/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: cert-manager-cainjector
summary: ROCK for the cert-manager-cainjector Project.
description: |
This ROCK is a drop-in replacement for the autoscaling/cert-manager-cainjector image.
version: 1.10.1
license: Apache-2.0

base: bare
build-base: [email protected]
platforms:
amd64:
arm64:

run-user: _daemon_
entrypoint-service: cert-manager-cainjector
services:
cert-manager-cainjector:
override: replace
summary: "cert-manager-cainjector service"
startup: enabled
command: "/cainjector-linux [ -h ]"
on-failure: shutdown

parts:
cert-manager-cainjector:
plugin: nil
source: https://github.com/cert-manager/cert-manager.git
source-type: git
source-tag: v1.10.1
source-depth: 1
build-snaps:
- jq
- go/1.22/stable
override-build: |
# CTR=echo is hacky way of passing docker check not required for build
make CTR=echo _bin/server/cainjector-linux-${CRAFT_PLATFORM}
cp _bin/server/cainjector-linux-${CRAFT_PLATFORM} ${CRAFT_PART_INSTALL}/cainjector-linux
prime:
- cainjector-linux
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: cert-manager-cainjector
summary: ROCK for the cert-manager-cainjector Project.
description: |
description: |
This ROCK is a drop-in replacement for the autoscaling/cert-manager-cainjector image.
version: "1.12.2"
license: Apache-2.0
Expand Down
39 changes: 39 additions & 0 deletions controller/1.10.1/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: cert-manager-controller
summary: ROCK for the cert-manager-controller Project.
description: |
This ROCK is a drop-in replacement for the autoscaling/cert-manager-controller image.
version: 1.10.1
license: Apache-2.0

base: bare
build-base: [email protected]
platforms:
amd64:
arm64:

run-user: _daemon_
entrypoint-service: cert-manager-controller
services:
cert-manager-controller:
override: replace
summary: "cert-manager-controller service"
startup: enabled
command: "/controller-linux [ -h ]"
on-failure: shutdown

parts:
cert-manager-controller:
plugin: nil
source: https://github.com/cert-manager/cert-manager.git
source-type: git
source-tag: v1.10.1
source-depth: 1
build-snaps:
- jq
- go/1.22/stable
override-build: |
# CTR=echo is hacky way of passing docker check not required for build
make CTR=echo _bin/server/controller-linux-${CRAFT_PLATFORM}
cp _bin/server/controller-linux-${CRAFT_PLATFORM} ${CRAFT_PART_INSTALL}/controller-linux
prime:
- controller-linux
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/.copyright.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copyright ${years} ${owner}.
See LICENSE file for licensing details
134 changes: 2 additions & 132 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,135 +1,5 @@
#
# Copyright 2024 Canonical, Ltd.
# See LICENSE file for licensing details
#
import logging
from pathlib import Path
from typing import Generator, List

import pytest
from test_util import config, harness, util

LOG = logging.getLogger(__name__)


def _harness_clean(h: harness.Harness):
"Clean up created instances within the test harness."

if config.SKIP_CLEANUP:
LOG.warning(
"Skipping harness cleanup. "
"It is your job now to clean up cloud resources"
)
else:
LOG.debug("Cleanup")
h.cleanup()


@pytest.fixture(scope="session")
def h() -> harness.Harness:
LOG.debug("Create harness for %s", config.SUBSTRATE)
if config.SUBSTRATE == "local":
h = harness.LocalHarness()
elif config.SUBSTRATE == "lxd":
h = harness.LXDHarness()
elif config.SUBSTRATE == "multipass":
h = harness.MultipassHarness()
elif config.SUBSTRATE == "juju":
h = harness.JujuHarness()
else:
raise harness.HarnessError(
"TEST_SUBSTRATE must be one of: local, lxd, multipass, juju"
)

yield h

_harness_clean(h)


def pytest_configure(config):
config.addinivalue_line(
"markers",
"node_count: Mark a test to specify how many instance nodes need to be created\n"
"disable_k8s_bootstrapping: By default, the first k8s node is bootstrapped. This marker disables that.",
)


@pytest.fixture(scope="function")
def node_count(request) -> int:
node_count_marker = request.node.get_closest_marker("node_count")
if not node_count_marker:
return 1
node_count_arg, *_ = node_count_marker.args
return int(node_count_arg)


@pytest.fixture(scope="function")
def disable_k8s_bootstrapping(request) -> int:
return bool(request.node.get_closest_marker("disable_k8s_bootstrapping"))


@pytest.fixture(scope="function")
def instances(
h: harness.Harness, node_count: int, tmp_path: Path, disable_k8s_bootstrapping: bool
) -> Generator[List[harness.Instance], None, None]:
"""Construct instances for a cluster.

Bootstrap and setup networking on the first instance, if `disable_k8s_bootstrapping` marker is not set.
"""
if not config.SNAP_CHANNEL:
pytest.fail("Set TEST_SNAP_CHANNEL to the channel of the k8s snap to install.")

if node_count <= 0:
pytest.xfail("Test requested 0 or fewer instances, skip this test.")

LOG.info(f"Creating {node_count} instances")
instances: List[harness.Instance] = []

for _ in range(node_count):
# Create <node_count> instances and setup the k8s snap in each.
instance = h.new_instance()
instances.append(instance)
util.setup_k8s_snap(instance)

if not disable_k8s_bootstrapping:
first_node, *_ = instances
first_node.exec(["k8s", "bootstrap"])

yield instances

if config.SKIP_CLEANUP:
LOG.warning("Skipping clean-up of instances, delete them on your own")
return

# Cleanup after each test.
# We cannot execute _harness_clean() here as this would also
# remove the session_instance. The harness ensures that everything is cleaned up
# at the end of the test session.
for instance in instances:
h.delete_instance(instance.id)


@pytest.fixture(scope="session")
def session_instance(
h: harness.Harness, tmp_path_factory: pytest.TempPathFactory
) -> Generator[harness.Instance, None, None]:
"""Constructs and bootstraps an instance that persists over a test session.

Bootstraps the instance with all k8sd features enabled to reduce testing time.
"""
LOG.info("Setup node and enable all features")

instance = h.new_instance()
util.setup_k8s_snap(instance)

bootstrap_config_path = "/home/ubuntu/bootstrap-session.yaml"
instance.send_file(
(config.MANIFESTS_DIR / "bootstrap-session.yaml").as_posix(),
bootstrap_config_path,
)

instance.exec(["k8s", "bootstrap", "--file", bootstrap_config_path])
util.wait_until_k8s_ready(instance, [instance])
util.wait_for_network(instance)
util.wait_for_dns(instance)

yield instance
pytest_plugins = ["k8s_test_harness.plugin"]
Loading
Loading