Skip to content

Commit

Permalink
K8s Lib Injection: Parametrize cluster agent image (#3879)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertomonteromiguel authored Jan 24, 2025
1 parent 059e215 commit 1daae04
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 36 deletions.
32 changes: 16 additions & 16 deletions .gitlab/k8s_gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ stages:
K8S_WEBLOG_IMG: "xyz"
K8S_SCENARIO: "xyz"
K8S_LIB_INIT_IMG: "xyz"
K8S_CLUSTER_VERSION: "xyz"
K8S_CLUSTER_IMG: "xyz"
K8S_INJECTOR_IMG: "xyz"
script:
- ./build.sh -i runner # rebuild runner in case there were changes
- source venv/bin/activate
- python --version
- pip freeze
- ./run.sh ${K8S_SCENARIO} --k8s-library ${TEST_LIBRARY} --k8s-weblog ${K8S_WEBLOG} --k8s-weblog-img ${K8S_WEBLOG_IMG} --k8s-lib-init-img ${K8S_LIB_INIT_IMG} --k8s-injector-img ${K8S_INJECTOR_IMG} --k8s-cluster-version ${K8S_CLUSTER_VERSION} --report-run-url $CI_JOB_URL --report-environment $ONBOARDING_FILTER_ENV
- ./run.sh ${K8S_SCENARIO} --k8s-library ${TEST_LIBRARY} --k8s-weblog ${K8S_WEBLOG} --k8s-weblog-img ${K8S_WEBLOG_IMG} --k8s-lib-init-img ${K8S_LIB_INIT_IMG} --k8s-injector-img ${K8S_INJECTOR_IMG} --k8s-cluster-img ${K8S_CLUSTER_IMG} --report-run-url $CI_JOB_URL --report-environment $ONBOARDING_FILTER_ENV
after_script: |
mkdir -p reports
cp -R logs_*/ reports/
Expand Down Expand Up @@ -90,14 +90,14 @@ k8s_java:
K8S_SCENARIO: [K8S_LIB_INJECTION_SPARK_DJM]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-java-init:latest", "ghcr.io/datadog/dd-trace-java/dd-lib-java-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-java-init-test-app]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-java-init-test-app:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE, K8S_LIB_INJECTION_OPERATOR]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-java-init:latest", "ghcr.io/datadog/dd-trace-java/dd-lib-java-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-java-init-test-app]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-java-init-test-app:latest]
Expand All @@ -115,7 +115,7 @@ k8s_dotnet:
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE, K8S_LIB_INJECTION_OPERATOR]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-dotnet-init:latest", "ghcr.io/datadog/dd-trace-dotnet/dd-lib-dotnet-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-dotnet-init-test-app]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-dotnet-init-test-app:latest]
Expand All @@ -133,7 +133,7 @@ k8s_nodejs:
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE, K8S_LIB_INJECTION_OPERATOR]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-js-init:latest", "ghcr.io/datadog/dd-trace-js/dd-lib-js-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [sample-app]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/sample-app:latest]
Expand All @@ -151,7 +151,7 @@ k8s_python:
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE, K8S_LIB_INJECTION_OPERATOR]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-python-init-test-django]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-python-init-test-django:latest]
Expand All @@ -163,42 +163,42 @@ k8s_python:
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_PROFILING_ENABLED]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-python-init-test-django-gunicorn-alpine]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-python-init-test-django-gunicorn-alpine:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_PROFILING_ENABLED]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-python-init-test-django-unsupported-package-force]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-python-init-test-django-unsupported-package-force:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_PROFILING_ENABLED]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-python-init-test-django-uvicorn]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-python-init-test-django-uvicorn:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_PROFILING_ENABLED]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-python-init-test-protobuf-old]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-python-init-test-protobuf-old:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_PROFILING_ENABLED]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-python-init-test-django-preinstalled]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-python-init-test-django-preinstalled:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-python-init:latest", "ghcr.io/datadog/dd-trace-py/dd-lib-python-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

k8s_ruby:
extends: .k8s_lib_injection_base
Expand All @@ -211,7 +211,7 @@ k8s_ruby:
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE, K8S_LIB_INJECTION_OPERATOR]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-ruby-init:latest", "ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-ruby-init-test-rails]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-ruby-init-test-rails:latest]
Expand All @@ -223,11 +223,11 @@ k8s_ruby:
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-ruby-init:latest", "ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']

- K8S_WEBLOG: [dd-lib-ruby-init-test-rails-gemsrb]
K8S_WEBLOG_IMG: [ghcr.io/datadog/system-tests/dd-lib-ruby-init-test-rails-gemsrb:latest]
K8S_SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE]
K8S_LIB_INIT_IMG: ["gcr.io/datadoghq/dd-lib-ruby-init:latest", "ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:latest_snapshot"]
K8S_INJECTOR_IMG: ["gcr.io/datadoghq/apm-inject:latest", "ghcr.io/datadog/apm-inject:latest_snapshot"]
K8S_CLUSTER_VERSION: ['7.56.2', '7.57.0', '7.59.0']
K8S_CLUSTER_IMG: ['gcr.io/datadoghq/cluster-agent:7.56.2', 'docker.io/datadog/cluster-agent-dev:master', 'gcr.io/datadoghq/cluster-agent:latest']
7 changes: 6 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def pytest_addoption(parser):
)
parser.addoption("--k8s-injector-img", type=str, action="store", help="Set injector image on the docker registry")
parser.addoption("--k8s-weblog-img", type=str, action="store", help="Set test app image on the docker registry")
parser.addoption("--k8s-cluster-version", type=str, action="store", help="Set the datadog agent version")
parser.addoption(
"--k8s-cluster-version", type=str, action="store", help="DEPRECATED. Set the datadog cluster version"
)
parser.addoption(
"--k8s-cluster-img", type=str, action="store", help="Set the datadog cluster image on the docker registry"
)

# Onboarding scenarios mandatory parameters
parser.addoption("--vm-weblog", type=str, action="store", help="Set virtual machine weblog")
Expand Down
54 changes: 40 additions & 14 deletions utils/_context/_scenarios/k8s_lib_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ def configure(self, config):
self.k8s_lib_init_img = config.option.k8s_lib_init_img
self.components["library"] = self._library.version

# Cluster version
self.k8s_cluster_version = config.option.k8s_cluster_version
self.components["cluster_agent"] = self.k8s_cluster_version
# Cluster agent version
if config.option.k8s_cluster_version is not None and config.option.k8s_cluster_img is not None:
raise ValueError("You mustn't set both k8s_cluster_version and k8s_cluster_img")
if config.option.k8s_cluster_version is None and config.option.k8s_cluster_img is None:
raise ValueError("You must set either k8s_cluster_version or k8s_cluster_img")
if config.option.k8s_cluster_version is not None:
logger.stdout("WARNING: The k8s_cluster_version is going to be deprecated, use k8s_cluster_img instead")
self.k8s_cluster_img = None
self.k8s_cluster_version = config.option.k8s_cluster_version
self.components["cluster_agent"] = self.k8s_cluster_version
else:
self.k8s_cluster_img = config.option.k8s_cluster_img
self.k8s_cluster_version = extract_cluster_agent_version(self.k8s_cluster_img)
self.components["cluster_agent"] = self.k8s_cluster_version

# Injector image version
self.k8s_injector_img = (
Expand All @@ -92,10 +103,11 @@ def configure(self, config):
dd_cluster_feature=self.dd_cluster_feature,
dd_cluster_uds=self.use_uds,
dd_cluster_version=self.k8s_cluster_version,
dd_cluster_img=self.k8s_cluster_img,
api_key=self._api_key if self.with_datadog_operator else None,
app_key=self._app_key if self.with_datadog_operator else None,
)
# Weblog handler
# Weblog handler (the lib init and injector imgs are set in weblog/pod as annotations)
self.test_weblog = K8sWeblog(
self.k8s_weblog_img,
self.library.library,
Expand All @@ -108,13 +120,15 @@ def configure(self, config):
)

def print_context(self):
logger.stdout(f"K8s Weblog: {self.k8s_weblog}")
logger.stdout(f"K8s Weblog image: {self.k8s_weblog_img}")
logger.stdout(f".:: K8s Lib injection test components ::.")
logger.stdout(f"Weblog: {self.k8s_weblog}")
logger.stdout(f"Weblog image: {self.k8s_weblog_img}")
logger.stdout(f"Library: {self._library}")
logger.stdout(f"K8s Cluster version: {self.k8s_cluster_version}")
logger.stdout(f"K8s Lib init image: {self.k8s_lib_init_img}")
logger.stdout(f"K8s Injector image: {self.k8s_injector_img}")
logger.stdout(f"K8s Injector version: {self._datadog_apm_inject_version}")
logger.stdout(f"Lib init image: {self.k8s_lib_init_img}")
logger.stdout(f"Cluster agent version: {self.k8s_cluster_version}")
logger.stdout(f"Cluster agent image: {self.k8s_cluster_img}")
logger.stdout(f"Injector version: {self._datadog_apm_inject_version}")
logger.stdout(f"Injector image: {self.k8s_injector_img}")

def get_warmups(self):
warmups = super().get_warmups()
Expand Down Expand Up @@ -275,6 +289,7 @@ def configure(self, config):
dd_cluster_feature=self.dd_cluster_feature,
dd_cluster_uds=self.use_uds,
dd_cluster_version=self.k8s_cluster_version,
dd_cluster_img=self.k8s_cluster_img,
)

self.test_weblog = K8sWeblog(
Expand Down Expand Up @@ -386,8 +401,7 @@ def extract_library_version(library_init_image):
logger.info(f"Library version: {version}")
return version
except Exception as e:
logger.error(f"Failed to extract library version: {e}")
logger.error(f"The library init imaged tried to pull is: {library_init_image}")
logger.error(f"The library init image failed to pull is: {library_init_image}")
raise ValueError(f"Failed to pull and extract library version: {e}")


Expand All @@ -405,6 +419,18 @@ def extract_injector_version(injector_image):
logger.info(f"Injector version: {version}")
return version
except Exception as e:
logger.error(f"Failed to extract injector version: {e}")
logger.error(f"The library init imaged tried to pull is: {injector_image}")
logger.error(f"The failed injector image failed to pull is: {injector_image}")
raise ValueError(f"Failed to pull and extract injector version: {e}")


def extract_cluster_agent_version(cluster_image):
"""Pull the datadog cluster image and extract the version from labels"""
logger.info("Get cluster agent version")
try:
cluster_docker_image = get_docker_client().images.pull(cluster_image)
version = cluster_docker_image.labels["org.opencontainers.image.version"]
logger.info(f"Cluster agent version: {version}")
return version
except Exception as e:
logger.error(f"The cluster agent images tried to pull is: {cluster_image}")
raise ValueError(f"Failed to pull and extract cluster agent version: {e}")
Loading

0 comments on commit 1daae04

Please sign in to comment.