Skip to content

Commit

Permalink
Fixes selecting container to use when using operator (#1958)
Browse files Browse the repository at this point in the history
* Fixes selecting container to use when using operator

* format fix

* more internal stuff
  • Loading branch information
aviramha authored Sep 24, 2023
1 parent dee1928 commit 9cf74e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/+select-container-in-operator.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes selecting container to use when using operator
13 changes: 13 additions & 0 deletions mirrord/config/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
}
}
/// <!--${internal}-->
/// Mirror the pod specified by [`PodTarget::pod`].
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash, Debug, JsonSchema)]
Expand Down
19 changes: 14 additions & 5 deletions mirrord/operator/src/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 9cf74e6

Please sign in to comment.