forked from metalbear-co/mirrord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy target scale down (metalbear-co#2054)
* Config * More CRD docs * warning when target is not a deployment * Config docs * Changelog entry * Scale to 0 * mirrord-schema update * Removed 'Option' from CRD * Erroring out on scale down + target is not a deployment * Config fix * doc improvement * Format * Config finally fixed * Checking target type in 'LayerConfig::verify' * Doc updated * mirrord-schema updated * Format
- Loading branch information
Showing
8 changed files
with
186 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added option to scale down target deployment when using `copy target` feature. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//! Config for the `copy target` feature. [`CopyTargetFileConfig`] does follow the pattern of other | ||
//! [`feature`](crate::feature) configs by not implementing | ||
//! [`MirrordToggleableConfig`](crate::util::MirrordToggleableConfig). The reason for this is that | ||
//! [`ToggleableConfig`](crate::util::ToggleableConfig) is enabled by default. This config should be | ||
//! disabled unless explicitly enabled. | ||
use mirrord_analytics::CollectAnalytics; | ||
use schemars::JsonSchema; | ||
use serde::Deserialize; | ||
|
||
use crate::config::{ConfigContext, FromMirrordConfig, MirrordConfig, Result}; | ||
|
||
/// Allows the user to target a pod created dynamically from the orignal [`target`](#target). | ||
/// The new pod inherits most of the original target's specification, e.g. labels. | ||
/// | ||
/// ```json | ||
/// { | ||
/// "feature": { | ||
/// "copy_target": { | ||
/// "scale_down": true | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// ```json | ||
/// { | ||
/// "feature": { | ||
/// "copy_target": true | ||
/// } | ||
/// } | ||
/// ``` | ||
#[derive(Clone, Debug, Deserialize, JsonSchema)] | ||
#[cfg_attr(test, derive(PartialEq, Eq))] | ||
#[serde(untagged)] | ||
pub enum CopyTargetFileConfig { | ||
Simple(bool), | ||
Advanced { | ||
/// ### feature.copy_target.scale_down {#feature-copy_target-scale_down} | ||
/// | ||
/// If this option is set and [`target`](#target) is a deployment, | ||
/// mirrord will scale it down to 0 for the time the copied pod is alive. | ||
scale_down: Option<bool>, | ||
}, | ||
} | ||
|
||
impl Default for CopyTargetFileConfig { | ||
fn default() -> Self { | ||
Self::Simple(false) | ||
} | ||
} | ||
|
||
impl MirrordConfig for CopyTargetFileConfig { | ||
type Generated = CopyTargetConfig; | ||
|
||
fn generate_config(self, _context: &mut ConfigContext) -> Result<Self::Generated> { | ||
let res = match self { | ||
Self::Simple(enabled) => Self::Generated { | ||
enabled, | ||
scale_down: false, | ||
}, | ||
Self::Advanced { scale_down } => Self::Generated { | ||
enabled: true, | ||
scale_down: scale_down.unwrap_or_default(), | ||
}, | ||
}; | ||
|
||
Ok(res) | ||
} | ||
} | ||
|
||
impl FromMirrordConfig for CopyTargetConfig { | ||
type Generator = CopyTargetFileConfig; | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct CopyTargetConfig { | ||
pub enabled: bool, | ||
pub scale_down: bool, | ||
} | ||
|
||
impl CollectAnalytics for &CopyTargetConfig { | ||
fn collect_analytics(&self, analytics: &mut mirrord_analytics::Analytics) { | ||
analytics.add("enabled", self.enabled); | ||
analytics.add("scale_down", self.scale_down); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters