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

k8s clean leftovers #3609

Merged
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
3 changes: 0 additions & 3 deletions tests/k8s_lib_injection/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def deploy_datadog_cluster_agent(self, use_uds=False, features=None):
def deploy_test_agent(self):
self.test_agent.deploy_test_agent()

def deploy_agent(self):
self.test_agent.deploy_agent()

def deploy_weblog_as_pod(self, with_admission_controller=True, use_uds=False, env=None, service_account=None):
if with_admission_controller:
self.test_weblog.install_weblog_pod_with_admission_controller(env=env, service_account=service_account)
Expand Down
54 changes: 0 additions & 54 deletions tests/k8s_lib_injection/test_k8s_manual_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,6 @@ def test_inject_uds_without_admission_controller(self, test_k8s_instance):
logger.info(f"Test test_inject_uds_without_admission_controller finished")


# TODO delete or update this scenario to use test agent
# @features.k8s_admission_controller
# @scenarios.k8s_library_injection_asm
class _TestAdmisionControllerAsm:
"""Test ASM features activation with admission controller."""

def test_inject_asm_admission_controller(self, test_k8s_instance):
logger.info(
f"Launching test test_inject_asm_admission_controller: Weblog: [{test_k8s_instance.k8s_kind_cluster.get_weblog_port()}] Agent: [{test_k8s_instance.k8s_kind_cluster.get_agent_port()}]"
)

asm_features = {
"datadog.asm.iast.enabled": "true",
"datadog.asm.sca.enabled": "true",
"datadog.asm.threats.enabled": "true",
}
test_k8s_instance.deploy_datadog_cluster_agent(features=asm_features)
test_k8s_instance.deploy_agent()

weblog_port = test_k8s_instance.k8s_kind_cluster.get_weblog_port()
weblog_host = test_k8s_instance.k8s_kind_cluster.cluster_host_name
logger.info(f"Waiting for weblog available [{weblog_host}:{weblog_port}]")
wait_for_port(weblog_port, weblog_host, 80.0)
logger.info(f"[{weblog_host}:{weblog_port}]: Weblog app is ready!")
warmup_weblog(f"http://{weblog_host}:{weblog_port}/")
logger.info(f"Making a request to weblog [{weblog_host}:{weblog_port}]")
request_uuid = make_get_request(f"http://{weblog_host}:{weblog_port}/")

logger.info(f"Http request done with uuid: [{request_uuid}] for [{weblog_host}:{weblog_port}]")
wait_backend_trace_id(request_uuid, 120.0, profile=False, validator=backend_trace_validator)


@features.k8s_admission_controller
@scenarios.k8s_library_injection_profiling
class TestAdmisionControllerProfiling:
Expand Down Expand Up @@ -154,28 +122,6 @@ def test_profiling_override_cluster_env(self, test_k8s_instance):
profiling_request_found = self._check_profiling_request_sent(test_k8s_instance.k8s_kind_cluster)
assert profiling_request_found, "No profiling request found"

def _test_inject_profiling_admission_controller_real(self, test_k8s_instance):
logger.info(
f"Launching test test_inject_profiling_admission_controller: Weblog: [{test_k8s_instance.k8s_kind_cluster.get_weblog_port()}] Agent: [{test_k8s_instance.k8s_kind_cluster.get_agent_port()}]"
)

test_k8s_instance.deploy_datadog_cluster_agent(features={"datadog.profiling.enabled": "auto"})
test_k8s_instance.deploy_agent()
test_k8s_instance.deploy_weblog_as_pod(
env={"DD_PROFILING_UPLOAD_PERIOD": "10", "DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD": "1500"}
)
weblog_port = test_k8s_instance.k8s_kind_cluster.get_weblog_port()
weblog_host = test_k8s_instance.k8s_kind_cluster.cluster_host_name
logger.info(f"Waiting for weblog available [{weblog_host}:{weblog_port}]")
wait_for_port(weblog_port, weblog_host, 80.0)
logger.info(f"[{weblog_host}:{weblog_port}]: Weblog app is ready!")
warmup_weblog(f"http://{weblog_host}:{weblog_port}/")
logger.info(f"Making a request to weblog [{weblog_host}:{weblog_port}]")
request_uuid = make_get_request(f"http://{weblog_host}:{weblog_port}/")

logger.info(f"Http request done with uuid: [{request_uuid}] for [{weblog_host}:{weblog_port}]")
wait_backend_trace_id(request_uuid, 120.0, profile=True)


def backend_trace_validator(trace_id, trace_data):
logger.info("Appsec trace validator")
Expand Down
40 changes: 1 addition & 39 deletions utils/k8s_lib_injection/k8s_datadog_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,21 @@


class K8sDatadog:
def __init__(self, output_folder, test_name, api_key=None, app_key=None, real_agent_image=None):
def __init__(self, output_folder, test_name, api_key=None, app_key=None):
self.k8s_kind_cluster = None
self.output_folder = output_folder
self.test_name = test_name
self.logger = None
self.k8s_wrapper = None
self._api_key = api_key
self._app_key = app_key
self.real_agent_image = real_agent_image

def configure(self, k8s_kind_cluster, k8s_wrapper):
self.k8s_kind_cluster = k8s_kind_cluster
self.k8s_wrapper = k8s_wrapper
self.logger = k8s_logger(self.output_folder, self.test_name, "k8s_logger")
self.logger.info(f"K8sDatadog configured with cluster: {self.k8s_kind_cluster.cluster_name}")

def deploy_agent(self):
""" Installs the real agent daemonset using previously download datadog-agent-apm template.
Following this doc: https://docs.datadoghq.com/containers/guide/kubernetes_daemonset/?tab=tcp"""
self.logger.info(
f"[Real agent] Deploying Datadog test agent on the cluster: {self.k8s_kind_cluster.cluster_name}"
)
agent_data = ""
with open("utils/k8s_lib_injection/resources/datadog-agent-apm.yaml", "r") as file:
agent_data = file.read()

if self.real_agent_image:
agent_data = agent_data.replace("gcr.io/datadoghq/agent:7.45.0", self.real_agent_image)

agent_config = f"{self.output_folder}/{self.k8s_kind_cluster.cluster_name}_datadog-agent-apm.yaml"

with open(agent_config, "w") as fp:
fp.write(agent_data)
fp.seek(0)
self.logger.info("[real agent] Creating agent")
kubectl_apply(
self.k8s_kind_cluster,
"https://raw.githubusercontent.com/DataDog/datadog-agent/master/Dockerfiles/manifests/rbac/clusterrole.yaml",
)
kubectl_apply(
self.k8s_kind_cluster,
"https://raw.githubusercontent.com/DataDog/datadog-agent/master/Dockerfiles/manifests/rbac/serviceaccount.yaml",
)
kubectl_apply(
self.k8s_kind_cluster,
"https://raw.githubusercontent.com/DataDog/datadog-agent/master/Dockerfiles/manifests/rbac/clusterrolebinding.yaml",
)

kubectl_apply(self.k8s_kind_cluster, agent_config)
self.logger.info("[real agent] Agent created. Waiting for the agent to be ready")
self.wait_for_test_agent()
self.logger.info("[real agent] Daemonset created")

def deploy_test_agent(self):
""" Installs the test agent pod."""

Expand Down
Loading
Loading