pub async fn new(
        store: Arc<dyn Store + Sync + Send>,
        config: &kubelet::config::Config,
        kubeconfig: kube::Config,
    ) -> anyhow::Result<Self> {
        let client = kube::Client::new(kubeconfig);
        let host = Arc::new(Mutex::new(WasccHost::new()));
        let log_path = config.data_dir.join(LOG_DIR_NAME);
        let volume_path = config.data_dir.join(VOLUME_DIR);
        let port_map = Arc::new(TokioMutex::new(BTreeMap::<u16, PodKey>::new()));
        tokio::fs::create_dir_all(&log_path).await?;
        tokio::fs::create_dir_all(&volume_path).await?;

        // wascc has native and portable capabilities.
        //
        // Native capabilities are either dynamic libraries (.so, .dylib, .dll)
        // or statically linked Rust libaries. If the native capabilty is a dynamic
        // library it must be loaded and configured through [`NativeCapability::from_file`].
        // If it is a statically linked libary it can be configured through
        // [`NativeCapability::from_instance`].
        //
        // Portable capabilities are WASM modules.  Portable capabilities
        // don't fully work, and won't until the WASI spec has matured.
        //
        // Here we are using the native capabilties as statically linked libraries that will
        // be compiled into the wascc-provider binary.
        let cloned_host = host.clone();
        tokio::task::spawn_blocking(move || {
            info!("Loading HTTP capability");
            let http_provider = HttpServerProvider::new();
            let data = NativeCapability::from_instance(http_provider, None)
                .map_err(|e| anyhow::anyhow!("Failed to instantiate HTTP capability: {}", e))?;

            cloned_host
                .lock()
                .unwrap()
                .add_native_capability(data)
                .map_err(|e| anyhow::anyhow!("Failed to add HTTP capability: {}", e))?;

            info!("Loading log capability");
            let logging_provider = LoggingProvider::new();
            let logging_capability = NativeCapability::from_instance(logging_provider, None)
                .map_err(|e| anyhow::anyhow!("Failed to instantiate log capability: {}", e))?;
            cloned_host
                .lock()
                .unwrap()
                .add_native_capability(logging_capability)
                .map_err(|e| anyhow::anyhow!("Failed to add log capability: {}", e))
        })
        .await??;
        Ok(Self {
            shared: SharedPodState {
                client,
                handles: Default::default(),
                store,
                volume_path,
                log_path,
                host,
                port_map,
            },
        })
    }
/// Returns a new wasCC provider configured to use the proper data directory
/// (including creating it if necessary)
Returns a new wasCC provider configured to use the proper data directory
(including creating it if necessary)
Returns a new wasCC provider configured to use the proper data directory ( including creating it if necessary )
pub async fn new(
        store: Arc<dyn Store + Sync + Send>,
        config: &kubelet::config::Config,
        kubeconfig: kube::Config,
    ) -> anyhow::Result<Self> {
        let client = kube::Client::new(kubeconfig);
        let host = Arc::new(Mutex::new(WasccHost::new()));
        let log_path = config.data_dir.join(LOG_DIR_NAME);
        let volume_path = config.data_dir.join(VOLUME_DIR);
        let port_map = Arc::new(TokioMutex::new(BTreeMap::<u16, PodKey>::new()));
        tokio::fs::create_dir_all(&log_path).await?;
        tokio::fs::create_dir_all(&volume_path).await?;
        // wascc has native and portable capabilities.
        //
        // Native capabilities are either dynamic libraries (.so, .dylib, .dll)
        // or statically linked Rust libaries. If the native capabilty is a dynamic
        // library it must be loaded and configured through [`NativeCapability::from_file`].
        // If it is a statically linked libary it can be configured through
        // [`NativeCapability::from_instance`].
        //
        // Portable capabilities are WASM modules.  Portable capabilities
        // don't fully work, and won't until the WASI spec has matured.
        //
        // Here we are using the native capabilties as statically linked libraries that will
        // be compiled into the wascc-provider binary.
        let cloned_host = host.clone();
        tokio::task::spawn_blocking(move || {
            info!("Loading HTTP capability");
            let http_provider = HttpServerProvider::new();
            let data = NativeCapability::from_instance(http_provider, None)
                .map_err(|e| anyhow::anyhow!("Failed to instantiate HTTP capability: {}", e))?;
            cloned_host
                .lock()
                .unwrap()
                .add_native_capability(data)
                .map_err(|e| anyhow::anyhow!("Failed to add HTTP capability: {}", e))?;
            info!("Loading log capability");
            let logging_provider = LoggingProvider::new();
            let logging_capability = NativeCapability::from_instance(logging_provider, None)
                .map_err(|e| anyhow::anyhow!("Failed to instantiate log capability: {}", e))?;
            cloned_host
                .lock()
                .unwrap()
                .add_native_capability(logging_capability)
                .map_err(|e| anyhow::anyhow!("Failed to add log capability: {}", e))
        })
        .await??;
        Ok(Self {
            shared: SharedPodState {
                client,
                handles: Default::default(),
                store,
                volume_path,
                log_path,
                host,
                port_map,
            },
        })
    }
pub async fn new ( store : Arc < dyn Store + Sync + Send > , config : & kubelet :: config :: Config , kubeconfig : kube :: Config , ) -> anyhow :: Result < Self > { let client = kube :: Client :: new ( kubeconfig ) ; let host = Arc :: new ( Mutex :: new ( WasccHost :: new ( ) ) ) ; let log_path = config . data_dir . join ( LOG_DIR_NAME ) ; let volume_path = config . data_dir . join ( VOLUME_DIR ) ; let port_map = Arc :: new ( TokioMutex :: new ( BTreeMap :: < u16 , PodKey > :: new ( ) ) ) ; tokio :: fs :: create_dir_all ( & log_path ) . await ? ; tokio :: fs :: create_dir_all ( & volume_path ) . await ? ; // wascc has native and portable capabilities. // // Native capabilities are either dynamic libraries (.so, .dylib, .dll) // or statically linked Rust libaries. If the native capabilty is a dynamic // library it must be loaded and configured through [`NativeCapability::from_file`]. // If it is a statically linked libary it can be configured through // [`NativeCapability::from_instance`]. // // Portable capabilities are WASM modules.  Portable capabilities // don't fully work, and won't until the WASI spec has matured. // // Here we are using the native capabilties as statically linked libraries that will // be compiled into the wascc-provider binary. let cloned_host = host . clone ( ) ; tokio :: task :: spawn_blocking ( move | | { info ! ( " " ) ; let http_provider = HttpServerProvider :: new ( ) ; let data = NativeCapability :: from_instance ( http_provider , None ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) ? ; cloned_host . lock ( ) . unwrap ( ) . add_native_capability ( data ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) ? ; info ! ( " " ) ; let logging_provider = LoggingProvider :: new ( ) ; let logging_capability = NativeCapability :: from_instance ( logging_provider , None ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) ? ; cloned_host . lock ( ) . unwrap ( ) . add_native_capability ( logging_capability ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) } ) . await ? ? ; Ok ( Self { shared : SharedPodState { client , handles : Default :: default ( ) , store , volume_path , log_path , host , port_map , } , } ) }
Returns a new wasCC provider configured to use the proper data directory
(including creating it if necessary)
Returns a new wasCC provider configured to use the proper data directory ( including creating it if necessary )
store
Arc<dyn Store + Sync + Send>
config
&kubelet::config::Config
kubeconfig
kube::Config
store
Arc<dyn Store + Sync + Send>
config
&kubelet::config::Config
kubeconfig
kube::Config