Skip to content

Commit

Permalink
Resolve logging issue for multi-container pod
Browse files Browse the repository at this point in the history
Clean history
  • Loading branch information
xinze-zheng committed Jan 12, 2024
1 parent 2c834c9 commit f55a067
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 101,185 deletions.
12 changes: 11 additions & 1 deletion acto/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def __init__(
is_reproduce: bool,
apply_testcase_f: FunctionType,
acto_namespace: int,
operator_container_name: str,
additional_exclude_paths: list[str] = None,
) -> None:
self.context = context
Expand All @@ -293,6 +294,7 @@ def __init__(
if additional_exclude_paths is not None
else []
)
self.operator_container_name = operator_container_name

self.custom_on_init = custom_on_init
self.custom_oracle = custom_oracle
Expand Down Expand Up @@ -425,6 +427,7 @@ def run_trial(
trial_dir,
self.kubeconfig,
self.context_name,
self.operator_container_name,
wait_time=self.wait_time,
)
checker: CheckerSet = self.checker_t(
Expand Down Expand Up @@ -869,6 +872,12 @@ def __init__(
self.checker_type = CheckerSet
self.snapshots = []

# Extract the operator_container_name from config
for deploy_step in self.operator_config.deploy.steps:
if deploy_step.apply != None and deploy_step.apply.operator:
self.operator_container_name = deploy_step.apply.operator_container_name
break

# generate configuration files for the cluster runtime
self.cluster.configure_cluster(
operator_config.num_nodes, self.operator_config.kubernetes_version
Expand Down Expand Up @@ -1183,7 +1192,8 @@ def run(
self.is_reproduce,
self.apply_testcase_f,
self.acto_namespace,
self.operator_config.diff_ignore_fields,
self.operator_container_name,
self.operator_config.diff_ignore_fields
)
runners.append(runner)

Expand Down
3 changes: 3 additions & 0 deletions acto/lib/operator_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class ApplyStep(BaseModel, extra="forbid"):
operator: bool = Field(
description="If the file contains the operator deployment",
default=False)
operator_container_name: Optional[str] = Field(
description="The container name of the operator in the operator pod",
default=None)
namespace: Optional[str] = Field(
description="Namespace for applying the file. If not specified, " +
"use the namespace in the file or Acto namespace. " +
Expand Down
17 changes: 13 additions & 4 deletions acto/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
trial_dir: str,
kubeconfig: str,
context_name: str,
operator_container_name: str,
custom_system_state_f: Optional[Callable[..., dict]] = None,
wait_time: int = 45,
):
Expand All @@ -42,6 +43,7 @@ def __init__(
self.trial_dir = trial_dir
self.kubeconfig = kubeconfig
self.context_name = context_name
self.operator_container_name = operator_container_name
self.wait_time = wait_time
self.log_length = 0

Expand Down Expand Up @@ -311,10 +313,17 @@ def collect_operator_log(self) -> list:
)
else:
logger.error("Failed to find operator pod")

log = self.core_v1_api.read_namespaced_pod_log(
name=operator_pod_list[0].metadata.name, namespace=self.namespace
)
if self.operator_container_name == None:
log = self.core_v1_api.read_namespaced_pod_log(
name=operator_pod_list[0].metadata.name,
namespace=self.namespace,
container=self.operator_container_name
)
else:
log = self.core_v1_api.read_namespaced_pod_log(
name=operator_pod_list[0].metadata.name,
namespace=self.namespace,
)

# only get the new log since previous result
new_log = log.split("\n")
Expand Down
Loading

0 comments on commit f55a067

Please sign in to comment.