Skip to content

Commit

Permalink
Fix ephemeral agent creation api using agent namespace (#1842)
Browse files Browse the repository at this point in the history
* Fix ephemeral agent creation api using agent namespace instead of target.
Add note about agent namespace being irrelevant in ephemeral.

* changelog

* ..

* fix

* ..

* ..
  • Loading branch information
aviramha committed Aug 23, 2023
1 parent f271475 commit 0e3ceef
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog.d/+ephemeral-namespace.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ephemeral agent creation api using agent namespace instead of target.
Add note about agent namespace being irrelevant in ephemeral.
2 changes: 1 addition & 1 deletion mirrord-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
},
"namespace": {
"title": "agent.namespace {#agent-namespace}",
"description": "Namespace where the agent shall live.\n\nDefaults to the current kubernetes namespace.",
"description": "Namespace where the agent shall live. Note: Doesn't work with ephemeral containers. Defaults to the current kubernetes namespace.",
"type": [
"string",
"null"
Expand Down
2 changes: 1 addition & 1 deletion mirrord/config/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct AgentConfig {
/// ### agent.namespace {#agent-namespace}
///
/// Namespace where the agent shall live.
///
/// Note: Doesn't work with ephemeral containers.
/// Defaults to the current kubernetes namespace.
#[config(env = "MIRRORD_AGENT_NAMESPACE")]
pub namespace: Option<String>,
Expand Down
8 changes: 8 additions & 0 deletions mirrord/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ impl LayerConfig {
warnings.push(PAUSE_WITHOUT_STEAL_WARNING.to_string());
}
}

if self.agent.ephemeral && self.agent.namespace.is_some() {
warnings.push(
"Agent namespace is ignored when using an ephemeral container for the agent."
.to_string(),
);
}

if self
.feature
.network
Expand Down
2 changes: 1 addition & 1 deletion mirrord/kube/src/api/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl ContainerApi for EphemeralContainer {
}))?;
debug!("Requesting ephemeral_containers_subresource");

let pod_api = get_k8s_resource_api(client, agent.namespace.as_deref());
let pod_api = get_k8s_resource_api(client, runtime_data.pod_namespace.as_deref());
let pod: Pod = pod_api.get(&runtime_data.pod_name).await?;
let pod_spec = pod.spec.ok_or(KubeApiError::PodSpecNotFound)?;

Expand Down
2 changes: 2 additions & 0 deletions mirrord/kube/src/api/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl Display for ContainerRuntime {
#[derive(Debug)]
pub struct RuntimeData {
pub pod_name: String,
pub pod_namespace: Option<String>,
pub node_name: String,
pub container_id: String,
pub container_runtime: ContainerRuntime,
Expand Down Expand Up @@ -103,6 +104,7 @@ impl RuntimeData {

Ok(RuntimeData {
pod_name,
pod_namespace: pod.metadata.namespace.clone(),
node_name,
container_id,
container_runtime,
Expand Down

0 comments on commit 0e3ceef

Please sign in to comment.