From 9cf74e6172eee7165003c7d4a3e3c31784633d6f Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Sun, 24 Sep 2023 17:42:38 +0300 Subject: [PATCH] Fixes selecting container to use when using operator (#1958) * Fixes selecting container to use when using operator * format fix * more internal stuff --- .../+select-container-in-operator.fixed.md | 1 + mirrord/config/src/target.rs | 13 +++++++++++++ mirrord/operator/src/crd.rs | 19 ++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 changelog.d/+select-container-in-operator.fixed.md diff --git a/changelog.d/+select-container-in-operator.fixed.md b/changelog.d/+select-container-in-operator.fixed.md new file mode 100644 index 00000000000..965dac9b3b6 --- /dev/null +++ b/changelog.d/+select-container-in-operator.fixed.md @@ -0,0 +1 @@ +Fixes selecting container to use when using operator \ No newline at end of file diff --git a/mirrord/config/src/target.rs b/mirrord/config/src/target.rs index ae47afd013d..b91f096a51f 100644 --- a/mirrord/config/src/target.rs +++ b/mirrord/config/src/target.rs @@ -211,6 +211,19 @@ impl FromStr for Target { } } +impl Target { + /// Get the target name - pod name, deployment name, rollout name.. + pub fn get_target_name(&self) -> String { + match self { + Target::Deployment(deployment) => deployment.deployment.clone(), + Target::Pod(pod) => pod.pod.clone(), + Target::Rollout(rollout) => rollout.rollout.clone(), + Target::Targetless => { + unreachable!("this shouldn't happen - called from operator on a flow where it's not targetless.") + } + } + } +} /// /// Mirror the pod specified by [`PodTarget::pod`]. #[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash, Debug, JsonSchema)] diff --git a/mirrord/operator/src/crd.rs b/mirrord/operator/src/crd.rs index dd7265fd394..81848739a08 100644 --- a/mirrord/operator/src/crd.rs +++ b/mirrord/operator/src/crd.rs @@ -21,12 +21,21 @@ pub struct TargetSpec { } impl TargetCrd { + /// Creates target name in format of target_type.target_name.[container.container_name] + /// for example: + /// deploy.nginx + /// deploy.nginx.container.nginx pub fn target_name(target: &Target) -> String { - match target { - Target::Deployment(target) => format!("deploy.{}", target.deployment), - Target::Pod(target) => format!("pod.{}", target.pod), - Target::Rollout(target) => format!("rollout.{}", target.rollout), - Target::Targetless => TARGETLESS_TARGET_NAME.to_string(), + let (type_name, target, container) = match target { + Target::Deployment(target) => ("deploy", &target.deployment, &target.container), + Target::Pod(target) => ("pod", &target.pod, &target.container), + Target::Rollout(target) => ("rollout", &target.rollout, &target.container), + Target::Targetless => return TARGETLESS_TARGET_NAME.to_string(), + }; + if let Some(container) = container { + format!("{}.{}.container.{}", type_name, target, container) + } else { + format!("{}.{}", type_name, target) } }