|
2 | 2 | # All rights reserved
|
3 | 3 | # Licensed under a 3-clause BSD style license (see LICENSE)
|
4 | 4 | import os
|
5 |
| -from contextlib import ExitStack |
| 5 | +from contextlib import ExitStack, contextmanager |
6 | 6 |
|
7 | 7 | import pytest
|
8 | 8 |
|
9 | 9 | from datadog_checks.dev import TempDir, run_command
|
10 | 10 | from datadog_checks.dev.fs import path_join
|
11 |
| -from datadog_checks.dev.kind import kind_run |
| 11 | +from datadog_checks.dev.kind import KindLoad, kind_run |
12 | 12 | from datadog_checks.dev.kube_port_forward import port_forward
|
13 | 13 |
|
14 | 14 | from .common import MOCKED_INSTANCE, PORT
|
|
17 | 17 | KIND_DIR = os.path.join(HERE, 'kind')
|
18 | 18 |
|
19 | 19 |
|
| 20 | +@contextmanager |
| 21 | +def build_and_load_kubectl_image(image_tag: str): |
| 22 | + print("Building custom kubectl image...") |
| 23 | + dockerfile_path = os.path.join(KIND_DIR, 'kubectl.Dockerfile') |
| 24 | + |
| 25 | + # Build the custom kubectl image |
| 26 | + run_command( |
| 27 | + ['docker', 'build', '-t', image_tag, '-f', dockerfile_path, '.'], |
| 28 | + check=True, |
| 29 | + ) |
| 30 | + yield |
| 31 | + |
| 32 | + |
20 | 33 | def setup_velero():
|
21 | 34 | """Set up Velero, MinIO and Nginx in the Kind cluster."""
|
22 | 35 | # Apply MinIO deployment
|
@@ -63,10 +76,12 @@ def get_instances(velero_host, velero_port, node_agent_host, node_agent_port):
|
63 | 76 | @pytest.fixture(scope='session')
|
64 | 77 | def dd_environment():
|
65 | 78 | kind_config = os.path.join(KIND_DIR, 'kind-config.yaml')
|
| 79 | + custom_kubectl_image_tag = "custom-kubectl:latest" |
66 | 80 |
|
67 | 81 | with TempDir('helm_dir') as helm_dir:
|
68 | 82 | with kind_run(
|
69 |
| - conditions=[setup_velero], |
| 83 | + wrappers=[build_and_load_kubectl_image(custom_kubectl_image_tag)], |
| 84 | + conditions=[KindLoad(custom_kubectl_image_tag), setup_velero], |
70 | 85 | kind_config=kind_config,
|
71 | 86 | env_vars={
|
72 | 87 | "HELM_CACHE_HOME": path_join(helm_dir, 'Caches'),
|
|
0 commit comments