Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tolerations for targetless agent. #3033

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mirrord/config/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ pub struct AgentConfig {

/// ### agent.tolerations {#agent-tolerations}
///
/// Set pod tolerations. (not with ephemeral agents)
/// Default is
/// Set pod tolerations. (not with ephemeral agents).
///
/// Defaults to `operator: Exists`.
///
/// ```json
/// [
/// {
/// "operator": "Exists"
/// "key": "meow", "operator": "Exists", "effect": "NoSchedule"
Razz4780 marked this conversation as resolved.
Show resolved Hide resolved
/// }
/// ]
/// ```
Expand Down
12 changes: 9 additions & 3 deletions mirrord/kube/src/api/container/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::api::{
runtime::RuntimeData,
};

/// The `targetless` agent variant is created by this, see its [`PodVariant::as_update`].
pub struct PodVariant<'c> {
agent: &'c AgentConfig,
command_line: Vec<String>,
Expand Down Expand Up @@ -67,8 +68,6 @@ impl ContainerVariant for PodVariant<'_> {
..
} = self;

let tolerations = agent.tolerations.as_ref().unwrap_or(&DEFAULT_TOLERATIONS);

let resources = agent.resources.clone().unwrap_or_else(|| {
serde_json::from_value(serde_json::json!({
"requests":
Expand Down Expand Up @@ -124,7 +123,7 @@ impl ContainerVariant for PodVariant<'_> {
spec: Some(PodSpec {
restart_policy: Some("Never".to_string()),
image_pull_secrets,
tolerations: Some(tolerations.clone()),
tolerations: agent.tolerations.clone(),
node_selector: Some(node_selector),
service_account_name: agent.service_account.clone(),
containers: vec![Container {
Expand All @@ -148,6 +147,10 @@ impl ContainerVariant for PodVariant<'_> {
}
}

/// The `targeted` agent variant is created by this.
///
/// It builds on top of [`PodVariant`], merging spec, etc from there. See
/// [`PodTargetedVariant::as_update`].
pub struct PodTargetedVariant<'c> {
inner: PodVariant<'c>,
runtime_data: &'c RuntimeData,
Expand Down Expand Up @@ -195,6 +198,8 @@ impl ContainerVariant for PodTargetedVariant<'_> {
let agent = self.agent_config();
let params = self.params();

let tolerations = agent.tolerations.as_ref().unwrap_or(&DEFAULT_TOLERATIONS);

let env = self.runtime_data.mesh.map(|mesh_vendor| {
let mut env = vec![EnvVar {
name: "MIRRORD_AGENT_IN_SERVICE_MESH".into(),
Expand All @@ -214,6 +219,7 @@ impl ContainerVariant for PodTargetedVariant<'_> {
let update = Pod {
spec: Some(PodSpec {
restart_policy: Some("Never".to_string()),
tolerations: Some(tolerations.clone()),
host_pid: Some(true),
node_name: Some(runtime_data.node_name.clone()),
volumes: Some(vec![
Expand Down
Loading