Skip to content

Commit

Permalink
test case add for kubectl container
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar committed Feb 3, 2025
1 parent ca8c2d0 commit 2ad77e2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ jobs:
test-containers:
name: tox
runs-on: ubuntu-latest
env:
K3S_CLUSTER_NAME: "test-k3s"
needs: gentestmatrix
strategy:
fail-fast: false
Expand Down Expand Up @@ -400,6 +402,13 @@ jobs:
echo -e "$(getent ahostsv4 $host | grep STREAM | cut -d' ' -f1 | head -n 1)\t$host" | sudo tee -a /etc/hosts
done
- uses: AbsaOSS/k3d-action@v2
name: "Create Single node k3d Cluster"
if: ${{ matrix.toxenv == 'kubectl' }}
with:
cluster-name: ${{ env.K3S_CLUSTER_NAME }}
args: --agents 1

- name: Run the tests for docker
run: python3 -m tox -e ${{ matrix.toxenv }} -- -n 3 --reruns 3 --durations=25 --durations-min=600.0 --pytest-container-log-level=debug
env:
Expand Down
19 changes: 19 additions & 0 deletions bci_tester/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,23 @@ def create_BCI(
forwarded_ports=[PortForwarding(container_port=80)],
)

_KUBECTL_VERSION_OS_MATRIX: Tuple[Tuple[str, Tuple[str, ...]], ...] = (
("1.28", ("15.6", "tumbleweed")),
("1.30", ("15.7",)),
("1.29", ("tumbleweed",)),
("1.30", ("tumbleweed",)),
("1.31", ("tumbleweed",)),
)

KUBECTL_CONTAINERS = [
create_BCI(
build_tag=f"{APP_CONTAINER_PREFIX}/:{kubectl_ver}",
bci_type=ImageType.APPLICATION,
available_versions=os_versions,
)
for kubectl_ver, os_versions in _KUBECTL_VERSION_OS_MATRIX
]

if OS_VERSION in ("16.0",):
KERNEL_MODULE_CONTAINER = create_BCI(
build_tag=f"{BCI_CONTAINER_PREFIX}/bci-sle16-kernel-module-devel:{OS_CONTAINER_TAG}",
Expand Down Expand Up @@ -1031,6 +1048,7 @@ def create_BCI(
+ RUST_CONTAINERS
+ SPACK_CONTAINERS
+ (DOTNET_CONTAINERS if LOCALHOST.system_info.arch == "x86_64" else [])
+ KUBECTL_CONTAINERS
)

#: all containers with zypper and with the flag to launch them as root
Expand Down Expand Up @@ -1113,6 +1131,7 @@ def create_BCI(
+ RUBY_CONTAINERS
+ RUST_CONTAINERS
+ SPACK_CONTAINERS
+ KUBECTL_CONTAINERS
)

ACC_CONTAINERS = POSTGRESQL_CONTAINERS
Expand Down
33 changes: 33 additions & 0 deletions tests/test_kubectl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

import pytest
from pytest_container import DerivedContainer
from pytest_container.container import ContainerLauncher
from pytest_container.runtime import OciRuntimeBase
from bci_tester.data import KUBECTL_CONTAINERS

@pytest.mark.parametrize("ctr_image", KUBECTL_CONTAINERS)
def test_kubectl_binary(
container_runtime: OciRuntimeBase,
pytestconfig: pytest.Config,
ctr_image: DerivedContainer,
) -> None:
kubectl_ctr = DerivedContainer(
base=ctr_image,
custom_entry_point="/bin/bash",
)

with ContainerLauncher.from_pytestconfig(
kubectl_ctr, container_runtime, pytestconfig
) as kubectl_launcher:
kubectl_launcher.launch_container()
kubectl_con = kubectl_launcher.container_data.connection
output = kubectl_con.check_output(
"kubectl create deployment nginx --image=nginx --dry-run=client -o yaml"
).strip()
assert len(output) == 383
assert (
output
== "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n creationTimestamp: null\n labels:\n app: nginx\n name: nginx\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: nginx\n strategy: {}\n template:\n metadata:\n creationTimestamp: null\n labels:\n app: nginx\n spec:\n containers:\n - image: nginx\n name: nginx\n resources: {}\nstatus: {}"
)

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = {py36,py39,py310,py311,py312,py313}-unit, all, base, cosign, fips, init, dotnet, python, ruby, node, go, openjdk, openjdk_devel, rust, php, busybox, 389ds, metadata, minimal, multistage, repository, doc, lint, get_urls, pcp, distribution, postgres, git, helm, nginx, kernel_module, mariadb, tomcat, spack, gcc, prometheus, grafana, kiwi, postfix, ai
envlist = {py36,py39,py310,py311,py312,py313}-unit, all, base, cosign, fips, init, dotnet, python, ruby, node, go, openjdk, openjdk_devel, rust, php, busybox, 389ds, metadata, minimal, multistage, repository, doc, lint, get_urls, pcp, distribution, postgres, git, helm, nginx, kernel_module, mariadb, tomcat, spack, gcc, prometheus, grafana, kiwi, postfix, ai, kubectl
skip_missing_interpreters = True

[common]
Expand Down

0 comments on commit 2ad77e2

Please sign in to comment.