Skip to content

Commit 59e081b

Browse files
committed
fix(kubernetes): reference proxy-pod companions by CR name in the pod template
The companion resources are named from the Sandbox CR name, but the workload pod template still derived the CA secret mount and HTTP_PROXY Service name from the bare sandbox name, and the create-rollback path cleaned up bare-name resources in the static namespace. In shared mode the workload then mounted a CA secret that did not exist and never became Ready. Thread the CR name through SandboxPodParams and use it for the pod template's companion references and the rollback cleanup, matching create_proxy_pod_resources. Caught by re-testing a shared-mode create on the cluster. Signed-off-by: Russell Bryant <rbryant@redhat.com>
1 parent 57e3bd7 commit 59e081b

1 file changed

Lines changed: 62 additions & 3 deletions

File tree

  • crates/openshell-driver-kubernetes/src

‎crates/openshell-driver-kubernetes/src/driver.rs‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,7 @@ impl KubernetesComputeDriver {
14211421
.resolve_sandbox_identity_in_namespace(&target_namespace)
14221422
.await;
14231423

1424+
let cr_name = self.config.kube_resource_name(workspace, name);
14241425
let params = SandboxPodParams {
14251426
default_image: &self.config.default_image,
14261427
image_pull_policy: &self.config.image_pull_policy,
@@ -1451,6 +1452,7 @@ impl KubernetesComputeDriver {
14511452
service_account_name: &self.config.service_account_name,
14521453
sandbox_id: &sandbox.id,
14531454
sandbox_name: &sandbox.name,
1455+
cr_name: &cr_name,
14541456
grpc_endpoint: &self.config.grpc_endpoint,
14551457
ssh_socket_path: self.ssh_socket_path(),
14561458
client_tls_secret_name: &self.config.client_tls_secret_name,
@@ -1472,7 +1474,7 @@ impl KubernetesComputeDriver {
14721474

14731475
let data = sandbox_to_k8s_spec(sandbox.spec.as_ref(), &params)
14741476
.map_err(KubernetesDriverError::InvalidArgument)?;
1475-
let kube_name = self.config.kube_resource_name(workspace, name);
1477+
let kube_name = cr_name.clone();
14761478
let mut obj = DynamicObject::new(&kube_name, &agent_sandbox_api.resource);
14771479
let mut annotations = sandbox_annotations(sandbox);
14781480
for key in [
@@ -1548,7 +1550,7 @@ impl KubernetesComputeDriver {
15481550
error = %err,
15491551
"Failed to create proxy-pod resources; deleting Sandbox CR"
15501552
);
1551-
self.cleanup_proxy_pod_resources(name, &self.config.namespace)
1553+
self.cleanup_proxy_pod_resources(params.cr_name, params.namespace)
15521554
.await;
15531555
let _ = tokio::time::timeout(
15541556
KUBE_API_TIMEOUT,
@@ -3657,7 +3659,7 @@ fn apply_supervisor_proxy_pod_topology(
36573659

36583660
apply_proxy_pod_affinity(spec, params.sandbox_id, params.proxy_pod_affinity);
36593661

3660-
let names = proxy_pod_resource_names(params.sandbox_name);
3662+
let names = proxy_pod_resource_names(params.cr_name);
36613663
let service_dns = proxy_pod_service_dns(&names.service, params.namespace);
36623664

36633665
let volumes = spec
@@ -4016,6 +4018,10 @@ struct SandboxPodParams<'a> {
40164018
service_account_name: &'a str,
40174019
sandbox_id: &'a str,
40184020
sandbox_name: &'a str,
4021+
/// Sandbox CR resource name (`kube_resource_name`), unique per sandbox in
4022+
/// every workspace mode. Companion resource names derive from this so they
4023+
/// match across the workload pod template and the companion objects.
4024+
cr_name: &'a str,
40194025
grpc_endpoint: &'a str,
40204026
ssh_socket_path: &'a str,
40214027
client_tls_secret_name: &'a str,
@@ -4060,6 +4066,7 @@ impl Default for SandboxPodParams<'_> {
40604066
service_account_name: DEFAULT_SANDBOX_SERVICE_ACCOUNT_NAME,
40614067
sandbox_id: "",
40624068
sandbox_name: "",
4069+
cr_name: "",
40634070
grpc_endpoint: "",
40644071
ssh_socket_path: "",
40654072
client_tls_secret_name: "",
@@ -7502,6 +7509,7 @@ mod tests {
75027509
namespace: "agents",
75037510
sandbox_id: "sandbox-123",
75047511
sandbox_name: "example-sandbox",
7512+
cr_name: "example-sandbox",
75057513
grpc_endpoint: "https://openshell-gateway.openshell.svc:8080",
75067514
proxy_uid: 2200,
75077515
sandbox_uid: 1500,
@@ -7618,6 +7626,7 @@ mod tests {
76187626
namespace: "agents",
76197627
sandbox_id: "sandbox-123",
76207628
sandbox_name: "example-sandbox",
7629+
cr_name: "example-sandbox",
76217630
proxy_uid: 2200,
76227631
sandbox_uid: 1500,
76237632
sandbox_gid: 1600,
@@ -7706,6 +7715,7 @@ mod tests {
77067715
service_account_name: "openshell-sandbox",
77077716
sandbox_id: "sandbox-123",
77087717
sandbox_name: "example-sandbox",
7718+
cr_name: "example-sandbox",
77097719
grpc_endpoint: "http://openshell-gateway.openshell.svc:8080",
77107720
proxy_uid: 2200,
77117721
sandbox_uid: 1500,
@@ -7843,6 +7853,7 @@ mod tests {
78437853
namespace: "agents",
78447854
sandbox_id: "sandbox-123",
78457855
sandbox_name: "example-sandbox",
7856+
cr_name: "example-sandbox",
78467857
proxy_pod_dns_peers: peers,
78477858
..SandboxPodParams::default()
78487859
};
@@ -7923,6 +7934,52 @@ mod tests {
79237934
assert_eq!(pod_spec["tolerations"][0]["key"], "gpu");
79247935
}
79257936

7937+
#[test]
7938+
fn proxy_pod_pod_template_references_companions_by_cr_name() {
7939+
// Shared mode: CR name is `<workspace>--<name>`, distinct from the bare
7940+
// sandbox name. The workload pod's CA secret mount and proxy URL must
7941+
// use the CR-name-derived companion names, or the pod mounts a secret
7942+
// that does not exist (and never becomes Ready).
7943+
let params = SandboxPodParams {
7944+
topology: SupervisorTopology::ProxyPod,
7945+
supervisor_image: "supervisor:latest",
7946+
namespace: "agents",
7947+
sandbox_id: "sandbox-1",
7948+
sandbox_name: "dev",
7949+
cr_name: "team-a--dev",
7950+
proxy_uid: 2000,
7951+
sandbox_uid: 1500,
7952+
sandbox_gid: 1500,
7953+
..SandboxPodParams::default()
7954+
};
7955+
let pod_template = sandbox_template_to_k8s(
7956+
&SandboxTemplate {
7957+
image: "agent:latest".to_string(),
7958+
..SandboxTemplate::default()
7959+
},
7960+
false,
7961+
&std::collections::HashMap::new(),
7962+
false,
7963+
&params,
7964+
);
7965+
let names = proxy_pod_resource_names("team-a--dev");
7966+
let service_dns = proxy_pod_service_dns(&names.service, "agents");
7967+
let agent = &pod_template["spec"]["containers"][0];
7968+
assert_eq!(
7969+
rendered_env(agent, "HTTP_PROXY"),
7970+
Some(format!("http://{service_dns}:3128").as_str())
7971+
);
7972+
let volumes = pod_template["spec"]["volumes"].as_array().unwrap();
7973+
assert!(
7974+
volumes.iter().any(|v| {
7975+
v["name"] == "openshell-proxy-pod-ca-source"
7976+
&& v["secret"]["secretName"] == serde_json::json!(names.proxy_ca_secret)
7977+
}),
7978+
"workload CA volume must reference the CR-name-derived secret {}",
7979+
names.proxy_ca_secret
7980+
);
7981+
}
7982+
79267983
#[test]
79277984
fn proxy_pod_resource_names_disambiguate_by_cr_name() {
79287985
// In shared mode two workspaces may hold a sandbox named `dev`, giving
@@ -7976,6 +8033,7 @@ mod tests {
79768033
namespace: "agents",
79778034
sandbox_id: "sandbox-123",
79788035
sandbox_name: "example-sandbox",
8036+
cr_name: "example-sandbox",
79798037
proxy_uid: 2200,
79808038
sandbox_uid: 1500,
79818039
sandbox_gid: 1500,
@@ -8017,6 +8075,7 @@ mod tests {
80178075
namespace: "agents",
80188076
sandbox_id: "sandbox-123",
80198077
sandbox_name: "example-sandbox",
8078+
cr_name: "example-sandbox",
80208079
..SandboxPodParams::default()
80218080
};
80228081
let pod_template = sandbox_template_to_k8s(

0 commit comments

Comments
 (0)