Skip to content

Commit

Permalink
Update "instances" fixture, removing the k8s snap when cleaning up
Browse files Browse the repository at this point in the history
At the moment, the "instances" fixture removes the test instances
without uninstalling the k8s snap. In case of LXD instances, this
can leak certain resources on the host, for example loopback
devices.

We'll update the fixture to remove the k8s snap as part of the
instance cleanup procedure.
  • Loading branch information
petrutlucian94 committed Nov 6, 2024
1 parent 4232ba2 commit 583bc9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 38 deletions.
2 changes: 2 additions & 0 deletions tests/integration/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def instances(
LOG.debug("Generating inspection reports for test instances")
_generate_inspection_report(h, instance.id)

util.remove_k8s_snap(instance)

h.delete_instance(instance.id)


Expand Down
40 changes: 2 additions & 38 deletions tests/integration/tests/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List

import pytest
from test_util import config, harness, util
from test_util import harness, util

LOG = logging.getLogger(__name__)

Expand All @@ -16,40 +16,4 @@ def test_node_cleanup(instances: List[harness.Instance]):
util.wait_for_dns(instance)
util.wait_for_network(instance)

LOG.info("Uninstall k8s...")
instance.exec(["snap", "remove", config.SNAP_NAME, "--purge"])

LOG.info("Waiting for shims to go away...")
util.stubbornly(retries=5, delay_s=5).on(instance).until(
lambda p: all(
x not in p.stdout.decode()
for x in ["containerd-shim", "cilium", "coredns", "/pause"]
)
).exec(["ps", "-fea"])

LOG.info("Waiting for kubelet and containerd mounts to go away...")
util.stubbornly(retries=5, delay_s=5).on(instance).until(
lambda p: all(
x not in p.stdout.decode()
for x in ["/var/lib/kubelet/pods", "/run/containerd/io.containerd"]
)
).exec(["mount"])

# NOTE(neoaggelos): Temporarily disable this as it fails on strict.
# For details, `snap changes` then `snap change $remove_k8s_snap_change`.
# Example output follows:
#
# 2024-02-23T14:10:42Z ERROR ignoring failure in hook "remove":
# -----
# ...
# ip netns delete cni-UUID1
# Cannot remove namespace file "/run/netns/cni-UUID1": Device or resource busy
# ip netns delete cni-UUID2
# Cannot remove namespace file "/run/netns/cni-UUID2": Device or resource busy
# ip netns delete cni-UUID3
# Cannot remove namespace file "/run/netns/cni-UUID3": Device or resource busy

# LOG.info("Waiting for CNI network namespaces to go away...")
# util.stubbornly(retries=5, delay_s=5).on(instance).until(
# lambda p: "cni-" not in p.stdout.decode()
# ).exec(["ip", "netns", "list"])
util.remove_k8s_snap(instance)
40 changes: 40 additions & 0 deletions tests/integration/tests/test_util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,46 @@ def setup_k8s_snap(
instance.exec(["/snap/k8s/current/k8s/hack/init.sh"], stdout=subprocess.DEVNULL)


def remove_k8s_snap(instance: harness.Instance):
LOG.info("Uninstall k8s...")
instance.exec(["snap", "remove", config.SNAP_NAME, "--purge"])

LOG.info("Waiting for shims to go away...")
stubbornly(retries=5, delay_s=5).on(instance).until(
lambda p: all(
x not in p.stdout.decode()
for x in ["containerd-shim", "cilium", "coredns", "/pause"]
)
).exec(["ps", "-fea"])

LOG.info("Waiting for kubelet and containerd mounts to go away...")
stubbornly(retries=5, delay_s=5).on(instance).until(
lambda p: all(
x not in p.stdout.decode()
for x in ["/var/lib/kubelet/pods", "/run/containerd/io.containerd"]
)
).exec(["mount"])

# NOTE(neoaggelos): Temporarily disable this as it fails on strict.
# For details, `snap changes` then `snap change $remove_k8s_snap_change`.
# Example output follows:
#
# 2024-02-23T14:10:42Z ERROR ignoring failure in hook "remove":
# -----
# ...
# ip netns delete cni-UUID1
# Cannot remove namespace file "/run/netns/cni-UUID1": Device or resource busy
# ip netns delete cni-UUID2
# Cannot remove namespace file "/run/netns/cni-UUID2": Device or resource busy
# ip netns delete cni-UUID3
# Cannot remove namespace file "/run/netns/cni-UUID3": Device or resource busy

# LOG.info("Waiting for CNI network namespaces to go away...")
# stubbornly(retries=5, delay_s=5).on(instance).until(
# lambda p: "cni-" not in p.stdout.decode()
# ).exec(["ip", "netns", "list"])


def wait_until_k8s_ready(
control_node: harness.Instance,
instances: List[harness.Instance],
Expand Down

0 comments on commit 583bc9a

Please sign in to comment.