diff --git a/logos/examples/tests/compose_attach_node_control.rs b/logos/examples/tests/compose_attach_node_control.rs index fa3befd..7b3e5fe 100644 --- a/logos/examples/tests/compose_attach_node_control.rs +++ b/logos/examples/tests/compose_attach_node_control.rs @@ -23,7 +23,7 @@ async fn compose_attach_mode_queries_node_api_opt_in() -> Result<()> { let attach_source = metadata.attach_source().map_err(|err| anyhow!("{err}"))?; let attached = ScenarioBuilder::deployment_with(|d| d.with_node_count(1)) .with_run_duration(Duration::from_secs(5)) - .with_attach_source(attach_source) + .with_existing_cluster(attach_source) .build()?; let attached_deployer = LbcComposeDeployer::default(); diff --git a/logos/examples/tests/k8s_attach_node_control.rs b/logos/examples/tests/k8s_attach_node_control.rs index 72b2c9d..f309eee 100644 --- a/logos/examples/tests/k8s_attach_node_control.rs +++ b/logos/examples/tests/k8s_attach_node_control.rs @@ -23,7 +23,7 @@ async fn k8s_attach_mode_queries_node_api_opt_in() -> Result<()> { let attach_source = metadata.attach_source().map_err(|err| anyhow!("{err}"))?; let attached = ScenarioBuilder::deployment_with(|d| d.with_node_count(1)) .with_run_duration(Duration::from_secs(5)) - .with_attach_source(attach_source) + .with_existing_cluster(attach_source) .build()?; let attached_deployer = LbcK8sDeployer::default(); diff --git a/testing-framework/core/src/scenario/definition.rs b/testing-framework/core/src/scenario/definition.rs index 15c7ea9..9739141 100644 --- a/testing-framework/core/src/scenario/definition.rs +++ b/testing-framework/core/src/scenario/definition.rs @@ -118,8 +118,14 @@ impl Scenario { } #[must_use] + pub fn existing_cluster(&self) -> Option<&AttachSource> { + self.sources.existing_cluster() + } + + #[must_use] + #[doc(hidden)] pub fn attached_source(&self) -> Option<&AttachSource> { - self.sources.attached_source() + self.existing_cluster() } #[must_use] @@ -243,8 +249,14 @@ macro_rules! impl_common_builder_methods { } #[must_use] + pub fn with_existing_cluster(self, cluster: AttachSource) -> Self { + self.map_core_builder(|builder| builder.with_existing_cluster(cluster)) + } + + #[must_use] + #[doc(hidden)] pub fn with_attach_source(self, attach: AttachSource) -> Self { - self.map_core_builder(|builder| builder.with_attach_source(attach)) + self.with_existing_cluster(attach) } #[must_use] @@ -556,11 +568,17 @@ impl Builder { } #[must_use] - pub fn with_attach_source(mut self, attach: AttachSource) -> Self { - self.sources = self.sources.with_attach(attach); + pub fn with_existing_cluster(mut self, cluster: AttachSource) -> Self { + self.sources = self.sources.with_attach(cluster); self } + #[must_use] + #[doc(hidden)] + pub fn with_attach_source(self, attach: AttachSource) -> Self { + self.with_existing_cluster(attach) + } + #[must_use] pub fn with_external_node(mut self, node: ExternalNodeSource) -> Self { self.sources = self.sources.with_external_node(node); diff --git a/testing-framework/core/src/scenario/sources/model.rs b/testing-framework/core/src/scenario/sources/model.rs index 5b0ec2c..df444f6 100644 --- a/testing-framework/core/src/scenario/sources/model.rs +++ b/testing-framework/core/src/scenario/sources/model.rs @@ -173,7 +173,7 @@ impl ScenarioSources { } #[must_use] - pub fn attached_source(&self) -> Option<&AttachSource> { + pub fn existing_cluster(&self) -> Option<&AttachSource> { match self { Self::Attached { attach, .. } => Some(attach), Self::Managed { .. } | Self::ExternalOnly { .. } => None, @@ -199,6 +199,11 @@ impl ScenarioSources { matches!(self, Self::Attached { .. }) } + #[must_use] + pub const fn uses_existing_cluster(&self) -> bool { + self.is_attached() + } + #[must_use] pub const fn is_external_only(&self) -> bool { matches!(self, Self::ExternalOnly { .. }) diff --git a/testing-framework/deployers/compose/src/deployer/orchestrator.rs b/testing-framework/deployers/compose/src/deployer/orchestrator.rs index c4fdc4f..9619e86 100644 --- a/testing-framework/deployers/compose/src/deployer/orchestrator.rs +++ b/testing-framework/deployers/compose/src/deployer/orchestrator.rs @@ -71,7 +71,7 @@ impl DeploymentOrchestrator { } })?; - if scenario.sources().is_attached() { + if scenario.sources().uses_existing_cluster() { return self .deploy_attached_only::(scenario, source_plan) .await @@ -215,7 +215,7 @@ impl DeploymentOrchestrator { } let attach = scenario - .attached_source() + .existing_cluster() .ok_or(ComposeRunnerError::InternalInvariant { message: "attached node control requested outside attached source mode", })?; @@ -243,7 +243,7 @@ impl DeploymentOrchestrator { Caps: Send + Sync, { let attach = scenario - .attached_source() + .existing_cluster() .ok_or(ComposeRunnerError::InternalInvariant { message: "compose attached cluster wait requested outside attached source mode", })?; @@ -373,7 +373,7 @@ where Caps: Send + Sync, { let project_name = scenario - .attached_source() + .existing_cluster() .and_then(|attach| attach.compose_project()) .map(ToOwned::to_owned); diff --git a/testing-framework/deployers/k8s/src/deployer/orchestrator.rs b/testing-framework/deployers/k8s/src/deployer/orchestrator.rs index ec1cb80..a41e8d5 100644 --- a/testing-framework/deployers/k8s/src/deployer/orchestrator.rs +++ b/testing-framework/deployers/k8s/src/deployer/orchestrator.rs @@ -179,7 +179,7 @@ where let observability = resolve_observability_inputs(scenario.capabilities())?; - if scenario.sources().is_attached() { + if scenario.sources().uses_existing_cluster() { let runner = deploy_attached_only::(scenario, source_plan, observability).await?; return Ok((runner, attached_metadata(scenario))); } @@ -250,11 +250,11 @@ where Caps: Send + Sync, { let namespace = scenario - .attached_source() + .existing_cluster() .and_then(|attach| attach.k8s_namespace()) .map(ToOwned::to_owned); let label_selector = scenario - .attached_source() + .existing_cluster() .and_then(|attach| attach.k8s_label_selector()) .map(ToOwned::to_owned); @@ -273,7 +273,7 @@ where Caps: Send + Sync, { let attach = scenario - .attached_source() + .existing_cluster() .ok_or_else(|| K8sRunnerError::InternalInvariant { message: "k8s attached cluster wait requested outside attached source mode".to_owned(), })?;