@@ -19,7 +19,10 @@ use bollard::query_parameters::{
1919use bytes:: Bytes ;
2020use futures:: { Stream , StreamExt } ;
2121use openshell_core:: config:: { DEFAULT_DOCKER_NETWORK_NAME , DEFAULT_STOP_TIMEOUT_SECS } ;
22- use openshell_core:: driver_utils:: SUPERVISOR_IMAGE_BINARY_PATH ;
22+ use openshell_core:: driver_utils:: {
23+ LABEL_MANAGED_BY , LABEL_MANAGED_BY_VALUE , LABEL_SANDBOX_ID , LABEL_SANDBOX_NAME ,
24+ LABEL_SANDBOX_NAMESPACE , SUPERVISOR_IMAGE_BINARY_PATH ,
25+ } ;
2326use openshell_core:: gpu:: cdi_gpu_device_ids;
2427use openshell_core:: proto:: compute:: v1:: {
2528 CreateSandboxRequest , CreateSandboxResponse , DeleteSandboxRequest , DeleteSandboxResponse ,
@@ -48,12 +51,6 @@ const WATCH_BUFFER: usize = 128;
4851const WATCH_POLL_INTERVAL : Duration = Duration :: from_secs ( 2 ) ;
4952const WATCH_POLL_MAX_BACKOFF : Duration = Duration :: from_secs ( 30 ) ;
5053
51- const MANAGED_BY_LABEL_KEY : & str = "openshell.ai/managed-by" ;
52- const MANAGED_BY_LABEL_VALUE : & str = "openshell" ;
53- const SANDBOX_ID_LABEL_KEY : & str = "openshell.ai/sandbox-id" ;
54- const SANDBOX_NAME_LABEL_KEY : & str = "openshell.ai/sandbox-name" ;
55- const SANDBOX_NAMESPACE_LABEL_KEY : & str = "openshell.ai/sandbox-namespace" ;
56-
5754const SUPERVISOR_MOUNT_PATH : & str = "/opt/openshell/bin/openshell-sandbox" ;
5855const TLS_CA_MOUNT_PATH : & str = "/etc/openshell/tls/client/ca.crt" ;
5956const TLS_CERT_MOUNT_PATH : & str = "/etc/openshell/tls/client/tls.crt" ;
@@ -683,9 +680,9 @@ impl DockerComputeDriver {
683680 ) -> Result < Option < ContainerSummary > , Status > {
684681 let mut label_filter_values = Vec :: new ( ) ;
685682 if !sandbox_id. is_empty ( ) {
686- label_filter_values. push ( format ! ( "{SANDBOX_ID_LABEL_KEY }={sandbox_id}" ) ) ;
683+ label_filter_values. push ( format ! ( "{LABEL_SANDBOX_ID }={sandbox_id}" ) ) ;
687684 } else if !sandbox_name. is_empty ( ) {
688- label_filter_values. push ( format ! ( "{SANDBOX_NAME_LABEL_KEY }={sandbox_name}" ) ) ;
685+ label_filter_values. push ( format ! ( "{LABEL_SANDBOX_NAME }={sandbox_name}" ) ) ;
689686 }
690687
691688 let filters =
@@ -706,15 +703,15 @@ impl DockerComputeDriver {
706703 return false ;
707704 } ;
708705 let namespace_matches = labels
709- . get ( SANDBOX_NAMESPACE_LABEL_KEY )
706+ . get ( LABEL_SANDBOX_NAMESPACE )
710707 . is_some_and ( |value| value == & self . config . sandbox_namespace ) ;
711708 let id_matches = sandbox_id. is_empty ( )
712709 || labels
713- . get ( SANDBOX_ID_LABEL_KEY )
710+ . get ( LABEL_SANDBOX_ID )
714711 . is_some_and ( |value| value == sandbox_id) ;
715712 let name_matches = sandbox_name. is_empty ( )
716713 || labels
717- . get ( SANDBOX_NAME_LABEL_KEY )
714+ . get ( LABEL_SANDBOX_NAME )
718715 . is_some_and ( |value| value == sandbox_name) ;
719716 namespace_matches && id_matches && name_matches
720717 } ) )
@@ -1015,17 +1012,17 @@ fn build_container_create_body(
10151012 let resource_limits = docker_resource_limits ( template) ?;
10161013 let mut labels = template. labels . clone ( ) ;
10171014 labels. insert (
1018- MANAGED_BY_LABEL_KEY . to_string ( ) ,
1019- MANAGED_BY_LABEL_VALUE . to_string ( ) ,
1015+ LABEL_MANAGED_BY . to_string ( ) ,
1016+ LABEL_MANAGED_BY_VALUE . to_string ( ) ,
10201017 ) ;
1021- labels. insert ( SANDBOX_ID_LABEL_KEY . to_string ( ) , sandbox. id . clone ( ) ) ;
1022- labels. insert ( SANDBOX_NAME_LABEL_KEY . to_string ( ) , sandbox. name . clone ( ) ) ;
1018+ labels. insert ( LABEL_SANDBOX_ID . to_string ( ) , sandbox. id . clone ( ) ) ;
1019+ labels. insert ( LABEL_SANDBOX_NAME . to_string ( ) , sandbox. name . clone ( ) ) ;
10231020 // The list/get/find paths filter by `config.sandbox_namespace`, so use
10241021 // the same value here. `DriverSandbox.namespace` is unset on the request
10251022 // path (the gateway elides it), and using it would produce containers
10261023 // that the driver itself cannot find afterwards.
10271024 labels. insert (
1028- SANDBOX_NAMESPACE_LABEL_KEY . to_string ( ) ,
1025+ LABEL_SANDBOX_NAMESPACE . to_string ( ) ,
10291026 config. sandbox_namespace . clone ( ) ,
10301027 ) ;
10311028
@@ -1217,8 +1214,8 @@ async fn ensure_bridge_network(docker: &Docker, network_name: &str) -> CoreResul
12171214 driver : Some ( DOCKER_NETWORK_DRIVER . to_string ( ) ) ,
12181215 attachable : Some ( true ) ,
12191216 labels : Some ( HashMap :: from ( [ (
1220- MANAGED_BY_LABEL_KEY . to_string ( ) ,
1221- MANAGED_BY_LABEL_VALUE . to_string ( ) ,
1217+ LABEL_MANAGED_BY . to_string ( ) ,
1218+ LABEL_MANAGED_BY_VALUE . to_string ( ) ,
12221219 ) ] ) ) ,
12231220 ..Default :: default ( )
12241221 } )
@@ -1397,10 +1394,10 @@ fn sandbox_from_container_summary(
13971394 readiness : & dyn SupervisorReadiness ,
13981395) -> Option < DriverSandbox > {
13991396 let labels = summary. labels . as_ref ( ) ?;
1400- let id = labels. get ( SANDBOX_ID_LABEL_KEY ) ?. clone ( ) ;
1401- let name = labels. get ( SANDBOX_NAME_LABEL_KEY ) ?. clone ( ) ;
1397+ let id = labels. get ( LABEL_SANDBOX_ID ) ?. clone ( ) ;
1398+ let name = labels. get ( LABEL_SANDBOX_NAME ) ?. clone ( ) ;
14021399 let namespace = labels
1403- . get ( SANDBOX_NAMESPACE_LABEL_KEY )
1400+ . get ( LABEL_SANDBOX_NAMESPACE )
14041401 . cloned ( )
14051402 . unwrap_or_default ( ) ;
14061403
@@ -1573,8 +1570,8 @@ fn managed_container_label_filters(
15731570 extra_values : impl IntoIterator < Item = String > ,
15741571) -> HashMap < String , Vec < String > > {
15751572 let mut values = vec ! [
1576- format!( "{MANAGED_BY_LABEL_KEY }={MANAGED_BY_LABEL_VALUE }" ) ,
1577- format!( "{SANDBOX_NAMESPACE_LABEL_KEY }={sandbox_namespace}" ) ,
1573+ format!( "{LABEL_MANAGED_BY }={LABEL_MANAGED_BY_VALUE }" ) ,
1574+ format!( "{LABEL_SANDBOX_NAMESPACE }={sandbox_namespace}" ) ,
15781575 ] ;
15791576 values. extend ( extra_values) ;
15801577 label_filters ( values)
0 commit comments