Skip to content

Commit f9e45dd

Browse files
committed
feat(kubernetes): reconcile ingress objects for exposed sandbox services
Add an opt-in service ingress reconciler to the Kubernetes compute driver. The gateway polls its persisted service endpoints for exposed-service hostnames and ensures one ingress object exists per hostname, targeting the gateway's own Service, so exact-host routing in shared-domain multi-gateway clusters no longer requires manual route creation. The reconciled kind is configurable - an OpenShift Route with TLS passthrough, a Gateway API HTTPRoute, or a networking.k8s.io Ingress (annotated for nginx SSL passthrough) - and objects carry OpenShell ownership labels with orphan deletion when a service is no longer exposed. The hostname source lives in the gateway (it owns endpoint persistence and hostname minting) and is handed to drivers through the compute driver build context; the reconciler consumes final hostnames only. The Helm chart exposes serviceIngress values wiring the release Service, namespace, port, and parent Gateway automatically, and grants matching RBAC when enabled. Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>
1 parent 28551bd commit f9e45dd

15 files changed

Lines changed: 1111 additions & 11 deletions

File tree

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

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ pub struct KubernetesComputeConfig {
311311
/// `NetworkPolicy` in each managed workspace namespace that permits TCP 2222
312312
/// only from gateway pods matching this peer.
313313
pub managed_ssh_ingress: ManagedSshIngressConfig,
314+
/// Automatic ingress reconciliation for exposed sandbox services.
315+
pub service_ingress: ServiceIngressConfig,
314316
/// Image that provides the trusted `openshell-sandbox` bootstrap binary.
315317
pub sandbox_runtime_image: String,
316318
/// Kubernetes `imagePullPolicy` for the sandbox runtime image.
@@ -442,6 +444,72 @@ pub struct ManagedSshIngressConfig {
442444
pub gateway_pod_selector: BTreeMap<String, String>,
443445
}
444446

447+
/// Kubernetes object kind reconciled for exposed sandbox services.
448+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
449+
#[serde(rename_all = "snake_case")]
450+
pub enum ServiceIngressKind {
451+
/// `OpenShift` `Route` with TLS passthrough. The router forwards by SNI
452+
/// and the gateway terminates TLS with its own certificate.
453+
#[default]
454+
Route,
455+
/// Gateway API `HTTPRoute` attached to the configured parent `Gateway`.
456+
HttpRoute,
457+
/// `networking.k8s.io/v1` `Ingress`. Requires an ingress controller that
458+
/// supports SSL passthrough (the annotation is set for nginx).
459+
Ingress,
460+
}
461+
462+
/// Automatic ingress reconciliation for exposed sandbox services.
463+
///
464+
/// When enabled, the gateway periodically lists its exposed service
465+
/// hostnames and ensures one ingress object of the configured kind exists
466+
/// per hostname, targeting the gateway's own Service. Objects are labeled as
467+
/// OpenShell-managed and orphaned entries are removed.
468+
#[derive(Debug, Clone, Serialize, Deserialize)]
469+
#[serde(default, deny_unknown_fields)]
470+
pub struct ServiceIngressConfig {
471+
pub enabled: bool,
472+
/// Object kind to reconcile for each exposed hostname.
473+
pub kind: ServiceIngressKind,
474+
/// Name of the gateway's Kubernetes `Service` that terminates service
475+
/// traffic.
476+
pub target_service_name: String,
477+
/// Namespace holding the gateway `Service` and the reconciled objects.
478+
pub target_service_namespace: String,
479+
/// Numeric port of `target_service_name` that serves sandbox service
480+
/// traffic (the gateway's main listener).
481+
pub target_service_port: u16,
482+
/// `spec.ingressClassName` for the `ingress` kind.
483+
#[serde(skip_serializing_if = "Option::is_none")]
484+
pub ingress_class: Option<String>,
485+
/// Parent `Gateway` name for the `httproute` kind. Defaults to the
486+
/// gateway's own namespace.
487+
#[serde(skip_serializing_if = "Option::is_none")]
488+
pub http_route_parent_gateway: Option<String>,
489+
/// Namespace of the parent `Gateway`. Defaults to
490+
/// `target_service_namespace`.
491+
#[serde(skip_serializing_if = "Option::is_none")]
492+
pub http_route_parent_namespace: Option<String>,
493+
/// Seconds between reconciliation passes.
494+
pub poll_interval_secs: u64,
495+
}
496+
497+
impl Default for ServiceIngressConfig {
498+
fn default() -> Self {
499+
Self {
500+
enabled: false,
501+
kind: ServiceIngressKind::default(),
502+
target_service_name: String::new(),
503+
target_service_namespace: String::new(),
504+
target_service_port: 8080,
505+
ingress_class: None,
506+
http_route_parent_gateway: None,
507+
http_route_parent_namespace: None,
508+
poll_interval_secs: 15,
509+
}
510+
}
511+
}
512+
445513
/// Lower bound enforced by kubelet for projected SA tokens.
446514
pub const MIN_SA_TOKEN_TTL_SECS: i64 = 600;
447515

@@ -487,6 +555,7 @@ impl Default for KubernetesComputeConfig {
487555
image_pull_policy: None,
488556
image_pull_secrets: Vec::new(),
489557
managed_ssh_ingress: ManagedSshIngressConfig::default(),
558+
service_ingress: ServiceIngressConfig::default(),
490559
sandbox_runtime_image: config::default_sandbox_runtime_image(),
491560
sandbox_runtime_image_pull_policy: None,
492561
supervisor_image: config::default_supervisor_image(),
@@ -530,7 +599,38 @@ impl KubernetesComputeConfig {
530599
self.validate_proxy_uid()?;
531600
self.validate_upstream_proxy_config()?;
532601
self.validate_allowed_pod_annotations()?;
533-
self.validate_allowed_pod_labels()
602+
self.validate_allowed_pod_labels()?;
603+
self.validate_service_ingress()
604+
}
605+
606+
/// Automatic service ingress reconciliation runs in every workspace mode,
607+
/// because the reconciled objects live in the gateway's own namespace.
608+
pub fn validate_service_ingress(&self) -> Result<(), String> {
609+
if !self.service_ingress.enabled {
610+
return Ok(());
611+
}
612+
let ingress = &self.service_ingress;
613+
if ingress.target_service_name.is_empty() {
614+
return Err("service_ingress requires target_service_name".into());
615+
}
616+
if ingress.target_service_namespace.is_empty() {
617+
return Err("service_ingress requires target_service_namespace".into());
618+
}
619+
if ingress.target_service_port == 0 {
620+
return Err("service_ingress requires a non-zero target_service_port".into());
621+
}
622+
if ingress.kind == ServiceIngressKind::HttpRoute
623+
&& ingress
624+
.http_route_parent_gateway
625+
.as_deref()
626+
.is_none_or(str::is_empty)
627+
{
628+
return Err("service_ingress kind=httproute requires http_route_parent_gateway".into());
629+
}
630+
if ingress.poll_interval_secs == 0 {
631+
return Err("service_ingress requires a non-zero poll_interval_secs".into());
632+
}
633+
Ok(())
534634
}
535635

536636
/// The shared supervisor serves only sandbox instances it can isolate: it

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ pub mod isolation;
88
mod lifecycle;
99
pub mod otel_tracing;
1010
mod resource_admission;
11-
mod sandbox_runtime;
11+
pub mod sandbox_runtime;
12+
pub mod service_ingress;
1213
mod shared_supervisor;
1314

1415
pub use config::{
1516
DEFAULT_GATEWAY_ID, DEFAULT_SANDBOX_SERVICE_ACCOUNT_NAME, DEFAULT_WORKSPACE_STORAGE_SIZE,
1617
KubernetesComputeConfig, KubernetesControlConnection, KubernetesImagePullPolicy,
17-
KubernetesSandboxRuntimeConfig, ManagedSshIngressConfig, SharedSupervisorConfig,
18-
SupervisorTopology, WorkspaceMode, managed_namespace_prefix,
18+
KubernetesSandboxRuntimeConfig, ManagedSshIngressConfig, ServiceIngressConfig,
19+
ServiceIngressKind, SharedSupervisorConfig, SupervisorTopology, WorkspaceMode,
20+
managed_namespace_prefix,
1921
};
2022
pub use driver::{KubernetesComputeDriver, KubernetesDriverError};
2123
pub use grpc::ComputeDriverService;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use openshell_core::proto::compute::v1::compute_driver_server::ComputeDriverServ
1313
use openshell_driver_kubernetes::{
1414
ComputeDriverService, DEFAULT_GATEWAY_ID, DEFAULT_SANDBOX_SERVICE_ACCOUNT_NAME,
1515
KubernetesComputeConfig, KubernetesComputeDriver, KubernetesImagePullPolicy,
16-
KubernetesSandboxRuntimeConfig, ManagedSshIngressConfig, WorkspaceMode,
16+
KubernetesSandboxRuntimeConfig, ManagedSshIngressConfig, ServiceIngressConfig, WorkspaceMode,
1717
};
1818

1919
#[derive(Parser, Debug)]
@@ -278,6 +278,10 @@ async fn main() -> Result<()> {
278278
gateway_namespace: args.managed_ssh_gateway_namespace.unwrap_or_default(),
279279
gateway_pod_selector: managed_ssh_gateway_pod_selector,
280280
},
281+
// Service ingress reconciliation is gateway-driven; the
282+
// standalone driver process has no access to the gateway's
283+
// exposed-service hostnames.
284+
service_ingress: ServiceIngressConfig::default(),
281285
sandbox_runtime_image: args
282286
.sandbox_runtime_image
283287
.unwrap_or_else(openshell_core::config::default_sandbox_runtime_image),

0 commit comments

Comments
 (0)